def get_table(search_start_date, search_end_date, channel_id=-1, server_id=-1): """ """ start_log_time = datetime.datetime.strptime(game_define.LOCAL_LOG_START_DATE, '%Y-%m-%d').date() # 总天数 table_lst = [] total_days = (search_end_date - search_start_date).days + 1 for i in xrange(total_days): row_lst = [] # 每行的日期 row_date = search_start_date + datetime.timedelta(days=i) # 获取今天全部日志 today_log_lst = mysql_util.get_role_action_lst('EVENT_ACTION_ROLE_LOGIN',start_log_time,row_date, channel_id, server_id,None, None) # 今日游戏玩家列表 today_login_user = daily_log_dat.get_user_uid_lst(today_log_lst) # 获取玩家时间段分布(5分钟) online_user_uid_lst = daily_log_dat.get_online_user_uid_lst(row_date, today_log_lst, 5) # 当前时间段Index now = datetime.datetime.now() minutes = now.hour * 60 + now.minute cur_online_lst_index = minutes / 5 online_time_result = dat_log_util.read_file_with_filename("USER_ONLINE_TIME",row_date,row_date) print online_time_result # 日期 show_date_str= row_date.strftime('%Y-%m-%d') # 今日总登录用户数 today_login_user_num = daily_log_dat.get_set_num_with_key(today_log_lst, 'uid') # 当前实时在线 cur_online_num = len(online_user_uid_lst[cur_online_lst_index]) # 当日峰值在线 today_max_online_num = _max_online_num_today(online_user_uid_lst) # 5分钟以内 online_5 = _get_online_user_num(online_time_result, 0, 5) # 5-10分钟 online_5_10 = _get_online_user_num(online_time_result, 5, 10) # 10-15分钟 online_10_15 = _get_online_user_num(online_time_result, 10, 15) # 15-20分钟 online_15_20 = _get_online_user_num(online_time_result, 15, 20) # 20-25分钟 online_20_25 = _get_online_user_num(online_time_result, 20, 25) # 25-30分钟 online_25_30 = _get_online_user_num(online_time_result, 25, 30) # 30-35分钟 online_30_35 = _get_online_user_num(online_time_result, 30, 35) # 35-40分钟 online_35_40 = _get_online_user_num(online_time_result, 35, 40) # 40-45分钟 online_40_45 = _get_online_user_num(online_time_result, 40, 45) # 45-50分钟 online_45_50 = _get_online_user_num(online_time_result, 45, 50) # 50-55分钟 online_50_55 = _get_online_user_num(online_time_result, 50, 55) # 55-60分钟 online_55_60 = _get_online_user_num(online_time_result, 55, 60) # 60-90分钟 online_60_90 = _get_online_user_num(online_time_result, 60,90) # 90-120分钟 online_90_120 = _get_online_user_num(online_time_result, 90,120) # 120分钟以上 online_120_99999 = _get_online_user_num(online_time_result, 120, 99999) row_lst.append(show_date_str) row_lst.append(today_login_user_num) row_lst.append(cur_online_num) row_lst.append(today_max_online_num) row_lst.append(online_5) row_lst.append(online_5_10) row_lst.append(online_10_15) row_lst.append(online_15_20) row_lst.append(online_20_25) row_lst.append(online_25_30) row_lst.append(online_30_35) row_lst.append(online_35_40) row_lst.append(online_40_45) row_lst.append(online_45_50) row_lst.append(online_50_55) row_lst.append(online_55_60) row_lst.append(online_60_90) row_lst.append(online_90_120) row_lst.append(online_120_99999) table_lst.append(row_lst) return table_lst
def get_table(search_start_date, search_end_date, register_start_date=None, register_end_date=None, channel_id=-1, server_id=-1): """ 获取各等级充值状况表格 """ # 获取搜索区间日志 now_date = datetime.date.today() if search_end_date >= now_date: search_end_date = search_end_date-datetime.timedelta(days=1) total_recharge_log_lst = [] total_days = (search_end_date - search_start_date).days + 1 for i in xrange(total_days): search_date = search_start_date + datetime.timedelta(days=i) date_str = "_" + search_date.strftime('%Y%m%d') recharge_log_lst = mysql_util.get_role_action_lst('EVENT_ACTION_RECHARGE_PLAYER' + str(date_str), search_date, search_date, channel_id, server_id, register_start_date, register_end_date) total_recharge_log_lst.extend(recharge_log_lst) channel_server_str = "" if channel_id >= 0: channel_server_str += "platform_id = " + str(channel_id) + " and " if server_id >= 0: channel_server_str += " server_id = " + str(server_id) + " and " if register_start_date: channel_server_str += " '%s' <= install and " % register_start_date if register_end_date: channel_server_str += " install <= '%s' " % register_end_date # if channel_server_str: # sql = "SELECT * FROM user_detail WHERE %s " % channel_server_str # else: # sql = "SELECT * FROM user_detail" # print sql # result = mysql_util.query(sql) # if channel_server_str: old_log_dict = dat_log_util.read_file_dict_with_filename("USER_DETAIL", search_end_date, server_id, 'tables') if register_start_date and register_end_date: new_log_dict = dict() for uid, detail in old_log_dict.items(): if register_start_date <= detail['install'] <= register_end_date: new_log_dict[uid] = detail else: new_log_dict = old_log_dict user_num_dict = dict() lost_user_num_dict = dict() arrive_user_num = dict() for dat in new_log_dict.values(): cur_lv = dat['level'] user_num_dict[cur_lv] = user_num_dict.get(cur_lv, 0) + 1 if dat['last_play_time'].date() < (search_end_date - datetime.timedelta(days=3)): lost_user_num_dict[cur_lv] = lost_user_num_dict.get(cur_lv, 0) + 1 for _table_lv in xrange(1, 121): arrive_num = sum([user_num_dict.get(lv, 0) for lv in xrange(_table_lv, 121)]) arrive_user_num[_table_lv] = arrive_num # 获取所有等级停留人数 table_row_lst = [] for _table_lv in xrange(1, 121): level_recharge_lst = daily_log_dat.get_recharge_lst_with_user_level(total_recharge_log_lst, _table_lv) recharge_uid_lst = daily_log_dat.get_user_uid_lst(level_recharge_lst) # 停留人数 user_num = user_num_dict.get(_table_lv, 0) # 流失人数 lost_num = lost_user_num_dict.get(_table_lv, 0) # 留存人数 stand_num = user_num - lost_num # 到达等级人数 arrive_num = arrive_user_num[_table_lv] # 充值金额 recharge_money = daily_log_dat.get_recharge_total_money(level_recharge_lst) # 充值次数 recharge_num = len(level_recharge_lst) # 充值人数 recharge_user_num = len(recharge_uid_lst) # 等级付费率 level_pay_rate = _get_level_pay_rate(recharge_user_num, arrive_num) # 等级流失率 流失人数/到达人数 level_lost_rate = _get_level_lost_rate(lost_num, arrive_num) content = [_table_lv, user_num, stand_num, lost_num, arrive_num, recharge_money, recharge_num, recharge_user_num, str(level_pay_rate * 100) + "%", str(level_lost_rate * 100) + "%"] table_row_lst.append(content) return table_row_lst
def get_table(search_start_date, search_end_date, channel_id=-1, server_id=-1): """ """ start_log_time = datetime.datetime.strptime( game_define.LOCAL_LOG_START_DATE, '%Y-%m-%d').date() # 总天数 table_lst = [] total_days = (search_end_date - search_start_date).days + 1 for i in xrange(total_days): row_lst = [] # 每行的日期 row_date = search_start_date + datetime.timedelta(days=i) # 获取今天全部日志 today_log_lst = mysql_util.get_role_action_lst( 'EVENT_ACTION_ROLE_LOGIN', start_log_time, row_date, channel_id, server_id, None, None) # 今日游戏玩家列表 today_login_user = daily_log_dat.get_user_uid_lst(today_log_lst) # 获取玩家时间段分布(5分钟) online_user_uid_lst = daily_log_dat.get_online_user_uid_lst( row_date, today_log_lst, 5) # 当前时间段Index now = datetime.datetime.now() minutes = now.hour * 60 + now.minute cur_online_lst_index = minutes / 5 online_time_result = dat_log_util.read_file_with_filename( "USER_ONLINE_TIME", row_date, row_date) print online_time_result # 日期 show_date_str = row_date.strftime('%Y-%m-%d') # 今日总登录用户数 today_login_user_num = daily_log_dat.get_set_num_with_key( today_log_lst, 'uid') # 当前实时在线 cur_online_num = len(online_user_uid_lst[cur_online_lst_index]) # 当日峰值在线 today_max_online_num = _max_online_num_today(online_user_uid_lst) # 5分钟以内 online_5 = _get_online_user_num(online_time_result, 0, 5) # 5-10分钟 online_5_10 = _get_online_user_num(online_time_result, 5, 10) # 10-15分钟 online_10_15 = _get_online_user_num(online_time_result, 10, 15) # 15-20分钟 online_15_20 = _get_online_user_num(online_time_result, 15, 20) # 20-25分钟 online_20_25 = _get_online_user_num(online_time_result, 20, 25) # 25-30分钟 online_25_30 = _get_online_user_num(online_time_result, 25, 30) # 30-35分钟 online_30_35 = _get_online_user_num(online_time_result, 30, 35) # 35-40分钟 online_35_40 = _get_online_user_num(online_time_result, 35, 40) # 40-45分钟 online_40_45 = _get_online_user_num(online_time_result, 40, 45) # 45-50分钟 online_45_50 = _get_online_user_num(online_time_result, 45, 50) # 50-55分钟 online_50_55 = _get_online_user_num(online_time_result, 50, 55) # 55-60分钟 online_55_60 = _get_online_user_num(online_time_result, 55, 60) # 60-90分钟 online_60_90 = _get_online_user_num(online_time_result, 60, 90) # 90-120分钟 online_90_120 = _get_online_user_num(online_time_result, 90, 120) # 120分钟以上 online_120_99999 = _get_online_user_num(online_time_result, 120, 99999) row_lst.append(show_date_str) row_lst.append(today_login_user_num) row_lst.append(cur_online_num) row_lst.append(today_max_online_num) row_lst.append(online_5) row_lst.append(online_5_10) row_lst.append(online_10_15) row_lst.append(online_15_20) row_lst.append(online_20_25) row_lst.append(online_25_30) row_lst.append(online_30_35) row_lst.append(online_35_40) row_lst.append(online_40_45) row_lst.append(online_45_50) row_lst.append(online_50_55) row_lst.append(online_55_60) row_lst.append(online_60_90) row_lst.append(online_90_120) row_lst.append(online_120_99999) table_lst.append(row_lst) return table_lst