Skip to content

Commit

Permalink
read forfeit from remark
Browse files Browse the repository at this point in the history
  • Loading branch information
djbrown committed Dec 18, 2024
1 parent 4b3ec66 commit b03c6c9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add `--dev` flag for development dependencies.
You may contribute to this Project using any IDE, Editor or Terminal you like, as long as your modifications obey the conventions defined by the [Style Guide for Python Code (PEP8)](https://www.python.org/dev/peps/pep-0008/).
The following commands will format your code accordingly:

- format code: `pipenv run black`
- format code: `pipenv run black src`
- sort imports: `pipenv run isort src`

Also make sure to check messages from the following linter commands before proposing:
Expand Down
3 changes: 0 additions & 3 deletions src/base/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def scrape_game(
home_goals, guest_goals = parsing.parse_goals(game_row)
report_number = parsing.parse_report_number(game_row[10])
remark = parsing.parse_game_remark(game_row[10])
forfeiting_team = parsing.parse_forfeiting_team(game_row[10], home_team, guest_team)

sports_hall = None
try:
Expand All @@ -81,7 +80,6 @@ def scrape_game(
guest_goals=guest_goals,
report_number=report_number,
remark=remark,
forfeiting_team=forfeiting_team,
)
LOGGER.info("CREATED Game: %s", game)
return
Expand All @@ -97,7 +95,6 @@ def scrape_game(
"opening_whistle": opening_whistle,
"sports_hall": sports_hall,
"remark": remark,
"forfeiting_team": forfeiting_team,
}
updated = ensure_defaults(game, defaults)

Expand Down
11 changes: 0 additions & 11 deletions src/base/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from lxml import html
from lxml.etree import _Element

from teams.models import Team


def html_dom(html_text: str) -> _Element:
return html.fromstring(html_text)
Expand Down Expand Up @@ -218,15 +216,6 @@ def parse_game_remark(cell: _Element) -> str:
return ""


def parse_forfeiting_team(cell: _Element, home_team: Team, guest_team: Team) -> Team | None:
text = str(html.tostring(cell))
if "2:0" in text:
return guest_team
if "0:2" in text:
return home_team
return None


def parse_game_time(text: str) -> timedelta | None:
if not text:
return None
Expand Down
18 changes: 9 additions & 9 deletions src/games/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ class Game(models.Model):
guest_goals = models.IntegerField(blank=True, null=True)
report_number = models.IntegerField(blank=True, null=True, unique=True)
remark = models.TextField(blank=True)
forfeiting_team = models.ForeignKey(
Team,
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="forfeiting_team",
)
spectators = models.IntegerField(blank=True, null=True)

class Meta:
Expand Down Expand Up @@ -116,14 +109,21 @@ def leg_title(self) -> str:
}
return mapping[self.leg()]

def forfeiting_team(self) -> Team | None:
if "2:0" in self.remark:
return self.guest_team
if "0:2" in self.remark:
return self.home_team
return None

def outcome(self) -> GameOutcome:
if self.home_goals is None and self.guest_goals is None:
return GameOutcome.OPEN
home_goals: int = Maybe.from_optional(self.home_goals).unwrap()
guest_goals: int = Maybe.from_optional(self.guest_goals).unwrap()
if home_goals > guest_goals or self.forfeiting_team == self.guest_team:
if home_goals > guest_goals or self.forfeiting_team() == self.guest_team:
return GameOutcome.HOME_WIN
if home_goals < guest_goals or self.forfeiting_team == self.home_team:
if home_goals < guest_goals or self.forfeiting_team() == self.home_team:
return GameOutcome.AWAY_WIN
if home_goals == guest_goals:
return GameOutcome.TIE
Expand Down
4 changes: 2 additions & 2 deletions src/games/tests/integration/test_import_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_forfeit_with_report(self):
self.assertEqual(game.remark, "(0:2), gg. Heim, techn. Wertung")
self.assertEqual(game.home_goals, 0)
self.assertEqual(game.guest_goals, 0)
self.assertEqual(game.forfeiting_team, game.home_team)
self.assertEqual(game.forfeiting_team(), game.home_team)

def test_forfeit_without_report(self):
self.assert_command("import_associations", "-a", 83)
Expand All @@ -140,7 +140,7 @@ def test_forfeit_without_report(self):
self.assertEqual(game.remark, "(2:0), gg. Gast")
self.assertEqual(game.home_goals, 0)
self.assertEqual(game.guest_goals, 0)
self.assertEqual(game.forfeiting_team, game.guest_team)
self.assertEqual(game.forfeiting_team(), game.guest_team)


class YouthTest(IntegrationTestCase):
Expand Down
2 changes: 1 addition & 1 deletion src/players/management/commands/import_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def import_game(self, game: Game):
import_game(game)
return

if game.forfeiting_team is not None:
if game.forfeiting_team() is not None:
LOGGER.debug("SKIPPING Game (forfeit): %s - %s", game.report_number, game)
return

Expand Down

0 comments on commit b03c6c9

Please sign in to comment.