Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Apr 10, 2024
1 parent 042d05f commit 360d013
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 0 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/worker/core/game/writeGameStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 17 additions & 3 deletions src/worker/core/headToHead/addGame.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { PHASE } from "../../../common";
import getWinner from "../../../common/getWinner";
import type { HeadToHead } from "../../../common/types";
import { idb } from "../../db";
import { g } from "../../util";

const addGame = async ({
tids,
pts,
sPts,
overtime,
playoffRound,
seriesWinner,
Expand All @@ -14,6 +16,7 @@ const addGame = async ({
}: {
tids: [number, number];
pts: [number, number];
sPts: [number, number] | undefined;
overtime: boolean;
playoffRound?: number;
seriesWinner?: number;
Expand All @@ -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] = {};
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 360d013

Please sign in to comment.