Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions pyracing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,98 @@ async def season_standings(

return []

async def season_tt_standings(
self,
season_id,
race_week=1,
car_class_id=None,
club_id=None,
division=None,
result_num_low=1,
result_num_high=25,
sort=ct.Sort.champ_points.value,
order=ct.Sort.descending.value
):
""" Returns the championship point standings of a time trial series.
"""
payload = {
'seasonid': season_id,
'carclassid': car_class_id,
'clubid': club_id,
# -1 for all weeks, or the week number to get a specific week.
# 0 indexed in iRacing, so the user passes the week number and we
# subtract one to get the 0 indexed position
'raceweek': race_week if race_week == -1 else race_week - 1,
'division': division,
'start': result_num_low,
'end': result_num_high,
'sort': sort,
'order': order
}

url = ct.URL_SEASON_TT_STANDINGS
response = await self._build_request(url, payload)

if response.json():
mapping = response.json().get('m')
response_data = response.json().get('d')

if mapping and response_data:
response_items = response_data.get('r')

if response_items:
renamed_items = [self._rename_numerical_keys(ri, mapping) for ri in response_items]

return [historical_data.SeasonTTStandings(x) for x in renamed_items if x]

return []

async def season_tt_results(
self,
season_id,
race_week=1,
car_class_id=None,
club_id=None,
division=None,
result_num_low=1,
result_num_high=25,
sort=ct.Sort.champ_points.value,
order=ct.Sort.descending.value
):
""" Returns the championship point standings of a time trial series.
"""
payload = {
'seasonid': season_id,
'carclassid': car_class_id,
'clubid': club_id,
# -1 for all weeks, or the week number to get a specific week.
# 0 indexed in iRacing, so the user passes the week number and we
# subtract one to get the 0 indexed position
'raceweek': race_week if race_week == -1 else race_week - 1,
'division': division,
'start': result_num_low,
'end': result_num_high,
'sort': sort,
'order': order
}

url = ct.URL_SEASON_TT_RESULTS
response = await self._build_request(url, payload)

if response.json():
mapping = response.json().get('m')
response_data = response.json().get('d')

if mapping and response_data:
response_items = response_data.get('r')

if response_items:
renamed_items = [self._rename_numerical_keys(ri, mapping) for ri in response_items]

return [historical_data.SeasonTTResults(x) for x in renamed_items if x]

return []

async def series_race_results(self, season_id, race_week=1):
""" Returns the race results for a season_id. race_week can be
specified to reduce the size of data returned.
Expand Down
2 changes: 2 additions & 0 deletions pyracing/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
URL_CURRENT_SEASONS = (mSite + '/GetSeasons')
URL_SEASON_STANDINGS = (mStats + '/GetSeasonStandings')
URL_SERIES_RACERESULTS = (mStats + '/GetSeriesRaceResults')
URL_SEASON_TT_STANDINGS = (mStats + '/GetSeasonTTStandings')
URL_SEASON_TT_RESULTS = (mStats + '/GetSeasonTTResults')

# RECENT HISTORICAL
URL_LASTRACE_STATS = (mStats + '/GetLastRacesStats')
Expand Down
49 changes: 49 additions & 0 deletions pyracing/response_objects/historical_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,55 @@ def __init__(self, data):
# self.custrow = dict['custrow']
# self.rowcount = dict['rowcount']

class SeasonTTStandings:
def __init__(self, data):
self.club_id = data['clubid']
self.club_name = parse_encode(data['clubname'])
self.cust_id = data['custid']
self.display_name = parse_encode(data['displayname'])
self.division = data['division']
self.dropped = data['dropped']
self.helm_color_1 = data['helmcolor1']
self.helm_color_2 = data['helmcolor2']
self.helm_color_3 = data['helmcolor3']
self.helm_pattern = data['helmpattern']
self.license_level_max = data['maxlicenselevel']
self.points = data['points']
self.pos = data['pos']
self.rank = data['rank']
self.row = data['rn']
self.starts = data['starts']
self.sub_level = parse_encode(data['sublevel'])
self.week = data['week']
self.wins = data['wins']

# Used only on webpage to highlight the member in relaton to others
# self.custrow = dict['custrow']
# self.rowcount = dict['rowcount']

class SeasonTTResults:
def __init__(self, data):
self.club_id = data['clubid']
self.cust_id = data['custid']
self.display_name = parse_encode(data['displayname'])
self.division = data['division']
self.helm_color_1 = data['helmcolor1']
self.helm_color_2 = data['helmcolor2']
self.helm_color_3 = data['helmcolor3']
self.helm_pattern = data['helmpattern']
self.license_level_max = data['maxlicenselevel']
self.points = data['points']
self.pos = data['pos']
self.rank = data['rank']
self.row = data['rn']
self.starts = data['starts']
self.sub_level = parse_encode(data['sublevel'])
self.best_time_formatted = data['besttimeformatted']
self.best_time = data['besttime']

# Used only on webpage to highlight the member in relaton to others
# self.custrow = dict['custrow']
# self.rowcount = dict['rowcount']

class DriverStats:
def __init__(self, data):
Expand Down