- Add app/lib/logger.ts: dev passes through to console; prod routes errors to Sentry.captureException and warnings to Sentry.captureMessage, with extra context preserved. Uses captureMessage (not captureException) for string-only args to avoid fabricated stack traces. - Add server/logger.ts: dev passes through; prod silences log/info but keeps warn/error on stderr (Sentry not initialized in that process). - Replace all console.* calls across 44 app files and 4 server files. - Upgrade no-console from warn → error in oxlint; exempt logger files and scripts/** via overrides. - Add typescript/no-inferrable-types rule; fix violations in services and simulators. Exempt test files (intentional string widening for switch/if tests would break under literal type inference). Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
import type { Route } from "./+types/admin.sports-seasons.$id.expected-values";
|
|
import { logger } from "~/lib/logger";
|
|
import { findSportsSeasonById } from "~/models/sports-season";
|
|
import { findParticipantsBySportsSeasonId } from "~/models/participant";
|
|
import {
|
|
upsertParticipantEV,
|
|
getAllParticipantEVsForSeason
|
|
} from "~/models/participant-expected-value";
|
|
|
|
export async function loader({ params }: Route.LoaderArgs) {
|
|
const sportsSeason = await findSportsSeasonById(params.id);
|
|
|
|
if (!sportsSeason) {
|
|
throw new Response("Sports season not found", { status: 404 });
|
|
}
|
|
|
|
const participants = await findParticipantsBySportsSeasonId(params.id);
|
|
const existingEVs = await getAllParticipantEVsForSeason(params.id);
|
|
|
|
// Create a map of participant ID to EV data
|
|
const evMap = new Map(existingEVs.map(ev => [ev.participantId, ev]));
|
|
|
|
return {
|
|
sportsSeason: sportsSeason as typeof sportsSeason & { sport: { id: string; name: string; type: string; slug: string } },
|
|
participants,
|
|
existingEVs: evMap,
|
|
};
|
|
}
|
|
|
|
const scoringRules = {
|
|
pointsFor1st: 100,
|
|
pointsFor2nd: 70,
|
|
pointsFor3rd: 45,
|
|
pointsFor4th: 45,
|
|
pointsFor5th: 20,
|
|
pointsFor6th: 20,
|
|
pointsFor7th: 20,
|
|
pointsFor8th: 20,
|
|
};
|
|
|
|
export async function action({ request, params }: Route.ActionArgs) {
|
|
const formData = await request.formData();
|
|
|
|
const participants = await findParticipantsBySportsSeasonId(params.id);
|
|
const participantIds = participants.map((p: { id: string }) => p.id);
|
|
|
|
try {
|
|
const results = await Promise.all(
|
|
participantIds.map(async (participantId) => {
|
|
const probFirst = parseFloat(formData.get(`probFirst_${participantId}`) as string || "0") / 100;
|
|
const probSecond = parseFloat(formData.get(`probSecond_${participantId}`) as string || "0") / 100;
|
|
const probThird = parseFloat(formData.get(`probThird_${participantId}`) as string || "0") / 100;
|
|
const probFourth = parseFloat(formData.get(`probFourth_${participantId}`) as string || "0") / 100;
|
|
const probFifth = parseFloat(formData.get(`probFifth_${participantId}`) as string || "0") / 100;
|
|
const probSixth = parseFloat(formData.get(`probSixth_${participantId}`) as string || "0") / 100;
|
|
const probSeventh = parseFloat(formData.get(`probSeventh_${participantId}`) as string || "0") / 100;
|
|
const probEighth = parseFloat(formData.get(`probEighth_${participantId}`) as string || "0") / 100;
|
|
|
|
return upsertParticipantEV({
|
|
participantId,
|
|
sportsSeasonId: params.id,
|
|
probabilities: {
|
|
probFirst,
|
|
probSecond,
|
|
probThird,
|
|
probFourth,
|
|
probFifth,
|
|
probSixth,
|
|
probSeventh,
|
|
probEighth,
|
|
},
|
|
scoringRules,
|
|
source: "manual",
|
|
});
|
|
})
|
|
);
|
|
|
|
const totalEV = results.reduce((sum, r) => sum + parseFloat(r.expectedValue), 0);
|
|
|
|
return { success: true, totalEV };
|
|
} catch (error) {
|
|
logger.error("Error saving probabilities:", error);
|
|
return {
|
|
error: error instanceof Error ? error.message : "Failed to save probabilities"
|
|
};
|
|
}
|
|
}
|