def get_checkpoint_cid_list(race_cid): """ 获取活动的所有关卡的cid,并缓存 :param race_cid: :return: """ key = '%s_CHECK_POINT_CID' % race_cid map_key = '%s_CHECK_POINT_MAP' % race_cid check_point_cid_list_str = RedisCache.get(key) check_point_map_str = RedisCache.get(map_key) if check_point_map_str and check_point_cid_list_str: check_point_cid_list = check_point_cid_list_str.split(',') checkpoint_map = json.loads(check_point_map_str) else: check_point_list = RaceGameCheckPoint.sync_find({ 'race_cid': race_cid }).sort('index').to_list(None) check_point_cid_list = [] checkpoint_map = dict() for check_point in check_point_list: check_point_cid_list.append(check_point.cid) checkpoint_map[check_point.cid] = check_point.index # 缓存所有关卡的cid RedisCache.set(key, ",".join(check_point_cid_list), 6 * 60 * 60) RedisCache.set(map_key, json.dumps(checkpoint_map), 6 * 60 * 60) return check_point_cid_list, checkpoint_map
def get_all_last_checkpoint(): """ 获取每个活动的最后一关 :return: """ _lp = {} race_list = Race.sync_find().to_list(None) for race in race_list: checkpoint = RaceGameCheckPoint.sync_find({'race_cid': race.cid}).sort([('index', ASC)]).to_list(None) if checkpoint: _lp[race.cid] = checkpoint[-1].cid return _lp
def get_all_race_checkpoint_map(): """ 获取所有活动 :return: """ _mp = {} cursor = RaceGameCheckPoint.sync_find() while True: try: cp = cursor.next() _mp[cp.cid] = cp.race_cid except StopIteration: break return _mp
def statistic_award_of_race(race_cid, daily_codes): """ 该活动下每个关卡参与人数、抽奖人数、中奖人数记录 :param race_cid: :return: """ check_point_list = RaceGameCheckPoint.sync_find({ "race_cid": race_cid }).to_list(None) result = [] check_point_list.sort(key=lambda checkpoint: checkpoint.index) for check_point in check_point_list: print("统计", check_point.alias, check_point.cid) statistic_award_info = statistic_award_info_of_check_point( check_point.cid, daily_codes) result.append(CheckPointAward(check_point, statistic_award_info)) print(statistic_award_info) # check_point_sort = sorted(check_point_list,key=lambda check_point: check_point.index) # check_point_alias = [x.alias for x in check_point_sort] # export_to_excel(result, check_point_alias) return result