diff --git a/TODO b/TODO index 3bd636f09d..abd1ef38c8 100644 --- a/TODO +++ b/TODO @@ -2,9 +2,6 @@ indicator of if trade will be accepted - https://old.reddit.com/r/BasketballGM/comments/1b3h2f6/monthly_suggestions_thread/kswqcuk/ shootouts -- fix all .won.pts - - writeGameStats headToHead - - is headToHead broken? - confirm for all sports - no injuries during shootout - if still tied, keep going one at a time diff --git a/src/worker/core/game/writeGameStats.ts b/src/worker/core/game/writeGameStats.ts index a387064ac3..c3a51525d5 100644 --- a/src/worker/core/game/writeGameStats.ts +++ b/src/worker/core/game/writeGameStats.ts @@ -680,6 +680,10 @@ const writeGameStats = async ( await headToHead.addGame({ tids: [gameStats.won.tid, gameStats.lost.tid], pts: [gameStats.won.pts, gameStats.lost.pts], + sPts: + gameStats.won.sPts === undefined + ? undefined + : [gameStats.won.sPts, gameStats.lost.sPts!], overtime: gameStats.overtimes > 0, playoffRound: currentRound, seriesWinner, diff --git a/src/worker/core/headToHead/addGame.ts b/src/worker/core/headToHead/addGame.ts index faeed20981..b42542449c 100644 --- a/src/worker/core/headToHead/addGame.ts +++ b/src/worker/core/headToHead/addGame.ts @@ -1,4 +1,5 @@ import { PHASE } from "../../../common"; +import getWinner from "../../../common/getWinner"; import type { HeadToHead } from "../../../common/types"; import { idb } from "../../db"; import { g } from "../../util"; @@ -6,6 +7,7 @@ import { g } from "../../util"; const addGame = async ({ tids, pts, + sPts, overtime, playoffRound, seriesWinner, @@ -14,6 +16,7 @@ const addGame = async ({ }: { tids: [number, number]; pts: [number, number]; + sPts: [number, number] | undefined; overtime: boolean; playoffRound?: number; seriesWinner?: number; @@ -39,6 +42,17 @@ const addGame = async ({ return; } + const winner = getWinner([ + { + pts: pts[i], + sPts: sPts?.[i], + }, + { + pts: pts[j], + sPts: sPts?.[j], + }, + ]); + if (!playoffs) { if (!headToHead.regularSeason[t0]) { headToHead.regularSeason[t0] = {}; @@ -56,13 +70,13 @@ const addGame = async ({ }; } - if (pts[i] > pts[j]) { + if (winner === 0) { if (overtime && otl) { headToHead.regularSeason[t0][t1].otw += 1; } else { headToHead.regularSeason[t0][t1].won += 1; } - } else if (pts[i] === pts[j]) { + } else if (winner === -1) { headToHead.regularSeason[t0][t1].tied += 1; } else { if (overtime && otl) { @@ -95,7 +109,7 @@ const addGame = async ({ }; } - if (pts[i] > pts[j]) { + if (winner === 0) { headToHead.playoffs[t0][t1].won += 1; } else { headToHead.playoffs[t0][t1].lost += 1;