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(register_star_date, register_end_date, channel_id=-1, server_id=-1): """ 新增K日收益统计 """ now_date = datetime.date.today() total_days = (now_date-register_star_date).days+1 all_login_log_lst = [] global ALL_RECHARGE_LOG_LST ALL_RECHARGE_LOG_LST = [] for i in xrange(total_days): search_date = register_star_date+datetime.timedelta(days=i) date_str = "_"+search_date.strftime('%Y%m%d') # 获得查询日期到今天的所有登陆 和 充值数据 login_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) 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_login_log_lst.extend(login_log_lst) ALL_RECHARGE_LOG_LST.extend(recharge_log_lst) # 计算数据 row_days = (register_end_date - register_star_date).days+1 table_lst = [] for _day in xrange(row_days): global ROW_NEW_USER_UID_LST ROW_NEW_USER_UID_LST = [] row_date = register_star_date + datetime.timedelta(days=_day) # 获取新用户 ROW_NEW_USER_UID_LST = daily_log_dat.get_set_with_key(all_login_log_lst, 'uid', function=lambda log: log['install'] == row_date) # 获取新增设备 new_device_num = daily_log_dat.get_set_num_with_key(all_login_log_lst, 'dev_id', function=lambda log: log['install'] == row_date) # 日期 recharge_date_1 = row_date + datetime.timedelta(days=0) recharge_date_2 = row_date + datetime.timedelta(days=1) recharge_date_3 = row_date + datetime.timedelta(days=2) recharge_date_4 = row_date + datetime.timedelta(days=3) recharge_date_5 = row_date + datetime.timedelta(days=4) recharge_date_6 = row_date + datetime.timedelta(days=5) recharge_date_7 = row_date + datetime.timedelta(days=6) recharge_date_15 = row_date + datetime.timedelta(days=14) recharge_date_30 = row_date + datetime.timedelta(days=29) recharge_date_up = row_date + datetime.timedelta(days=29) # 获取充值总额 row = [] row.append(row_date.strftime('%Y-%m-%d')) row.append(new_device_num) row.append(compute_k_days(recharge_date_1)) # 第1日 row.append(compute_k_days(recharge_date_2)) # 第2日 row.append(compute_k_days(recharge_date_3)) # 第3日 row.append(compute_k_days(recharge_date_4)) # 第4日 row.append(compute_k_days(recharge_date_5)) # 第5日 row.append(compute_k_days(recharge_date_6)) # 第6日 row.append(compute_k_days(recharge_date_7)) # 第7日 row.append(compute_k_days(recharge_date_7, _to_days=recharge_date_15)) # 第7~30日 row.append(compute_k_days(recharge_date_15, _to_days=recharge_date_30)) # 第15~30日 row.append(compute_k_days(recharge_date_up, compute='greater')) # 第30日以后 table_lst.append(row) return table_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(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_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(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
def get_table(register_star_date, register_end_date, channel_id=-1, server_id=-1): """ 新增K日收益统计 """ now_date = datetime.date.today() total_days = (now_date - register_star_date).days + 1 all_login_log_lst = [] global ALL_RECHARGE_LOG_LST ALL_RECHARGE_LOG_LST = [] for i in xrange(total_days): search_date = register_star_date + datetime.timedelta(days=i) date_str = "_" + search_date.strftime('%Y%m%d') # 获得查询日期到今天的所有登陆 和 充值数据 login_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) 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_login_log_lst.extend(login_log_lst) ALL_RECHARGE_LOG_LST.extend(recharge_log_lst) # 计算数据 row_days = (register_end_date - register_star_date).days + 1 table_lst = [] for _day in xrange(row_days): global ROW_NEW_USER_UID_LST ROW_NEW_USER_UID_LST = [] row_date = register_star_date + datetime.timedelta(days=_day) # 获取新用户 ROW_NEW_USER_UID_LST = daily_log_dat.get_set_with_key( all_login_log_lst, 'uid', function=lambda log: log['install'] == row_date) # 获取新增设备 new_device_num = daily_log_dat.get_set_num_with_key( all_login_log_lst, 'dev_id', function=lambda log: log['install'] == row_date) # 日期 recharge_date_1 = row_date + datetime.timedelta(days=0) recharge_date_2 = row_date + datetime.timedelta(days=1) recharge_date_3 = row_date + datetime.timedelta(days=2) recharge_date_4 = row_date + datetime.timedelta(days=3) recharge_date_5 = row_date + datetime.timedelta(days=4) recharge_date_6 = row_date + datetime.timedelta(days=5) recharge_date_7 = row_date + datetime.timedelta(days=6) recharge_date_15 = row_date + datetime.timedelta(days=14) recharge_date_30 = row_date + datetime.timedelta(days=29) recharge_date_up = row_date + datetime.timedelta(days=29) # 获取充值总额 row = [] row.append(row_date.strftime('%Y-%m-%d')) row.append(new_device_num) row.append(compute_k_days(recharge_date_1)) # 第1日 row.append(compute_k_days(recharge_date_2)) # 第2日 row.append(compute_k_days(recharge_date_3)) # 第3日 row.append(compute_k_days(recharge_date_4)) # 第4日 row.append(compute_k_days(recharge_date_5)) # 第5日 row.append(compute_k_days(recharge_date_6)) # 第6日 row.append(compute_k_days(recharge_date_7)) # 第7日 row.append(compute_k_days(recharge_date_7, _to_days=recharge_date_15)) # 第7~30日 row.append(compute_k_days(recharge_date_15, _to_days=recharge_date_30)) # 第15~30日 row.append(compute_k_days(recharge_date_up, compute='greater')) # 第30日以后 table_lst.append(row) return table_lst