Beispiel #1
0
def select_all():
    predictions = []

    sql = "SELECT * FROM predictions"
    results = run_sql(sql)

    for row in results:
        player = player_repository.select(row['player_id'])
        match = match_repository.select(row['match_id'])

        if row['team_1_id'] == None:
            home_player_team = None
        else:
            home_player_team = player_team_repository.select(row['team_1_id'])
        if row['team_2_id'] == None:
            away_player_team = None
        else:
            away_player_team = player_team_repository.select(row['team_2_id'])

        prediction = Prediction(player, match, home_player_team,
                                away_player_team, row['id'])
        prediction.has_prediction = row['has_prediction']
        prediction.goals['home'] = row['home_goals']
        prediction.goals['away'] = row['away_goals']
        predictions.append(prediction)
    return predictions
Beispiel #2
0
def select(id):
    prediction = None

    sql = "SELECT * FROM predictions WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        player = player_repository.select(result['player_id'])
        match = match_repository.select(result['match_id'])

        if result['team_1_id'] == None:
            home_player_team = None
        else:
            home_player_team = player_team_repository.select(
                result['team_1_id'])
        if result['team_2_id'] == None:
            away_player_team = None
        else:
            away_player_team = player_team_repository.select(
                result['team_2_id'])

        prediction = Prediction(player, match, home_player_team,
                                away_player_team, result['id'])
        prediction.has_prediction = result['has_prediction']
        prediction.goals['home'] = result['home_goals']
        prediction.goals['away'] = result['away_goals']
    return prediction
Beispiel #3
0
def select_all():
    player_groups = []

    sql = "SELECT * FROM player_groups"
    results = run_sql(sql)

    for row in results:
        player = player_repository.select(row['player_id'])
        team_1 = player_team_repository.select(row['team_1_id'])
        team_2 = player_team_repository.select(row['team_2_id'])
        team_3 = player_team_repository.select(row['team_3_id'])
        team_4 = player_team_repository.select(row['team_4_id'])
        player_teams = [team_1, team_2, team_3, team_4]
        group = PlayerGroup(player, row['name'], player_teams, row['id'])
        player_groups.append(group)
    return player_groups
Beispiel #4
0
def select(id):
    group = None

    sql = "SELECT * FROM player_groups WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        player = player_repository.select(result['player_id'])
        team_1 = player_team_repository.select(result['team_1_id'])
        team_2 = player_team_repository.select(result['team_2_id'])
        team_3 = player_team_repository.select(result['team_3_id'])
        team_4 = player_team_repository.select(result['team_4_id'])
        player_teams = [team_1, team_2, team_3, team_4]
        group = PlayerGroup(player, result['name'], player_teams, result['id'])
    return group
def player_groups(player):
    player_groups = []

    sql = "SELECT * FROM player_groups WHERE player_id = %s"
    values = [player.id]
    results = run_sql(sql, values)

    for row in results:
        player_teams = []
        player_teams.append(player_team_repository.select(row['team_1_id']))
        player_teams.append(player_team_repository.select(row['team_2_id']))
        player_teams.append(player_team_repository.select(row['team_3_id']))
        player_teams.append(player_team_repository.select(row['team_4_id']))
        player_group = PlayerGroup(player, row['name'], player_teams,
                                   row['id'])
        player_groups.append(player_group)
    return player_groups
def predictions(player):
    predictions = []

    sql = "SELECT * FROM predictions WHERE player_id = %s ORDER BY id ASC"
    values = [player.id]
    results = run_sql(sql, values)

    for row in results:
        match = match_repository.select(row['match_id'])

        if row['team_1_id'] == None:
            home_player_team = None
        else:
            home_player_team = player_team_repository.select(row['team_1_id'])
        if row['team_2_id'] == None:
            away_player_team = None
        else:
            away_player_team = player_team_repository.select(row['team_2_id'])

        prediction = Prediction(player, match, home_player_team,
                                away_player_team, row['id'])
        prediction.set_goals(row['home_goals'], row['away_goals'])
        predictions.append(prediction)
    return predictions