Exemplo n.º 1
0
    def days_response(self, n):
        response_data = []

        time_fmt = '\'%Y-%m-%d %H:%M\''
        group_con = "strftime({0}, created_time)".format(time_fmt)
        what_con = ','.join(["{0} as date",
                             "count({0}) as count"]).format(group_con)
        n_days_ago = datetime.datetime.now() - datetime.timedelta(days=int(n))
        having_con = "{0} > {1}".format(group_con,
                                        n_days_ago.strftime(time_fmt))

        select_command = [
            'select {0} from upgradeclient'.format(what_con),
            'group by {0}'.format(group_con), 'having {0}'.format(having_con)
        ]

        select_results = db.select(' '.join(select_command))
        if select_results is None:
            return self.json_response([])
        for ins in select_results:
            response_data.append(
                [self.make_time('%Y-%m-%d %H:%M', ins[0]), ins[-1]])
        response_data.sort(key=lambda s: s[0])

        return response_data
Exemplo n.º 2
0
    def GET(self):
        response_data = []

        date_fmt = '\'%Y-%m-%d\''
        what_con = "dao_name, file_type, count(dao_name||file_type) as count"
        group_con = "strftime({0}, created_time)".format(date_fmt)
        today = (datetime.datetime.now() - datetime.timedelta(days=1))
        having_con = "dao_name!='' and file_type!=''"
        # 查询数据库中所有记录
        # having_con = "{0} = {1} and dao_name!='' and file_type!=''".format(group_con, today.strftime(date_fmt))
        select_command = [
            'select {0} from upgradeclient'.format(what_con),
            'group by dao_name||file_type', 'having {0}'.format(having_con)
        ]
        select_results = db.select(' '.join(select_command))
        if select_results is None:
            return self.json_response([])
        response_dict = {}
        for ins in select_results:
            key = '_'.join(ins[:-1])
            response_dict.update({key: ins[-1]})
        sum_value = float(sum(response_dict.values()))
        for k in response_dict:
            percent = round(100 * response_dict[k] / sum_value, 2)
            response_data.append([k, percent])

        return self.json_response(response_data)
Exemplo n.º 3
0
    def GET(self):
        response_data = []

        date_fmt = '\'%Y-%m-%d\''
        what_con = "log_class, count(log_class) as count"
        group_con = "strftime({0}, created_time)".format(date_fmt)
        today = (datetime.datetime.now() - datetime.timedelta(days=1))
        # 查询数据库中所有记录
        # having_con = "{0} = {1}".format(group_con, today.strftime(date_fmt))
        select_command = [
            'select {0} from upgradeclient'.format(what_con),
            'group by log_class',
            # 'having {0}'.format(having_con)
        ]
        select_results = db.select(' '.join(select_command))
        if select_results is None:
            return self.json_response([])
        response_dict = {}
        for ins in select_results:
            response_dict.update([ins])
        sum_value = float(sum(response_dict.values()))
        for k in response_dict:
            percent = round(100 * response_dict[k] / sum_value, 2)
            response_data.append([k, percent])

        return self.json_response(response_data)
Exemplo n.º 4
0
    def GET(self):
        response_data = {'total': 0, 'rows': []}
        response_keys = [
            'id',
            'log_level',
            'log_name',
            'log_class',
            'dao_name',
            'file_type',
            'file_name',
            'file_url',
            'last_author',
            'last_date',
            'last_revision',
            'last_action',
            'log_message',
            'created_time',
        ]

        input_storage = web.input()
        limit_page = getattr(input_storage, 'page', 1)
        limit_rows = getattr(input_storage, 'rows', 20)
        log_level = getattr(input_storage, 'log_level', None)
        log_class = getattr(input_storage, 'log_class', None)
        dao_name = getattr(input_storage, 'dao_name', None)
        file_type = getattr(input_storage, 'file_type', None)
        log_message = getattr(input_storage, 'log_message', None)

        where_con = "log_name!='' and dao_name!=''"
        if log_level is not None:
            where_con += " and log_level='{0}' ".format(log_level)
        if log_class is not None:
            where_con += " and log_class='{0}'".format(log_class)
        if dao_name is not None:
            where_con += " and dao_name='{0}' ".format(dao_name)
        if file_type is not None:
            where_con += " and file_type='{0}' ".format(file_type)
        if log_message is not None:
            where_con += " and log_message like '%{0}%' ".format(log_message)

        select_command = [
            'select * from upgradeclient', 'where {0}'.format(where_con),
            'order by created_time desc'
        ]
        select_results = db.select(' '.join(select_command))
        if select_results is None:
            return self.json_response([])

        sta_num = (int(limit_page) - 1) * int(limit_rows)
        end_num = int(limit_page) * int(limit_rows)
        for ins in select_results:
            response_data['total'] += 1
            if sta_num <= response_data['total'] < end_num:
                response_data['rows'].append(dict(zip(response_keys, ins)))

        response_data['rows'].sort(key=lambda s: s['created_time'],
                                   reverse=True)

        return self.json_response(response_data)
Exemplo n.º 5
0
    def get_data(self, name):
        res_data = []

        today = datetime.datetime.now().strftime('%Y-%m-%d')
        fmtdata = (name, today)
        select_command = [
            'select *',
            'from upgradeclient',
            'where log_level=\'error\' and  dao_name=\'{0}\' and strftime(\'%Y-%m-%d\', created_time)=\'{1}\''.format(
                *fmtdata
            )
        ]
        select_results = db.select(' '.join(select_command))
        if select_results is None:
            return res_data
        for ins in select_results:
            res_data.append(ins)

        return res_data
Exemplo n.º 6
0
    def GET(self):
        response_data = []

        loglevels = ['info', 'warning', 'error']
        input_storage = web.input(log_limit=20, log_level='info')
        log_limit = input_storage.log_limit
        log_level = loglevels[loglevels.index(input_storage.log_level):]

        kwargs = zip([
            'log_level',
        ] * len(log_level), log_level)

        select_where_condition = ' '.join(
            Helper.combin_sql_conditions('or', kwargs))

        select_command = [
            'select * from upgradeclient',
            'where {0}'.format(select_where_condition),
            'order by created_time desc', 'limit {0}'.format(log_limit)
        ]

        select_results = db.select(' '.join(select_command))
        if select_results is None:
            return self.json_response([])
        for ins in select_results:
            created_date, created_time = ins[-1].split()
            response_data.append({
                'id': ins[0],
                'log_level': ins[1],
                'log_message': ins[12],
                'created_date': created_date.strip(),
                'created_time': created_time.strip()
            })
        response_data.sort(key=lambda s: '{0} {1}'.format(
            s['created_date'], s['created_time']),
                           reverse=True)

        return self.json_response(response_data)