Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
PUSH IN PROD added stanley cup champions board.
Browse files Browse the repository at this point in the history
  • Loading branch information
riffnshred committed Sep 26, 2020
1 parent 3dbdfd1 commit 8d58182
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 18 deletions.
Binary file added assets/images/stanleycupchamps_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions src/boards/stanley_cup_champions.py
Original file line number Diff line number Diff line change
@@ -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)
39 changes: 25 additions & 14 deletions src/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/data/scoreboard_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 16 additions & 4 deletions src/renderer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -121,16 +124,17 @@ 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):
""" Post Game state """
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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
1 change: 1 addition & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 8d58182

Please sign in to comment.