def print_h2h_fixtures(self, count=5, before=datetime.datetime.now()): print("H2H FIXTURES") last_h2h = self.get_h2h_fixtures(count, before) print(FixturesOperation.to_string(last_h2h)) print(FixturesOperation.stats(last_h2h, self.home_team.team_id), '\n') print("H2H FIXTURES H/A") last_h_a_h2h = self.get_h2h_h_a_fixtures(count, before) print(FixturesOperation.to_string(last_h_a_h2h)) print(FixturesOperation.stats(last_h_a_h2h, self.home_team.team_id))
def test_fixtures_sort(): f1 = Fixture(1, datetime.datetime(2015, 5, 3), 'end', 10, 'ABC', 20, 'XYZ', Result(5, 1)) f2 = Fixture(1, datetime.datetime(2016, 10, 20), 'end', 10, 'ABC', 20, 'XYZ', Result(5, 1)) f3 = Fixture(1, datetime.datetime(2005, 8, 19), 'end', 10, 'ABC', 20, 'XYZ', Result(5, 1)) fixtures = [f1, f2, f3] FixturesOperation.sort_fixtures_by_date(fixtures) assert fixtures == [f3, f1, f2]
def test_match_id_with(): f1 = Fixture(1, datetime.datetime(2015, 5, 3), 'end', 10, 'ABC', 30, 'XYZ', Result(5, 1)) f2 = Fixture(2, datetime.datetime(2016, 10, 20), 'end', 10, 'ABC', 15, 'XYZ', Result(5, 1)) f3 = Fixture(3, datetime.datetime(2005, 8, 19), 'end', 10, 'ABC', 20, 'XYZ', Result(5, 1)) fixtures = [f3, f1, f2] assert FixturesOperation.match_id_with(fixtures, 15) == 2 assert FixturesOperation.match_id_with(fixtures, 5) == -1
def get_points_goals(fixtures, team_id): stats = FixturesOperation.stats(fixtures, team_id) matches = stats[0] + stats[1] + stats[2] if matches <= 0: return 0, 0 return int( (stats[0] - stats[1]) * 100 / matches), int(stats[3] * 100 / matches)
def _download_h2h_fixtures(self): match_id = FixturesOperation.match_id_with(self.home_team.fixtures, self.away_team.team_id) if match_id == -1: return [] return FootballData.get_fixtures_h2h(match_id)
def get_last_fixtures_points_goals(team_fixtures, team_id, key=lambda x: True, match_date=datetime.datetime.now(), count=5): last_fixtures = FixturesOperation.last_fixtures(team_fixtures, count, match_date, key) return get_points_goals(last_fixtures, team_id)
def test_free_days(): f1 = Fixture(1, datetime.datetime(2015, 5, 3), 'end', 10, 'ABC', 20, 'XYZ', Result(5, 1)) f2 = Fixture(1, datetime.datetime(2016, 10, 20), 'end', 10, 'ABC', 20, 'XYZ', Result(5, 1)) f3 = Fixture(1, datetime.datetime(2005, 8, 19), 'end', 10, 'ABC', 20, 'XYZ', Result(5, 1)) fixtures = [f3, f1, f2] assert FixturesOperation.free_days(fixtures, datetime.datetime(2015, 5, 20)) == 17 assert FixturesOperation.free_days(fixtures, datetime.datetime(2016, 10, 25)) == 5 assert FixturesOperation.free_days(fixtures, datetime.datetime(2005, 8, 20)) == 1 assert FixturesOperation.free_days(fixtures, datetime.datetime(2005, 8, 10)) == 0
def test_stats(): f1 = Fixture(1, datetime.datetime(2015, 5, 3), 'end', 10, 'ABC', 30, 'XYZ', Result(5, 1)) f2 = Fixture(2, datetime.datetime(2016, 10, 20), 'end', 10, 'ABC', 15, 'XYZ', Result(4, 3)) f3 = Fixture(3, datetime.datetime(2005, 8, 19), 'end', 10, 'ABC', 20, 'XYZ', Result(0, 0)) f4 = Fixture(3, datetime.datetime(2005, 8, 19), 'end', 10, 'ABC', 20, 'XYZ', Result(0, 1)) fixtures = [f3, f1, f2, f4] assert FixturesOperation.stats(fixtures, 10) == (2, 1, 1, 4)
def get_row_with_fixtures(fixtures, team_id, fixture_key, match_date=datetime.datetime.now(), count=5): # 0 - POINTS # 1 - GOALS # 2 - POINTS_KEY # 3 - GOALS_KEY # 4 - FREE_DAYS row = [0, 0, 0, 0, 0] row[0], row[1] = get_last_fixtures_points_goals(fixtures, team_id, lambda x: True, match_date, count) row[2], row[3] = get_last_fixtures_points_goals(fixtures, team_id, fixture_key, match_date, count) row[4] = FixturesOperation.free_days(fixtures, match_date) return row
def get_h2h_match_id(home_team_id, away_team_id, match_date=datetime.datetime.now()): home_team_fixtures = get_team_fixtures_all(home_team_id, match_date) return FixturesOperation.match_id_with(home_team_fixtures, away_team_id)
def get_h2h_h_a_fixtures(self, count=5, before=datetime.datetime.now()): return FixturesOperation.last_fixtures( self.h2h_fixtures, count, before, lambda x: x.home_team_id == self.home_team.team_id)
def get_h2h_fixtures(self, count=5, before=datetime.datetime.now()): return FixturesOperation.last_fixtures(self.h2h_fixtures, count, before)
def print_away_fixtures(self, count=5, before=datetime.datetime.now()): print("AWAY FIXTURES:", self.name) fixtures = self.get_away_fixtures(count, before) print(FixturesOperation.to_string(fixtures)) print(FixturesOperation.stats(fixtures, self.team_id))
def get_away_fixtures(self, count=5, before=datetime.datetime.now()): return FixturesOperation.last_fixtures( self.fixtures, count, before, lambda x: x.away_team_id == self.team_id)