Skip to content

Commit

Permalink
Add rotation option if your preferred team is live but in an inning b…
Browse files Browse the repository at this point in the history
…reak (#187)

* Standings coords update (#177)

* Bump version number (#175)

* Updated standings renderer coords for a little more control

* Bump version number

* Overhauled the config file to be more readable

* Added one more scrolling speed option between the fastest and the default

* Add check that the scrolling speed is in range

* Added option to start rotating again during an inning break if your team is playing

* Added option to start rotating again during an inning break if your team is playing

* Correctly look at the first team in preferred teams

* Check preferred team's game status before rotation

* Check for offday. And move the else where it belongs

* Totally forgot I added the inning break method to Status

* Removed hard coded strings
  • Loading branch information
swemoney authored and ajbowler committed Jul 23, 2018
1 parent da104ad commit abb2f75
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ A default `config.json.example` file is included for reference. Copy this file t
"while_preferred_team_live": Options for rotating while your chosen preferred_teams is live
"enabled" Bool Rotation is enabled while your configured preferred_teams game is live.
"during_inning_breaks" Bool Rotation is enabled while your configured preferred_teams game is live during an inning break.
"end_of_day" String A 24-hour time you wish to consider the end of the previous day before starting to display the current day's games. Uses local time from your pi.
"full_team_names" Bool If true and on a 64-wide board, displays the full team name on the scoreboard instead of their abbreviation. This config option is ignored on 32-wide boards. Defaults to true when on a 64-wide board.
Expand Down
23 changes: 22 additions & 1 deletion data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pregame import Pregame
from scoreboard import Scoreboard
from status import Status
from inning import Inning
import urllib
import layout
import mlbgame
Expand Down Expand Up @@ -116,6 +117,15 @@ def refresh_overview(self):
if attempts_remaining <= 0 and self.config.rotation_enabled:
self.advance_to_next_game()

# Will use a network call to fetch the preferred team's game overview
def fetch_preferred_team_overview(self):
if not self.is_offday_for_preferred_team():
urllib.urlcleanup()
game = self.games[self.game_index_for_preferred_team()]
game_overview = mlbgame.overview(game.game_id)
debug.log("Preferred Team's Game Status: {}, {} {}".format(game_overview.status, game_overview.inning_state, game_overview.inning))
return game_overview

def __update_layout_state(self):
self.config.layout.set_state()
if self.overview.status == Status.WARMUP:
Expand Down Expand Up @@ -156,7 +166,18 @@ def current_game(self):
return self.games[self.current_game_index]

def advance_to_next_game(self):
self.current_game_index = self.__next_game_index()
# We only need to check the preferred team's game status if we're
# rotating during mid-innings
if self.config.rotation_preferred_team_live_mid_inning and not self.is_offday_for_preferred_team:
preferred_overview = self.fetch_preferred_team_overview()
if Status.is_live(preferred_overview.status) and not Status.is_inning_break(preferred_overview.inning_state):
self.current_game_index = self.game_index_for_preferred_team()
self.overview = preferred_overview
self.needs_refresh = False
self.__update_layout_state()
self.print_overview_debug()
else:
self.current_game_index = self.__next_game_index()
return self.current_game()

def game_index_for_preferred_team(self):
Expand Down
1 change: 1 addition & 0 deletions data/scoreboard_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, filename_base, width, height):
self.rotation_only_preferred = json["rotation"]["only_preferred"]
self.rotation_rates = json["rotation"]["rates"]
self.rotation_preferred_team_live_enabled = json["rotation"]["while_preferred_team_live"]["enabled"]
self.rotation_preferred_team_live_mid_inning = json["rotation"]["while_preferred_team_live"]["during_inning_breaks"]

# Misc config options
self.end_of_day = json["end_of_day"]
Expand Down
7 changes: 7 additions & 0 deletions data/status.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from inning import Inning

class Status:
CANCELLED = 'Cancelled'
COMPLETED_EARLY = 'Completed Early'
Expand Down Expand Up @@ -46,3 +48,8 @@ def is_fresh(status):
comes between In Progress and Final and allows a few minutes to see the final outcome before
the rotation kicks in."""
return status in [Status.IN_PROGRESS, Status.GAME_OVER]

@staticmethod
def is_inning_break(inning_state):
"""Returns whether a game is in an inning break (mid/end). Pass in the inning state."""
return inning_state not in [Inning.TOP, Inning.BOTTOM]
5 changes: 4 additions & 1 deletion renderers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def render(self):
if endtime - self.data.games_refresh_time >= GAMES_REFRESH_RATE:
self.data.refresh_games()

self.data.refresh_overview()
if self.data.needs_refresh:
self.data.refresh_overview()

if Status.is_complete(self.data.overview.status):
if Final(self.data.current_game()).winning_pitcher == 'Unknown':
Expand All @@ -93,6 +94,8 @@ def __should_rotate_to_next_game(self, overview):

showing_preferred_team = self.data.config.preferred_teams[0] in [overview.away_team_name, overview.home_team_name]
if showing_preferred_team and Status.is_live(overview.status):
if self.data.config.rotation_preferred_team_live_mid_inning == True and Status.is_inning_break(overview.inning_state):
return True
return False

return True
Expand Down

0 comments on commit abb2f75

Please sign in to comment.