Ejemplo n.º 1
0
def end_game(league_id, game_id):
    game = game_repo.select(game_id)
    game_repo.end_game(game)
    team1 = team_repo.select(game.team_1.id)
    team2 = team_repo.select(game.team_2.id)

    if game.team_1_score > game.team_2_score:
        team1.wins += 1
        team2.losses += 1
    elif game.team_1_score < game.team_2_score:
        team1.losses += 1
        team2.wins += 1
    else:
        team1.draws += 1
        team2.draws += 1

    team1.games_played += 1
    team1.goals_for += game.team_1_score
    team1.goals_against += game.team_2_score
    team1.goal_difference = team1.goals_for - team1.goals_against
    team1.points = 3 * team1.wins + team1.draws

    team2.games_played += 1
    team2.goals_for += game.team_2_score
    team2.goals_against += game.team_1_score
    team2.goal_difference = team2.goals_for - team2.goals_against
    team2.points = 3 * team2.wins + team2.draws

    team_repo.play_game(team1, team2)

    return redirect(f"/edit/games/league/{league_id}")
Ejemplo n.º 2
0
def show_game(id):
    game = game_repo.select(id)
    team_1_goals = game_repo.team_1_goals(game)
    team_2_goals = game_repo.team_2_goals(game)
    return render_template("games/show.html",
                           title="SCORECARD",
                           game=game,
                           team_1_goals=team_1_goals,
                           team_2_goals=team_2_goals)
Ejemplo n.º 3
0
def get_winner(id):
    game = game_repo.select(id)
    winner = game.winner(game.home_team, game.away_team)
    return render_template("/games/simulate.html", game=game, winner=winner)


# @games_blueprint.route("/games/<id>/book")
# def book_tickets(id):
#     game = game_repo.select(id)
#     return render_template("/games/book.html", game=game)
Ejemplo n.º 4
0
def select(id):
    green = None
    sql = "SELECT * FROM greens WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        player = player_repo.select(result['player_id'])
        game = game_repo.select(result['game_id'])
        green = Green(player, game, result['id'])
    return green
Ejemplo n.º 5
0
def select(id):
    yellow = None
    sql = "SELECT * FROM yellows WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        player = player_repo.select(result['player_id'])
        game = game_repo.select(result['game_id'])
        yellow = Yellow(player, game, result['id'])
    return yellow
Ejemplo n.º 6
0
def select_all():
    greens = []

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

    for result in results:
        player = player_repo.select(result['player_id'])
        game = game_repo.select(result['game_id'])
        green = Green(player, game, result['id'])
        greens.append(green)
    return greens
Ejemplo n.º 7
0
def update_individual_game(id):
    game = game_repo.select(id)
    players = game_repo.players(game)
    team_1_goals = game_repo.team_1_goals(game)
    team_2_goals = game_repo.team_2_goals(game)
    return render_template("games/show.html",
                           title="SCORECARD - EDITING",
                           game=game,
                           team_1_goals=team_1_goals,
                           team_2_goals=team_2_goals,
                           players=players,
                           editing=True)
Ejemplo n.º 8
0
def select_all():
    yellows = []

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

    for result in results:
        player = player_repo.select(result['player_id'])
        game = game_repo.select(result['game_id'])
        yellow = Yellow(player, game, result['id'])
        yellows.append(yellow)
    return yellows
Ejemplo n.º 9
0
def select_all():
    reds = []

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

    for result in results:
        player = player_repo.select(result['player_id'])
        game = game_repo.select(result['game_id'])
        red = Red(player, game, result['id'])
        reds.append(red)
    return reds
Ejemplo n.º 10
0
def new_goal_individual(league_id, game_id):
    game = game_repo.select(game_id)
    player_id = request.form['player_id']
    player = player_repo.select(player_id)
    goal = Goal(player, game)
    goal_repo.save(goal)
    if player.team.id == game.team_1.id:
        game.team_1_score += 1
    else:
        game.team_2_score += 1
    player.goals_scored += 1
    game_repo.goal_scored(game)
    player_repo.goal_scored(player)

    return redirect(f"/edit/games/{game_id}")
Ejemplo n.º 11
0
def show(id):
    game = game_repo.select(id)
    return render_template("/games/show.html", game=game)
Ejemplo n.º 12
0
def edit_game(id):
    teams = team_repo.select_all()
    game = game_repo.select(id)
    return render_template('/games/edit.html', game=game, teams=teams)
Ejemplo n.º 13
0
import repositories.player_repo as player_repo
from models.playlist import Playlist
import repositories.playlist_repo as playlist_repo
from models.possible_game import PossibleGame
import repositories.possible_game_repo as possible_game_repo
from models.red import Red
import repositories.red_repo as red_repo
from models.team import Team
import repositories.team_repo as team_repo
from models.yellow import Yellow
import repositories.yellow_repo as yellow_repo


goals = goal_repo.select_all()
for goal in goals:
    game = game_repo.select(goal.game.id)
    player = player_repo.select(goal.player.id)
    team = team_repo.select(goal.player.team.id)
    if team.id == game.team_1.id:
        game.team_1_score += 1
    elif team.id == game.team_2.id:
        game.team_2_score += 1
    player.goals_scored += 1
    game_repo.goal_scored(game)
    player_repo.goal_scored(player)

games = game_repo.finished_games()
for game in games:
    team1 = team_repo.select(game.team_1.id)
    team2 = team_repo.select(game.team_2.id)
    
Ejemplo n.º 14
0
def start_game(league_id, game_id):
    game = game_repo.select(game_id)
    game_repo.start_game(game)
    return redirect(f"/edit/games/league/{league_id}")