Пример #1
0
def adjust_race_report_accuracy(race_cid):
    """
    活动报表线上数据填充正确率数据
    :param race_cid:
    :return:
    """
    race = Race.sync_find_one({'cid': race_cid})
    if not race:
        print("活动不存在, 请检查!")
        return
    #  找到该活动下面所有的关卡
    check_point_cid_list = RaceGameCheckPoint.sync_distinct("cid", {'race_cid': race_cid})
    print(check_point_cid_list)
    if not check_point_cid_list:
        print("该活动下面没有关卡")
        return
    #  给race_mapping从历史记录统计正确率
    try:
        for check_point_cid in check_point_cid_list:
            check_point_history_list = MemberCheckPointHistory.sync_find({"check_point_cid": check_point_cid}).to_list(
                None)
            for check_point_history in check_point_history_list:
                race_mapping = RaceMapping.sync_find_one(
                    {'member_cid': check_point_history.member_cid, "race_cid": race_cid},
                    read_preference=ReadPreference.PRIMARY)
                race_mapping.total_count += len(check_point_history.result)
                num = 0
                for result in check_point_history.result:
                    if result.get("true_answer"):
                        num += 1
                race_mapping.total_correct += num
                race_mapping.sync_save()
    except Exception as e:
        print(str(e))
Пример #2
0
def get_game_check_point_rules(race_cid, race_check_point_cid=None):
    """
    获取关卡抽题规则
    :param check_point_cid:
    :return:
    """
    try:
        cp_cid_list = []
        if race_check_point_cid:
            cp_cid_list.append(race_check_point_cid)
        else:
            cid_list = RaceGameCheckPoint.sync_distinct(
                'rule_cid', {
                    'race_cid': race_cid,
                    'rule_cid': {
                        '$ne': None
                    }
                })
            if cid_list:
                cp_cid_list.extend(cid_list)

        if cp_cid_list:
            race_rule_list = RaceSubjectChoiceRules.sync_find({
                'race_cid': race_cid,
                'cid': {
                    '$in': cp_cid_list
                }
            }).to_list(None)
            if race_rule_list:
                return race_rule_list
    except Exception:
        logger.error(traceback.format_exc())
    return None
Пример #3
0
def check(race_cid: str):
    """
    检查多少人参与活动但是没有答过题目的
    :param race_cid:
    :return:
    """
    race = Race.sync_get_by_cid(race_cid)
    #  市级活动,如六安市,扬州市
    if race.city_code:
        city_code_list = AdministrativeDivision.sync_distinct(
            'code', {'code': race.city_code})
        #  该活动的所属城市范围
        city_name_list = AdministrativeDivision.sync_distinct(
            'title', {'code': race.city_code})
    else:
        prov = AdministrativeDivision.sync_find_one(
            {'code': race.province_code})
        city_code_list = AdministrativeDivision.sync_distinct(
            'code', {'parent_code': race.province_code})
        city_name_list = AdministrativeDivision.sync_distinct(
            'title', {'parent_code': race.province_code})
    dist_list = []
    print(city_name_list, '1')
    for city_code in city_code_list:
        #  该活动区县的范围
        dist_list += AdministrativeDivision.sync_distinct(
            'title', {'parent_code': city_code})
    quantity = 0
    member_cid_list = RaceMapping.sync_distinct(
        "member_cid", {
            'race_cid': race_cid,
            'auth_address.city': {
                '$in': city_name_list
            },
            'auth_address.province': {
                '$ne': None
            },
            'auth_address.district': {
                '$in': dist_list
            }
        })
    check_point_cid = RaceGameCheckPoint.sync_distinct("cid",
                                                       {"race_cid": race_cid})
    for i in member_cid_list:
        member = Member.sync_get_by_cid(i)
        if member:
            history = MemberCheckPointHistory.sync_find_one({
                'check_point_cid': {
                    '$in': check_point_cid
                },
                "member_cid": i
            })
            if not history:
                quantity += 1
    print(quantity)
Пример #4
0
def export_history(race_cid):
    """

    :param race_cid:
    :return:
    """
    checkpoint_cids = RaceGameCheckPoint.sync_distinct('cid', {
        'race_cid': race_cid,
        'redpkt_rule_cid': {
            '$ne': ''
        }
    })
    cursor = MemberCheckPointHistory.sync_aggregate(
        [
            MatchStage({
                'check_point_cid': {
                    '$in': checkpoint_cids
                },
                'status': STATUS_RESULT_CHECK_POINT_WIN
            }),
        ],
        read_preference=ReadPreference.PRIMARY).batch_size(2048)

    index = 0
    history_list = set()
    while True:
        try:
            data: MemberCheckPointHistory = cursor.next()
            history_list.add('%s-%s' % (data.check_point_cid, data.member_cid))

            print('has exec', index)
            index += 1
        except StopIteration:
            break

    with open('./history-%s.json' % race_cid, 'w', encoding='utf-8') as f:
        dist_list = json.dumps(list(history_list), ensure_ascii=False)
        f.write(dist_list)