refactor: rename functions across codebase for clarity
This commit is contained in:
24
app/games.py
24
app/games.py
@@ -7,7 +7,7 @@ from app.config import DB_PATH
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def process_record(record):
|
||||
def format_record(record):
|
||||
if record == "N/A":
|
||||
return "N/A"
|
||||
else:
|
||||
@@ -16,7 +16,7 @@ def process_record(record):
|
||||
return "-".join(formatted_parts)
|
||||
|
||||
|
||||
def extract_game_info(scoreboard_data):
|
||||
def parse_games(scoreboard_data):
|
||||
if not scoreboard_data:
|
||||
return []
|
||||
|
||||
@@ -36,8 +36,8 @@ def extract_game_info(scoreboard_data):
|
||||
"Home Logo": game["homeTeam"]["logo"],
|
||||
"Away Logo": game["awayTeam"]["logo"],
|
||||
"Game State": game_state,
|
||||
"Period": process_period(game),
|
||||
"Time Remaining": process_time_remaining(game),
|
||||
"Period": get_period(game),
|
||||
"Time Remaining": get_time_remaining(game),
|
||||
"Time Running": game["clock"]["running"]
|
||||
if game_state == "LIVE"
|
||||
else "N/A",
|
||||
@@ -45,11 +45,11 @@ def extract_game_info(scoreboard_data):
|
||||
if game_state == "LIVE"
|
||||
else "N/A",
|
||||
"Priority": calculate_game_priority(game),
|
||||
"Start Time": process_start_time(game),
|
||||
"Home Record": process_record(game["homeTeam"]["record"])
|
||||
"Start Time": get_start_time(game),
|
||||
"Home Record": format_record(game["homeTeam"]["record"])
|
||||
if game["gameState"] in ["PRE", "FUT"]
|
||||
else "N/A",
|
||||
"Away Record": process_record(game["awayTeam"]["record"])
|
||||
"Away Record": format_record(game["awayTeam"]["record"])
|
||||
if game["gameState"] in ["PRE", "FUT"]
|
||||
else "N/A",
|
||||
"Home Shots": game["homeTeam"]["sog"]
|
||||
@@ -77,7 +77,7 @@ def convert_game_state(game_state):
|
||||
return state_mapping.get(game_state, game_state)
|
||||
|
||||
|
||||
def process_period(game):
|
||||
def get_period(game):
|
||||
if game["gameState"] in ["PRE", "FUT"]:
|
||||
return 0
|
||||
elif game["gameState"] in ["FINAL", "OFF"]:
|
||||
@@ -86,7 +86,7 @@ def process_period(game):
|
||||
return game["periodDescriptor"]["number"]
|
||||
|
||||
|
||||
def process_time_remaining(game):
|
||||
def get_time_remaining(game):
|
||||
if game["gameState"] in ["PRE", "FUT"]:
|
||||
return "20:00"
|
||||
elif game["gameState"] in ["FINAL", "OFF"]:
|
||||
@@ -96,10 +96,10 @@ def process_time_remaining(game):
|
||||
return "END" if time_remaining == "00:00" else time_remaining
|
||||
|
||||
|
||||
def process_start_time(game):
|
||||
def get_start_time(game):
|
||||
if game["gameState"] in ["PRE", "FUT"]:
|
||||
utc_time = game["startTimeUTC"]
|
||||
est_time = utc_to_est_time(utc_time)
|
||||
est_time = utc_to_eastern(utc_time)
|
||||
return est_time.lstrip("0")
|
||||
else:
|
||||
return "N/A"
|
||||
@@ -224,7 +224,7 @@ def get_team_standings(team_name):
|
||||
}
|
||||
|
||||
|
||||
def utc_to_est_time(utc_time):
|
||||
def utc_to_eastern(utc_time):
|
||||
utc_datetime = datetime.strptime(utc_time, "%Y-%m-%dT%H:%M:%SZ")
|
||||
est_offset = timedelta(hours=-4)
|
||||
est_datetime = utc_datetime + est_offset
|
||||
|
||||
Reference in New Issue
Block a user