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

NFL Schedule Fix (Draft) #415

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
86 changes: 84 additions & 2 deletions src/worker/core/phase/newPhaseRegularSeason.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { season } from "..";
import { idb } from "../../db";
import { g, helpers, local, logEvent, toUI } from "../../util";
import { getDivisionRanks } from "../../util/orderTeams";
import type { Conditions, PhaseReturn } from "../../../common/types";
import {
EMAIL_ADDRESS,
Expand All @@ -23,8 +24,89 @@ const newPhaseRegularSeason = async (
},
"noCopyCache",
);

await season.setSchedule(season.newSchedule(teams));
//As I understand it, this is the relevant area to generate a regular season schedule
if (isSport("football") && teams.length === 32) {
// This needs to be more strict, should verify league is in default configuration
const year = g.get("season");
const startingYear = g.get("startingSeason");
const rawTeams =
//Borrowed some of this logic from the standing view, which may not be the optimum way to get ranked teams.
await idb.getCopies.teamsPlus(
{
attrs: ["tid"],
seasonAttrs: [
"won",
"lost",
"tied",
"otl",
"winp",
"pts",
"ptsPct",
"wonHome",
"lostHome",
"tiedHome",
"otlHome",
"wonAway",
"lostAway",
"tiedAway",
"otlAway",
"wonDiv",
"lostDiv",
"tiedDiv",
"otlDiv",
"wonConf",
"lostConf",
"tiedConf",
"otlConf",
"cid",
"did",
"abbrev",
"region",
"name",
"clinchedPlayoffs",
],
stats: ["pts", "oppPts", "gp"],
season: year > startingYear ? year - 1 : year, //TODO: We want the previous year's schedule, otherwise just place in TID order
showNoStats: true,
},
"noCopyCache",
);
const rankedTeams: number[] = Array(rawTeams.length);
//If it's not the first season, base order on previous season's ranking, otherwise, just do order received
if (year > startingYear) {
// rankings will give the row
// TODO: THIS DOES NOT WORK RIGHT
const rankings = await getDivisionRanks(rawTeams, rawTeams, {
skipDivisionLeaders: false,
skipTiebreakers: false,
season: g.get("season"),
});
// division ID and conference ID thankfully maps to our general concept. So we create an array, and then assign all teams to their
//expected location
rawTeams.forEach(team => {
const row = rankings.get(team.tid);
const col = team.seasonAttrs.did;
//Assign teams based on rank
rankedTeams[row! * 8 + col] = team.tid;
});
} else {
//this does work right
rawTeams.forEach(team => {
const col = team.seasonAttrs.did;
//Assign teams based on order received.
for (let i = 0; i < 4; i++) {
if (rankedTeams[i * 8 + col] === undefined) {
rankedTeams[i * 8 + col] = team.tid;
break;
}
}
});
}
const matches = await season.generateMatches(rankedTeams, g.get("season"));
season.setSchedule([], season.scheduleSort(matches));
} else {
await season.setSchedule(season.newSchedule(teams));
}

if (g.get("autoDeleteOldBoxScores")) {
const tx = idb.league.transaction("games", "readwrite");
Expand Down
4 changes: 4 additions & 0 deletions src/worker/core/season/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import getSchedule from "./getSchedule";
import newSchedule from "./newSchedule";
import newSchedulePlayoffsDay from "./newSchedulePlayoffsDay";
import setSchedule from "./setSchedule";
import scheduleSort from "./scheduleSortSpeculative";
import updateOwnerMood from "./updateOwnerMood";
import validatePlayoffSettings from "./validatePlayoffSettings";
import generateMatches from "./newScheduleSpeculative.Football";

export default {
addDaysToSchedule,
doAwards,
genPlayoffSeeds,
genPlayoffSeries,
generateMatches,
getAwardCandidates,
getDaysLeftSchedule,
getInitialNumGamesConfDivSettings,
Expand All @@ -28,6 +31,7 @@ export default {
newSchedule,
newSchedulePlayoffsDay,
setSchedule,
scheduleSort,
updateOwnerMood,
validatePlayoffSettings,
};
Loading