def test_single_win_value_resolution(self): # Single Win resolution place = 1 stake = 10 odds = "2:1" eachWay = 0 result = resolveBetValue(place, stake, odds, eachWay) self.assertEqual(result, 30.0)
def test_no_win_value_resolution(self): # No-win resolution place = 4 stake = 10 odds = "2:1" eachWay = 1 result = resolveBetValue(place, stake, odds, eachWay) self.assertEqual(result, 0)
def test_each_way_win_value_resolution(self): # Each-way Win resolution place = 1 stake = 10 odds = "2:1" eachWay = 1 result = resolveBetValue(place, stake, odds, eachWay) self.assertEqual(result, 44.0)
def test_each_way_place_resolution(self): # Each-way Place resolution place = 2 stake = 10 odds = "2:1" eachWay = 1 result = resolveBetValue(place, stake, odds, eachWay) self.assertEqual(result, 14.0)
def calculate_and_store_bets(race_id): db_conn, db_curs = get_db() db_curs.execute('SELECT * FROM bet WHERE race_id = %s', (race_id, )) bets = db_curs.fetchall() # Get the results db_curs.execute( 'SELECT result.place, result.horse_id, horse.name AS horsename, horse.odds AS horseodds FROM result INNER JOIN horse ON horse.id = result.horse_id WHERE result.race_id = %s', (race_id, )) results = db_curs.fetchall() to_store = {} for bet in bets: # if the bets horse_id in results result = get_result_for_horse(bet['horse_id'], results) if result: # calculate bet + store # total_stake = resolveStake(bet['amount'], bet['each_way']) calc = resolveBetValue(result['place'], bet['amount'], result['horseodds'], bet['each_way']) to_store[bet['id']] = (calc, bet['horseracing_user_id']) try: for id, val in to_store.items(): db_curs.execute('UPDATE bet SET amount_won = %s WHERE id = %s', (val[0], id)) db_curs.execute( 'SELECT horseracing_user.amount FROM horseracing_user WHERE id = %s', (val[1], )) wallet = db_curs.fetchone() new_wallet = wallet['amount'] + val[0] db_curs.execute( 'UPDATE horseracing_user SET amount = %s WHERE id = %s', (new_wallet, val[1])) db_conn.commit() except psycopg2.Error as e: return render_template('admin/failure.html', message="Failed to update bets: %s" % e)