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

Commit ecf1690

Browse files
committed
Fix Issue 130, Changed how goal details are handled and preped for rendering
1 parent 1c39793 commit ecf1690

File tree

7 files changed

+168
-78
lines changed

7 files changed

+168
-78
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.0
1+
1.3.1

src/boards/seriesticker.py

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ def render(self):
6262
font=self.font,
6363
fill=(0,0,0)
6464
)
65+
self.index += 1
6566

67+
# # If something fails in the process of drawing the series table due to failed API request
68+
# # Continue in the loop and skip this series.
69+
# if not self.draw_series_table(series):
70+
# debug.error('Failed Draw the series table due to failed API request. Skiping to the next series')
71+
# continue
72+
73+
6674
self.draw_series_table(series)
67-
6875
self.matrix.render()
69-
self.index += 1
7076
self.sleepEvent.wait(10)
7177

7278
def draw_series_table(self, series):
@@ -106,49 +112,61 @@ def draw_series_table(self, series):
106112
offset_correction = 0
107113

108114
for game in series.games:
109-
110-
# Request the game overview
111-
overview = nhl_api.overview(game["gameId"])
112-
113-
# get the scoreboard
114-
scoreboard = Scoreboard(overview, self.data)
115-
116-
if self.data.status.is_final(overview.status) and hasattr(scoreboard, "winning_team"):
117-
if scoreboard.winning_team == series.top_team.id:
118-
winning_row = top_row
119-
loosing_row = bottom_row
120-
winning_team_color = color_top_team
121-
winning_bg_color = color_top_bg
122-
else:
123-
winning_row = bottom_row
124-
loosing_row = top_row
125-
winning_team_color = color_bottom_team
126-
winning_bg_color = color_bottom_bg
127-
128-
# Look loosing score text needs an offset
129-
if len(str(scoreboard.winning_score)) == 2 and len(str(scoreboard.winning_score)) == 1:
130-
offset_correction = 1
131-
132-
self.matrix.draw_text(
133-
((rec_width + 15 + offset_correction), loosing_row),
134-
str(scoreboard.loosing_score),
135-
font=self.font,
136-
fill=loosing_color,
137-
backgroundColor=None,
138-
backgroundOffset=[1, 1, 1, 1]
139-
)
140-
141-
position = self.matrix.draw_text(
142-
(rec_width + 15, winning_row),
143-
str(scoreboard.winning_score),
144-
font=self.font,
145-
fill=(winning_team_color['r'], winning_team_color['g'], winning_team_color['b']),
146-
backgroundColor=(winning_bg_color['r'], winning_bg_color['g'], winning_bg_color['b']),
147-
backgroundOffset=[1, 1, 1, 1]
148-
)
149-
150-
# Increment
151-
rec_width += (position["size"][0] + 4)
115+
attempts_remaining = 5
116+
while attempts_remaining > 0:
117+
try:
118+
# Request the game overview
119+
overview = nhl_api.overview(game["gameId"])
120+
# get the scoreboard
121+
scoreboard = Scoreboard(overview, self.data)
122+
123+
if self.data.status.is_final(overview.status) and hasattr(scoreboard, "winning_team"):
124+
if scoreboard.winning_team == series.top_team.id:
125+
winning_row = top_row
126+
loosing_row = bottom_row
127+
winning_team_color = color_top_team
128+
winning_bg_color = color_top_bg
129+
else:
130+
winning_row = bottom_row
131+
loosing_row = top_row
132+
winning_team_color = color_bottom_team
133+
winning_bg_color = color_bottom_bg
134+
135+
# Look loosing score text needs an offset
136+
if len(str(scoreboard.winning_score)) == 2 and len(str(scoreboard.winning_score)) == 1:
137+
offset_correction = 1
138+
139+
self.matrix.draw_text(
140+
((rec_width + 15 + offset_correction), loosing_row),
141+
str(scoreboard.loosing_score),
142+
font=self.font,
143+
fill=loosing_color,
144+
backgroundColor=None,
145+
backgroundOffset=[1, 1, 1, 1]
146+
)
147+
148+
position = self.matrix.draw_text(
149+
(rec_width + 15, winning_row),
150+
str(scoreboard.winning_score),
151+
font=self.font,
152+
fill=(winning_team_color['r'], winning_team_color['g'], winning_team_color['b']),
153+
backgroundColor=(winning_bg_color['r'], winning_bg_color['g'], winning_bg_color['b']),
154+
backgroundOffset=[1, 1, 1, 1]
155+
)
156+
157+
# Increment
158+
rec_width += (position["size"][0] + 4)
159+
break
160+
161+
except ValueError as error_message:
162+
self.data.network_issues = True
163+
debug.error("Failed to get the Games for the {} VS {} series: {} attempts remaining".format(series.top_team.abbrev, series.bottom_team.abbrev, attempts_remaining))
164+
debug.error(error_message)
165+
attempts_remaining -= 1
166+
sleep(2)
167+
# If one of the request for player info failed after 5 attempts, return an empty dictionary
168+
if attempts_remaining == 0:
169+
return False
152170

153171

154172
def show_indicator(self, index, slides):

src/boards/team_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,6 @@ def draw_team_summary(self, stats, prev_game_scoreboard, next_game_scoreboard, b
203203
draw.text((0, 61), "VS {}".format(next_game_scoreboard.away_team.abbrev), fill=(255, 255, 255),
204204
font=self.font)
205205
else:
206-
draw.text((1, 61), "--------", fill=(200, 200, 200), font=self.font)
206+
draw.text((1, 52), "--------", fill=(200, 200, 200), font=self.font)
207207

208208
return image

src/data/scoreboard.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from data.team import TeamScore
22
from data.periods import Periods
33
from utils import convert_time
4+
from time import sleep
5+
import debug
46
import nhl_api
57

68

@@ -24,7 +26,7 @@ def filter_scoring_plays(plays, away_id, home_id):
2426

2527
return away, home
2628

27-
def get_goal_players(players_list):
29+
def get_goal_players(players_list,data):
2830
"""
2931
Grab the list of players involved in a goal and return their Id except for assists which is a list of Ids
3032
"""
@@ -40,24 +42,29 @@ def get_goal_players(players_list):
4042
try:
4143
if player["playerType"] == "Scorer":
4244
scorerId = player['player']['id']
43-
scorer = nhl_api.player(scorerId)
45+
scorer["info"] = nhl_api.player(scorerId)
46+
scorer["points"] = player['seasonTotal']
4447
if player["playerType"] == "Assist":
4548
assistsId = player['player']['id']
46-
assists.append(nhl_api.player(assistsId))
49+
assists.append({"info":nhl_api.player(assistsId), "points":player['seasonTotal']})
4750
if player["playerType"] == "Goalie":
4851
goalieId = player['player']['id']
4952
goalie = nhl_api.player(goalieId)
5053

54+
data.network_issues = False
5155
break
5256
except ValueError as error_message:
53-
self.network_issues = True
57+
data.network_issues = True
5458
debug.error("Failed to get the players info related to a GOAL. {} attempt remaining.".format(attempts_remaining))
5559
debug.error(error_message)
5660
attempts_remaining -= 1
57-
sleep(NETWORK_RETRY_SLEEP_TIME)
61+
sleep(2)
62+
63+
# If one of the request for player info failed after 5 attempts, return an empty dictionary
64+
if attempts_remaining == 0:
65+
return {}
5866

59-
return scorer, assists, goalie
60-
67+
return {"scorer":scorer, "assists":assists, "goalie":goalie}
6168

6269
class Scoreboard:
6370
def __init__(self, overview, data):
@@ -74,10 +81,28 @@ def __init__(self, overview, data):
7481
if hasattr(overview,"plays"):
7582
plays = overview.plays
7683
away_scoring_plays, home_scoring_plays = filter_scoring_plays(plays,away.team.id,home.team.id)
84+
# Get the Away Goal details
85+
# If the request to the API fails,return an empty list of goal plays.
86+
# This method is there to prevent the goal board to display the wrong info
7787
for play in away_scoring_plays:
78-
away_goal_plays.append(Goal(play))
88+
players = get_goal_players(play['players'], data)
89+
if players:
90+
away_goal_plays.append(Goal(play, players))
91+
else:
92+
debug.error("Failed to get Goal details for current live game. will retry on data refresh")
93+
away_goal_plays = []
94+
break
95+
# Get the Home Goal details
96+
# If the request to the API fails,return an empty list of goal plays
97+
# This method is there to prevent the goal board to display the wrong info
7998
for play in home_scoring_plays:
80-
home_goal_plays.append(Goal(play))
99+
players = get_goal_players(play['players'], data)
100+
if players:
101+
home_goal_plays.append(Goal(play,players))
102+
else:
103+
debug.error("Failed to get Goal details for current live game. will retry on data refresh")
104+
home_goal_plays = []
105+
break
81106

82107
self.away_team = TeamScore(away.team.id, away_abbrev, away.team.name, away.goals, away.shotsOnGoal, away.powerPlay,
83108
away.numSkaters, away.goaliePulled, away_goal_plays)
@@ -107,9 +132,10 @@ def __str__(self):
107132
return output
108133

109134
class Goal:
110-
def __init__(self, play):
111-
players = play['players']
112-
self.scorer, self.assists, self.goalie = get_goal_players(players)
135+
def __init__(self, play, players):
136+
self.scorer = players["scorer"]
137+
self.assists = players["assists"]
138+
self.goalie = players["goalie"]
113139
self.team = play['team']['id']
114140
self.period = play['about']['ordinalNum']
115141
self.periodTime = play['about']['periodTime']

src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
SCRIPT_NAME = "NHL-LED-SCOREBOARD"
2323

24-
SCRIPT_VERSION = "1.3.0"
24+
SCRIPT_VERSION = "1.3.1"
2525

2626

2727
def run():

src/renderer/goal.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def render(self):
4141

4242
#Show the Assists information
4343
self.matrix.clear()
44-
self.draw_assists()
44+
self.draw_details()
4545

4646
self.matrix.render()
4747
self.sleepEvent.wait(self.rotation_rate)
@@ -58,7 +58,7 @@ def draw_scorer(self):
5858
self.draw_hashtag()
5959
self.matrix.draw_text(
6060
(11, 8),
61-
str(self.scorer.primaryNumber),
61+
str(self.scorer["info"].primaryNumber),
6262
font=self.font_medium,
6363
fill=(255,255,255)
6464
)
@@ -72,43 +72,63 @@ def draw_scorer(self):
7272

7373
self.matrix.draw_text(
7474
(8, 20),
75-
self.scorer.firstName.upper(),
75+
self.scorer["info"].firstName.upper(),
7676
font=self.font,
7777
fill=(255,255,255)
7878
)
7979
self.matrix.draw_text(
8080
(8, 26),
81-
self.scorer.lastName.upper(),
81+
self.scorer["info"].lastName.upper(),
8282
font=self.font,
8383
fill=(255,255,255)
8484
)
8585

86-
def draw_assists(self):
86+
def draw_details(self):
8787
self.matrix.draw.rectangle([0,0,64,6], fill=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b']))
8888
self.matrix.draw_text(
8989
(1, 1),
9090
"GOAL @ {}/{}".format(self.periodTime,self.period),
9191
font=self.font,
9292
fill=(self.team_txt_color['r'], self.team_txt_color['g'], self.team_txt_color['b'])
9393
)
94-
94+
95+
scorer_name_coord = self.matrix.draw_text(
96+
(1, 8),
97+
self.scorer["info"].lastName.upper(),
98+
font=self.font,
99+
fill=(255, 255, 255)
100+
)
101+
scorer_points_x_coord = scorer_name_coord["position"][0] + scorer_name_coord["size"][0] + 3
102+
self.matrix.draw_text(
103+
(scorer_points_x_coord, 8),
104+
str(self.scorer["points"]),
105+
font=self.font,
106+
fill=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b'])
107+
)
108+
95109
self.matrix.draw_text(
96-
(1, 9),
110+
(1, 15),
97111
"ASSISTS",
98112
font=self.font,
99-
fill=(self.team_txt_color['r'], self.team_txt_color['g'], self.team_txt_color['b']),
100-
backgroundColor=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b'])
113+
fill=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b']),
101114
)
102115

103-
assists_y_pos = 16
116+
assists_y_pos = 21
104117
if self.assists:
105-
for player in self.assists:
106-
self.matrix.draw_text(
118+
for i in range(len(self.assists)):
119+
assist_name_coord = self.matrix.draw_text(
107120
(1, assists_y_pos),
108-
player.lastName.upper(),
121+
self.assists[i]["info"].lastName.upper(),
109122
font=self.font,
110123
fill=(255, 255, 255)
111124
)
125+
assists_points_x_coord = assist_name_coord["position"][0] + assist_name_coord["size"][0] + 3
126+
self.matrix.draw_text(
127+
(assists_points_x_coord, assists_y_pos),
128+
str(self.assists[i]["points"]),
129+
font=self.font,
130+
fill=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b'])
131+
)
112132
assists_y_pos += 6
113133
else:
114134
self.matrix.draw_text(

0 commit comments

Comments
 (0)