def get_table(from_date, to_date, channel_id=-1, server_id=-1): """ 获取在线表数据 """ dis_minute = 5 # 5分钟间隔 from_datetime = datetime.datetime.strptime(str(from_date), '%Y-%m-%d') to_datetime = datetime.datetime.strptime(str(to_date), '%Y-%m-%d') new_log_lst = daily_log_dat.get_new_log_lst(from_datetime.date(), to_datetime.date()) if channel_id >= 0: new_log_lst = daily_log_dat.filter_logs(new_log_lst, function=lambda x: x['platform_id'] == channel_id) if server_id >= 0: new_log_lst = daily_log_dat.filter_logs(new_log_lst, function=lambda x: x['server_id'] == server_id) total_line = int((to_datetime - from_datetime).total_seconds() / (dis_minute * 60)) row_lst = [] for line in xrange(total_line): row = [] get_start_datetime = from_datetime + datetime.timedelta(minutes=dis_minute * line) get_end_datetime = get_start_datetime + datetime.timedelta(minutes=dis_minute) cur_user_num = daily_log_dat.get_set_num_with_key(new_log_lst, 'uid', function=lambda log: get_start_datetime <= log['log_time'] <= get_end_datetime) row.append(get_end_datetime.strftime("%Y-%m-%d %H:%M:%S")) row.append(cur_user_num) row_lst.append(row) return row_lst
def get_table(start_time, end_time, channel_id=-1, server_id=-1): """ start_time 起始时间 end_time 结束时间 """ new_log_lst=[] new_log_lst = daily_log_dat.get_new_log_lst(start_time, end_time) if channel_id >= 0: new_log_lst = daily_log_dat.filter_logs(new_log_lst, function=lambda x: x['platform_id'] == channel_id) if server_id >= 0: new_log_lst = daily_log_dat.filter_logs(new_log_lst, function=lambda x: x['server_id'] == server_id) # 获取登录事件 action_login_lst = daily_log_dat.filter_logs(new_log_lst, action=game_define.EVENT_ACTION_ROLE_LOGIN) # 获取所有设备列表 device_lst = daily_log_dat.get_set_with_key(new_log_lst, 'dev_id') ip_lst = daily_log_dat.get_set_with_key(new_log_lst, 'login_ip') # 获取单设备账号数比率 device_account_result = _get_device_account_result(device_lst, action_login_lst) device_account_num_dict = _get_device_account_num(device_account_result) device_account_rate_dict = _get_device_account_rate(device_account_num_dict) # 获取单IP对应设备数 ip_device_result = _get_ip_device_result(ip_lst, action_login_lst) ip_device_num_dict = _get_ip_device_num(ip_device_result) ip_device_rate_dict = _get_ip_device_rate(ip_device_num_dict) max_row = max(len(device_account_num_dict), len(ip_device_num_dict)) row_lst = [] for x in xrange(1, max_row + 1): row = [] # 单设备对应账号数 row.append(device_account_num_dict.get(x, 0)) # 占比 row.append(device_account_rate_dict.get(x, 0)) # 单ip对应设备数 row.append(ip_device_num_dict.get(x, 0)) # 占比 row.append(ip_device_rate_dict.get(x, 0)) row_lst.append(row) return row_lst
def get_table(from_date, to_date, channel_id=-1, server_id=-1): """ 获取在线表数据 """ dis_minute = 5 # 5分钟间隔 from_datetime = datetime.datetime.strptime(str(from_date), '%Y-%m-%d') to_datetime = datetime.datetime.strptime(str(to_date), '%Y-%m-%d') new_log_lst = daily_log_dat.get_new_log_lst(from_datetime.date(), to_datetime.date()) if channel_id >= 0: new_log_lst = daily_log_dat.filter_logs( new_log_lst, function=lambda x: x['platform_id'] == channel_id) if server_id >= 0: new_log_lst = daily_log_dat.filter_logs( new_log_lst, function=lambda x: x['server_id'] == server_id) total_line = int( (to_datetime - from_datetime).total_seconds() / (dis_minute * 60)) row_lst = [] for line in xrange(total_line): row = [] get_start_datetime = from_datetime + datetime.timedelta( minutes=dis_minute * line) get_end_datetime = get_start_datetime + datetime.timedelta( minutes=dis_minute) cur_user_num = daily_log_dat.get_set_num_with_key( new_log_lst, 'uid', function=lambda log: get_start_datetime <= log[ 'log_time'] <= get_end_datetime) row.append(get_end_datetime.strftime("%Y-%m-%d %H:%M:%S")) row.append(cur_user_num) row_lst.append(row) return row_lst