From 82e501d6a569f773482428b900547917f5ee54f2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Feb 2026 22:30:28 +0000 Subject: [PATCH] Code review fixes for futures-odds page - Remove unused upsertParticipantEVWithNormalization import - Remove debug console.log statements left in save action - Move normalizeName to module level (pure function, no component deps) - Pre-compute normalized participant names once in findParticipantMatch instead of re-normalizing across three separate passes - Fix array index key on unmatched list to use composite string key - Drop unused result variable from upsertParticipantEV call https://claude.ai/code/session_01JvgcqKSJZ36bEztfg6CkWP --- .../admin.sports-seasons.$id.futures-odds.tsx | 52 +++++++------------ 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/app/routes/admin.sports-seasons.$id.futures-odds.tsx b/app/routes/admin.sports-seasons.$id.futures-odds.tsx index d15cda3..f3bef04 100644 --- a/app/routes/admin.sports-seasons.$id.futures-odds.tsx +++ b/app/routes/admin.sports-seasons.$id.futures-odds.tsx @@ -19,10 +19,7 @@ import { calculateICMFromOdds, icmResultToArray, } from '~/services/icm-calculator'; -import { - upsertParticipantEV, - upsertParticipantEVWithNormalization, -} from '~/models/participant-expected-value'; +import { upsertParticipantEV } from '~/models/participant-expected-value'; import { Loader2, Info, CheckCircle2, AlertCircle } from 'lucide-react'; export async function loader({ params }: Route.LoaderArgs) { @@ -133,13 +130,6 @@ export async function action({ request, params }: Route.ActionArgs) { // Save probabilities from preview (passed through form) // This ensures saved values match exactly what user saw in preview for (const { participantId, odds } of futuresOdds) { - // Debug: check what's in form data - const probFirstRaw = formData.get(`prob_first_${participantId}`); - const probSecondRaw = formData.get(`prob_second_${participantId}`); - console.log(`[Futures Odds Save DEBUG] Looking for participant ${participantId}`); - console.log(` prob_first_${participantId} = ${probFirstRaw} (type: ${typeof probFirstRaw})`); - console.log(` prob_second_${participantId} = ${probSecondRaw} (type: ${typeof probSecondRaw})`); - // Read probabilities from form data (preview results) const probFirst = parseFloat(formData.get(`prob_first_${participantId}`) as string) || 0; const probSecond = parseFloat(formData.get(`prob_second_${participantId}`) as string) || 0; @@ -150,11 +140,9 @@ export async function action({ request, params }: Route.ActionArgs) { const probSeventh = parseFloat(formData.get(`prob_seventh_${participantId}`) as string) || 0; const probEighth = parseFloat(formData.get(`prob_eighth_${participantId}`) as string) || 0; - console.log(`[Futures Odds Save] ${participantId}: P(1st)=${probFirst}, P(2nd)=${probSecond}, P(3rd)=${probThird}, P(4th)=${probFourth}, P(5th)=${probFifth}, P(6th)=${probSixth}, P(7th)=${probSeventh}, P(8th)=${probEighth}, sum=${probFirst+probSecond+probThird+probFourth+probFifth+probSixth+probSeventh+probEighth}`); - // Use upsertParticipantEV (not WithNormalization) because ICM probabilities // are already correct - they sum to <1.0 for teams unlikely to finish top 8 - const result = await upsertParticipantEV({ + await upsertParticipantEV({ participantId, sportsSeasonId: sportsSeasonId, probabilities: { @@ -171,11 +159,8 @@ export async function action({ request, params }: Route.ActionArgs) { source: 'futures_odds', sourceOdds: odds, }); - - console.log(`[Futures Odds Save] Saved ${participantId}: DB probFirst=${result.probFirst}, EV=${result.expectedValue}`); } - console.log('[Futures Odds Save] All probabilities saved, redirecting...'); return redirect(`/admin/sports-seasons/${sportsSeasonId}/expected-values`); } @@ -189,6 +174,10 @@ export async function action({ request, params }: Route.ActionArgs) { } } +function normalizeName(name: string): string { + return name.toLowerCase().replace(/[^a-z0-9\s]/g, '').replace(/\s+/g, ' ').trim(); +} + export default function AdminSportsSeasonFuturesOdds() { const { sportsSeason, participants, existingOdds } = useLoaderData(); const actionData = useActionData(); @@ -213,33 +202,28 @@ export default function AdminSportsSeasonFuturesOdds() { unmatched: Array<{ inputName: string; odds: number }>; } | null>(null); - function normalizeName(name: string): string { - return name.toLowerCase().replace(/[^a-z0-9\s]/g, '').replace(/\s+/g, ' ').trim(); - } - function findParticipantMatch(inputName: string) { const normalizedInput = normalizeName(inputName); + // Pre-compute normalized names once for all three passes + const normalized = participants.map(p => ({ p, n: normalizeName(p.name) })); // Exact match - let match = participants.find(p => normalizeName(p.name) === normalizedInput); - if (match) return match; + const exact = normalized.find(({ n }) => n === normalizedInput); + if (exact) return exact.p; // Contains match (one contains the other) - match = participants.find(p => { - const normalizedP = normalizeName(p.name); - return normalizedP.includes(normalizedInput) || normalizedInput.includes(normalizedP); - }); - if (match) return match; + const contains = normalized.find(({ n }) => n.includes(normalizedInput) || normalizedInput.includes(n)); + if (contains) return contains.p; // Word-overlap match (at least half the significant words overlap) const inputWords = normalizedInput.split(' ').filter(w => w.length > 2); - match = participants.find(p => { - const pWords = normalizeName(p.name).split(' ').filter(w => w.length > 2); - const overlap = inputWords.filter(w => pWords.includes(w)); - return overlap.length > 0 && overlap.length >= Math.min(inputWords.length, pWords.length) * 0.5; + const overlap = normalized.find(({ n }) => { + const pWords = n.split(' ').filter(w => w.length > 2); + const shared = inputWords.filter(w => pWords.includes(w)); + return shared.length > 0 && shared.length >= Math.min(inputWords.length, pWords.length) * 0.5; }); - return match || null; + return overlap?.p ?? null; } function parseBulkText() { @@ -349,7 +333,7 @@ export default function AdminSportsSeasonFuturesOdds() {
{parseResults.unmatched.map((u, i) => ( -
+
{u.inputName} {u.odds > 0 ? '+' : ''}{u.odds}