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

Commit

Permalink
Fix Issue 130, Changed how goal details are handled and preped for re…
Browse files Browse the repository at this point in the history
…ndering
  • Loading branch information
riffnshred committed Aug 9, 2020
1 parent 1c39793 commit ecf1690
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 78 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1
108 changes: 63 additions & 45 deletions src/boards/seriesticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ def render(self):
font=self.font,
fill=(0,0,0)
)
self.index += 1

# # If something fails in the process of drawing the series table due to failed API request
# # Continue in the loop and skip this series.
# if not self.draw_series_table(series):
# debug.error('Failed Draw the series table due to failed API request. Skiping to the next series')
# continue


self.draw_series_table(series)

self.matrix.render()
self.index += 1
self.sleepEvent.wait(10)

def draw_series_table(self, series):
Expand Down Expand Up @@ -106,49 +112,61 @@ def draw_series_table(self, series):
offset_correction = 0

for game in series.games:

# Request the game overview
overview = nhl_api.overview(game["gameId"])

# get the scoreboard
scoreboard = Scoreboard(overview, self.data)

if self.data.status.is_final(overview.status) and hasattr(scoreboard, "winning_team"):
if scoreboard.winning_team == series.top_team.id:
winning_row = top_row
loosing_row = bottom_row
winning_team_color = color_top_team
winning_bg_color = color_top_bg
else:
winning_row = bottom_row
loosing_row = top_row
winning_team_color = color_bottom_team
winning_bg_color = color_bottom_bg

# Look loosing score text needs an offset
if len(str(scoreboard.winning_score)) == 2 and len(str(scoreboard.winning_score)) == 1:
offset_correction = 1

self.matrix.draw_text(
((rec_width + 15 + offset_correction), loosing_row),
str(scoreboard.loosing_score),
font=self.font,
fill=loosing_color,
backgroundColor=None,
backgroundOffset=[1, 1, 1, 1]
)

position = self.matrix.draw_text(
(rec_width + 15, winning_row),
str(scoreboard.winning_score),
font=self.font,
fill=(winning_team_color['r'], winning_team_color['g'], winning_team_color['b']),
backgroundColor=(winning_bg_color['r'], winning_bg_color['g'], winning_bg_color['b']),
backgroundOffset=[1, 1, 1, 1]
)

# Increment
rec_width += (position["size"][0] + 4)
attempts_remaining = 5
while attempts_remaining > 0:
try:
# Request the game overview
overview = nhl_api.overview(game["gameId"])
# get the scoreboard
scoreboard = Scoreboard(overview, self.data)

if self.data.status.is_final(overview.status) and hasattr(scoreboard, "winning_team"):
if scoreboard.winning_team == series.top_team.id:
winning_row = top_row
loosing_row = bottom_row
winning_team_color = color_top_team
winning_bg_color = color_top_bg
else:
winning_row = bottom_row
loosing_row = top_row
winning_team_color = color_bottom_team
winning_bg_color = color_bottom_bg

# Look loosing score text needs an offset
if len(str(scoreboard.winning_score)) == 2 and len(str(scoreboard.winning_score)) == 1:
offset_correction = 1

self.matrix.draw_text(
((rec_width + 15 + offset_correction), loosing_row),
str(scoreboard.loosing_score),
font=self.font,
fill=loosing_color,
backgroundColor=None,
backgroundOffset=[1, 1, 1, 1]
)

position = self.matrix.draw_text(
(rec_width + 15, winning_row),
str(scoreboard.winning_score),
font=self.font,
fill=(winning_team_color['r'], winning_team_color['g'], winning_team_color['b']),
backgroundColor=(winning_bg_color['r'], winning_bg_color['g'], winning_bg_color['b']),
backgroundOffset=[1, 1, 1, 1]
)

# Increment
rec_width += (position["size"][0] + 4)
break

except ValueError as error_message:
self.data.network_issues = True
debug.error("Failed to get the Games for the {} VS {} series: {} attempts remaining".format(series.top_team.abbrev, series.bottom_team.abbrev, attempts_remaining))
debug.error(error_message)
attempts_remaining -= 1
sleep(2)
# If one of the request for player info failed after 5 attempts, return an empty dictionary
if attempts_remaining == 0:
return False


def show_indicator(self, index, slides):
Expand Down
2 changes: 1 addition & 1 deletion src/boards/team_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@ def draw_team_summary(self, stats, prev_game_scoreboard, next_game_scoreboard, b
draw.text((0, 61), "VS {}".format(next_game_scoreboard.away_team.abbrev), fill=(255, 255, 255),
font=self.font)
else:
draw.text((1, 61), "--------", fill=(200, 200, 200), font=self.font)
draw.text((1, 52), "--------", fill=(200, 200, 200), font=self.font)

return image
50 changes: 38 additions & 12 deletions src/data/scoreboard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from data.team import TeamScore
from data.periods import Periods
from utils import convert_time
from time import sleep
import debug
import nhl_api


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

return away, home

def get_goal_players(players_list):
def get_goal_players(players_list,data):
"""
Grab the list of players involved in a goal and return their Id except for assists which is a list of Ids
"""
Expand All @@ -40,24 +42,29 @@ def get_goal_players(players_list):
try:
if player["playerType"] == "Scorer":
scorerId = player['player']['id']
scorer = nhl_api.player(scorerId)
scorer["info"] = nhl_api.player(scorerId)
scorer["points"] = player['seasonTotal']
if player["playerType"] == "Assist":
assistsId = player['player']['id']
assists.append(nhl_api.player(assistsId))
assists.append({"info":nhl_api.player(assistsId), "points":player['seasonTotal']})
if player["playerType"] == "Goalie":
goalieId = player['player']['id']
goalie = nhl_api.player(goalieId)

data.network_issues = False
break
except ValueError as error_message:
self.network_issues = True
data.network_issues = True
debug.error("Failed to get the players info related to a GOAL. {} attempt remaining.".format(attempts_remaining))
debug.error(error_message)
attempts_remaining -= 1
sleep(NETWORK_RETRY_SLEEP_TIME)
sleep(2)

# If one of the request for player info failed after 5 attempts, return an empty dictionary
if attempts_remaining == 0:
return {}

return scorer, assists, goalie

return {"scorer":scorer, "assists":assists, "goalie":goalie}

class Scoreboard:
def __init__(self, overview, data):
Expand All @@ -74,10 +81,28 @@ def __init__(self, overview, data):
if hasattr(overview,"plays"):
plays = overview.plays
away_scoring_plays, home_scoring_plays = filter_scoring_plays(plays,away.team.id,home.team.id)
# Get the Away Goal details
# If the request to the API fails,return an empty list of goal plays.
# This method is there to prevent the goal board to display the wrong info
for play in away_scoring_plays:
away_goal_plays.append(Goal(play))
players = get_goal_players(play['players'], data)
if players:
away_goal_plays.append(Goal(play, players))
else:
debug.error("Failed to get Goal details for current live game. will retry on data refresh")
away_goal_plays = []
break
# Get the Home Goal details
# If the request to the API fails,return an empty list of goal plays
# This method is there to prevent the goal board to display the wrong info
for play in home_scoring_plays:
home_goal_plays.append(Goal(play))
players = get_goal_players(play['players'], data)
if players:
home_goal_plays.append(Goal(play,players))
else:
debug.error("Failed to get Goal details for current live game. will retry on data refresh")
home_goal_plays = []
break

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

class Goal:
def __init__(self, play):
players = play['players']
self.scorer, self.assists, self.goalie = get_goal_players(players)
def __init__(self, play, players):
self.scorer = players["scorer"]
self.assists = players["assists"]
self.goalie = players["goalie"]
self.team = play['team']['id']
self.period = play['about']['ordinalNum']
self.periodTime = play['about']['periodTime']
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

SCRIPT_NAME = "NHL-LED-SCOREBOARD"

SCRIPT_VERSION = "1.3.0"
SCRIPT_VERSION = "1.3.1"


def run():
Expand Down
46 changes: 33 additions & 13 deletions src/renderer/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def render(self):

#Show the Assists information
self.matrix.clear()
self.draw_assists()
self.draw_details()

self.matrix.render()
self.sleepEvent.wait(self.rotation_rate)
Expand All @@ -58,7 +58,7 @@ def draw_scorer(self):
self.draw_hashtag()
self.matrix.draw_text(
(11, 8),
str(self.scorer.primaryNumber),
str(self.scorer["info"].primaryNumber),
font=self.font_medium,
fill=(255,255,255)
)
Expand All @@ -72,43 +72,63 @@ def draw_scorer(self):

self.matrix.draw_text(
(8, 20),
self.scorer.firstName.upper(),
self.scorer["info"].firstName.upper(),
font=self.font,
fill=(255,255,255)
)
self.matrix.draw_text(
(8, 26),
self.scorer.lastName.upper(),
self.scorer["info"].lastName.upper(),
font=self.font,
fill=(255,255,255)
)

def draw_assists(self):
def draw_details(self):
self.matrix.draw.rectangle([0,0,64,6], fill=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b']))
self.matrix.draw_text(
(1, 1),
"GOAL @ {}/{}".format(self.periodTime,self.period),
font=self.font,
fill=(self.team_txt_color['r'], self.team_txt_color['g'], self.team_txt_color['b'])
)


scorer_name_coord = self.matrix.draw_text(
(1, 8),
self.scorer["info"].lastName.upper(),
font=self.font,
fill=(255, 255, 255)
)
scorer_points_x_coord = scorer_name_coord["position"][0] + scorer_name_coord["size"][0] + 3
self.matrix.draw_text(
(scorer_points_x_coord, 8),
str(self.scorer["points"]),
font=self.font,
fill=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b'])
)

self.matrix.draw_text(
(1, 9),
(1, 15),
"ASSISTS",
font=self.font,
fill=(self.team_txt_color['r'], self.team_txt_color['g'], self.team_txt_color['b']),
backgroundColor=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b'])
fill=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b']),
)

assists_y_pos = 16
assists_y_pos = 21
if self.assists:
for player in self.assists:
self.matrix.draw_text(
for i in range(len(self.assists)):
assist_name_coord = self.matrix.draw_text(
(1, assists_y_pos),
player.lastName.upper(),
self.assists[i]["info"].lastName.upper(),
font=self.font,
fill=(255, 255, 255)
)
assists_points_x_coord = assist_name_coord["position"][0] + assist_name_coord["size"][0] + 3
self.matrix.draw_text(
(assists_points_x_coord, assists_y_pos),
str(self.assists[i]["points"]),
font=self.font,
fill=(self.team_bg_color['r'], self.team_bg_color['g'], self.team_bg_color['b'])
)
assists_y_pos += 6
else:
self.matrix.draw_text(
Expand Down
Loading

0 comments on commit ecf1690

Please sign in to comment.