From db2b95b1daf2352594e968e53499d287892b8589 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Fri, 14 Jul 2023 18:00:46 -0700 Subject: [PATCH 01/16] renders play result for hits and walks --- colors/scoreboard.json.example | 10 ++++++++ coordinates/w64h32.json.example | 10 ++++++++ data/scoreboard/__init__.py | 12 +++++++++ renderers/games/game.py | 43 ++++++++++++++++++++++++--------- renderers/main.py | 2 +- 5 files changed, 64 insertions(+), 13 deletions(-) diff --git a/colors/scoreboard.json.example b/colors/scoreboard.json.example index ddff96ab..6dc30961 100644 --- a/colors/scoreboard.json.example +++ b/colors/scoreboard.json.example @@ -128,6 +128,16 @@ "r": 255, "g": 235, "b": 59 + }, + "hit": { + "r": 255, + "g": 235, + "b": 59 + }, + "walk": { + "r": 255, + "g": 235, + "b": 59 } }, "batter_count": { diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index d36bd9e6..93a01aff 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -143,6 +143,16 @@ "x": 15, "y": 29, "font_name": "5x7" + }, + "hit": { + "x": 15, + "y": 29, + "font_name": "5x7" + }, + "walk": { + "x": 15, + "y": 29, + "font_name": "5x7" } }, "batter_count": { diff --git a/data/scoreboard/__init__.py b/data/scoreboard/__init__.py index 6ac59f6d..88b2c4cf 100644 --- a/data/scoreboard/__init__.py +++ b/data/scoreboard/__init__.py @@ -41,6 +41,18 @@ def strikeout(self): def strikeout_looking(self): return self.play_result == "strikeout_looking" + + def single(self): + return self.play_result == "single" + + def double(self): + return self.play_result == "double" + + def triple(self): + return self.play_result == "triple" + + def walk(self): + return self.play_result == "walk" def get_text_for_reason(self): if self.note: diff --git a/renderers/games/game.py b/renderers/games/game.py index cac05611..7953cdcd 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -9,13 +9,12 @@ from renderers import scrollingtext from renderers.games import nohitter - +PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "home_run", "strikeout", "strikeout_looking"] def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboard, text_pos, animation_time): pos = 0 if scoreboard.inning.state == Inning.TOP or scoreboard.inning.state == Inning.BOTTOM: - - pos = _render_at_bat( + pos = _render_at_bat( canvas, layout, colors, @@ -23,21 +22,24 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa text_pos, scoreboard.strikeout(), scoreboard.strikeout_looking(), + scoreboard.play_result, (animation_time // 6) % 2, - scoreboard.pitches, + scoreboard.pitches + ) # Check if we're deep enough into a game and it's a no hitter or perfect game - should_display_nohitter = layout.coords("nohitter")["innings_until_display"] - if scoreboard.inning.number > should_display_nohitter: - if layout.state_is_nohitter(): - nohitter.render_nohit_text(canvas, layout, colors) + should_display_nohitter = layout.coords("nohitter")["innings_until_display"] + if scoreboard.inning.number > should_display_nohitter: + if layout.state_is_nohitter(): + nohitter.render_nohit_text(canvas, layout, colors) _render_count(canvas, layout, colors, scoreboard.pitches) _render_outs(canvas, layout, colors, scoreboard.outs) _render_bases(canvas, layout, colors, scoreboard.bases, scoreboard.homerun(), (animation_time % 16) // 5) _render_inning_display(canvas, layout, colors, scoreboard.inning) + else: _render_inning_break(canvas, layout, colors, scoreboard.inning) _render_due_up(canvas, layout, colors, scoreboard.atbat) @@ -46,18 +48,36 @@ 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): +def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, strikeout, looking, play_result, animation, pitches: Pitches): 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: + if play_result and play_result in PLAY_RESULT_UPDATES: + if animation and strikeout: __render_strikeout(canvas, layout, colors, looking) + else: + __render_play_result(canvas, layout, colors, play_result) return plength else: blength = __render_batter_text(canvas, layout, colors, atbat.batter, text_pos) return max(plength, blength) +def __render_play_result(canvas, layout, colors, play_result): + text = "" + if play_result == "single": + text = "1B" + elif play_result == "double": + text = "2B" + elif play_result == "triple": + text = "3B" + elif play_result == "walk": + text = "BB" + elif play_result == "home_run": + text = "HR" + coords = layout.coords("atbat.strikeout") + color = colors.graphics_color("atbat.strikeout") + font = layout.font("atbat.strikeout") + graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) def __render_strikeout(canvas, layout, colors, looking): coords = layout.coords("atbat.strikeout") @@ -66,7 +86,6 @@ def __render_strikeout(canvas, layout, colors, looking): text = "ꓘ" if looking else "K" graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) - def __render_batter_text(canvas, layout, colors, batter, text_pos): coords = layout.coords("atbat.batter") color = colors.graphics_color("atbat.batter") diff --git a/renderers/main.py b/renderers/main.py index c98ef020..dd4dd5e0 100644 --- a/renderers/main.py +++ b/renderers/main.py @@ -153,7 +153,7 @@ def __draw_game(self): self.data.scrolling_finished = True else: # draw a live game - if scoreboard.homerun() or scoreboard.strikeout(): + if scoreboard.homerun() or scoreboard.strikeout() or scoreboard.single() or scoreboard.double() or scoreboard.triple() or scoreboard.walk(): self.animation_time += 1 else: self.animation_time = 0 From 31ecbc9db16beb9d8835d9671ce7dc6aee68383a Mon Sep 17 00:00:00 2001 From: jimcreel Date: Fri, 14 Jul 2023 22:03:12 -0700 Subject: [PATCH 02/16] replaced __render_strikeout with __render_play_result --- renderers/games/game.py | 108 ++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 42 deletions(-) diff --git a/renderers/games/game.py b/renderers/games/game.py index 7953cdcd..b2c94b78 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -9,30 +9,66 @@ from renderers import scrollingtext from renderers.games import nohitter -PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "home_run", "strikeout", "strikeout_looking"] +PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "strikeout", "strikeout_looking"] + +PLAY_RESULTS = { + "single": { + "short": "1B", + "long": "Single" + }, + "double": { + "short": "2B", + "long": "Double" + }, + "triple": { + "short": "3B", + "long": "Triple" + }, + "home_run": { + "short": "HR", + "long": "Home Run" + }, + "walk": { + "short": "BB", + "long": "Walk" + }, + "intent_walk": { + "short": "IBB", + "long": "Int. Walk" + }, + "strikeout": { + "short": "K", + "long": "K" + }, + "strikeout_looking": { + "short": "ꓘ", + "long" : "ꓘ" + } + +} + def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboard, text_pos, animation_time): pos = 0 - if scoreboard.inning.state == Inning.TOP or scoreboard.inning.state == Inning.BOTTOM: - pos = _render_at_bat( - canvas, - layout, - colors, - scoreboard.atbat, - text_pos, - scoreboard.strikeout(), - scoreboard.strikeout_looking(), - scoreboard.play_result, - (animation_time // 6) % 2, - scoreboard.pitches - - ) + pos = _render_at_bat( + canvas, + layout, + colors, + scoreboard.atbat, + text_pos, + scoreboard.strikeout(), + scoreboard.strikeout_looking(), + scoreboard.play_result, + (animation_time // 6) % 2, + scoreboard.pitches + + ) # Check if we're deep enough into a game and it's a no hitter or perfect game - should_display_nohitter = layout.coords("nohitter")["innings_until_display"] - if scoreboard.inning.number > should_display_nohitter: - if layout.state_is_nohitter(): - nohitter.render_nohit_text(canvas, layout, colors) + should_display_nohitter = layout.coords("nohitter")["innings_until_display"] + if scoreboard.inning.number > should_display_nohitter: + if layout.state_is_nohitter(): + nohitter.render_nohit_text(canvas, layout, colors) _render_count(canvas, layout, colors, scoreboard.pitches) _render_outs(canvas, layout, colors, scoreboard.outs) @@ -48,14 +84,13 @@ 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, play_result, animation, pitches: Pitches): +def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, strikeout, looking, play_result, animation, pitches: Pitches): 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 play_result and play_result in PLAY_RESULT_UPDATES: - if animation and strikeout: - __render_strikeout(canvas, layout, colors, looking) - else: + if play_result in PLAY_RESULT_UPDATES: + if animation: + if looking: play_result += "_looking" __render_play_result(canvas, layout, colors, play_result) return plength else: @@ -64,26 +99,14 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, strikeout, lo def __render_play_result(canvas, layout, colors, play_result): text = "" - if play_result == "single": - text = "1B" - elif play_result == "double": - text = "2B" - elif play_result == "triple": - text = "3B" - elif play_result == "walk": - text = "BB" - elif play_result == "home_run": - text = "HR" - coords = layout.coords("atbat.strikeout") - color = colors.graphics_color("atbat.strikeout") - font = layout.font("atbat.strikeout") - graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) - -def __render_strikeout(canvas, layout, colors, looking): - coords = layout.coords("atbat.strikeout") + if layout.width > 64: + text = PLAY_RESULTS[play_result]["long"] + else: + text = PLAY_RESULTS[play_result]["short"] + print(text) + coords = layout.coords("atbat.batter") if layout.width > 64 else layout.coords("atbat.strikeout") color = colors.graphics_color("atbat.strikeout") font = layout.font("atbat.strikeout") - text = "ꓘ" if looking else "K" graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) def __render_batter_text(canvas, layout, colors, batter, text_pos): @@ -261,6 +284,7 @@ def __fill_out_circle(canvas, out, color): # --------------- inning information --------------- def _render_inning_break(canvas, layout, colors, inning: Inning): + text_font = layout.font("inning.break.text") num_font = layout.font("inning.break.number") text_coords = layout.coords("inning.break.text") From 88f81bbbcd80fdfc8f08ab29a07d5960db04a287 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Fri, 14 Jul 2023 22:04:05 -0700 Subject: [PATCH 03/16] condensed scoreboard methods to catch all hits in one --- data/scoreboard/__init__.py | 12 +++--------- renderers/main.py | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/data/scoreboard/__init__.py b/data/scoreboard/__init__.py index 88b2c4cf..7e50cd17 100644 --- a/data/scoreboard/__init__.py +++ b/data/scoreboard/__init__.py @@ -42,17 +42,11 @@ def strikeout(self): def strikeout_looking(self): return self.play_result == "strikeout_looking" - def single(self): - return self.play_result == "single" - - def double(self): - return self.play_result == "double" - - def triple(self): - return self.play_result == "triple" + def hit(self): + return self.play_result == "single" or self.play_result == "double" or self.play_result == "triple" def walk(self): - return self.play_result == "walk" + return self.play_result == "walk" or self.play_result == "intent_walk" def get_text_for_reason(self): if self.note: diff --git a/renderers/main.py b/renderers/main.py index dd4dd5e0..bf7eb5ac 100644 --- a/renderers/main.py +++ b/renderers/main.py @@ -153,7 +153,7 @@ def __draw_game(self): self.data.scrolling_finished = True else: # draw a live game - if scoreboard.homerun() or scoreboard.strikeout() or scoreboard.single() or scoreboard.double() or scoreboard.triple() or scoreboard.walk(): + if scoreboard.homerun() or scoreboard.strikeout() or scoreboard.hit() or scoreboard.walk(): self.animation_time += 1 else: self.animation_time = 0 From 943b0a336e0eb6658b13233383369c7fe6a7875b Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 09:30:01 -0700 Subject: [PATCH 04/16] enabled short and long play descriptions in coords files. render all play results through the play_result method --- coordinates/w128h32.json.example | 5 +- coordinates/w128h64.json.example | 5 +- coordinates/w192h64.json.example | 5 +- coordinates/w32h32.json.example | 5 +- coordinates/w64h32.json.example | 5 +- coordinates/w64h64.json.example | 5 +- renderers/games/game.py | 90 +++++++++++++++----------------- 7 files changed, 61 insertions(+), 59 deletions(-) diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index d3c59047..61fb3716 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -183,9 +183,10 @@ "append_pitcher_name": false }, "loop": 64, - "strikeout": { + "play_result": { "x": 84, - "y": 30 + "y": 30, + "desc_length": "Short" } }, "pregame": { diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index 52fe6f11..ed8535c6 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -145,9 +145,10 @@ "append_pitcher_name": false }, "loop": 68, - "strikeout": { + "play_result": { "x": 32, - "y": 60 + "y": 60, + "desc_length": "Long" } }, "batter_count": { diff --git a/coordinates/w192h64.json.example b/coordinates/w192h64.json.example index 9a10db27..3e9fe786 100644 --- a/coordinates/w192h64.json.example +++ b/coordinates/w192h64.json.example @@ -145,9 +145,10 @@ "append_pitcher_name": false }, "loop": 68, - "strikeout": { + "play_result": { "x": 32, - "y": 60 + "y": 60, + "desc_length": "Long" } }, "batter_count": { diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index f872886a..da1604d0 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -163,9 +163,10 @@ "append_pitcher_name": false }, "loop": 16, - "strikeout": { + "play_result": { "x": 33, - "y": 33 + "y": 33, + "desc_length": "Short" } }, "batter_count": { diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index 93a01aff..fe8f6a2a 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -139,10 +139,11 @@ "append_pitcher_name": false }, "loop": 36, - "strikeout": { + "play_result": { "x": 15, "y": 29, - "font_name": "5x7" + "font_name": "5x7", + "desc_length": "Short" }, "hit": { "x": 15, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index bde2213a..93fe3d10 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -139,9 +139,10 @@ "append_pitcher_name": false }, "loop": 64, - "strikeout": { + "play_result": { "x": 31, - "y": 36 + "y": 36, + "desc_length": "Short" } }, "pregame": { diff --git a/renderers/games/game.py b/renderers/games/game.py index b2c94b78..a3411fc5 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -6,46 +6,49 @@ from data.scoreboard.bases import Bases from data.scoreboard.inning import Inning from data.scoreboard.pitches import Pitches + from renderers import scrollingtext from renderers.games import nohitter PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "strikeout", "strikeout_looking"] -PLAY_RESULTS = { - "single": { - "short": "1B", - "long": "Single" - }, - "double": { - "short": "2B", - "long": "Double" - }, - "triple": { - "short": "3B", - "long": "Triple" - }, - "home_run": { - "short": "HR", - "long": "Home Run" - }, - "walk": { - "short": "BB", - "long": "Walk" - }, - "intent_walk": { - "short": "IBB", - "long": "Int. Walk" - }, - "strikeout": { - "short": "K", - "long": "K" - }, - "strikeout_looking": { - "short": "ꓘ", - "long" : "ꓘ" - } +PLAY_RESULTS ={ + "single": { + "short": "1B", + "long": "Single" + }, + "double": { + "short": "2B", + "long": "Double" + }, + "triple": { + "short": "3B", + "long": "Triple" + }, + "home_run": { + "short": "HR", + "long": "Home Run" + }, + "walk": { + "short": "BB", + "long": "Walk" + }, + "intent_walk": { + "short": "IBB", + "long": "Int. Walk" + }, + "strikeout": { + "short": "K", + "long": "K" + }, + "strikeout_looking": { + "short": "ꓘ", + "long" : "ꓘ" + } + } + -} + def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboard, text_pos, animation_time): pos = 0 @@ -56,8 +59,6 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa colors, scoreboard.atbat, text_pos, - scoreboard.strikeout(), - scoreboard.strikeout_looking(), scoreboard.play_result, (animation_time // 6) % 2, scoreboard.pitches @@ -84,13 +85,12 @@ 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, play_result, animation, pitches: Pitches): +def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, animation, pitches: Pitches): 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 play_result in PLAY_RESULT_UPDATES: if animation: - if looking: play_result += "_looking" __render_play_result(canvas, layout, colors, play_result) return plength else: @@ -98,15 +98,11 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, strikeout, lo return max(plength, blength) def __render_play_result(canvas, layout, colors, play_result): - text = "" - if layout.width > 64: - text = PLAY_RESULTS[play_result]["long"] - else: - text = PLAY_RESULTS[play_result]["short"] - print(text) - coords = layout.coords("atbat.batter") if layout.width > 64 else layout.coords("atbat.strikeout") - color = colors.graphics_color("atbat.strikeout") - font = layout.font("atbat.strikeout") + + coords = layout.coords("atbat.play_result") + color = colors.graphics_color("atbat.play_result") + font = layout.font("atbat.play_result") + text = PLAY_RESULTS[play_result][coords["desc_length"]] graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) def __render_batter_text(canvas, layout, colors, batter, text_pos): From 51a17b2ecf0e98b5a603d582d1c9efc7c62d4141 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 11:37:24 -0700 Subject: [PATCH 05/16] moved play results to data/plays.py, adjusted play_result positioning --- colors/scoreboard.json.example | 12 +--------- coordinates/w128h32.json.example | 2 +- coordinates/w128h64.json.example | 2 +- coordinates/w192h64.json.example | 2 +- coordinates/w32h32.json.example | 2 +- coordinates/w64h32.json.example | 2 +- coordinates/w64h64.json.example | 2 +- data/plays.py | 36 ++++++++++++++++++++++++++++ renderers/games/game.py | 41 ++------------------------------ 9 files changed, 45 insertions(+), 56 deletions(-) create mode 100644 data/plays.py diff --git a/colors/scoreboard.json.example b/colors/scoreboard.json.example index 6dc30961..b2275f36 100644 --- a/colors/scoreboard.json.example +++ b/colors/scoreboard.json.example @@ -124,17 +124,7 @@ "g": 255, "b": 255 }, - "strikeout": { - "r": 255, - "g": 235, - "b": 59 - }, - "hit": { - "r": 255, - "g": 235, - "b": 59 - }, - "walk": { + "play_result": { "r": 255, "g": 235, "b": 59 diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index 61fb3716..4324094b 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -184,7 +184,7 @@ }, "loop": 64, "play_result": { - "x": 84, + "x": 60, "y": 30, "desc_length": "Short" } diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index ed8535c6..eb29fb8a 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -146,7 +146,7 @@ }, "loop": 68, "play_result": { - "x": 32, + "x": 16, "y": 60, "desc_length": "Long" } diff --git a/coordinates/w192h64.json.example b/coordinates/w192h64.json.example index 3e9fe786..eaf05fc7 100644 --- a/coordinates/w192h64.json.example +++ b/coordinates/w192h64.json.example @@ -146,7 +146,7 @@ }, "loop": 68, "play_result": { - "x": 32, + "x": 16, "y": 60, "desc_length": "Long" } diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index da1604d0..9cce89ea 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -165,7 +165,7 @@ "loop": 16, "play_result": { "x": 33, - "y": 33, + "y": 15, "desc_length": "Short" } }, diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index fe8f6a2a..766e5dbc 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -141,7 +141,7 @@ "loop": 36, "play_result": { "x": 15, - "y": 29, + "y": 15, "font_name": "5x7", "desc_length": "Short" }, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index 93fe3d10..b016e99b 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -141,7 +141,7 @@ "loop": 64, "play_result": { "x": 31, - "y": 36, + "y": 18, "desc_length": "Short" } }, diff --git a/data/plays.py b/data/plays.py new file mode 100644 index 00000000..027f1057 --- /dev/null +++ b/data/plays.py @@ -0,0 +1,36 @@ +PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "strikeout", "strikeout_looking"] + +PLAY_RESULTS ={ + "single": { + "Short": "1B", + "Long": "Single" + }, + "double": { + "Short": "2B", + "Long": "Double" + }, + "triple": { + "Short": "3B", + "Long": "Triple" + }, + "home_run": { + "Short": "HR", + "Long": "Home Run" + }, + "walk": { + "Short": "BB", + "Long": "Walk" + }, + "intent_walk": { + "Short": "IBB", + "Long": "Int. Walk" + }, + "strikeout": { + "Short": "K", + "Long": "K" + }, + "strikeout_looking": { + "Short": "ꓘ", + "Long" : "ꓘ" + } + } diff --git a/renderers/games/game.py b/renderers/games/game.py index a3411fc5..0473e049 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -6,49 +6,11 @@ from data.scoreboard.bases import Bases from data.scoreboard.inning import Inning from data.scoreboard.pitches import Pitches +from data.plays import PLAY_RESULT_UPDATES, PLAY_RESULTS from renderers import scrollingtext from renderers.games import nohitter -PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "strikeout", "strikeout_looking"] - -PLAY_RESULTS ={ - "single": { - "short": "1B", - "long": "Single" - }, - "double": { - "short": "2B", - "long": "Double" - }, - "triple": { - "short": "3B", - "long": "Triple" - }, - "home_run": { - "short": "HR", - "long": "Home Run" - }, - "walk": { - "short": "BB", - "long": "Walk" - }, - "intent_walk": { - "short": "IBB", - "long": "Int. Walk" - }, - "strikeout": { - "short": "K", - "long": "K" - }, - "strikeout_looking": { - "short": "ꓘ", - "long" : "ꓘ" - } - } - - - def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboard, text_pos, animation_time): pos = 0 @@ -95,6 +57,7 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, return plength else: blength = __render_batter_text(canvas, layout, colors, atbat.batter, text_pos) + print(blength) return max(plength, blength) def __render_play_result(canvas, layout, colors, play_result): From 3f94d7126fe36e6dd62760351c111d4fcc29d6e2 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 11:39:01 -0700 Subject: [PATCH 06/16] removed debug printing --- renderers/games/game.py | 1 - 1 file changed, 1 deletion(-) diff --git a/renderers/games/game.py b/renderers/games/game.py index 0473e049..f785bc57 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -57,7 +57,6 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, return plength else: blength = __render_batter_text(canvas, layout, colors, atbat.batter, text_pos) - print(blength) return max(plength, blength) def __render_play_result(canvas, layout, colors, play_result): From 585a996ad066816530fa4396a3a86d133adda982 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 12:01:48 -0700 Subject: [PATCH 07/16] fixing short positioning for small screens --- coordinates/w64h32.json.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index 766e5dbc..fe8f6a2a 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -141,7 +141,7 @@ "loop": 36, "play_result": { "x": 15, - "y": 15, + "y": 29, "font_name": "5x7", "desc_length": "Short" }, From d74e92962cc9570328e180b6e29845eadd9cd9fb Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 12:02:35 -0700 Subject: [PATCH 08/16] fixing positioning for small screens --- coordinates/w32h32.json.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index 9cce89ea..da1604d0 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -165,7 +165,7 @@ "loop": 16, "play_result": { "x": 33, - "y": 15, + "y": 33, "desc_length": "Short" } }, From a3ae6f86ed2ca46d5655d875faf4c8ec6e6d2c00 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 12:03:04 -0700 Subject: [PATCH 09/16] fixing positioning for small screens --- coordinates/w64h64.json.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index b016e99b..93fe3d10 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -141,7 +141,7 @@ "loop": 64, "play_result": { "x": 31, - "y": 18, + "y": 36, "desc_length": "Short" } }, From 6d3bdc4720271cc7b040dc5842d6e2249d675ec8 Mon Sep 17 00:00:00 2001 From: Jim Creel Date: Sat, 15 Jul 2023 21:46:09 -0700 Subject: [PATCH 10/16] constantized play results, removed play_result trigger list --- coordinates/w128h64.json.example | 2 +- data/plays.py | 95 ++++++++++++++++++++------------ data/scoreboard/__init__.py | 6 +- renderers/games/game.py | 10 +++- 4 files changed, 72 insertions(+), 41 deletions(-) diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index eb29fb8a..6aa5f343 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -148,7 +148,7 @@ "play_result": { "x": 16, "y": 60, - "desc_length": "Long" + "desc_length": "long" } }, "batter_count": { diff --git a/data/plays.py b/data/plays.py index 027f1057..205a113d 100644 --- a/data/plays.py +++ b/data/plays.py @@ -1,36 +1,61 @@ -PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "strikeout", "strikeout_looking"] +SINGLE = "single" +DOUBLE = "double" +TRIPLE = "triple" +HOME_RUN = "home_run" -PLAY_RESULTS ={ - "single": { - "Short": "1B", - "Long": "Single" - }, - "double": { - "Short": "2B", - "Long": "Double" - }, - "triple": { - "Short": "3B", - "Long": "Triple" - }, - "home_run": { - "Short": "HR", - "Long": "Home Run" - }, - "walk": { - "Short": "BB", - "Long": "Walk" - }, - "intent_walk": { - "Short": "IBB", - "Long": "Int. Walk" - }, - "strikeout": { - "Short": "K", - "Long": "K" - }, - "strikeout_looking": { - "Short": "ꓘ", - "Long" : "ꓘ" - } - } +WALK = "walk" +INTENTIONAL_WALK = "intent_walk" + +STRIKEOUT = "strikeout" +STRIKEOUT_LOOKING = "strikeout_looking" + +HITS = [ + SINGLE, + DOUBLE, + TRIPLE +] + +WALKS = [ + WALK, + INTENTIONAL_WALK +] + +STRIKEOUTS = [ + STRIKEOUT, + STRIKEOUT_LOOKING +] + +PLAY_RESULTS = { + SINGLE: { + "short": "1B", + "long": "Single" + }, + DOUBLE: { + "short": "2B", + "long": "Double" + }, + TRIPLE: { + "short": "3B", + "long": "Triple" + }, + HOME_RUN: { + "short": "HR", + "long": "Home Run" + }, + WALK: { + "short": "BB", + "long": "Walk" + }, + INTENTIONAL_WALK: { + "short": "IBB", + "long": "Int. Walk" + }, + STRIKEOUT: { + "short": "K", + "long": "K" + }, + STRIKEOUT_LOOKING: { + "short": "ꓘ", + "long": "ꓘ" + } +} \ No newline at end of file diff --git a/data/scoreboard/__init__.py b/data/scoreboard/__init__.py index 7e50cd17..78f71918 100644 --- a/data/scoreboard/__init__.py +++ b/data/scoreboard/__init__.py @@ -5,6 +5,8 @@ from data.scoreboard.outs import Outs from data.scoreboard.pitches import Pitches from data.scoreboard.team import Team +from data import plays + class Scoreboard: @@ -43,10 +45,10 @@ def strikeout_looking(self): return self.play_result == "strikeout_looking" def hit(self): - return self.play_result == "single" or self.play_result == "double" or self.play_result == "triple" + return self.play_result in plays.HITS def walk(self): - return self.play_result == "walk" or self.play_result == "intent_walk" + return self.play_result in plays.WALKS def get_text_for_reason(self): if self.note: diff --git a/renderers/games/game.py b/renderers/games/game.py index f785bc57..95e01139 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -6,7 +6,7 @@ from data.scoreboard.bases import Bases from data.scoreboard.inning import Inning from data.scoreboard.pitches import Pitches -from data.plays import PLAY_RESULT_UPDATES, PLAY_RESULTS +from data.plays import PLAY_RESULTS from renderers import scrollingtext from renderers.games import nohitter @@ -51,7 +51,8 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, 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 play_result in PLAY_RESULT_UPDATES: + results = list(PLAY_RESULTS.keys()) + if play_result in results: if animation: __render_play_result(canvas, layout, colors, play_result) return plength @@ -64,7 +65,10 @@ def __render_play_result(canvas, layout, colors, play_result): coords = layout.coords("atbat.play_result") color = colors.graphics_color("atbat.play_result") font = layout.font("atbat.play_result") - text = PLAY_RESULTS[play_result][coords["desc_length"]] + try: + text = PLAY_RESULTS[play_result][coords["desc_length"]] + except KeyError: + return # There's no text or coordinates to render graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) def __render_batter_text(canvas, layout, colors, batter, text_pos): From b6c230c3d4ccc70e6aecfbcc2417bd1817790e77 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 21:55:10 -0700 Subject: [PATCH 11/16] updated w64h32 to remove hit and walk coords --- coordinates/w64h32.json.example | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index fe8f6a2a..4a25e93d 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -144,17 +144,8 @@ "y": 29, "font_name": "5x7", "desc_length": "Short" - }, - "hit": { - "x": 15, - "y": 29, - "font_name": "5x7" - }, - "walk": { - "x": 15, - "y": 29, - "font_name": "5x7" } + }, "batter_count": { "x": 34, From 03e2b63063c5b73d8050a04dbbc06a8096ef92fb Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sun, 16 Jul 2023 10:12:30 -0700 Subject: [PATCH 12/16] added separate color key for strikeout, updated keys for play_result desc_length in small displays --- colors/scoreboard.json.example | 5 +++++ coordinates/w128h32.json.example | 2 +- coordinates/w32h32.json.example | 2 +- coordinates/w64h32.json.example | 2 +- coordinates/w64h64.json.example | 2 +- renderers/games/game.py | 5 ++++- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/colors/scoreboard.json.example b/colors/scoreboard.json.example index b2275f36..b016193b 100644 --- a/colors/scoreboard.json.example +++ b/colors/scoreboard.json.example @@ -128,6 +128,11 @@ "r": 255, "g": 235, "b": 59 + }, + "strikeout": { + "r": 255, + "g": 0, + "b": 0 } }, "batter_count": { diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index 4324094b..6c224155 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -186,7 +186,7 @@ "play_result": { "x": 60, "y": 30, - "desc_length": "Short" + "desc_length": "short" } }, "pregame": { diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index da1604d0..5d8b0ed6 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -166,7 +166,7 @@ "play_result": { "x": 33, "y": 33, - "desc_length": "Short" + "desc_length": "short" } }, "batter_count": { diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index 4a25e93d..0a268819 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -143,7 +143,7 @@ "x": 15, "y": 29, "font_name": "5x7", - "desc_length": "Short" + "desc_length": "short" } }, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index 93fe3d10..611f98f0 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -142,7 +142,7 @@ "play_result": { "x": 31, "y": 36, - "desc_length": "Short" + "desc_length": "short" } }, "pregame": { diff --git a/renderers/games/game.py b/renderers/games/game.py index 95e01139..4773c4dc 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -63,7 +63,10 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, def __render_play_result(canvas, layout, colors, play_result): coords = layout.coords("atbat.play_result") - color = colors.graphics_color("atbat.play_result") + if "strikeout" in play_result: + color = colors.graphics_color("atbat.strikeout") + else: + color = colors.graphics_color("atbat.play_result") font = layout.font("atbat.play_result") try: text = PLAY_RESULTS[play_result][coords["desc_length"]] From 6557fd9e0a837065030f9e48286f66bb1a178e85 Mon Sep 17 00:00:00 2001 From: pawptart Date: Sun, 16 Jul 2023 19:37:55 -0400 Subject: [PATCH 13/16] Bump version to v6.5.0 --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 6bb344b1..96825d08 100644 --- a/version.py +++ b/version.py @@ -1,5 +1,5 @@ SCRIPT_NAME = "MLB LED Scoreboard" -SCRIPT_VERSION = "6.4.1" +SCRIPT_VERSION = "6.5.0" if __name__ == "__main__": From 5c28bdc3e01a6ce83dbded2679a873355286c98a Mon Sep 17 00:00:00 2001 From: pawptart Date: Sun, 16 Jul 2023 19:50:41 -0400 Subject: [PATCH 14/16] Standardize desc_length field on lowercase values --- README.md | 2 +- coordinates/README.md | 2 +- coordinates/w128h32.json.example | 2 +- coordinates/w128h64.json.example | 2 +- coordinates/w32h32.json.example | 2 +- coordinates/w64h32.json.example | 2 +- coordinates/w64h64.json.example | 2 +- renderers/games/game.py | 7 +++---- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e2fb9182..4d77072d 100755 --- a/README.md +++ b/README.md @@ -259,7 +259,7 @@ A default `config.json.example` file is included for reference. Copy this file t ### Additional Features * Runs/Hits/Errors - Runs are always shown on the games screen, but you can enable or adjust spacing of a "runs, hits, errors" display. Take a look at the [coordinates readme file](/coordinates/README.md) for details. -* Pitch Data - Pitch data can be shown on the game screen, See the [coordinates readme file](/coordinates/README.md) for details. In addition, the Short and Long pitch description can be changed in data/pitches.py +* Pitch Data - Pitch data can be shown on the game screen, See the [coordinates readme file](/coordinates/README.md) for details. In addition, the `short` and `long` pitch description can be changed in data/pitches.py ### Flags diff --git a/coordinates/README.md b/coordinates/README.md index a86d8872..301bd590 100644 --- a/coordinates/README.md +++ b/coordinates/README.md @@ -21,7 +21,7 @@ The layout can have a couple of different states where things are rendered diffe ## Pitch Data * `enabled` (true/false) turn feature on/off * `mph` (true/false) When rendering pitch speed add mph after (99 mph) -* `desc_length` (Short/Long) The short or long pitch type description, you can change both the short and long description to your liking in data/pitches as long as you do not change the index value. +* `desc_length` (short/long) The short or long pitch type description, you can change both the short and long description to your liking in data/pitches as long as you do not change the index value. ## Updates The software develops and releases features with full support for the default layouts, so custom layouts may look unsatisfactory if you update to later versions of the scoreboard. If you as a user decide to create a custom layout file, you are responsible for tweaking the coordinates to your liking with each update. diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index bc916972..e8b4269c 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -173,7 +173,7 @@ "y": 50, "enabled": false, "mph": false, - "desc_length": "Short" + "desc_length": "short" }, "pitch_count": { "font_name": "4x6", diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index babb6d54..0004716b 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -135,7 +135,7 @@ "y": 50, "enabled": true, "mph": true, - "desc_length": "Long" + "desc_length": "long" }, "pitch_count": { "font_name": "4x6", diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index 44598f71..f70569e3 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -153,7 +153,7 @@ "y": 50, "enabled": false, "mph": false, - "desc_length": "Short" + "desc_length": "short" }, "pitch_count": { "font_name": "4x6", diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index b8345e24..0dbe4721 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -130,7 +130,7 @@ "y": 50, "enabled": false, "mph": false, - "desc_length": "Short" + "desc_length": "short" }, "pitch_count": { "x": 1, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index f97c1b27..106bda6e 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -129,7 +129,7 @@ "y": 50, "enabled": false, "mph": false, - "desc_length": "Short" + "desc_length": "short" }, "pitch_count": { "font_name": "4x6", diff --git a/renderers/games/game.py b/renderers/games/game.py index 4773c4dc..d309ade7 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -61,7 +61,6 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, return max(plength, blength) def __render_play_result(canvas, layout, colors, play_result): - coords = layout.coords("atbat.play_result") if "strikeout" in play_result: color = colors.graphics_color("atbat.strikeout") @@ -69,7 +68,7 @@ def __render_play_result(canvas, layout, colors, play_result): color = colors.graphics_color("atbat.play_result") font = layout.font("atbat.play_result") try: - text = PLAY_RESULTS[play_result][coords["desc_length"]] + text = PLAY_RESULTS[play_result][coords["desc_length"].lower()] except KeyError: return # There's no text or coordinates to render graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) @@ -130,9 +129,9 @@ def __render_pitch_text(canvas, layout, colors, pitches: Pitches): mph = " " if coords["mph"]: mph = "mph " - if coords["desc_length"] == "Long": + if coords["desc_length"].lower() == "long": pitch_text = str(pitches.last_pitch_speed) + mph + pitches.last_pitch_type_long - elif coords["desc_length"] == "Short": + elif coords["desc_length"].lower() == "short": pitch_text = str(pitches.last_pitch_speed) + mph + pitches.last_pitch_type else: pitch_text = "" From 2c2db6537079e808f975ed988c506f408265fb52 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Sun, 16 Jul 2023 20:32:03 -0400 Subject: [PATCH 15/16] Allow more config of play results --- coordinates/w128h32.json.example | 9 +++- coordinates/w128h64.json.example | 9 +++- coordinates/w192h64.json.example | 11 ++++- coordinates/w32h32.json.example | 9 +++- coordinates/w64h32.json.example | 12 ++++- coordinates/w64h64.json.example | 9 +++- data/plays.py | 78 +++++++++++--------------------- renderers/games/game.py | 33 +++++++++----- 8 files changed, 100 insertions(+), 70 deletions(-) diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index e8b4269c..c181acdf 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -183,10 +183,17 @@ "append_pitcher_name": false }, "loop": 64, + "strikeout": { + "x": 60, + "y": 30, + "desc_length": "short", + "enabled": true + }, "play_result": { "x": 60, "y": 30, - "desc_length": "short" + "desc_length": "short", + "enabled": true } }, "pregame": { diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index 0004716b..184a7e0c 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -145,10 +145,17 @@ "append_pitcher_name": false }, "loop": 68, + "strikeout": { + "x": 16, + "y": 60, + "desc_length": "long", + "enabled": true + }, "play_result": { "x": 16, "y": 60, - "desc_length": "long" + "desc_length": "long", + "enabled": true } }, "batter_count": { diff --git a/coordinates/w192h64.json.example b/coordinates/w192h64.json.example index 5334dc6a..6f010530 100644 --- a/coordinates/w192h64.json.example +++ b/coordinates/w192h64.json.example @@ -135,7 +135,7 @@ "y": 50, "enabled": true, "mph": true, - "desc_length": "Long" + "desc_length": "long" }, "pitch_count": { "font_name": "4x6", @@ -145,10 +145,17 @@ "append_pitcher_name": false }, "loop": 68, + "strikeout": { + "x": 16, + "y": 60, + "desc_length": "long", + "enabled": true + }, "play_result": { "x": 16, "y": 60, - "desc_length": "Long" + "desc_length": "long", + "enabled": true } }, "batter_count": { diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index f70569e3..31a8dd0a 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -163,10 +163,17 @@ "append_pitcher_name": false }, "loop": 16, + "strikeout": { + "x": 33, + "y": 33, + "desc_length": "short", + "enabled": false + }, "play_result": { "x": 33, "y": 33, - "desc_length": "short" + "desc_length": "short", + "enabled": false } }, "batter_count": { diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index 0dbe4721..a9ee194b 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -139,13 +139,21 @@ "append_pitcher_name": false }, "loop": 36, + "strikeout": { + "x": 15, + "y": 29, + "font_name": "5x7", + "desc_length": "short", + "enabled": true + }, "play_result": { "x": 15, "y": 29, "font_name": "5x7", - "desc_length": "short" + "desc_length": "short", + "enabled": true } - + }, "batter_count": { "x": 34, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index 106bda6e..5ec273bb 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -139,10 +139,17 @@ "append_pitcher_name": false }, "loop": 64, + "strikeout": { + "x": 31, + "y": 36, + "desc_length": "short", + "enabled": true + }, "play_result": { "x": 31, "y": 36, - "desc_length": "short" + "desc_length": "short", + "enabled": true } }, "pregame": { diff --git a/data/plays.py b/data/plays.py index 205a113d..c1701093 100644 --- a/data/plays.py +++ b/data/plays.py @@ -1,61 +1,37 @@ -SINGLE = "single" -DOUBLE = "double" -TRIPLE = "triple" +SINGLE = "single" +DOUBLE = "double" +TRIPLE = "triple" HOME_RUN = "home_run" -WALK = "walk" +WALK = "walk" INTENTIONAL_WALK = "intent_walk" +HIT_BY_PITCH = "hit_by_pitch" -STRIKEOUT = "strikeout" +STRIKEOUT = "strikeout" +STRIKEOUT_ALT = "strike_out" STRIKEOUT_LOOKING = "strikeout_looking" -HITS = [ - SINGLE, - DOUBLE, - TRIPLE -] +ERROR = "error" +FIELDERS_CHOICE = "fielders_choice" -WALKS = [ - WALK, - INTENTIONAL_WALK -] +HITS = [SINGLE, DOUBLE, TRIPLE] -STRIKEOUTS = [ - STRIKEOUT, - STRIKEOUT_LOOKING -] +WALKS = [WALK, INTENTIONAL_WALK, HIT_BY_PITCH] + +OTHERS = [ERROR, FIELDERS_CHOICE] + +STRIKEOUTS = [STRIKEOUT, STRIKEOUT_ALT, STRIKEOUT_LOOKING] PLAY_RESULTS = { - SINGLE: { - "short": "1B", - "long": "Single" - }, - DOUBLE: { - "short": "2B", - "long": "Double" - }, - TRIPLE: { - "short": "3B", - "long": "Triple" - }, - HOME_RUN: { - "short": "HR", - "long": "Home Run" - }, - WALK: { - "short": "BB", - "long": "Walk" - }, - INTENTIONAL_WALK: { - "short": "IBB", - "long": "Int. Walk" - }, - STRIKEOUT: { - "short": "K", - "long": "K" - }, - STRIKEOUT_LOOKING: { - "short": "ꓘ", - "long": "ꓘ" - } -} \ No newline at end of file + SINGLE: {"short": "1B", "long": "Single"}, + DOUBLE: {"short": "2B", "long": "Double"}, + TRIPLE: {"short": "3B", "long": "Triple"}, + WALK: {"short": "BB", "long": "Walk"}, + INTENTIONAL_WALK: {"short": "IBB", "long": "Int. Walk"}, + STRIKEOUT: {"short": "K", "long": "K"}, + STRIKEOUT_ALT: {"short": "K", "long": "K"}, + STRIKEOUT_LOOKING: {"short": "ꓘ", "long": "ꓘ"}, + HIT_BY_PITCH: {"short": "HBP", "long": "Hit Bttr"}, + ERROR: {"short": "E", "long": "Error"}, + FIELDERS_CHOICE: {"short": "FC", "long": "Fielder's Chc"}, +} diff --git a/renderers/games/game.py b/renderers/games/game.py index d309ade7..5c2e1960 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -24,8 +24,7 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa scoreboard.play_result, (animation_time // 6) % 2, scoreboard.pitches - - ) + ) # Check if we're deep enough into a game and it's a no hitter or perfect game should_display_nohitter = layout.coords("nohitter")["innings_until_display"] @@ -38,7 +37,7 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa _render_bases(canvas, layout, colors, scoreboard.bases, scoreboard.homerun(), (animation_time % 16) // 5) _render_inning_display(canvas, layout, colors, scoreboard.inning) - + else: _render_inning_break(canvas, layout, colors, scoreboard.inning) _render_due_up(canvas, layout, colors, scoreboard.atbat) @@ -47,12 +46,12 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa # --------------- at-bat --------------- -def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, animation, pitches: Pitches): +def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, animation, pitches: Pitches): 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) results = list(PLAY_RESULTS.keys()) - if play_result in results: + if play_result in results and __should_render_play_result(play_result, layout): if animation: __render_play_result(canvas, layout, colors, play_result) return plength @@ -60,19 +59,31 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, blength = __render_batter_text(canvas, layout, colors, atbat.batter, text_pos) return max(plength, blength) + +def __should_render_play_result(play_result, layout): + if "strikeout" in play_result: + coords = layout.coords("atbat.strikeout") + else: + coords = layout.coords("atbat.play_result") + return coords["enabled"] + + def __render_play_result(canvas, layout, colors, play_result): - coords = layout.coords("atbat.play_result") if "strikeout" in play_result: color = colors.graphics_color("atbat.strikeout") - else: + coords = layout.coords("atbat.strikeout") + font = layout.font("atbat.strikeout") + else: color = colors.graphics_color("atbat.play_result") - font = layout.font("atbat.play_result") + coords = layout.coords("atbat.play_result") + font = layout.font("atbat.play_result") try: - text = PLAY_RESULTS[play_result][coords["desc_length"].lower()] + text = PLAY_RESULTS[play_result][coords["desc_length"].lower()] except KeyError: - return # There's no text or coordinates to render + return graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) + def __render_batter_text(canvas, layout, colors, batter, text_pos): coords = layout.coords("atbat.batter") color = colors.graphics_color("atbat.batter") @@ -248,7 +259,7 @@ def __fill_out_circle(canvas, out, color): # --------------- inning information --------------- def _render_inning_break(canvas, layout, colors, inning: Inning): - + text_font = layout.font("inning.break.text") num_font = layout.font("inning.break.number") text_coords = layout.coords("inning.break.text") From 9ab5327b7d445e70be4bbbdc4b714e4f8c302995 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Sun, 16 Jul 2023 20:37:52 -0400 Subject: [PATCH 16/16] Add test --- tests/test_data_up_to_date.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_data_up_to_date.py b/tests/test_data_up_to_date.py index ba7062e5..64e8b4c8 100644 --- a/tests/test_data_up_to_date.py +++ b/tests/test_data_up_to_date.py @@ -17,18 +17,22 @@ def test_status_complete(self): self.assertSetEqual(official_statuses, our_statuses) def test_teams_complete(self): - teams = statsapi.get('teams', {'sportIds':1})['teams'] + teams = statsapi.get("teams", {"sportIds": 1})["teams"] - abbr_to_full = {t['teamName']:t['name'] for t in teams} + abbr_to_full = {t["teamName"]: t["name"] for t in teams} self.assertEqual(abbr_to_full, data.teams.TEAM_FULL) - full_to_abbr = {t['name']:t['abbreviation'] for t in teams} + full_to_abbr = {t["name"]: t["abbreviation"] for t in teams} self.assertEqual(full_to_abbr, data.teams.TEAM_ABBR_LN) def test_pitches_complete(self): - pitches = set(p["code"] for p in statsapi.meta("pitchTypes")) + pitches = set(p["code"] for p in statsapi.meta("pitchTypes")) self.assertSetEqual(pitches, set(data.pitches.PITCH_SHORT.keys())) self.assertSetEqual(pitches, set(data.pitches.PITCH_LONG.keys())) + def test_results_exist(self): + events = set(e["code"] for e in statsapi.meta("eventTypes")) + events.add("strikeout_looking") # our custom event + self.assertTrue(events.issuperset(data.plays.PLAY_RESULTS.keys())) if __name__ == "__main__":