Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 6.1.1 #434

Merged
merged 8 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion colors/scoreboard.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
"g": 255,
"b": 255
},
"pitch_count": {
"r": 255,
"g": 255,
"b": 255
},
"strikeout": {
"r": 255,
"g": 235,
Expand Down Expand Up @@ -293,4 +298,4 @@
"b": 59
}
}
}
}
8 changes: 7 additions & 1 deletion coordinates/w128h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,17 @@
"font_name": "4x6",
"x": 1,
"y": 50,
"width": 41,
"enabled": false,
"mph": false,
"desc_length": "Short"
},
"pitch_count": {
"font_name": "4x6",
"x": 1,
"y": 50,
"enabled": false,
"append_pitcher_name": false
},
"loop": 64,
"strikeout": {
"x": 84,
Expand Down
8 changes: 7 additions & 1 deletion coordinates/w128h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,17 @@
"font_name": "4x6",
"x": 1,
"y": 50,
"width": 41,
"enabled": true,
"mph": true,
"desc_length": "Long"
},
"pitch_count": {
"font_name": "4x6",
"x": 1,
"y": 50,
"enabled": false,
"append_pitcher_name": false
},
"loop": 68,
"strikeout": {
"x": 32,
Expand Down
8 changes: 7 additions & 1 deletion coordinates/w32h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,17 @@
"font_name": "4x6",
"x": 1,
"y": 50,
"width": 41,
"enabled": false,
"mph": false,
"desc_length": "Short"
},
"pitch_count": {
"font_name": "4x6",
"x": 1,
"y": 50,
"enabled": false,
"append_pitcher_name": false
},
"loop": 16,
"strikeout": {
"x": 33,
Expand Down
8 changes: 6 additions & 2 deletions coordinates/w64h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,18 @@
"width": 24
},
"pitch": {
"font_name": "4x6",
"x": 1,
"y": 50,
"width": 41,
"enabled": false,
"mph": false,
"desc_length": "Short"
},
"pitch_count": {
"x": 1,
"y": 50,
"enabled": false,
"append_pitcher_name": false
},
"loop": 36,
"strikeout": {
"x": 15,
Expand Down
8 changes: 7 additions & 1 deletion coordinates/w64h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,17 @@
"font_name": "4x6",
"x": 1,
"y": 50,
"width": 41,
"enabled": false,
"mph": false,
"desc_length": "Short"
},
"pitch_count": {
"font_name": "4x6",
"x": 1,
"y": 50,
"enabled": false,
"append_pitcher_name": false
},
"loop": 64,
"strikeout": {
"x": 31,
Expand Down
35 changes: 28 additions & 7 deletions data/game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from datetime import datetime
from typing import Optional

import statsapi

Expand All @@ -12,7 +13,7 @@
+ "currentPlay,result,eventType,playEvents,isPitch,pitchData,startSpeed,details,type,code,description,decisions,"
+ "winner,loser,save,id,linescore,outs,balls,strikes,note,inningState,currentInning,currentInningOrdinal,offense,"
+ "batter,inHole,onDeck,first,second,third,defense,pitcher,boxscore,teams,runs,players,seasonStats,pitching,wins,"
+ "losses,saves,era,hits,errors,weather,condition,temp,wind"
+ "losses,saves,era,hits,errors,stats,pitching,numberOfPitches,weather,condition,temp,wind"
)

SCHEDULE_API_FIELDS = "dates,date,games,status,detailedState,abstractGameState,reason"
Expand All @@ -22,18 +23,24 @@

class Game:
@staticmethod
def from_ID(game_id, date, broadcasts=None):
game = Game(game_id, date, broadcasts or [])
def from_scheduled(game_data) -> Optional["Game"]:
game = Game(
game_data["game_id"],
game_data["game_date"],
game_data["national_broadcasts"] or [],
game_data["series_status"] or "",
)
if game.update(True) == UpdateStatus.SUCCESS:
return game
return None

def __init__(self, game_id, date, broadcasts):
def __init__(self, game_id, date, broadcasts, series_status):
self.game_id = game_id
self.date = date.strftime("%Y-%m-%d")
self.date = date
self.starttime = time.time()
self._data = {}
self._broadcasts = broadcasts
self._series_status = series_status
self._status = {}

def update(self, force=False) -> UpdateStatus:
Expand Down Expand Up @@ -220,8 +227,8 @@ def on_deck(self):

def pitcher(self):
try:
batter_id = self._data["liveData"]["linescore"]["defense"]["pitcher"]["id"]
return self.boxscore_name(batter_id)
pitcher_id = self._data["liveData"]["linescore"]["defense"]["pitcher"]["id"]
return self.boxscore_name(pitcher_id)
except:
return ""

Expand All @@ -246,6 +253,17 @@ def last_pitch(self):
except:
return None

def current_pitcher_pitch_count(self):
try:
pitcher_id = self._data["liveData"]["linescore"]["defense"]["pitcher"]["id"]
ID = Game._format_id(pitcher_id)
try:
return self._data["liveData"]["boxscore"]["teams"]["away"]["players"][ID]["stats"]["pitching"]["numberOfPitches"]
except:
return self._data["liveData"]["boxscore"]["teams"]["away"]["players"][ID]["stats"]["pitching"]["numberOfPitches"]
except:
return 0

def note(self):
try:
return self._data["liveData"]["linescore"]["note"]
Expand All @@ -264,6 +282,9 @@ def reason(self):
def broadcasts(self):
return self._broadcasts

def series_status(self):
return self._series_status

def current_play_result(self):
result = self._data["liveData"]["plays"].get("currentPlay", {}).get("result", {}).get("eventType", "")
if result == "strikeout" and (
Expand Down
4 changes: 2 additions & 2 deletions data/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def next_game(self):
):
game_index = self._game_index_for_preferred_team()
scheduled_game = self._games[game_index]
preferred_game = Game.from_ID(scheduled_game["game_id"], self.date, scheduled_game["national_broadcasts"])
preferred_game = Game.from_scheduled(scheduled_game)
if preferred_game is not None:
debug.log(
"Preferred Team's Game Status: %s, %s %d",
Expand Down Expand Up @@ -146,7 +146,7 @@ def __next_game_index(self):
def __current_game(self):
if self._games:
scheduled_game = self._games[self.current_idx]
return Game.from_ID(scheduled_game["game_id"], self.date, scheduled_game["national_broadcasts"])
return Game.from_scheduled(scheduled_game)
return None

@staticmethod
Expand Down
7 changes: 6 additions & 1 deletion data/scoreboard/pitches.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Pitches:
def __init__(self, game: Game):
self.balls = game.balls()
self.strikes = game.strikes()
self.pitch_count = game.current_pitcher_pitch_count()
last_pitch = game.last_pitch()
if last_pitch is None:
self.last_pitch_speed = "0"
Expand All @@ -17,4 +18,8 @@ def __init__(self, game: Game):
self.last_pitch_type_long = data.pitches.fetch_long(last_pitch[1])

def __str__(self) -> str:
return f"Count: {self.balls} - {self.strikes}. Last pitch: {self.last_pitch_speed}mph {self.last_pitch_type} {self.last_pitch_long}"
return (
f"Count: {self.balls} - {self.strikes}. "
+ f"Last pitch: {self.last_pitch_speed}mph {self.last_pitch_type} {self.last_pitch_long} "
+ f" Total pitches: {self.pitch_count}"
)
3 changes: 3 additions & 0 deletions data/scoreboard/postgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def __init__(self, game: Game):
self.losing_pitcher_wins = 0
self.losing_pitcher_losses = 0

self.series_status = game.series_status()


def __str__(self):
return "<{} {}> W: {} {}-{}; L: {} {}-{}; S: {} ({})".format(
self.__class__.__name__,
Expand Down
1 change: 1 addition & 0 deletions data/scoreboard/pregame.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, game: Game, time_format):
self.home_starter = PITCHER_TBD

self.national_broadcasts = game.broadcasts()
self.series_status = game.series_status()

def __convert_time(self, game_time_utc):
"""Converts MLB's pregame times (UTC) into the local time zone"""
Expand Down
30 changes: 22 additions & 8 deletions renderers/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa

# --------------- at-bat ---------------
def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, strikeout, looking, animation, pitches: Pitches):
plength = __render_pitcher_text(canvas, layout, colors, atbat.pitcher, text_pos)
plength = __render_pitcher_text(canvas, layout, colors, atbat.pitcher, pitches, text_pos)
__render_pitch_text(canvas, layout, colors, pitches)
__render_pitch_count(canvas, layout, colors, pitches)
if strikeout:
if animation:
__render_strikeout(canvas, layout, colors, looking)
Expand Down Expand Up @@ -88,11 +89,16 @@ def __render_batter_text(canvas, layout, colors, batter, text_pos):
return pos


def __render_pitcher_text(canvas, layout, colors, pitcher, text_pos):
def __render_pitcher_text(canvas, layout, colors, pitcher, pitches: Pitches, text_pos):
coords = layout.coords("atbat.pitcher")
color = colors.graphics_color("atbat.pitcher")
font = layout.font("atbat.pitcher")
bgcolor = colors.graphics_color("default.background")

pitch_count = layout.coords("atbat.pitch_count")
if pitch_count["enabled"] and pitch_count["append_pitcher_name"]:
pitcher += f" ({pitches.pitch_count})"

pos = scrollingtext.render_text(
canvas,
coords["x"] + font["size"]["width"] * 2,
Expand All @@ -113,20 +119,28 @@ def __render_pitch_text(canvas, layout, colors, pitches: Pitches):
coords = layout.coords("atbat.pitch")
color = colors.graphics_color("atbat.pitch")
font = layout.font("atbat.pitch")
bgcolor = colors.graphics_color("default.background")
if int(pitches.last_pitch_speed) > 0 and layout.coords("atbat.pitch")["enabled"]:
if int(pitches.last_pitch_speed) and coords["enabled"]:
mph = " "
if layout.coords("atbat.pitch")["mph"]:
if coords["mph"]:
mph = "mph "
if layout.coords("atbat.pitch")["desc_length"] == "Long":
if coords["desc_length"] == "Long":
pitch_text = str(pitches.last_pitch_speed) + mph + pitches.last_pitch_type_long
elif layout.coords("atbat.pitch")["desc_length"] == "Short":
elif ["desc_length"] == "Short":
pitch_text = str(pitches.last_pitch_speed) + mph + pitches.last_pitch_type
else:
pitch_text = None
pitch_text = ""
graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, pitch_text)


def __render_pitch_count(canvas, layout, colors, pitches: Pitches):
coords = layout.coords("atbat.pitch_count")
color = colors.graphics_color("atbat.pitch_count")
font = layout.font("atbat.pitch_count")
if coords["enabled"] and not coords["append_pitcher_name"]:
pitch_count = f"{pitches.pitch_count}P"
graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, pitch_count)


# --------------- bases ---------------
def _render_bases(canvas, layout, colors, bases: Bases, home_run, animation):
base_runners = bases.runners
Expand Down
12 changes: 9 additions & 3 deletions renderers/games/postgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
NORMAL_GAME_LENGTH = 9


def render_postgame(canvas, layout: Layout, colors: Color, postgame: Postgame, scoreboard: Scoreboard, text_pos):
def render_postgame(
canvas, layout: Layout, colors: Color, postgame: Postgame, scoreboard: Scoreboard, text_pos, is_playoffs
):
_render_final_inning(canvas, layout, colors, scoreboard)
return _render_decision_scroll(canvas, layout, colors, postgame, text_pos)
return _render_decision_scroll(canvas, layout, colors, postgame, text_pos, is_playoffs)


def _render_decision_scroll(canvas, layout, colors, postgame, text_pos):
def _render_decision_scroll(canvas, layout, colors, postgame, text_pos, is_playoffs):
coords = layout.coords("final.scrolling_text")
font = layout.font("final.scrolling_text")
color = colors.graphics_color("final.scrolling_text")
Expand All @@ -30,6 +32,10 @@ def _render_decision_scroll(canvas, layout, colors, postgame, text_pos):
)
if postgame.save_pitcher:
scroll_text += " SV: {} ({})".format(postgame.save_pitcher, postgame.save_pitcher_saves)

if is_playoffs:
scroll_text += " " + postgame.series_status

return scrollingtext.render_text(
canvas, coords["x"], coords["y"], coords["width"], font, color, bgcolor, scroll_text, text_pos
)
Expand Down
11 changes: 8 additions & 3 deletions renderers/games/pregame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from utils import center_text_position


def render_pregame(canvas, layout: Layout, colors: Color, pregame: Pregame, probable_starter_pos, pregame_weather):
text_len = _render_pregame_info(canvas, layout, colors, pregame, probable_starter_pos, pregame_weather)
def render_pregame(
canvas, layout: Layout, colors: Color, pregame: Pregame, probable_starter_pos, pregame_weather, is_playoffs
):
text_len = _render_pregame_info(canvas, layout, colors, pregame, probable_starter_pos, pregame_weather, is_playoffs)

if layout.state_is_warmup():
_render_warmup(canvas, layout, colors, pregame)
Expand Down Expand Up @@ -35,7 +37,7 @@ def _render_warmup(canvas, layout, colors, pregame):
graphics.DrawText(canvas, font["font"], warmup_x, coords["y"], color, warmup_text)


def _render_pregame_info(canvas, layout, colors, pregame, probable_starter_pos, pregame_weather):
def _render_pregame_info(canvas, layout, colors, pregame: Pregame, probable_starter_pos, pregame_weather, is_playoffs):
coords = layout.coords("pregame.scrolling_text")
font = layout.font("pregame.scrolling_text")
color = colors.graphics_color("pregame.scrolling_text")
Expand All @@ -46,6 +48,9 @@ def _render_pregame_info(canvas, layout, colors, pregame, probable_starter_pos,
if pregame_weather and pregame.pregame_weather:
pitchers_text += " Weather: " + pregame.pregame_weather

if is_playoffs:
pitchers_text += " " + pregame.series_status

return scrollingtext.render_text(
canvas, coords["x"], coords["y"], coords["width"], font, color, bgcolor, pitchers_text, probable_starter_pos
)
Loading