From 4d91b861a38aa1e08ef1e458a3a29cc1be321767 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Tue, 3 Sep 2024 19:05:00 -0400 Subject: [PATCH 1/6] Allow better name customization --- data/game.py | 13 +-- data/schedule.py | 12 +-- data/standings.py | 19 ++-- data/teams.py | 169 +++++++++++++++++++++------------- tests/test_data_up_to_date.py | 12 ++- 5 files changed, 133 insertions(+), 92 deletions(-) diff --git a/data/game.py b/data/game.py index 9996bec4..b1311e44 100644 --- a/data/game.py +++ b/data/game.py @@ -5,6 +5,7 @@ import statsapi import debug +from data import teams from data.update import UpdateStatus from data.delay_buffer import CircularQueue @@ -84,14 +85,14 @@ def current_delay(self): return (len(self._data_wait_queue) - 1) * GAME_UPDATE_RATE def home_name(self): - return self._current_data["gameData"]["teams"]["home"]["teamName"] + return teams.TEAM_ID_NAME[self._current_data["gameData"]["teams"]["home"]["id"]] def home_abbreviation(self): - return self._current_data["gameData"]["teams"]["home"]["abbreviation"] - + return teams.TEAM_ID_ABBR[self._current_data["gameData"]["teams"]["home"]["id"]] + def home_record(self): return self._current_data["gameData"]["teams"]["home"]["record"] or {} - + def away_record(self): return self._current_data["gameData"]["teams"]["away"]["record"] or {} @@ -111,10 +112,10 @@ def pregame_weather(self): return wx def away_name(self): - return self._current_data["gameData"]["teams"]["away"]["teamName"] + return teams.TEAM_ID_NAME[self._current_data["gameData"]["teams"]["away"]["id"]] def away_abbreviation(self): - return self._current_data["gameData"]["teams"]["away"]["abbreviation"] + return teams.TEAM_ID_ABBR[self._current_data["gameData"]["teams"]["away"]["id"]] def status(self): return self._status["detailedState"] diff --git a/data/schedule.py b/data/schedule.py index 194e0f45..2e48ba21 100644 --- a/data/schedule.py +++ b/data/schedule.py @@ -58,7 +58,7 @@ def update(self, force=False) -> UpdateStatus: # but this is fine, since self.games_live() is will work even if we don't do this update games = live_games - if len(games) > 0: + if len(games) > 0: self.current_idx %= len(games) self._games = games @@ -75,7 +75,7 @@ def __should_update(self): def is_offday_for_preferred_team(self): if self.config.preferred_teams: return not any( - data.teams.TEAM_FULL[self.config.preferred_teams[0]] in [game["away_name"], game["home_name"]] + data.teams.TEAM_NAME_ID[self.config.preferred_teams[0]] in [game["away_id"], game["home_id"]] for game in self.__all_games # only care if preferred team is actually in list ) else: @@ -131,12 +131,12 @@ def next_game(self): def _game_index_for_preferred_team(self): if self.config.preferred_teams: - team_name = data.teams.TEAM_FULL[self.config.preferred_teams[0]] + team_id = data.teams.TEAM_NAME_ID[self.config.preferred_teams[0]] return next( ( i for i, game in enumerate(self._games) - if team_name in [game["away_name"], game["home_name"]] and status.is_live(game["status"]) + if team_id in [game["away_id"], game["home_id"]] and status.is_live(game["status"]) ), -1, # no live games for preferred team ) @@ -158,5 +158,5 @@ def __current_game(self): @staticmethod def __filter_list_of_games(games, filter_teams): - teams = [data.teams.TEAM_FULL[t] for t in filter_teams] - return list(game for game in games if set([game["away_name"], game["home_name"]]).intersection(set(teams))) + teams = set(data.teams.TEAM_NAME_ID[t] for t in filter_teams) + return list(game for game in games if set([game["away_id"], game["home_id"]]).intersection(teams)) diff --git a/data/standings.py b/data/standings.py index 5d017b2c..14e4de26 100644 --- a/data/standings.py +++ b/data/standings.py @@ -11,7 +11,7 @@ API_FIELDS = ( - "records,standingsType,teamRecords,team,abbreviation,division,league,nameShort,gamesBack,wildCardGamesBack," + "records,standingsType,teamRecords,team,id,abbreviation,division,league,nameShort,gamesBack,wildCardGamesBack," "wildCardEliminationNumber,clinched,wins,losses" ) @@ -131,7 +131,7 @@ def __init__(self, data, wc=False): class Team: def __init__(self, data, wc): - self.team_abbrev = data["team"]["abbreviation"] + self.team_abbrev = teams.TEAM_ID_ABBR[data["team"]["id"]] self.w = data["wins"] self.l = data["losses"] # noqa: E741 if wc: @@ -183,9 +183,9 @@ def get_series_winner(self, data, ID): else: champ = "TBD" if game["teams"]["home"].get("isWinner"): - champ = League.get_abbr(game["teams"]["home"]["team"]["name"]) + champ = get_abbr(game["teams"]["home"]["team"]["id"]) elif game["teams"]["away"].get("isWinner"): - champ = League.get_abbr(game["teams"]["away"]["team"]["name"]) + champ = get_abbr(game["teams"]["away"]["team"]["id"]) return champ @staticmethod @@ -196,11 +196,11 @@ def get_seeds(data, ID): if s["series"]["id"] == ID ) higher, lower = ( - series["games"][0]["teams"]["home"]["team"]["name"], - series["games"][0]["teams"]["away"]["team"]["name"], + series["games"][0]["teams"]["home"]["team"]["id"], + series["games"][0]["teams"]["away"]["team"]["id"], ) - return (League.get_abbr(higher), League.get_abbr(lower)) + return (get_abbr(higher), get_abbr(lower)) def __str__(self): return f"""{self.wc5} ---| @@ -214,6 +214,5 @@ def __str__(self): """ - @staticmethod - def get_abbr(name, default="TBD"): - return f"{teams.TEAM_ABBR_LN.get(name, default):>3}" +def get_abbr(id, default="TBD"): + return f"{teams.TEAM_ID_ABBR.get(id, default):>3}" diff --git a/data/teams.py b/data/teams.py index 8dde88de..a0122483 100644 --- a/data/teams.py +++ b/data/teams.py @@ -1,72 +1,109 @@ # the following were created like so # import statsapi -# teams = statsapi.get('teams', {'sportIds':1})['teams'] -# -# TEAM_FULL = {t['teamName']:t['name'] for t in teams} -# TEAM_ABBR_LN = {t['name']:t['abbreviation'] for t in teams} +# _teams = statsapi.get('teams', {'sportIds':1})['teams'] +# TEAM_ID_ABBR = {t["id"]: t["abbreviation"] for t in _teams} +# TEAM_ID_NAME = {t["id"]: t["teamName"] for t in _teams} +# TEAM_NAME_ID = {t["teamName"]: t["id"] for t in _teams} -TEAM_FULL = { - "Athletics": "Oakland Athletics", - "Pirates": "Pittsburgh Pirates", - "Padres": "San Diego Padres", - "Mariners": "Seattle Mariners", - "Giants": "San Francisco Giants", - "Cardinals": "St. Louis Cardinals", - "Rays": "Tampa Bay Rays", - "Rangers": "Texas Rangers", - "Blue Jays": "Toronto Blue Jays", - "Twins": "Minnesota Twins", - "Phillies": "Philadelphia Phillies", - "Braves": "Atlanta Braves", - "White Sox": "Chicago White Sox", - "Marlins": "Miami Marlins", - "Yankees": "New York Yankees", - "Brewers": "Milwaukee Brewers", - "Angels": "Los Angeles Angels", - "D-backs": "Arizona Diamondbacks", - "Orioles": "Baltimore Orioles", - "Red Sox": "Boston Red Sox", - "Cubs": "Chicago Cubs", - "Reds": "Cincinnati Reds", - "Guardians": "Cleveland Guardians", - "Rockies": "Colorado Rockies", - "Tigers": "Detroit Tigers", - "Astros": "Houston Astros", - "Royals": "Kansas City Royals", - "Dodgers": "Los Angeles Dodgers", - "Nationals": "Washington Nationals", - "Mets": "New York Mets", +# Can be customized, but will require changing in colors/teams.json as well +TEAM_ID_ABBR = { + 133: "OAK", + 134: "PIT", + 135: "SD", + 136: "SEA", + 137: "SF", + 138: "STL", + 139: "TB", + 140: "TEX", + 141: "TOR", + 142: "MIN", + 143: "PHI", + 144: "ATL", + 145: "CWS", + 146: "MIA", + 147: "NYY", + 158: "MIL", + 108: "LAA", + 109: "AZ", + 110: "BAL", + 111: "BOS", + 112: "CHC", + 113: "CIN", + 114: "CLE", + 115: "COL", + 116: "DET", + 117: "HOU", + 118: "KC", + 119: "LAD", + 120: "WSH", + 121: "NYM", } -TEAM_ABBR_LN = { - "Oakland Athletics": "OAK", - "Pittsburgh Pirates": "PIT", - "San Diego Padres": "SD", - "Seattle Mariners": "SEA", - "San Francisco Giants": "SF", - "St. Louis Cardinals": "STL", - "Tampa Bay Rays": "TB", - "Texas Rangers": "TEX", - "Toronto Blue Jays": "TOR", - "Minnesota Twins": "MIN", - "Philadelphia Phillies": "PHI", - "Atlanta Braves": "ATL", - "Chicago White Sox": "CWS", - "Miami Marlins": "MIA", - "New York Yankees": "NYY", - "Milwaukee Brewers": "MIL", - "Los Angeles Angels": "LAA", - "Arizona Diamondbacks": "AZ", - "Baltimore Orioles": "BAL", - "Boston Red Sox": "BOS", - "Chicago Cubs": "CHC", - "Cincinnati Reds": "CIN", - "Cleveland Guardians": "CLE", - "Colorado Rockies": "COL", - "Detroit Tigers": "DET", - "Houston Astros": "HOU", - "Kansas City Royals": "KC", - "Los Angeles Dodgers": "LAD", - "Washington Nationals": "WSH", - "New York Mets": "NYM", +# Can be customized +TEAM_ID_NAME = { + 133: "Athletics", + 134: "Pirates", + 135: "Padres", + 136: "Mariners", + 137: "Giants", + 138: "Cardinals", + 139: "Rays", + 140: "Rangers", + 141: "Blue Jays", + 142: "Twins", + 143: "Phillies", + 144: "Braves", + 145: "White Sox", + 146: "Marlins", + 147: "Yankees", + 158: "Brewers", + 108: "Angels", + 109: "D-backs", + 110: "Orioles", + 111: "Red Sox", + 112: "Cubs", + 113: "Reds", + 114: "Guardians", + 115: "Rockies", + 116: "Tigers", + 117: "Astros", + 118: "Royals", + 119: "Dodgers", + 120: "Nationals", + 121: "Mets", +} + + +# Can be customized, but names in the config.json file must match +TEAM_NAME_ID = { + "Athletics": 133, + "Pirates": 134, + "Padres": 135, + "Mariners": 136, + "Giants": 137, + "Cardinals": 138, + "Rays": 139, + "Rangers": 140, + "Blue Jays": 141, + "Twins": 142, + "Phillies": 143, + "Braves": 144, + "White Sox": 145, + "Marlins": 146, + "Yankees": 147, + "Brewers": 158, + "Angels": 108, + "D-backs": 109, + "Orioles": 110, + "Red Sox": 111, + "Cubs": 112, + "Reds": 113, + "Guardians": 114, + "Rockies": 115, + "Tigers": 116, + "Astros": 117, + "Royals": 118, + "Dodgers": 119, + "Nationals": 120, + "Mets": 121, } diff --git a/tests/test_data_up_to_date.py b/tests/test_data_up_to_date.py index 64e8b4c8..a5fa39ec 100644 --- a/tests/test_data_up_to_date.py +++ b/tests/test_data_up_to_date.py @@ -19,10 +19,14 @@ def test_status_complete(self): def test_teams_complete(self): teams = statsapi.get("teams", {"sportIds": 1})["teams"] - abbr_to_full = {t["teamName"]: t["name"] for t in teams} - self.assertEqual(abbr_to_full, data.teams.TEAM_FULL) - full_to_abbr = {t["name"]: t["abbreviation"] for t in teams} - self.assertEqual(full_to_abbr, data.teams.TEAM_ABBR_LN) + id_to_abbr = {t["id"]: t["abbreviation"] for t in teams} + self.assertEqual(id_to_abbr, data.teams.TEAM_ID_ABBR) + + id_to_name = {t["id"]: t["teamName"] for t in teams} + self.assertEqual(id_to_name, data.teams.TEAM_ID_NAME) + + name_to_id = {t["teamName"]: t["id"] for t in teams} + self.assertEqual(name_to_id, data.teams.TEAM_NAME_ID) def test_pitches_complete(self): pitches = set(p["code"] for p in statsapi.meta("pitchTypes")) From 393afb7c8dd6ba9ad376ea5c89c5b95ff036ff12 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Mon, 7 Oct 2024 11:44:24 -0400 Subject: [PATCH 2/6] Fix offday calculation --- data/schedule.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/data/schedule.py b/data/schedule.py index 194e0f45..45c2cfff 100644 --- a/data/schedule.py +++ b/data/schedule.py @@ -82,10 +82,7 @@ def is_offday_for_preferred_team(self): return True def is_offday(self): - if self.config.standings_no_games: - return not len(self.__all_games) # care about all MLB - else: # only care if we can't rotate a game - return not len(self._games) + return not len(self.__all_games) # care about all MLB def games_live(self): return any(status.is_fresh(g["status"]) or (status.is_live(g["status"])) for g in self._games) From 05d7965fa8d0ab39b3cba747b4896a5f093be7e9 Mon Sep 17 00:00:00 2001 From: Tyler Porter Date: Mon, 4 Nov 2024 11:56:24 -0500 Subject: [PATCH 3/6] Athletics leave Oakland --- data/teams.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/teams.py b/data/teams.py index 8dde88de..3f81a9d4 100644 --- a/data/teams.py +++ b/data/teams.py @@ -6,7 +6,7 @@ # TEAM_ABBR_LN = {t['name']:t['abbreviation'] for t in teams} TEAM_FULL = { - "Athletics": "Oakland Athletics", + "Athletics": "Athletics", "Pirates": "Pittsburgh Pirates", "Padres": "San Diego Padres", "Mariners": "Seattle Mariners", @@ -39,7 +39,7 @@ } TEAM_ABBR_LN = { - "Oakland Athletics": "OAK", + "Athletics": "ATH", "Pittsburgh Pirates": "PIT", "San Diego Padres": "SD", "Seattle Mariners": "SEA", From 04339a9b0d3d1a710274a7fcbde5ab033ad5d81d Mon Sep 17 00:00:00 2001 From: Tyler Porter Date: Sun, 3 Nov 2024 21:22:21 -0500 Subject: [PATCH 4/6] Allow selection of driver version and set 14ab2ff as current default Make the driver version a cmd line flag instead of config Update README driver text Actually do the checkout --- README.md | 27 +++++++++++++++------------ install.sh | 55 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 94b8f16a..26a8a7a4 100755 --- a/README.md +++ b/README.md @@ -135,26 +135,29 @@ It will also install the following python libraries that are required for certai * [MLB-StatsAPI](https://pypi.org/project/MLB-StatsAPI/): The main library that fetches and parses all of the actual MLB data being displayed * [RGBMatrixEmulator](https://github.com/ty-porter/RGBMatrixEmulator): The emulation library for the matrix display. Useful for running on MacOS or Linux, or for development. -#### Installation on Non-Raspberry Pi Hardware +#### Customizing the Installation -The installation script is designed for physical hardware. When attempting to install it on other platforms, you should not use `sudo` to install the dependencies. In addition, you can pass the `--emulator-only` argument to skip installation steps that aren't required. +Additional flags are available for customizing your install: ``` -sh install.sh --emulator-only -``` +-a, --skip-all Skip all dependencies and config installation (equivalent to -c -p -m). +-c, --skip-config Skip updating JSON configuration files. +-m, --skip-matrix Skip building matrix driver dependency. Video display will default to emulator mode. +-p, --skip-python Skip Python 3 installation. Requires manual Python 3 setup if not already installed. -Additional flags are available for customizing your install: +-v, --no-venv Do not create a virtual environment for the dependencies. +-e, --emulator-only Do not install dependencies under sudo. Skips building matrix dependencies (equivalent to -m) +-d, --driver Specify a branch name or commit SHA for the rpi-rgb-led-matrix library. (Optional. Defaults may change.) +-h, --help Display this help message ``` --p, --skip-python Skips Python 3 installation. You will need to install it via your platform's appropriate package manager. --m, --skip-matrix Skips RPI-specific matrix driver installation and build. --c, --skip-config Skips default config overwrite without prompting. --a, --skip-all Performs all above skips. ---no-venv Do not create a virtual environment for the dependencies. ---emulator-only Do not install dependencies under sudo. Skips building matrix dependencies. +#### Installation on Non-Raspberry Pi Hardware + +The installation script is designed for physical hardware. When attempting to install it on other platforms, you should not use `sudo` to install the dependencies. In addition, you can pass the `--emulator-only` argument to skip installation steps that aren't required. --h, --help Displays help +``` +sh install.sh --emulator-only ``` #### Updating diff --git a/install.sh b/install.sh index b9563b98..d442221b 100755 --- a/install.sh +++ b/install.sh @@ -1,58 +1,65 @@ #!/bin/bash +SKIP_PYTHON=false +SKIP_CONFIG=false +SKIP_MATRIX=false +NO_SUDO=false +SKIP_VENV=false +DRIVER_SHA=14ab2ff + usage() { cat < Date: Mon, 4 Nov 2024 12:01:13 -0500 Subject: [PATCH 5/6] Bump version --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 3f68b6da..36d9a3a7 100644 --- a/version.py +++ b/version.py @@ -1,5 +1,5 @@ SCRIPT_NAME = "MLB LED Scoreboard" -SCRIPT_VERSION = "8.0.2" +SCRIPT_VERSION = "8.1.0" if __name__ == "__main__": From 583d3ba5d31586af9ca444b8c4ff3fa698e84228 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Tue, 5 Nov 2024 12:02:57 -0500 Subject: [PATCH 6/6] Update colors/teams.json --- colors/teams.json.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colors/teams.json.example b/colors/teams.json.example index 8ed4648c..32f20c3e 100644 --- a/colors/teams.json.example +++ b/colors/teams.json.example @@ -272,7 +272,7 @@ "b": 64 } }, - "oak": { + "ath": { "home": { "r": 2, "g": 70,