Skip to content

Commit

Permalink
added age grade interpolation for running events
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Robinson committed Jul 30, 2024
1 parent d9650cf commit 00d3c70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion athlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def get_distance(discipline: str) -> Optional[int]:
return int(1000 * qty)
elif remains.lower() in ('kw', 'kmw'):
return int(1000 * qty)
elif remains in ('M', 'Mi', 'MI'):
elif remains in ('M', 'Mi', 'MI', 'MT'): # MT = Mile Track in latest factors
return int(1609 * qty)
elif remains in ('Y', 'y', 'YD', 'yd'):
return int(0.9144 * qty)
Expand Down
17 changes: 14 additions & 3 deletions athlib/wma/agegrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,35 @@ def calculate_factor(self, gender, age, event):
except ValueError:
# parse event code and get distance
distance = get_distance(event)
# print("finding row by distance %s" % distance)
self.find_row_by_distance(distance,
table,
label='wma.%s' % (gender))
# we have rows above and below.
event_shorter = table[self._fx][0]
event_longer = table[self._fx1][0]
# print(f"Longer = {event_longer}")
# print(f"Shorter = {event_shorter}")
factor_shorter = self.calculate_factor(gender, age, event_shorter)
distance_shorter = get_distance(event_shorter)

factor_longer = self.calculate_factor(gender, age, event_longer)
distance_longer = get_distance(event_longer)

# fraction between longer and shorter
frac = (distance - distance_shorter) / (distance_longer - distance_shorter)
# print(f"d={distance}, ds={distance_shorter}, dl={distance_longer}")


if distance_shorter is None: # really short sprint,
return factor_longer

if distance_longer is None: # more than 200 miles
return factor_shorter

frac = distance - distance_shorter
frac = frac / (distance_longer - distance_shorter)
factor_interpolated = ((1 - frac) * factor_shorter) + (frac * factor_longer)
return factor_interpolated


# for a known event, is all this interpolation of ages and distances needed?
# AR 2024

Expand Down

0 comments on commit 00d3c70

Please sign in to comment.