@@ -149,16 +149,6 @@ def parse_schedule_page(url, sport, gender):
149149 for event in game_data ["box_score" ]:
150150 if "cor_score" in event and "opp_score" in event :
151151 event ["cor_score" ], event ["opp_score" ] = event ["opp_score" ], event ["cor_score" ]
152-
153- if sport == "Ice Hockey" :
154- location_data = game_data ["location" ].split ("\n " ) if game_data ["location" ] else ["" ]
155- geo_location = location_data [0 ]
156- is_home_game = "Ithaca" in geo_location
157-
158- if not is_home_game and game_data ["box_score" ]:
159- for event in game_data ["box_score" ]:
160- if "cor_score" in event and "opp_score" in event :
161- event ["cor_score" ], event ["opp_score" ] = event ["opp_score" ], event ["cor_score" ]
162152
163153 else :
164154 game_data ["box_score" ] = None
@@ -220,6 +210,27 @@ def process_game_data(game_data):
220210 if game_data ["score_breakdown" ] and is_home_game :
221211 game_data ["score_breakdown" ] = game_data ["score_breakdown" ][::- 1 ]
222212
213+ # consistency check for ice hockey, since can be randomly ordered
214+ if game_data ["sport" ] == "Ice Hockey" and game_data ["score_breakdown" ] and game_data ["box_score" ]:
215+ # Get final scores from box score
216+ final_box_cor_score = None
217+ final_box_opp_score = None
218+ for event in reversed (game_data ["box_score" ]):
219+ if "cor_score" in event and "opp_score" in event :
220+ final_box_cor_score = event ["cor_score" ]
221+ final_box_opp_score = event ["opp_score" ]
222+ break
223+
224+ # Compare with score breakdown
225+ if final_box_cor_score and len (game_data ["score_breakdown" ]) >= 2 :
226+ cor_final = game_data ["score_breakdown" ][0 ][- 1 ]
227+ opp_final = game_data ["score_breakdown" ][1 ][- 1 ]
228+
229+ # If they don't match, flip the arrays
230+ if str (final_box_cor_score ) != str (cor_final ) or str (final_box_opp_score ) != str (opp_final ):
231+ print ("flipping" )
232+ game_data ["score_breakdown" ] = game_data ["score_breakdown" ][::- 1 ]
233+
223234 # finds any existing game with the same key fields regardless of time
224235 curr_game = GameService .get_game_by_key_fields (
225236 city ,
0 commit comments