Exemplo n.º 1
0
    def __fill(self, fixtures: List[Fixture], half: Half):
        home_data = {}
        away_data = {}
        for fixture in fixtures:
            if fixture.full_time():
                if fixture.home_team not in home_data:
                    home_data[fixture.home_team] = Data()

                if fixture.away_team not in away_data:
                    away_data[fixture.away_team] = Data()

                home = home_data[fixture.home_team]
                away = away_data[fixture.away_team]

                results = []
                if half == Half.both:
                    if fixture.full_time() is not None:
                        results.append(fixture.full_time())
                elif half == Half.first:
                    if fixture.first_half() is not None:
                        results.append(fixture.first_half())
                elif half == Half.second:
                    if fixture.second_half() is not None:
                        results.append(fixture.second_half())
                elif half == Half.separate:
                    if fixture.first_half() is not None:
                        results.append(fixture.first_half())
                    if fixture.second_half() is not None:
                        results.append(fixture.second_half())
                else:
                    assert False

                if results:
                    for result in results:
                        if win(result):
                            home.wins += 1
                            away.losses += 1
                        elif loss(result):
                            home.losses += 1
                            away.wins += 1
                        else:
                            home.draws += 1
                            away.draws += 1

                        home.goals_for += result.left
                        home.goals_against += result.right
                        away.goals_for += result.right
                        away.goals_against += result.left

        for team in home_data.keys():
            home = home_data[team]
            away = away_data[team]
            total = combine(home, away)
            row = TableRow(team, total.games(), home.wins, home.draws,
                           home.losses, home.goals_for, home.goals_against,
                           away.wins, away.draws, away.losses, away.goals_for,
                           away.goals_against, total.wins, total.draws,
                           total.losses, total.goals_for, total.goals_against,
                           total.wins * 3 + total.draws)
            self.append(row)
Exemplo n.º 2
0
def populate(stats: Statistics, result: Result):
    if result:
        if win(result):
            stats.wins += 1
        elif loss(result):
            stats.losses += 1
        else:
            assert draw(result)
            stats.draws += 1

        stats.goals_for += result.left
        stats.goals_against += result.right
        stats.scores[(result.left, result.right)] += 1
Exemplo n.º 3
0
def decide_cell_color(result: Result, left_color: Tuple[float, float, float],
                      right_color: Tuple[float, float, float],
                      neutral_color: Tuple[float, float, float],
                      unknown_color: Tuple[float, float, float]):
    if result:
        if win(result):
            return left_color
        elif loss(result):
            return right_color
        else:
            return neutral_color
    else:
        return unknown_color
Exemplo n.º 4
0
def compute_statistics(season: Season, team: Team, venue: Venue, half: Half, summary: List[Statistics]):
    fixtures = []
    season.sort_fixtures()
    for fixture in season.fixtures():
        if fixture.first_half() is not None and fixture.second_half() is not None:
            if venue == Venue.any:
                if fixture.home_team == team or fixture.away_team == team:
                    fixtures.append(fixture)
            elif venue == Venue.away:
                if fixture.away_team == team:
                    fixtures.append(fixture)
            elif venue == Venue.home:
                if fixture.home_team == team:
                    fixtures.append(fixture)

    for fixture in fixtures:
        if half == Half.both:
            result = fixture.full_time()
        elif half == Half.first:
            result = fixture.first_half()
        elif half == Half.second:
            result = fixture.second_half()
        else:
            assert False

        if fixture.away_team == team:
            result = result.reverse()

        stats = Statistics()
        if win(result):
            stats.wins += 1
            stats.points += 3
        elif draw(result):
            stats.draws += 1
            stats.points += 1
        else:
            assert loss(result)
            stats.losses += 1

        stats.goals_for = result.left
        stats.goals_against = result.right

        if not summary:
            summary.append(stats)
        else:
            summary.append(combine(stats, summary[-1]))
Exemplo n.º 5
0
def update_stats(stats: Statistics, result: Result):
    stats.goals_for += result.left
    stats.goals_against += result.right

    if win(result):
        stats.wins += 1
    elif loss(result):
        stats.losses += 1
    else:
        assert draw(result)
        stats.draws += 1

    if bts(result):
        stats.bts += 1

    if result.left > 0:
        stats.scored += 1

    if result.right > 0:
        stats.conceded += 1

    stats.goals[result.left + result.right] += 1
    stats.scores[(result.left, result.right)] += 1