diff --git a/assets/images/stanleycupchamps_bg.png b/assets/images/stanleycupchamps_bg.png new file mode 100644 index 00000000..9d2f21f7 Binary files /dev/null and b/assets/images/stanleycupchamps_bg.png differ diff --git a/src/boards/stanley_cup_champions.py b/src/boards/stanley_cup_champions.py new file mode 100644 index 00000000..f1109546 --- /dev/null +++ b/src/boards/stanley_cup_champions.py @@ -0,0 +1,64 @@ +from PIL import Image +from utils import get_file + +class StanleyCupChampions: + def __init__(self, data, team_id, matrix, sleepEvent): + print("Display stanleycup champions {} ".format(data.teams_info[team_id].abbreviation)) + self.team_id = team_id + self.team_abbrev = data.teams_info[team_id].abbreviation + self.data = data + self.team_info = data.teams_info[team_id] + self.matrix = matrix + self.team_colors = data.config.team_colors + self.font = data.config.layout.font + self.sleepEvent = sleepEvent + self.sleepEvent.clear() + + def render(self): + self.matrix.clear() + bg_img = Image.open(get_file('assets/images/stanleycupchamps_bg.png')) + self.matrix.draw_image((0,0), bg_img) + + team_color_main = self.team_colors.color("{}.primary".format(self.team_id)) + team_color_accent = self.team_colors.color("{}.text".format(self.team_id)) + + + self.matrix.render() + self.sleepEvent.wait(0.5) + self.matrix.draw_text( + (18, 7), + self.team_abbrev, + font=self.font, + fill=(team_color_accent['r'], team_color_accent['g'], team_color_accent['b']), + backgroundColor=(team_color_main['r'], team_color_main['g'], team_color_main['b']), + backgroundOffset=[6, 1, 6, 1] + ) + self.matrix.render() + self.sleepEvent.wait(0.5) + self.matrix.draw_text( + (37, 7), + str(self.data.year), + font=self.font, + fill=(0, 0, 0), + backgroundColor=(200,200,200) + ) + self.matrix.render() + self.sleepEvent.wait(0.5) + self.matrix.draw_text( + (12, 14), + "STANLEY CUP", + font=self.font, + fill=(255,255,255), + ) + self.matrix.render() + self.sleepEvent.wait(0.5) + self.matrix.draw_text( + (16, 21), + "CHAMPIONS", + font=self.font, + fill=(team_color_accent['r'], team_color_accent['g'], team_color_accent['b']), + backgroundColor=(team_color_main['r'], team_color_main['g'], team_color_main['b']), + backgroundOffset=[4, 1, 4, 1] + ) + self.matrix.render() + self.sleepEvent.wait(10) \ No newline at end of file diff --git a/src/data/data.py b/src/data/data.py index 97b7757b..9f869c1f 100644 --- a/src/data/data.py +++ b/src/data/data.py @@ -150,6 +150,11 @@ def __init__(self, config): # Fetch the playoff data self.refresh_playoff() + self.isPlayoff = False + + # Stanley cup round flag + self.stanleycup_round = False + # Get Covid 19 Data self.covid19 = covid19_data() @@ -415,21 +420,27 @@ def refresh_playoff(self): self.current_round_name = self.current_round.names.name if self.current_round_name == "Stanley Cup Qualifier": self.current_round_name = "Qualifier" + if self.playoffs.default_round == 4: + self.stanleycup_round = True + debug.info("defaultround number is : {}".format(self.playoffs.default_round)) - - try: - # Grab the series of the current round of playoff. - self.series = self.current_round.series - - # Check if prefered team are part of the current round of playoff - self.pref_series = prioritize_pref_series(filter_list_of_series(self.series, self.pref_teams), self.pref_teams) - - # If the user as set to show his favorite teams in the seriesticker - if self.config.seriesticker_preferred_teams_only and self.pref_series: - self.series = self.pref_series - except AttributeError: - debug.error("The {} Season playoff has to started yet or unavailable".format(self.playoffs.season)) - + + try: + # Grab the series of the current round of playoff. + self.series = self.current_round.series + + # Check if prefered team are part of the current round of playoff + self.pref_series = prioritize_pref_series(filter_list_of_series(self.series, self.pref_teams), self.pref_teams) + + # If the user as set to show his favorite teams in the seriesticker + if self.config.seriesticker_preferred_teams_only and self.pref_series: + self.series = self.pref_series + except AttributeError: + debug.error("The {} Season playoff has to started yet or unavailable".format(self.playoffs.season)) + self.isPlayoff = False + break + + self.isPlayoff = True break except ValueError as error_message: diff --git a/src/data/scoreboard_config.py b/src/data/scoreboard_config.py index 74e2be55..10857686 100644 --- a/src/data/scoreboard_config.py +++ b/src/data/scoreboard_config.py @@ -131,6 +131,9 @@ def __init__(self, filename_base, args, size): self.config = Config(size) + if args.testScChampions != None: + self.testScChampions = args.testScChampions + def read_json(self, filename): # Find and return a json file diff --git a/src/renderer/main.py b/src/renderer/main.py index c67d04cc..a6c623d7 100755 --- a/src/renderer/main.py +++ b/src/renderer/main.py @@ -4,6 +4,7 @@ import debug from boards.boards import Boards from boards.clock import Clock +from boards.stanley_cup_champions import StanleyCupChampions from data.scoreboard import Scoreboard from renderer.scoreboard import ScoreboardRenderer from renderer.goal import GoalRenderer @@ -37,6 +38,9 @@ def render(self): # Offseason (Show offseason related stuff) debug.info("It's offseason") self.__render_offday() + elif self.data.config.testScChampions: + self.test_stanley_cup_champion(self.data.config.testScChampions) + else: # Season. if not self.data.config.live_mode: @@ -66,7 +70,6 @@ def __render_offday(self): debug.info('This is a new day') return self.data.refresh_data() - self.boards._off_day(self.data, self.matrix,self.sleepEvent) def __render_game_day(self): @@ -121,8 +124,9 @@ def __render_game_day(self): debug.info("Game Over") self.scoreboard = Scoreboard(self.data.overview, self.data) self.check_new_goals() + self.check_stanley_cup_champion() self.__render_postgame(self.scoreboard) - # sleep(self.refresh_rate) + self.sleepEvent.wait(self.refresh_rate) elif self.status.is_final(self.data.overview.status): @@ -130,7 +134,7 @@ def __render_game_day(self): debug.info("FINAL") self.scoreboard = Scoreboard(self.data.overview, self.data) self.check_new_goals() - + self.check_stanley_cup_champion() self.__render_postgame(self.scoreboard) self.sleepEvent.wait(self.refresh_rate) @@ -158,7 +162,6 @@ def __render_game_day(self): self.sleepEvent.wait(self.refresh_rate) self.boards._scheduled(self.data, self.matrix,self.sleepEvent) - sleep(5) self.data.refresh_data() self.data.refresh_overview() if self.data.network_issues: @@ -303,3 +306,12 @@ def draw_end_of_game_indicator(self): color = self.matrix.graphics.Color(255, 0, 0) self.matrix.graphics.DrawLine(self.matrix.matrix, (self.matrix.width * .5) - 8, self.matrix.height - 2, (self.matrix.width * .5) + 8, self.matrix.height - 2, color) self.matrix.graphics.DrawLine(self.matrix.matrix, (self.matrix.width * .5) - 9, self.matrix.height - 1, (self.matrix.width * .5) + 9, self.matrix.height - 1, color) + + def check_stanley_cup_champion(self): + if self.data.isPlayoff and self.data.stanleycup_round: + for x in range(len(self.data.current_round.series[0].matchupTeams)): + if self.data.current_round.series[0].matchupTeams[x].seriesRecord.wins >= 4: + StanleyCupChampions(self.data, self.data.current_round.series[0].matchupTeams[x].team.id, self.matrix, self.sleepEvent).render() + + def test_stanley_cup_champion(self, team_id): + StanleyCupChampions(self.data, team_id, self.matrix, self.sleepEvent).render() \ No newline at end of file diff --git a/src/utils.py b/src/utils.py index 3eb07ed6..a44dec6e 100644 --- a/src/utils.py +++ b/src/utils.py @@ -71,6 +71,7 @@ def args(): parser.add_argument("--terminal-mode", action="store", help="Run on terminal instead of matrix. (Default: False)", default=False, type=bool) parser.add_argument("--updatecheck", action="store", help="Check for updates (Default: False)", default=False, type=bool) parser.add_argument("--updaterepo", action="store", help="Github repo (Default: riffnshred/nhl-scoreboard)", default="riffnshred/nhl-led-scoreboard", type=str) + parser.add_argument("--testScChampions", action="store", help="A flag to test the stanley cup champions board. Put your team's ID", default=None, type=int) return parser.parse_args()