def get_table(search_start_date, search_end_date, channel_id=-1, server_id=-1):

    # 搜索日期到今天的所有日志
    retained_day = search_start_date - datetime.timedelta(days=3)
    all_log_lst = daily_log_dat.get_new_log_lst(retained_day, search_end_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_login_log_lst = daily_log_dat.filter_logs(
        all_log_lst, action=game_define.EVENT_ACTION_ROLE_LOGIN)
    # 获取玩家游戏天数字典
    user_play_day_dict = daily_log_dat.split_log_users_play_days(
        all_login_log_lst)
    # 展示日期数
    show_days = (search_end_date - search_start_date).days

    table_result = []
    for i in xrange(show_days + 1):
        row_date = search_start_date + datetime.timedelta(days=i)
        # 获取所有流失用户
        lost_user_lst = daily_log_dat.get_lost_user_set(
            all_login_log_lst, row_date)

        row = _get_row(row_date, user_play_day_dict, lost_user_lst)
        table_result.append(row)
    return table_result
def get_table(search_start_date, search_end_date, channel_id=-1, server_id=-1):

    # 搜索日期到今天的所有日志
    retained_day = search_start_date - datetime.timedelta(days=3)
    all_log_lst = daily_log_dat.get_new_log_lst(retained_day, search_end_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_login_log_lst = daily_log_dat.filter_logs(all_log_lst, action=game_define.EVENT_ACTION_ROLE_LOGIN)
    # 获取玩家游戏天数字典
    user_play_day_dict = daily_log_dat.split_log_users_play_days(all_login_log_lst)
    # 展示日期数
    show_days = (search_end_date - search_start_date).days

    table_result = []
    for i in xrange(show_days + 1):
        row_date = search_start_date + datetime.timedelta(days=i)
        # 获取所有流失用户
        lost_user_lst = daily_log_dat.get_lost_user_set(all_login_log_lst, row_date)

        row = _get_row(row_date, user_play_day_dict, lost_user_lst)
        table_result.append(row)
    return table_result
Beispiel #3
0
def get_table(search_start_date, search_end_date, channel_id=-1, server_id=-1):

    # 搜索日期到今天的所有日志
    retained_day = search_start_date - datetime.timedelta(days=4)
    all_log_lst = daily_log_dat.get_new_log_lst(retained_day, search_end_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_login_lst = daily_log_dat.filter_logs(
        all_log_lst, action=game_define.EVENT_ACTION_ROLE_LOGIN)
    # 获取日期数
    search_days = (search_end_date - search_start_date).days

    table_result = []
    for i in xrange(search_days + 1):
        cur_date = search_start_date + datetime.timedelta(days=i)
        # 今日全部日志
        today_login_lst = daily_log_dat.get_new_log_lst_with_log(
            all_login_lst, cur_date, cur_date)
        # 获取登录日志列表
        today_login_uid_lst = daily_log_dat.get_set_with_key(
            today_login_lst, 'uid')

        today_new_user_login_lst = daily_log_dat.filter_logs(
            today_login_lst, function=lambda log: log['install'] == cur_date)
        today_new_user_uid_num = daily_log_dat.get_set_num_with_key(
            today_new_user_login_lst, 'uid')
        # 登录用户数
        today_login_uid_num = len(today_login_uid_lst)
        # 活跃用户数
        today_active_uid_num = today_new_user_uid_num

        # 流失用户(3天内没登录)
        today_lost_uid_num = len(
            daily_log_dat.get_lost_user_set(all_login_lst, cur_date))
        # 回流用户(3天内没登录 但今天登录)
        login_back_num = len(
            daily_log_dat.get_lost_back_user_set(all_login_lst, cur_date))

        row = [
            cur_date.strftime("%m/%d/%Y"), today_login_uid_num,
            today_active_uid_num, today_lost_uid_num, login_back_num
        ]
        table_result.append(row)

    return table_result
def get_table(search_start_date, search_end_date, channel_id=-1, server_id=-1):

    # 搜索日期到今天的所有日志
    retained_day = search_start_date - datetime.timedelta(days=4)
    all_log_lst = daily_log_dat.get_new_log_lst(retained_day, search_end_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_login_lst = daily_log_dat.filter_logs(all_log_lst, action=game_define.EVENT_ACTION_ROLE_LOGIN)
    # 获取日期数
    search_days = (search_end_date - search_start_date).days

    table_result = []
    for i in xrange(search_days + 1):
        cur_date = search_start_date + datetime.timedelta(days=i)
        # 今日全部日志
        today_login_lst = daily_log_dat.get_new_log_lst_with_log(all_login_lst, cur_date, cur_date)
        # 获取登录日志列表
        today_login_uid_lst = daily_log_dat.get_set_with_key(today_login_lst, "uid")

        today_new_user_login_lst = daily_log_dat.filter_logs(
            today_login_lst, function=lambda log: log["install"] == cur_date
        )
        today_new_user_uid_num = daily_log_dat.get_set_num_with_key(today_new_user_login_lst, "uid")
        # 登录用户数
        today_login_uid_num = len(today_login_uid_lst)
        # 活跃用户数
        today_active_uid_num = today_new_user_uid_num

        # 流失用户(3天内没登录)
        today_lost_uid_num = len(daily_log_dat.get_lost_user_set(all_login_lst, cur_date))
        # 回流用户(3天内没登录 但今天登录)
        login_back_num = len(daily_log_dat.get_lost_back_user_set(all_login_lst, cur_date))

        row = [
            cur_date.strftime("%m/%d/%Y"),
            today_login_uid_num,
            today_active_uid_num,
            today_lost_uid_num,
            login_back_num,
        ]
        table_result.append(row)

    return table_result
def get_table(search_date, server_id):

    # 搜索日期到今天的所有日志
    retained_day = search_date - datetime.timedelta(days=4)
    all_login_lst = []
    total_days = (search_date - retained_day).days + 1
    for i in xrange(total_days):
        search_date = retained_day + datetime.timedelta(days=i)
        date_str = "_" + search_date.strftime('%Y%m%d')
        login_lst = mysql_util.get_role_action_lst(
            'EVENT_ACTION_ROLE_LOGIN' + str(date_str), search_date,
            search_date, -1, server_id, None, None)
        all_login_lst.extend(login_lst)

    table_result = []
    cur_date = search_date
    # 今日全部日志
    today_login_lst = daily_log_dat.get_new_log_lst_with_log(
        all_login_lst, cur_date, cur_date)
    # 获取登录日志列表
    today_login_uid_lst = daily_log_dat.get_set_with_key(
        today_login_lst, 'uid')

    today_new_user_login_lst = daily_log_dat.filter_logs(
        today_login_lst, function=lambda log: log['install'] == cur_date)
    today_new_user_uid_num = daily_log_dat.get_set_num_with_key(
        today_new_user_login_lst, 'uid')
    # 登录用户数
    today_login_uid_num = len(today_login_uid_lst)
    # 活跃用户数
    today_active_uid_num = today_new_user_uid_num

    # 流失用户(3天内没登录)
    today_lost_uid_num = len(
        daily_log_dat.get_lost_user_set(all_login_lst, cur_date))
    # 回流用户(3天内没登录 但今天登录)
    login_back_num = len(
        daily_log_dat.get_lost_back_user_set(all_login_lst, cur_date))

    row = [
        cur_date.strftime("%m/%d/%Y"), today_login_uid_num,
        today_active_uid_num, today_lost_uid_num, login_back_num
    ]
    table_result.append(row)

    return table_result
def get_table(search_date, server_id):

    # 搜索日期到今天的所有日志
    retained_day = search_date - datetime.timedelta(days=4)
    all_login_lst = []
    total_days = (search_date - retained_day).days + 1
    for i in xrange(total_days):
        search_date = retained_day + datetime.timedelta(days=i)
        date_str = "_" + search_date.strftime("%Y%m%d")
        login_lst = mysql_util.get_role_action_lst(
            "EVENT_ACTION_ROLE_LOGIN" + str(date_str), search_date, search_date, -1, server_id, None, None
        )
        all_login_lst.extend(login_lst)

    table_result = []
    cur_date = search_date
    # 今日全部日志
    today_login_lst = daily_log_dat.get_new_log_lst_with_log(all_login_lst, cur_date, cur_date)
    # 获取登录日志列表
    today_login_uid_lst = daily_log_dat.get_set_with_key(today_login_lst, "uid")

    today_new_user_login_lst = daily_log_dat.filter_logs(
        today_login_lst, function=lambda log: log["install"] == cur_date
    )
    today_new_user_uid_num = daily_log_dat.get_set_num_with_key(today_new_user_login_lst, "uid")
    # 登录用户数
    today_login_uid_num = len(today_login_uid_lst)
    # 活跃用户数
    today_active_uid_num = today_new_user_uid_num

    # 流失用户(3天内没登录)
    today_lost_uid_num = len(daily_log_dat.get_lost_user_set(all_login_lst, cur_date))
    # 回流用户(3天内没登录 但今天登录)
    login_back_num = len(daily_log_dat.get_lost_back_user_set(all_login_lst, cur_date))

    row = [cur_date.strftime("%m/%d/%Y"), today_login_uid_num, today_active_uid_num, today_lost_uid_num, login_back_num]
    table_result.append(row)

    return table_result
def get_table(search_date, register_start_date=None, register_end_date=None, channel_id=-1, server_id=-1):
    """
        获取各等级充值状况表格
    """
    # 获取搜索区间日志
    # 本地写入的开始日期
    log_start_date = datetime.datetime.strptime(game_define.LOCAL_LOG_START_DATE, '%Y-%m-%d').date()
    new_log_lst = daily_log_dat.get_new_log_lst(log_start_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)


    #获取符合条件的日志
    if register_start_date and register_end_date:
        recharge_log_lst = daily_log_dat.filter_logs(new_log_lst, action=game_define.EVENT_ACTION_RECHARGE_PLAYER, function=lambda log: register_start_date <= log['install'] <= register_end_date)
    else:
        recharge_log_lst = daily_log_dat.filter_logs(new_log_lst, action=game_define.EVENT_ACTION_RECHARGE_PLAYER)

    # 获取所有充值玩家UID
    all_uid_log_lst = daily_log_dat.get_set_with_key(recharge_log_lst, 'uid')

    # 获取全部玩家当前等级
    uid_level_dict = dict()
    for _uid in all_uid_log_lst:
        uid_level_dict[_uid] = daily_log_dat.get_max_int_with_key(new_log_lst, 'level', function=lambda log:log['uid'] == _uid)

    # print("uid_level_dict " + str(uid_level_dict))

    # 获取全部玩家最后登录间隔天数
    uid_last_login_distance = dict()
    for _uid in all_uid_log_lst:
        # 获取玩家最后登录日志
        _user_login_logs = daily_log_dat.filter_logs(new_log_lst, action=game_define.EVENT_ACTION_ROLE_LOGIN, function=lambda log:log['uid'] == _uid)
        if _user_login_logs:
            last_login_log = _user_login_logs[0]
            for _log in _user_login_logs:
                if _log['log_time'] > last_login_log['log_time']:
                    last_login_log = _log
            # 计算距离搜索日的日期
            last_login_dis_day = (search_date - last_login_log['log_time'].date()).days  # 最后登录间隔日期
        else:
            last_login_dis_day = 300
        # 记录
        uid_last_login_distance[_uid] = last_login_dis_day

    # 获取所有等级停留人数
    table_row_lst = []
    for _table_lv in xrange(1, 121):
        level_uid_lst = _get_level_uid_lst(_table_lv, uid_level_dict)
        lost_uid_lst = daily_log_dat.get_lost_user_set(level_uid_lst, search_date)
        arrive_uid_lst = _get_arrive_level_uid_lst(_table_lv, uid_level_dict)
        level_recharge_lst = daily_log_dat.get_recharge_lst_with_user_level(recharge_log_lst, _table_lv)
        recharge_uid_lst = daily_log_dat.get_user_uid_lst(level_recharge_lst)
        # 停留人数
        user_num = len(level_uid_lst)
        # 流失人数
        lost_num = len(lost_uid_lst)
        # 留存人数
        stand_num = user_num - lost_num
        # 到达等级人数
        arrive_num = len(arrive_uid_lst)
        # 充值金额
        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, lost_num, stand_num, arrive_num, recharge_money, recharge_num, recharge_user_num, level_pay_rate, level_lost_rate]
        table_row_lst.append(content)

    return table_row_lst
def get_table(search_start_date,
              search_end_date,
              register_start_date=None,
              register_end_date=None,
              channel_id=-1,
              server_id=-1):
    """
        获取展示表格
        register_start_date 注册开始时间
        register_end_date 注册结束时间
        search_start_date 查询开始时间
        search_end_date 查询结束时间
    """
    # 获取搜索区间日志
    new_log_lst = daily_log_dat.get_new_log_lst(search_start_date,
                                                search_end_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)
    #获取符合条件的日志
    if register_start_date and register_end_date:
        new_log_lst = daily_log_dat.filter_logs(
            new_log_lst,
            function=lambda log: register_start_date <= log[
                'install'] <= register_end_date)

    # 获取新增用户部分日志
    all_login_lst = daily_log_dat.filter_logs(
        new_log_lst, action=game_define.EVENT_ACTION_ROLE_LOGIN)
    all_uid_log_lst = daily_log_dat.get_set_with_key(all_login_lst, 'uid')

    # 获取全部玩家最后登录间隔天数
    uid_level_dict = dict()
    for _uid in all_uid_log_lst:
        uid_level_dict[_uid] = daily_log_dat.get_max_int_with_key(
            all_login_lst, 'level', function=lambda x: x['uid'] == _uid)

    # 获取全部玩家最后登录间隔天数
    uid_last_login_distance = dict()
    for _uid in all_uid_log_lst:
        # 获取玩家最后登录日志
        _user_login_logs = daily_log_dat.filter_logs(
            new_log_lst,
            action=game_define.EVENT_ACTION_ROLE_LOGIN,
            function=lambda log: log['uid'] == _uid)
        if _user_login_logs:
            last_login_log = _user_login_logs[0]
            for _log in _user_login_logs:
                if _log['log_time'] > last_login_log['log_time']:
                    last_login_log = _log
            # 计算距离搜索日的日期
            last_login_dis_day = (
                search_end_date -
                last_login_log['log_time'].date()).days  # 最后登录间隔日期
        else:
            last_login_dis_day = 300
        # 记录
        uid_last_login_distance[_uid] = last_login_dis_day

    # 遍历全部等级
    table_row_lst = []
    for _table_lv in xrange(1, 121):
        level_uid_lst = _get_level_uid_lst(_table_lv, uid_level_dict)
        lost_uid_lst = daily_log_dat.get_lost_user_set(new_log_lst,
                                                       search_end_date)
        arrive_uid_lst = _get_arrive_level_uid_lst(_table_lv, uid_level_dict)

        # 停留人数
        user_num = len(level_uid_lst)
        # 流失人数
        lost_num = len(lost_uid_lst)
        # 留存人数
        stand_num = user_num - lost_num
        # 到达等级人数
        arrive_num = len(arrive_uid_lst)
        # 等级流失率
        level_lost_rate = _get_level_lost_rate(lost_num, arrive_num)
        # 等级	停留人数	留存人数	流失人数	到达人数	等级流失率
        content = [
            _table_lv, user_num, stand_num, lost_num, arrive_num,
            level_lost_rate
        ]
        table_row_lst.append(content)

    return table_row_lst