Skip to content

Commit

Permalink
pattern changes and tests for relays
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Robinson committed Jun 18, 2024
1 parent edd00d9 commit 02bd41c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions athlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def get_distance(discipline: str) -> Optional[int]:
"""

# Ignore final words like ' road'

discipline = discipline.split()[0]
if discipline == "XC":
return None
Expand All @@ -129,7 +128,9 @@ def get_distance(discipline: str) -> Optional[int]:
g2 = m.group(2).upper()
if g2 in ['RELAY', 'DMR', 'SMR']: return None #cowardly refusing to guess
if g2 == "SWR": return 1000
return int(m.group(1))*int(g2.rstrip('hH'))


return int(m.group(1)) * get_distance(g2)

m = PAT_LEADING_FLOAT.match(discipline)
if not m:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ def test_get_distance(self):
self.assertEqual(get_distance("3KW"), 3000)
self.assertEqual(get_distance("3kmW"), 3000)
self.assertEqual(get_distance("T26"), None)

self.assertEqual(get_distance("4xRELAY"), None)
self.assertEqual(get_distance("4xDMR"), None)
self.assertEqual(get_distance("4xSMR"), None)
self.assertEqual(get_distance("4xSWR"), 1000)

self.assertEqual(get_distance("6x5000"), 30000)
self.assertEqual(get_distance("6x5K"), 30000)
self.assertEqual(get_distance("6x3M"), 6 * 3 * 1609)



def test_get_duration_event_time(self):
"Extract seconds from duration event code"
from athlib.utils import get_duration_event_time
Expand Down Expand Up @@ -322,6 +329,7 @@ def test_event_codes_match_correctly(self):
('6x5000', PAT_RELAYS),
('6x5K', PAT_RELAYS),
('3x3M', PAT_RELAYS),
('10x12K', PAT_RELAYS),

('5K',PAT_ROAD),
('5M',PAT_ROAD),
Expand Down

0 comments on commit 02bd41c

Please sign in to comment.