-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #4
- Loading branch information
Showing
4 changed files
with
106 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,20 @@ | ||
from rgbmatrix import RGBMatrix | ||
from utils import args, refresh_scoreboard, bump_counter | ||
from utils import args | ||
from renderer import render_games, render_standings | ||
import datetime | ||
import mlbgame | ||
import time | ||
|
||
args = args() | ||
|
||
# TODO: Uncomment once the season starts, testing with random games for now | ||
# games = mlbgame.games(year, month, day)[0] | ||
games = mlbgame.games(2017, 5, 10)[0] | ||
|
||
# Get the game to start on. If the provided team does not have a game today, | ||
# or the team name isn't provided, then the first game in the list is used. | ||
game_idx = 0 | ||
if args.team: | ||
game_idx = next( | ||
(i for i, game in enumerate(games) if game.away_team == | ||
args.team or game.home_team == args.team), 0 | ||
) | ||
game = games[game_idx] | ||
|
||
# Initialize the matrix and fill it in with a dark blue color | ||
rgb = RGBMatrix() | ||
matrix = rgb.CreateFrameCanvas() | ||
matrix.Fill(7, 14, 25) | ||
|
||
# Refresh the board every 15 seconds and rotate the games if the command flag is passed | ||
starttime = time.time() | ||
while True: | ||
success = refresh_scoreboard(matrix, game) | ||
matrix = rgb.SwapOnVSync(matrix) | ||
time.sleep(15.0 - ((time.time() - starttime) % 15.0)) | ||
if args.rotate: | ||
game_idx = bump_counter(game_idx, games, bool(args.rotate)) | ||
game = games[game_idx] | ||
matrix.Fill(7, 14, 25) | ||
matrix = RGBMatrix() | ||
canvas = matrix.CreateFrameCanvas() | ||
args = args() | ||
|
||
if not success: | ||
# TODO https://github.com/ajbowler/mlb-led-scoreboard/issues/13 | ||
continue | ||
if args.standings: | ||
standings = mlbgame.standings(datetime.datetime(2017, 9, 30)) | ||
division = next(division for division in standings.divisions if division.name == args.standings) | ||
render_standings(matrix, canvas, division) | ||
else: | ||
# TODO: Uncomment once the season starts, testing with random games for now | ||
# games = mlbgame.games(year, month, day)[0] | ||
games = mlbgame.games(2017, 9, 30)[0] | ||
render_games(matrix, canvas, games, args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from utils import refresh_scoreboard, bump_counter | ||
from rgbmatrix import graphics | ||
import time | ||
|
||
def render_games(matrix, canvas, games, args): | ||
# Get the game to start on. If the provided team does not have a game today, | ||
# or the team name isn't provided, then the first game in the list is used. | ||
game_idx = 0 | ||
if args.team: | ||
game_idx = next( | ||
(i for i, game in enumerate(games) if game.away_team == | ||
args.team or game.home_team == args.team), 0 | ||
) | ||
game = games[game_idx] | ||
|
||
# Refresh the board every 15 seconds and rotate the games if the command flag is passed | ||
starttime = time.time() | ||
canvas.Fill(7, 14, 25) | ||
while True: | ||
success = refresh_scoreboard(canvas, game) | ||
canvas = matrix.SwapOnVSync(canvas) | ||
time.sleep(15.0 - ((time.time() - starttime) % 15.0)) | ||
if args.rotate: | ||
game_idx = bump_counter(game_idx, games, bool(args.rotate)) | ||
game = games[game_idx] | ||
canvas.Fill(7, 14, 25) | ||
|
||
if not success: | ||
# TODO https://github.com/ajbowler/mlb-led-scoreboard/issues/13 | ||
continue | ||
|
||
def render_standings(matrix, canvas, division): | ||
font = graphics.Font() | ||
font.LoadFont('Assets/tom-thumb.bdf') | ||
text_color = graphics.Color(171, 181, 170) | ||
|
||
canvas.Fill(37, 102, 30) | ||
|
||
stat = 'w' | ||
starttime = time.time() | ||
while True: | ||
offset = 6 | ||
for team in division.teams: | ||
abbrev = '{:3s}'.format(team.team_abbrev) | ||
text = '%s %s' % (abbrev, getattr(team, stat)) | ||
graphics.DrawText(canvas, font, 1, offset, text_color, text) | ||
|
||
for x in range(0, canvas.width): | ||
canvas.SetPixel(x, offset, 13, 25, 11) | ||
for y in range(0, canvas.height): | ||
canvas.SetPixel(14, y, 13, 35, 11) | ||
offset += 6 | ||
|
||
matrix.SwapOnVSync(canvas) | ||
time.sleep(5.0 - ((time.time() - starttime) % 5.0)) | ||
|
||
canvas.Fill(37, 102, 30) | ||
stat = 'w' if stat == 'l' else 'l' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters