| 1 |  |  | from dataclasses import dataclass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | from datetime import datetime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | from typing import Any, List | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | import pytz | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | from models import ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     from_bool, from_datetime, from_int, from_list, from_none, from_str, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     from_union | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | @dataclass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class Racer: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     racer_id: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     RacerName: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     @staticmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     def from_dict(obj: Any) -> 'Racer': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         if not isinstance(obj, dict): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             return None | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         racer_id = from_int(obj.get("racer_id")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         RacerName = from_str(obj.get("RacerName")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         return Racer(racer_id=racer_id, RacerName=RacerName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | def racers_from_dict(s: Any) -> List[Racer]: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     assert isinstance(s, List) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     if not s: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         return [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     return from_union( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         [lambda x: from_list(Racer.from_dict, x), from_none], s | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | @dataclass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | class Flag: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     Mode: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     flag_id: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     HoursToComplete: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     @staticmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     def from_dict(obj: Any) -> 'Flag': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         if not isinstance(obj, dict): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             return None | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         Mode = from_str(obj.get("Mode")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         flag_id = from_int(obj.get("flag_id")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         HoursToComplete = from_int(obj.get("HoursToComplete")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return Flag( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             Mode=Mode, flag_id=flag_id, HoursToComplete=HoursToComplete) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | def flags_from_dict(s: Any) -> List[Flag]: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     assert isinstance(s, List) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     if not s: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     return from_union( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         [lambda x: from_list(Flag.from_dict, x), from_none], s | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | @dataclass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | class Season: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     season_id: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     SeasonName: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     IsCurrentSeason: bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     @staticmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     def from_dict(obj: Any) -> 'Season': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         if not isinstance(obj, dict): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             return None | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         season_id = from_int(obj.get("season_id")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         SeasonName = from_str(obj.get("SeasonName")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         IsCurrentSeason = from_bool(obj.get("IsCurrentSeason")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         return Season( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             season_id=season_id, SeasonName=SeasonName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             IsCurrentSeason=IsCurrentSeason | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | def seasons_from_dict(s: Any) -> List[Season]: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     assert isinstance(s, List) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     if not s: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         return [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     return from_union( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         [lambda x: from_list(Season.from_dict, x), from_none], s | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | @dataclass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | class Standings: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     RacerName: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     Season: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     Mode: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     Rating: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     Rank: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     Change: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     Wins: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     Losses: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     Ties: int | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |     @staticmethod | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |     def from_dict(obj: Any) -> 'Standings': | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |         if not isinstance(obj, dict): | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |             return None | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |         RacerName = from_str(obj.get("RacerName")) | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |         Season = from_str(obj.get("Season")) | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |         Mode = from_str(obj.get("Mode")) | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |         Rating = from_int(obj.get("Rating")) | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |         Rank = from_int(obj.get("Rank")) | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |         Change = from_int(obj.get("Change")) | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |         Wins = from_int(obj.get("Wins")) | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |         Losses = from_int(obj.get("Losses")) | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |         Ties = from_int(obj.get("Ties")) | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |         return Standings( | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |             RacerName=RacerName, Season=Season, Mode=Mode, Rating=Rating, | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |             Rank=Rank, Change=Change, Wins=Wins, Losses=Losses, Ties=Ties) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | def standings_from_dict(s: Any) -> List[Standings]: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     assert isinstance(s, List) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     if not s: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         return [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     return from_union( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         [lambda x: from_list(Standings.from_dict, x), from_none], s | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | @dataclass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | class RacerResult: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     RacerName: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     OpponentRacerName: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     Mode: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     race_id: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     Season: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     Result: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     FinishTime: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     OpponentFinishTime: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     def from_dict(obj: Any) -> 'RacerResult': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         if not isinstance(obj, dict): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             return None | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         RacerName = from_str(obj.get("RacerName")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         OpponentRacerName = from_str(obj.get("OpponentRacerName")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         Mode = from_str(obj.get("Mode")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         race_id = from_int(obj.get("race_id")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         Season = from_str(obj.get("Season")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         Result = from_str(obj.get("Result")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         FinishTime = from_str(obj.get("FinishTime")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         OpponentFinishTime = from_str(obj.get("OpponentFinishTime")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         return RacerResult( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             RacerName=RacerName, OpponentRacerName=OpponentRacerName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             Mode=Mode, race_id=race_id, Season=Season, Result=Result, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             FinishTime=FinishTime, OpponentFinishTime=OpponentFinishTime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | def racer_results_from_dict(s: Any) -> List[RacerResult]: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     assert isinstance(s, List) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     if not s: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         return [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     return from_union( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         [lambda x: from_list(RacerResult.from_dict, x), from_none], s | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | @dataclass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | class ScheduleItem: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     race_id: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     Season: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     Mode: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     StartTime: datetime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     RaceName: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     HasCompleted: bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     ParticipantCount: int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     @staticmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     def from_dict(obj: Any) -> 'Standings': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         if not isinstance(obj, dict): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |             return None | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         race_id = from_int(obj.get("race_id")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         Season = from_str(obj.get("Season")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         Mode = from_str(obj.get("Mode")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         StartTime = (pytz.timezone('US/Eastern').localize( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |                 from_datetime(obj.get("StartTime")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |             )) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         RaceName = from_str(obj.get("RaceName")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         HasCompleted = from_bool(obj.get("HasCompleted")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         ParticipantCount = from_int(obj.get("ParticipantCount")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         return ScheduleItem( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |             race_id=race_id, Season=Season, Mode=Mode, StartTime=StartTime, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |             RaceName=RaceName, HasCompleted=HasCompleted, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             ParticipantCount=ParticipantCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | def schedule_from_dict(s: Any) -> List[ScheduleItem]: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |     assert isinstance(s, List) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     if not s: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         return [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |     return from_union( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         [lambda x: from_list(ScheduleItem.from_dict, x), from_none], s | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 202 |  |  |     ) | 
            
                                                        
            
                                    
            
            
                | 203 |  |  |  |