def get_table(search_date, channel_id=-1, cur_server=-1): # new_log_lst = daily_log_dat.get_new_log_lst(search_date, search_date) #获取全部新手引导日志 all_newbie_log_lst = dat_log_util.read_file(game_define.EVENT_ACTION_FINISH_NEWBIE, search_date, search_date, cur_server) # print all_newbie_log_lst if channel_id >= 0: all_newbie_log_lst = daily_log_dat.filter_logs(all_newbie_log_lst, function=lambda x: x['platform_id'] == channel_id) if cur_server >= 0: all_newbie_log_lst = daily_log_dat.filter_logs(all_newbie_log_lst, function=lambda x: x['server_id'] == cur_server) # 总共5个引导步骤 (1-6) total_user = daily_log_dat.get_set_num_with_key(all_newbie_log_lst, 'uid') complete_user_dict = dict() newbie_name = [u'第一场战斗', u'抽取宝贝球', u'加入队伍', u'自动战斗', u'每日任务'] for i in xrange(1, 6): # 当前引导的所有日志 guide_index_log_lst = daily_log_dat.filter_logs(all_newbie_log_lst, function=lambda x: x['newbie_id'] == i) complete_user_num = daily_log_dat.get_set_num_with_key(guide_index_log_lst, 'uid') complete_user_dict[i] = complete_user_num table_result = [] for i in xrange(1, 6): next_num = complete_user_dict.get(i+1,0) row = [ i, newbie_name[i-1], complete_user_dict[i], # 完成人数 ] table_result.append(row) return table_result
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(search_date, channel_id=-1, server_id=-1): """ 角色首次充值等级 """ # start_log_time = datetime.datetime.strptime(game_define.LOCAL_LOG_START_DATE, '%Y-%m-%d').date() # 全部日志 # all_log_lst = daily_log_dat.get_new_log_lst(start_log_time, search_date) # # if channel_id >= 0: # all_log_lst = daily_log_dat.filter_logs(all_log_lst, function=lambda x: x['platform_id'] == channel_id) # if server_id >= 0: # all_log_lst = daily_log_dat.filter_logs(all_log_lst, function=lambda x: x['server_id'] == server_id) # # # 全部充值日志 # all_recharge_log_lst = daily_log_dat.filter_logs(all_log_lst, action=game_define.EVENT_ACTION_RECHARGE_PLAYER) date_str = "_"+search_date.strftime('%Y%m%d') all_recharge_log_lst = mysql_util.get_role_action_lst('EVENT_ACTION_RECHARGE_PLAYER'+str(date_str),search_date,search_date, channel_id, server_id,None, None) all_first_recharge_log_lst = daily_log_dat.filter_logs(all_recharge_log_lst, function=lambda log:log['old_rmb'] == 0) table_lst = [] for _table_lv in xrange(1, 121): # 全部当前等级充值日志 recharge_lv_log_lst = daily_log_dat.filter_logs(all_recharge_log_lst, function=lambda log: log['level'] == _table_lv) # 全部当前等级充值 用户ID列表 recharge_lv_user_lst = daily_log_dat.get_set_with_key(recharge_lv_log_lst, 'uid') # 全部当前等级首次充值日志 first_recharge_lv_log_lst = daily_log_dat.filter_logs(all_first_recharge_log_lst, function=lambda log: log['level'] == _table_lv) # 全部当前等级首次充值 用户ID列表 first_recharge_lv_user_lst = daily_log_dat.get_set_with_key(first_recharge_lv_log_lst, 'uid') # 首次充值人数 first_recharge_user_num = len(first_recharge_lv_user_lst) if first_recharge_user_num == 0: continue # 首次充值总金额 first_recharge_total_money = daily_log_dat.get_sum_int_with_key(first_recharge_lv_log_lst, "add_rmb") # 总体充值人数 recharge_user_num = len(recharge_lv_user_lst) # 总体充值金额 recharge_total_money = daily_log_dat.get_sum_int_with_key(recharge_lv_log_lst, "add_rmb") # 首次金额占比 first_recharge_money_rate = get_first_recharge_money_rate(first_recharge_total_money,recharge_total_money) # 首次人数占比 first_recharge_user_rate = get_first_recharge_user_rate(first_recharge_user_num,recharge_user_num) row = [_table_lv, first_recharge_user_num, first_recharge_total_money, recharge_user_num, recharge_total_money, str(first_recharge_money_rate * 100)+"%", str(first_recharge_user_rate * 100)+"%"] table_lst.append(row) return table_lst
def get_table(search_date, channel_id=-1, cur_server=-1): # new_log_lst = daily_log_dat.get_new_log_lst(search_date, search_date) # #获取全部新手引导日志 # all_guide_log_lst = daily_log_dat.filter_logs(new_log_lst, action=game_define.EVENT_ACTION_FINISH_GUIDE) all_guide_log_lst = dat_log_util.read_file( game_define.EVENT_ACTION_FINISH_GUIDE, search_date, search_date, cur_server) # print all_guide_log_lst if channel_id >= 0: all_guide_log_lst = daily_log_dat.filter_logs( all_guide_log_lst, function=lambda x: x['platform_id'] == channel_id) if cur_server >= 0: all_guide_log_lst = daily_log_dat.filter_logs( all_guide_log_lst, function=lambda x: x['server_id'] == cur_server) # 总共5个引导步骤 (1-6) total_user = daily_log_dat.get_set_num_with_key(all_guide_log_lst, 'uid') complete_user_dict = dict() guide_name = [ u'宠物升级突破_4级开启', u'宠物升星_17级开启', u'宠物进化_10级开启', u'宠物技能升级_13级开启', u'宠物洗练_30级开启', u'宠物装备强化_23级开启', u'新队伍位置_6级开启' ] # 引导步骤按解锁等级排序 unlock_order = [1, 7, 6, 3, 4, 2, 5] for i in xrange(1, 8): # 当前引导的所有日志 guide_index_log_lst = daily_log_dat.filter_logs( all_guide_log_lst, function=lambda x: x['guide_id'] == i) complete_user_num = daily_log_dat.get_set_num_with_key( guide_index_log_lst, 'uid') complete_user_dict[i] = complete_user_num table_result = [] for i in unlock_order: next_num = complete_user_dict.get(i + 1, 0) row = [ search_date.strftime('%Y-%m-%d'), i, guide_name[i - 1], complete_user_dict[i], # 完成人数 ] table_result.append(row) return table_result
def mysql_filter(mysql_dist): global CUR_SERVER_ID, CUR_UID_ID temp_lst = [] # if CUR_CHANNEL_ID >= 0: # log_dist = daily_log_dat.filter_logs(log_dist, function=lambda x: x['platform_id'] == CUR_CHANNEL_ID) if CUR_SERVER_ID >= 0: mysql_dist = daily_log_dat.filter_logs( mysql_dist, function=lambda x: x['server_id'] == CUR_SERVER_ID) if -1 == CUR_SERVER_ID: mysql_dist = mysql_dist ser_lst, platform_lst = daily_log._get_server_list(None, None) for each_item in mysql_dist: user_log_time = each_item['log_time'].strftime("%Y-%m-%d %H:%M:%S") user_uid = int(each_item['uid']) user_add_rmb = each_item['add_rmb'] user_order_id = each_item['order_id'] user_old_rmb = int(each_item['old_rmb']) user_server_id = int(each_item['server_id']) user_platform_id = int(each_item['platform_id']) if user_old_rmb == 0: user_first_cost = "是" else: user_first_cost = "否" # 取服务器 平台名字 user_ser_str, user_platform_str = "", "" for each_ser_dict, each_plat_dict in zip(ser_lst, platform_lst): if user_platform_id == int(each_plat_dict['id']): user_platform_str = each_plat_dict['name'] if user_server_id == int(each_ser_dict['id']): user_ser_str = each_ser_dict['name'] if CUR_UID_ID: if user_uid == CUR_UID_ID: row_lst = [ user_log_time, user_uid, user_add_rmb, user_order_id, user_first_cost, user_ser_str, user_platform_str, ] temp_lst.append(row_lst) else: row_lst = [ user_log_time, user_uid, user_add_rmb, user_order_id, user_first_cost, user_ser_str, user_platform_str, ] temp_lst.append(row_lst) return temp_lst
def mysql_filter(mysql_dist): global CUR_SERVER_ID, CUR_UID_ID temp_lst = [] # if CUR_CHANNEL_ID >= 0: # log_dist = daily_log_dat.filter_logs(log_dist, function=lambda x: x['platform_id'] == CUR_CHANNEL_ID) if CUR_SERVER_ID >= 0: mysql_dist = daily_log_dat.filter_logs(mysql_dist, function=lambda x: x['server_id'] == CUR_SERVER_ID) if -1 == CUR_SERVER_ID: mysql_dist = mysql_dist ser_lst, platform_lst = daily_log._get_server_list(None, None) for each_item in mysql_dist: user_log_time = each_item['log_time'].strftime("%Y-%m-%d %H:%M:%S") user_uid = int(each_item['uid']) user_add_rmb = each_item['add_rmb'] user_order_id = each_item['order_id'] user_old_rmb = int(each_item['old_rmb']) user_server_id = int(each_item['server_id']) user_platform_id = int(each_item['platform_id']) if user_old_rmb == 0: user_first_cost = "是" else: user_first_cost = "否" # 取服务器 平台名字 user_ser_str, user_platform_str = "", "" for each_ser_dict, each_plat_dict in zip(ser_lst, platform_lst): if user_platform_id == int(each_plat_dict['id']): user_platform_str = each_plat_dict['name'] if user_server_id == int(each_ser_dict['id']): user_ser_str = each_ser_dict['name'] if CUR_UID_ID: if user_uid == CUR_UID_ID: row_lst = [ user_log_time, user_uid, user_add_rmb, user_order_id, user_first_cost, user_ser_str, user_platform_str, ] temp_lst.append(row_lst) else: row_lst = [ user_log_time, user_uid, user_add_rmb, user_order_id, user_first_cost, user_ser_str, user_platform_str, ] temp_lst.append(row_lst) return temp_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_day_distance_result(desc, recharge_log, first_recharge_log, from_day, to_day=99999): """ 获取行数据 """ #获取 第N天就充值的玩家UID列表 days_recharge_log_lst = daily_log_dat.filter_logs(recharge_log, function=lambda log: from_day <= (log['log_time'].date() - log['install']).days < to_day) days_first_recharge_log_lst = daily_log_dat.filter_logs(first_recharge_log, function=lambda log: from_day <= (log['log_time'].date() - log['install']).days < to_day) # 获取人数 total_user_num = daily_log_dat.get_set_num_with_key(days_recharge_log_lst, 'uid') first_total_user_num = daily_log_dat.get_set_num_with_key(days_first_recharge_log_lst, 'uid') # 获取充值总金额 total_money = daily_log_dat.get_sum_int_with_key(days_recharge_log_lst, 'add_rmb') first_total_money = daily_log_dat.get_sum_int_with_key(days_first_recharge_log_lst, 'add_rmb') # 获取比率 money_rate = _get_money_rate(first_total_money, total_money) user_rate = _get_user_rate(first_total_user_num, total_user_num) return [desc, first_total_user_num, first_total_money, total_user_num, total_money, str((money_rate * 100))+"%", str((user_rate * 100))+"%"]
def get_table(search_from_date, search_to_date, channel_id=-1, server_id=-1): """ 充值周期 """ # 获取指定日期 所有日志 # all_log_lst = daily_log_dat.get_new_log_lst(search_from_date, search_to_date) # # if channel_id >= 0: # all_log_lst = daily_log_dat.filter_logs(all_log_lst, function=lambda x: x['platform_id'] == channel_id) # if server_id >= 0: # all_log_lst = daily_log_dat.filter_logs(all_log_lst, function=lambda x: x['server_id'] == server_id) # 获取到今天为止的日志 now_date = datetime.date.today() total_days = (now_date - search_from_date).days+1 all_log_lst = [] for i in xrange(total_days): search_date = search_from_date + datetime.timedelta(days=i) date_str = "_"+search_date.strftime('%Y%m%d') log_lst = mysql_util.get_role_action_lst('EVENT_ACTION_RECHARGE_PLAYER'+str(date_str), search_date, search_date, channel_id, server_id, None, None) all_log_lst.extend(log_lst) # 获取区间内所有新安装用户 new_install_uid_lst = daily_log_dat.get_set_with_key(all_log_lst, 'uid', function=lambda log: search_from_date <= log['install'] <= search_to_date) # 用指定日期新用户 获取所有充值日志 all_recharge_log = daily_log_dat.filter_logs(all_log_lst, function=lambda log: log['uid'] in new_install_uid_lst) # 获取全部首冲日志 all_first_recharge_log = daily_log_dat.filter_logs(all_recharge_log, function=lambda log: log['old_rmb'] == 0) table_result = [] table_result.append(_get_day_distance_result('1日', all_recharge_log, all_first_recharge_log, 0, 1)) table_result.append(_get_day_distance_result('2日', all_recharge_log, all_first_recharge_log, 1, 2)) table_result.append(_get_day_distance_result('3日', all_recharge_log, all_first_recharge_log, 2, 3)) table_result.append(_get_day_distance_result('4日', all_recharge_log, all_first_recharge_log, 3, 4)) table_result.append(_get_day_distance_result('5日', all_recharge_log, all_first_recharge_log, 4, 5)) table_result.append(_get_day_distance_result('6日', all_recharge_log, all_first_recharge_log, 5, 6)) table_result.append(_get_day_distance_result('7日', all_recharge_log, all_first_recharge_log, 6, 7)) table_result.append(_get_day_distance_result('7-15日', all_recharge_log, all_first_recharge_log, 7, 15)) table_result.append(_get_day_distance_result('15-30日', all_recharge_log, all_first_recharge_log, 15, 30)) table_result.append(_get_day_distance_result('30日以上', all_recharge_log, all_first_recharge_log, 30)) return table_result
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(search_date, channel_id=-1, cur_server=-1): # new_log_lst = daily_log_dat.get_new_log_lst(search_date, search_date) # #获取全部新手引导日志 # all_guide_log_lst = daily_log_dat.filter_logs(new_log_lst, action=game_define.EVENT_ACTION_FINISH_GUIDE) all_guide_log_lst = dat_log_util.read_file(game_define.EVENT_ACTION_FINISH_GUIDE, search_date, search_date, cur_server) # print all_guide_log_lst if channel_id >= 0: all_guide_log_lst = daily_log_dat.filter_logs(all_guide_log_lst, function=lambda x: x['platform_id'] == channel_id) if cur_server >= 0: all_guide_log_lst = daily_log_dat.filter_logs(all_guide_log_lst, function=lambda x: x['server_id'] == cur_server) # 总共5个引导步骤 (1-6) total_user = daily_log_dat.get_set_num_with_key(all_guide_log_lst, 'uid') complete_user_dict = dict() guide_name = [u'宠物升级突破_4级开启', u'宠物升星_17级开启', u'宠物进化_10级开启', u'宠物技能升级_13级开启', u'宠物洗练_30级开启', u'宠物装备强化_23级开启', u'新队伍位置_6级开启'] # 引导步骤按解锁等级排序 unlock_order = [1, 7, 6, 3, 4, 2, 5] for i in xrange(1, 8): # 当前引导的所有日志 guide_index_log_lst = daily_log_dat.filter_logs(all_guide_log_lst, function=lambda x: x['guide_id'] == i) complete_user_num = daily_log_dat.get_set_num_with_key(guide_index_log_lst, 'uid') complete_user_dict[i] = complete_user_num table_result = [] for i in unlock_order: next_num = complete_user_dict.get(i+1,0) row = [ search_date.strftime('%Y-%m-%d'), i, guide_name[i-1], complete_user_dict[i], # 完成人数 ] table_result.append(row) return table_result
def get_table(search_date, channel_id=-1, server_id=-1): """ 获取首次游戏时间长度 """ # new_log_lst = dat_log_util.read_file(search_date,search_date) # print new_log_lst # new_log_lst = daily_log_dat.get_new_log_lst(search_date, search_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) date_str = "_" + search_date.strftime('%Y%m%d') new_log_lst = mysql_util.get_role_action_lst( 'EVENT_ACTION_ROLE_LOGIN' + str(date_str), search_date, search_date, channel_id, server_id, None, None) # print("new_log_lst: "+str(new_log_lst)) # 获取指定日期新用户 new_use_uid_lst = daily_log_dat.get_set_with_key( new_log_lst, 'uid', function=lambda log: log['install'] == search_date) # 获取新玩家的所有日志 new_user_log_lst = daily_log_dat.filter_logs( new_log_lst, function=lambda log: log['uid'] in new_use_uid_lst) user_online_time_dict = _get_online_time_dict(new_user_log_lst, new_use_uid_lst) # print("user_online_time_dict: "+str(user_online_time_dict)) table_dat = [] table_dat.append(_get_row_dat("0-15s", user_online_time_dict, 0, 15)) table_dat.append(_get_row_dat("15-30s", user_online_time_dict, 15, 30)) table_dat.append(_get_row_dat("30s-1m", user_online_time_dict, 30, 60)) table_dat.append(_get_row_dat("1m-2m", user_online_time_dict, 60, 120)) table_dat.append(_get_row_dat("2m-3m", user_online_time_dict, 120, 180)) table_dat.append(_get_row_dat("3m-5m", user_online_time_dict, 180, 300)) table_dat.append(_get_row_dat("5m-10m", user_online_time_dict, 300, 600)) table_dat.append(_get_row_dat("10m-15m", user_online_time_dict, 600, 900)) table_dat.append(_get_row_dat("15m-30m", user_online_time_dict, 900, 1800)) table_dat.append(_get_row_dat("30m-60m", user_online_time_dict, 1800, 3600)) table_dat.append( _get_row_dat("60m-120m", user_online_time_dict, 3600, 7200)) table_dat.append(_get_row_dat("大于120m", user_online_time_dict, 7200)) # print("table_dat: "+str(table_dat)) return table_dat
def get_table(search_date, channel_id=-1, server_id=-1): """ 获取首次游戏时间长度 """ # new_log_lst = dat_log_util.read_file(search_date,search_date) # print new_log_lst # new_log_lst = daily_log_dat.get_new_log_lst(search_date, search_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) date_str = "_" + search_date.strftime('%Y%m%d') new_log_lst = mysql_util.get_role_action_lst('EVENT_ACTION_ROLE_LOGIN' + str(date_str), search_date, search_date, channel_id, server_id, None, None) # print("new_log_lst: "+str(new_log_lst)) # 获取指定日期新用户 new_use_uid_lst = daily_log_dat.get_set_with_key(new_log_lst, 'uid', function=lambda log: log['install'] == search_date) # 获取新玩家的所有日志 new_user_log_lst = daily_log_dat.filter_logs(new_log_lst, function=lambda log: log['uid'] in new_use_uid_lst) user_online_time_dict = _get_online_time_dict(new_user_log_lst, new_use_uid_lst) # print("user_online_time_dict: "+str(user_online_time_dict)) table_dat = [] table_dat.append(_get_row_dat("0-15s", user_online_time_dict, 0, 15)) table_dat.append(_get_row_dat("15-30s", user_online_time_dict, 15, 30)) table_dat.append(_get_row_dat("30s-1m", user_online_time_dict, 30, 60)) table_dat.append(_get_row_dat("1m-2m", user_online_time_dict, 60, 120)) table_dat.append(_get_row_dat("2m-3m", user_online_time_dict, 120, 180)) table_dat.append(_get_row_dat("3m-5m", user_online_time_dict, 180, 300)) table_dat.append(_get_row_dat("5m-10m", user_online_time_dict, 300, 600)) table_dat.append(_get_row_dat("10m-15m", user_online_time_dict, 600, 900)) table_dat.append(_get_row_dat("15m-30m", user_online_time_dict, 900, 1800)) table_dat.append(_get_row_dat("30m-60m", user_online_time_dict, 1800, 3600)) table_dat.append(_get_row_dat("60m-120m", user_online_time_dict, 3600, 7200)) table_dat.append(_get_row_dat("大于120m", user_online_time_dict, 7200)) # print("table_dat: "+str(table_dat)) return table_dat
def get_table(search_start_date, search_end_date, register_start_date=None, register_end_date=None, server_id=-1): """ 获取展示表格 register_start_date 注册开始时间 register_end_date 注册结束时间 search_start_date 查询开始时间 search_end_date 查询结束时间 """ all_stone_shop_log_lst = dat_log_util.read_file( game_define.EVENT_ACTION_STONE_SHOP_BUY, search_start_date, search_end_date, server_id) # if channel_id >= 0: # all_stone_shop_log_lst = daily_log_dat.filter_logs(all_stone_shop_log_lst, function=lambda x: x['platform_id'] == channel_id) # if server_id >= 0: # all_stone_shop_log_lst = daily_log_dat.filter_logs(all_stone_shop_log_lst, function=lambda x: x['server_id'] == server_id) #获取符合条件的日志 if register_start_date and register_end_date: all_stone_shop_log_lst = daily_log_dat.filter_logs( all_stone_shop_log_lst, function=lambda log: register_start_date <= log[ 'install'] <= register_end_date) # print all_stone_shop_log_lst # 全部钻石商城物品购买日志 # print("all_stone_shop_log_lst: "+str(all_stone_shop_log_lst)) # 获取所有钻石商城物品玩家设备 # device_lst = daily_log_dat.get_set_with_key(all_stone_shop_log_lst, 'dev_id') # 获取所有钻石商城物品购买日志玩家UID all_uid_lst = daily_log_dat.get_set_with_key(all_stone_shop_log_lst, 'uid') # 消耗钻石总数 total_cost_stone = daily_log_dat.get_sum_int_with_key( all_stone_shop_log_lst, 'cost_stone') # 根据ID拆分日志 item_logs_dict = dict() for _log in all_stone_shop_log_lst: _item_info = _log['add_item_list'] _item_tid = _item_info[0] if _item_tid in item_logs_dict: item_logs_dict[_item_tid].append(_log) else: lst = [_log] item_logs_dict[_item_tid] = lst table_lst = [] for _item_tid, _log in item_logs_dict.items(): user_num = daily_log_dat.get_set_num_with_key(_log, 'uid') # 购买物品 item_config = game_config.get_item_config(int(_item_tid)) event_log_act = item_config['name'] # 钻石数 cost_stone = daily_log_dat.get_sum_int_with_key(_log, 'cost_stone') # 次数 cost_num = len(_log) # 参与率 take_part_rate = _get_rate(user_num, len(all_uid_lst)) # 钻石比率 first_cost_stone_rate = _get_rate(cost_stone, total_cost_stone) # 人数比率 # cur_user_num_rate = _get_rate(user_num, len(all_uid_lst)) row = [ event_log_act, cost_stone, user_num, cost_num, str(take_part_rate * 100) + "%", str(first_cost_stone_rate * 100) + "%" ] table_lst.append(row) return table_lst