Use recalculateStandings directly after EV simulation
Replaces recalculateAffectedLeagues (which carries Discord notification and daily snapshot side effects) with a direct call to recalculateStandings per affected fantasy season. This updates the cached projectedPoints in teamStandings so the standings page stays in sync with the team page after a simulation, without triggering unrelated side effects. https://claude.ai/code/session_01S9Pk4wTSphANMhPWaURPTn
This commit is contained in:
parent
7cf37aace8
commit
e284d08f2b
1 changed files with 12 additions and 3 deletions
|
|
@ -17,7 +17,10 @@ import { batchUpsertParticipantEvSnapshots } from "~/models/ev-snapshot";
|
|||
import { findParticipantsBySportsSeasonId } from "~/models/participant";
|
||||
import { getSimulator, type SimulatorType } from "~/services/simulations/registry";
|
||||
import { calculateEV, type ScoringRules } from "~/services/ev-calculator";
|
||||
import { recalculateAffectedLeagues } from "~/models/scoring-calculator";
|
||||
import { recalculateStandings } from "~/models/scoring-calculator";
|
||||
import { database } from "~/database/context";
|
||||
import * as schema from "~/database/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
// Default scoring rules — matches the season table defaults.
|
||||
// Per-league EV is recalculated from probabilities using league-specific rules in standings.
|
||||
|
|
@ -100,8 +103,14 @@ export async function action({ params }: Route.ActionArgs) {
|
|||
// Persist updated EVs (transactional)
|
||||
await batchUpsertParticipantEVs(evInputs);
|
||||
|
||||
// Force standings recalculation so projectedPoints reflects the new EV
|
||||
await recalculateAffectedLeagues(sportsSeasonId);
|
||||
// Refresh cached projectedPoints in teamStandings for all affected fantasy seasons
|
||||
const db = database();
|
||||
const seasonSports = await db.query.seasonSports.findMany({
|
||||
where: eq(schema.seasonSports.sportsSeasonId, sportsSeasonId),
|
||||
});
|
||||
for (const { seasonId } of seasonSports) {
|
||||
await recalculateStandings(seasonId, db);
|
||||
}
|
||||
|
||||
// Take EV snapshot from simulation output (not re-read from DB)
|
||||
const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue