From b145eef6b855b08bfbe4935684e9eedb79f7ec3a Mon Sep 17 00:00:00 2001 From: Jeremy Scheff Date: Mon, 15 Apr 2024 10:25:38 -0400 Subject: [PATCH] isScoringPlay -> formatScoringSummaryEvent --- TODO | 1 - ... => formatScoringSummaryEvent.football.ts} | 18 ++++++++++++----- .../formatScoringSummaryEvent.hockey.ts | 12 +++++++++++ .../util/processLiveGameEvents.football.tsx | 20 ++++++------------- .../core/GameSim.football/PlayByPlayLogger.ts | 12 +++++------ src/worker/views/playoffs.ts | 3 --- 6 files changed, 36 insertions(+), 30 deletions(-) rename src/common/{isScoringPlay.football.ts => formatScoringSummaryEvent.football.ts} (56%) create mode 100644 src/common/formatScoringSummaryEvent.hockey.ts diff --git a/TODO b/TODO index 0c500eeb7a..e9afa11ec1 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,6 @@ indicator of if trade will be accepted allow undoing a trade shootouts -- isScoringPlay -> formatScoringSummaryEvent - confirm for all sports - check what fast-forward options are shown during shootout - show shootout result somewhere diff --git a/src/common/isScoringPlay.football.ts b/src/common/formatScoringSummaryEvent.football.ts similarity index 56% rename from src/common/isScoringPlay.football.ts rename to src/common/formatScoringSummaryEvent.football.ts index 12fc38ba83..b5744a4ee9 100644 --- a/src/common/isScoringPlay.football.ts +++ b/src/common/formatScoringSummaryEvent.football.ts @@ -1,12 +1,13 @@ import type { PlayByPlayEvent, - PlayByPlayEventInputScore, + PlayByPlayEventScore, } from "../worker/core/GameSim.football/PlayByPlayLogger"; -export const isScoringPlay = ( +export const formatScoringSummaryEvent = ( event: PlayByPlayEvent, -): event is PlayByPlayEventInputScore => { - return ( + period: number, +): PlayByPlayEventScore | undefined => { + if ( (event as any).safety || (event as any).td || event.type === "extraPoint" || @@ -14,5 +15,12 @@ export const isScoringPlay = ( // Include missed FGs event.type === "fieldGoal" || event.type === "shootoutShot" - ); + ) { + const scoringSummaryEvent = { + ...event, + quarter: period, + } as PlayByPlayEventScore; + + return scoringSummaryEvent; + } }; diff --git a/src/common/formatScoringSummaryEvent.hockey.ts b/src/common/formatScoringSummaryEvent.hockey.ts new file mode 100644 index 0000000000..c171630c77 --- /dev/null +++ b/src/common/formatScoringSummaryEvent.hockey.ts @@ -0,0 +1,12 @@ +import type { + PlayByPlayEvent, + PlayByPlayEventScore, +} from "../worker/core/GameSim.hockey/PlayByPlayLogger"; + +export const formatScoringSummaryEvent = ( + event: PlayByPlayEvent, +): PlayByPlayEventScore | undefined => { + if (event.type === "goal" || event.type === "shootoutShot") { + return event; + } +}; diff --git a/src/ui/util/processLiveGameEvents.football.tsx b/src/ui/util/processLiveGameEvents.football.tsx index eb548a18a5..9611cb82a4 100644 --- a/src/ui/util/processLiveGameEvents.football.tsx +++ b/src/ui/util/processLiveGameEvents.football.tsx @@ -1,5 +1,5 @@ import { getPeriodName } from "../../common"; -import { isScoringPlay } from "../../common/isScoringPlay.football"; +import { formatScoringSummaryEvent } from "../../common/formatScoringSummaryEvent.football"; import { helpers, local } from "."; import type { PlayByPlayEvent } from "../../worker/core/GameSim.football/PlayByPlayLogger"; import type { ReactNode } from "react"; @@ -515,7 +515,7 @@ const processLiveGameEvents = ({ const actualT = eAny.t === 0 ? 1 : eAny.t === 1 ? 0 : undefined; const otherT = actualT === 0 ? 1 : 0; - const scoringSummary = isScoringPlay(e); + const scoringSummaryEvent = formatScoringSummaryEvent(e, quarters.length); let quarterText; if (quarters.length === 0) { @@ -957,14 +957,9 @@ const processLiveGameEvents = ({ } // Extra fieldGoal check is to include missed field goals - if (scoringSummary) { + if (scoringSummaryEvent) { const scoreInfo = getScoreInfo(e); - if ( - scoreInfo && - (scoreInfo.points > 0 || - scoreInfo.type === "FG" || - scoreInfo.type === "SH") - ) { + if (scoreInfo) { play.scoreInfo = scoreInfo; } } @@ -1004,11 +999,8 @@ const processLiveGameEvents = ({ } } - if (scoringSummary) { - boxScore.scoringSummary.push({ - ...e, - quarter: quarters.length, - }); + if (scoringSummaryEvent) { + boxScore.scoringSummary.push(scoringSummaryEvent); } } diff --git a/src/worker/core/GameSim.football/PlayByPlayLogger.ts b/src/worker/core/GameSim.football/PlayByPlayLogger.ts index a1980d978f..0402c0d6ac 100644 --- a/src/worker/core/GameSim.football/PlayByPlayLogger.ts +++ b/src/worker/core/GameSim.football/PlayByPlayLogger.ts @@ -1,4 +1,4 @@ -import { isScoringPlay } from "../../../common/isScoringPlay.football"; +import { formatScoringSummaryEvent } from "../../../common/formatScoringSummaryEvent.football"; import type { TeamNum } from "./types"; export type PlayByPlayEventInputScore = @@ -109,7 +109,7 @@ export type PlayByPlayEventInputScore = clock: number; }; -type PlayByPlayEventInput = +export type PlayByPlayEventInput = | PlayByPlayEventInputScore | { type: "quarter"; @@ -313,11 +313,9 @@ class PlayByPlayLogger { }); } - if (isScoringPlay(event)) { - this.scoringSummary.push({ - ...event, - quarter: this.quarter, - }); + const scoringSummaryEvent = formatScoringSummaryEvent(event, this.quarter); + if (scoringSummaryEvent) { + this.scoringSummary.push(scoringSummaryEvent); } } diff --git a/src/worker/views/playoffs.ts b/src/worker/views/playoffs.ts index d54b35e650..dd66cea059 100644 --- a/src/worker/views/playoffs.ts +++ b/src/worker/views/playoffs.ts @@ -99,10 +99,8 @@ const updatePlayoffs = async ( series = result.series; playIns = result.playIns; } - console.log(1, structuredClone(series)); await helpers.augmentSeries(series, inputs.season); - console.log(2, structuredClone(series)); if (playIns) { await helpers.augmentSeries(playIns, inputs.season); @@ -114,7 +112,6 @@ const updatePlayoffs = async ( away?: SeriesTeam; }[][]; const playIns2 = playIns as PlayIns; - console.log(2, structuredClone(series2)); // Formatting for the table in playoffs.html const matchups: {