Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v8.1.0 #563

Merged
merged 11 commits into from
Nov 6, 2024
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion colors/teams.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
"b": 64
}
},
"oak": {
"ath": {
"home": {
"r": 2,
"g": 70,
Expand Down
13 changes: 7 additions & 6 deletions data/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import statsapi

import debug
from data import teams
from data.update import UpdateStatus
from data.delay_buffer import CircularQueue

Expand Down Expand Up @@ -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 {}

Expand All @@ -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"]
Expand Down
17 changes: 7 additions & 10 deletions data/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,17 +75,14 @@ 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:
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)
Expand Down Expand Up @@ -131,12 +128,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
)
Expand All @@ -158,5 +155,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))
19 changes: 9 additions & 10 deletions data/standings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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} ---|
Expand All @@ -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}"
169 changes: 103 additions & 66 deletions data/teams.py
Original file line number Diff line number Diff line change
@@ -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: "ATH",
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,
}
Loading
Loading