''')
    avg = 0
    for row in mysql.fetchall():
        avg = row['average']
    mysql.execute('drop table match_count')
    return avg


mysql.execute('''
    select game_date, count(*) as count from dfs_avg_preds group by game_date
having count > 14
''')
for row in mysql.fetchall():
    game_date = row['game_date']
    try:
        best_node = optimizer.get_best_lineup('dfs_avg_preds', str(game_date))
    except:
        continue
    actual_value = best_node.actual_value
    predicted_value = best_node.value
    point_threshold = get_point_threshold(game_date)
    mysql.execute(
        """insert into dfs_backtesting(game_date, predicted_value, actual_value, point_threshold) values("{game_date}","{predicted_value}","{actual_value}","{point_threshold}")"""
        .format(game_date=game_date,
                predicted_value=predicted_value,
                actual_value=actual_value,
                point_threshold=point_threshold))
    con.commit()

print('Finished')
# simple average win rate: 0.2244
    select game_date, count(*) as count from matches where game_date = '{game_date}';
    '''.format(game_date=game_date))
    mysql.execute('''
    select average from match_count left join FanDuel_avg_worst_winning_score as worst on match_count.count = worst.games 
    ''')
    avg = 0
    for row in mysql.fetchall():
        avg = row['average']
    mysql.execute('drop table match_count')    
    return avg

mysql.execute('''
    select game_date, count(*) as count from dfs_avg_preds group by game_date
having count > 14
''')
for row in mysql.fetchall():
    game_date = row['game_date']
    try:
        best_node = optimizer.get_best_lineup('dfs_avg_preds',str(game_date))
    except:
        continue
    actual_value = best_node.actual_value
    predicted_value = best_node.value
    point_threshold = get_point_threshold(game_date)
    mysql.execute("""insert into dfs_backtesting(game_date, predicted_value, actual_value, point_threshold) values("{game_date}","{predicted_value}","{actual_value}","{point_threshold}")""".format(game_date=game_date,predicted_value=predicted_value,actual_value=actual_value,point_threshold=point_threshold))
    con.commit()

print('Finished')
# simple average win rate: 0.2244