def populate_match(league, weight_schedule, date): utcnow = datetime.datetime.utcnow() log_file_name = utcnow.strftime('/tmp/bet_web/%y-%m-%d-MatchGetter.log') logging.basicConfig(filename=log_file_name, level=logging.INFO, format='%(asctime)s %(message)s') matches = get_match_data(league, date) logging.info('Matches collected: date="{}" league={} count={}'.format( date, league, len(matches))) for league, match_time, handicap_display, team_a, team_b, premium_a, premium_b, score_a, score_b in matches: # 从tournament的weight_schedule里取得对应权重 weight = 2 for (t, w) in weight_schedule: if match_time < t: weight = w break match = insert_match(league, match_time, handicap_display, team_a, team_b, premium_a, premium_b, score_a, score_b, weight) update_match_handicap(match_id=match.id, handicap_display=handicap_display) update_match_score(match_id=match.id, score_a=score_a, score_b=score_b) return
def test_Match_update_profit_and_loss_with_self_auction( choice_a, choice_b, no_choice, handicap, score_a, score_b, expected, auction2): # prepare gamblers choice_a = [model.insert_gambler(g) for g in choice_a] choice_b = [model.insert_gambler(g) for g in choice_b] no_choice = [model.insert_gambler(g) for g in no_choice] # prepare match match = model.insert_match('硬糙', datetime.datetime(2018, 4, 1, 20, 30), '平手', '水宫', '纽尔联', 1.01, 1.39, 0, 1) # prepare bet choice for g in choice_a: model.update_match_gamblers(match.id, 'a', g, cutoff_check=False) for g in choice_b: model.update_match_gamblers(match.id, 'b', g, cutoff_check=False) # prepare match score model.update_match_score(match.id, score_a, score_b) # prepare match handicap model.update_match_handicap(match.id, handicap, cutoff_check=False) # calculate PNL match = model.find_match_by_id(match.id) result = match.update_profit_and_loss_result( required_gamblers=model.find_gamblers()) for k, v in expected.items(): assert result.get(k) == v
def match2(): # complex handicap return model.insert_match('硬糙', datetime.datetime(2018, 3, 31, 22, 10), '半球/一球', '纽尔联', '哈尔德', 2.02, 1.84, 2, 1)
def match1(): # simple handicap return model.insert_match('硬糙', datetime.datetime(2018, 3, 31, 19, 30), '受一球', '水宫', '利浦', 2.08, 1.78, 2, 4)