Skip to content

Commit

Permalink
fix: split age class and club when combined together in upload file
Browse files Browse the repository at this point in the history
  • Loading branch information
brownben committed May 27, 2024
1 parent edff65a commit 9bc66b0
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions backend/src/utils/import_file/import_file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Any, Callable, Generator, Iterable, Literal, Optional, TypedDict

from ..age_class import date_to_age_class
Expand Down Expand Up @@ -114,14 +115,31 @@ def result_has_hours_but_no_seconds(result: ImportedRecord) -> bool:
return results


COMBINED_AGE_CLASS_CLUB_REGEX = re.compile(
r"[MHWFD][0-9]+ \((.*)\)", flags=re.IGNORECASE
)


def fix_combined_age_class_club(
results: list[ImportedRecord],
) -> list[ImportedRecord]:
for result in results:
if match := COMBINED_AGE_CLASS_CLUB_REGEX.match(result["club"] or ""):
result["ageClass"] = result["club"].split(" ")[0] if result["club"] else ""
result["club"] = match.group(1)

return results


def import_results(
parser: Callable[[str], Iterable[ImportedRecord]], file: str
) -> Generator[ImportedResult, None, None]:
raw_records = parser(file)
fixed_records = fix_times_from_excel(list(raw_records))
records = fix_times_from_excel(list(raw_records))
records = fix_combined_age_class_club(records)

return (
ImportedResult(result)
for result in fixed_records
for result in records
if any(value != "" for value in result.values())
)

0 comments on commit 9bc66b0

Please sign in to comment.