示例#1
0
def get_fight_history_models():
    # 获取对战历史
    return MemberGameHistory.sync_find(
        {
            'status': STATUS_RESULT_GAME_PK_WIN,
            'fight_datetime': {
                '$ne': None
            }
        },
        read_preference=ReadPreference.PRIMARY).sort([('fight_datetime', ASC)
                                                      ]).batch_size(32)
def export_member_game_history(cond: dict):
    """
    获取该用户的对战历史
    :param cond:
    :return:
    """
    member = Member.sync_find_one(cond)
    if not member:
        return

    workbook = xlsxwriter.Workbook('%s的游戏历史明细.xlsx' % member.nick_name)
    worksheet = workbook.add_worksheet('game_history')

    history_list = MemberGameHistory.sync_find({
        'member_cid': member.cid,
        'created_dt': {
            '$gte': datetime.now().replace(2019, 1, 1, 0, 0, 0, 0)
        }
    }).sort('created_dt').to_list(None)

    cols = ['时间', '所处段位', '状态', '钻石增减']
    for col_index, col_name in enumerate(cols):
        worksheet.write(0, col_index + 1, col_name)

    print(history_list)
    for index, his in enumerate(history_list):
        cols = [
            datetime2str(his.created_dt),
            TYPE_DAN_GRADE_DICT.get(his.dan_grade, str(his.dan_grade)),
            STATUS_RESULT_CHECK_POINT_DICT.get(his.status),
            str(his.result)
        ]
        for col_index, col_name in enumerate(cols):
            worksheet.write(index + 1, col_index + 1, col_name)

    worksheet2 = workbook.add_worksheet('diamond_detail')
    details = MemberDiamondDetail.sync_find({
        'member_cid': member.cid
    }).sort('created_dt').to_list(None)
    cols = ['时间', '奖励来源', '奖励类型', '钻石增减']
    for col_index, col_name in enumerate(cols):
        worksheet2.write(0, col_index + 1, col_name)

    for index, detl in enumerate(details):
        cols = [
            datetime2str(detl.reward_datetime),
            SOURCE_MEMBER_DIAMOND_DICT.get(detl.source), detl.content,
            detl.diamond
        ]
        for col_index, col_name in enumerate(cols):
            worksheet2.write(index + 1, col_index + 1, col_name)

    workbook.close()
示例#3
0
def get_fight_history_models():
    # 获取对战历史
    return MemberGameHistory.sync_find(dict(record_flag=1)).batch_size(32)
            city_code = complete_member_city_code(member.province_code, member.city_code)
            mls.city_code = city_code
            mls.district_code = member.district_code
            mls.gender = member.sex
            mls.age_group = member.age_group
            mls.education = member.education
            mls.category = member.category
            # 学习总次数
            mls.learn_times += 1
            # 答题正确数
            correct_quantity = _do_count_subject_correct_quantity(mls, history)
            # 统计答题正确数的次数
            _do_count_correct_quantity(mls, correct_quantity)
            # 获取题目详情
            subject_list, subject_answer_dict = _do_get_subjects_detail(history)
            # 统计维度详情
            _do_count_dimension_detail(mls, subject_list, subject_answer_dict)
            mls.created_dt = history.created_dt
            mls.updated_dt = history.updated_dt
            mls.sync_save()
    except ValueError:
        trace_i = traceback.format_exc()
        print(trace_i)


if __name__ == '__main__':
    history_list = MemberGameHistory.sync_find(read_preference=ReadPreference.PRIMARY).batch_size(128)
    for index, history in enumerate(history_list):
        init_member_learning_day_statistics(history)
        print(index + 1, history.cid)
示例#5
0
#! /usr/bin/python3
from datetime import datetime

from db.models import MemberGameHistory, Member

member_game_history_list = MemberGameHistory.sync_find({
    'updated_dt': {
        '$gte': datetime.now().replace(2019, 1, 29, 16, 30, 0, 0)
    }
})

i, j = 1, 1
for his in member_game_history_list:
    # step1: 将段位减1
    if his.dan_grade == 12:
        # step2: 恢复原有钻石
        member = Member.sync_find_one({'cid': his.member_cid})
        member.diamond += 6000
        member.sync_save()
        j += 1

    his.dan_grade -= 1
    his.sync_save()
    i += 1

print('dan_grade changed count: %s' % i)
print('diamond changed count: %s' % j)
                            mdds.updated_dt = history.updated_dt
                            if mdds not in insert_mdds_list:
                                mdds.sync_save()
        if insert_mdds_list:
            MemberDailyDimensionStatistics.sync_insert_many(insert_mdds_list)

    except ValueError:
        trace_i = traceback.format_exc()
        result['msg'] = trace_i
        print(trace_i)


def _get_daily_code(dt: datetime.datetime = None):
    """
    获取对接标识
    :return:
    """
    if not dt:
        dt = datetime.datetime.now()
    return datetime2str(dt, date_format='%Y%m%d000000')


if __name__ == '__main__':
    t1 = datetime.datetime.now().replace(year=2019, month=5, day=5, hour=12, minute=0, second=0, microsecond=0)
    t2 = datetime.datetime.now().replace(year=2019, month=5, day=17, hour=12, minute=0, second=0, microsecond=0)
    history_list = MemberGameHistory.sync_find({'created_dt': {'$gte': t1, '$lte': t2}},
                                               read_preference=ReadPreference.PRIMARY).batch_size(128)
    for index, history in enumerate(history_list):
        start_dashboard_report_statistics_without_delay(history)
        print(index + 1, history.cid)
示例#7
0
            model.sync_insert_many(insert_mdds_list)

    except ValueError:
        trace_i = traceback.format_exc()
        result['msg'] = trace_i
        print(trace_i)


def _get_daily_code(dt: datetime.datetime = None):
    """
    获取对接标识
    :return:
    """
    if not dt:
        dt = datetime.datetime.now()
    return datetime2str(dt, date_format='%Y%m%d000000')


if __name__ == '__main__':
    index = int(sys.argv[1])
    model = create_model(MemberDailyDimensionStatistics, index)
    skip_num = int(sys.argv[2])
    limit_num = int(sys.argv[3])
    print(index, skip_num, limit_num)

    history_list = MemberGameHistory.sync_find(read_preference=ReadPreference.PRIMARY).skip(skip_num).limit(
        limit_num).batch_size(128)
    for index, history in enumerate(history_list):
        start_dashboard_report_statistics_without_delay(history, model)
        print(index + 1, history.cid)
示例#8
0
from commons.common_utils import datetime2str
from db import SEX_DICT, TYPE_AGE_GROUP_DICT, TYPE_EDUCATION_DICT
from db.models import MemberGameHistory, Member, AdministrativeDivision
from pymongo import ReadPreference
from xlsxwriter import Workbook

six_month_ago = datetime.now().replace(year=2018,
                                       month=10,
                                       day=1,
                                       hour=0,
                                       minute=0,
                                       second=0,
                                       microsecond=0)
cursor = MemberGameHistory.sync_find({'created_dt': {
    '$gte': six_month_ago
}},
                                     read_preference=ReadPreference.PRIMARY)

workbook = Workbook('近6个月的游戏数据.xlsx')
worksheet = workbook.add_worksheet()
menu = ['序号', '昵称', '性别', '年龄段', '受教育程度', '省份', '城市', '总题数', '答对题目数量', '答题时间']
for index, m in enumerate(menu):
    worksheet.write_string(0, index, m)

post_code_map = {}
row = 0
while True:
    row += 1
    try:
        history = cursor.next()
        worksheet.write_number(row, 0, row)
def get_fight_history_models():
    # 获取对战历史
    return MemberGameHistory.sync_find(
        dict(record_flag=1),
        read_preference=ReadPreference.PRIMARY).batch_size(32)