Add bulk import to futures odds page
Adds a textarea where admins can paste odds from FanDuel, DraftKings, OddsChecker, or any site. A client-side parser extracts American odds from each line and fuzzy-matches team names to participants (exact, substring, and word-overlap matching). Shows matched/unmatched results before applying to the individual input fields. https://claude.ai/code/session_01JvgcqKSJZ36bEztfg6CkWP
This commit is contained in:
parent
740ffbb411
commit
7ce7b04fca
1 changed files with 155 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ import { getAllParticipantEVsForSeason } from '~/models/participant-expected-val
|
||||||
import { Button } from '~/components/ui/button';
|
import { Button } from '~/components/ui/button';
|
||||||
import { Input } from '~/components/ui/input';
|
import { Input } from '~/components/ui/input';
|
||||||
import { Label } from '~/components/ui/label';
|
import { Label } from '~/components/ui/label';
|
||||||
|
import { Textarea } from '~/components/ui/textarea';
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
|
|
@ -22,7 +23,7 @@ import {
|
||||||
upsertParticipantEV,
|
upsertParticipantEV,
|
||||||
upsertParticipantEVWithNormalization,
|
upsertParticipantEVWithNormalization,
|
||||||
} from '~/models/participant-expected-value';
|
} from '~/models/participant-expected-value';
|
||||||
import { Loader2, Info } from 'lucide-react';
|
import { Loader2, Info, CheckCircle2, AlertCircle } from 'lucide-react';
|
||||||
|
|
||||||
export async function loader({ params }: Route.LoaderArgs) {
|
export async function loader({ params }: Route.LoaderArgs) {
|
||||||
const sportsSeasonId = params.id;
|
const sportsSeasonId = params.id;
|
||||||
|
|
@ -205,6 +206,85 @@ export default function AdminSportsSeasonFuturesOdds() {
|
||||||
return initial;
|
return initial;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Bulk import state
|
||||||
|
const [bulkText, setBulkText] = useState('');
|
||||||
|
const [parseResults, setParseResults] = useState<{
|
||||||
|
matched: Array<{ participantId: string; name: string; odds: number; inputName: string }>;
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Exact match
|
||||||
|
let match = participants.find(p => normalizeName(p.name) === normalizedInput);
|
||||||
|
if (match) return match;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
});
|
||||||
|
|
||||||
|
return match || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseBulkText() {
|
||||||
|
const lines = bulkText.split('\n');
|
||||||
|
// Match lines that end with an American-style odds number (+/- then 2–6 digits)
|
||||||
|
const oddsPattern = /^(.+?)\s+([+-]\d{2,6})\s*$/;
|
||||||
|
|
||||||
|
const matched: Array<{ participantId: string; name: string; odds: number; inputName: string }> = [];
|
||||||
|
const unmatched: Array<{ inputName: string; odds: number }> = [];
|
||||||
|
const seenParticipants = new Set<string>();
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
const trimmed = line.trim();
|
||||||
|
if (!trimmed || trimmed.length < 3) continue;
|
||||||
|
|
||||||
|
const match = oddsPattern.exec(trimmed);
|
||||||
|
if (!match) continue;
|
||||||
|
|
||||||
|
const inputName = match[1].trim();
|
||||||
|
const odds = parseInt(match[2], 10);
|
||||||
|
if (isNaN(odds)) continue;
|
||||||
|
|
||||||
|
const participant = findParticipantMatch(inputName);
|
||||||
|
if (participant && !seenParticipants.has(participant.id)) {
|
||||||
|
seenParticipants.add(participant.id);
|
||||||
|
matched.push({ participantId: participant.id, name: participant.name, odds, inputName });
|
||||||
|
} else if (!participant) {
|
||||||
|
unmatched.push({ inputName, odds });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setParseResults({ matched, unmatched });
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyMatches() {
|
||||||
|
if (!parseResults) return;
|
||||||
|
const newOdds = { ...oddsValues };
|
||||||
|
for (const m of parseResults.matched) {
|
||||||
|
newOdds[m.participantId] = m.odds.toString();
|
||||||
|
}
|
||||||
|
setOddsValues(newOdds);
|
||||||
|
setParseResults(null);
|
||||||
|
setBulkText('');
|
||||||
|
}
|
||||||
|
|
||||||
const isSubmitting = navigation.state === 'submitting';
|
const isSubmitting = navigation.state === 'submitting';
|
||||||
const isGenerating = isSubmitting && navigation.formData?.get('intent') === 'preview';
|
const isGenerating = isSubmitting && navigation.formData?.get('intent') === 'preview';
|
||||||
const isSaving = isSubmitting && navigation.formData?.get('intent') === 'save';
|
const isSaving = isSubmitting && navigation.formData?.get('intent') === 'save';
|
||||||
|
|
@ -218,6 +298,80 @@ export default function AdminSportsSeasonFuturesOdds() {
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Bulk Import */}
|
||||||
|
<Card className="mb-6">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Bulk Import</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Paste odds from FanDuel, DraftKings, OddsChecker, or any site. Each line should end with
|
||||||
|
American odds (e.g. <code>Kansas City Chiefs +450</code>). Team names are fuzzy-matched to
|
||||||
|
participants.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<Textarea
|
||||||
|
placeholder={`Paste odds here, one team per line:\nKansas City Chiefs +450\nSan Francisco 49ers +600\nBaltimore Ravens +700`}
|
||||||
|
value={bulkText}
|
||||||
|
onChange={e => { setBulkText(e.target.value); setParseResults(null); }}
|
||||||
|
rows={8}
|
||||||
|
className="font-mono text-sm"
|
||||||
|
/>
|
||||||
|
<Button type="button" variant="outline" onClick={parseBulkText} disabled={!bulkText.trim()}>
|
||||||
|
Parse Odds
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{parseResults && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
{parseResults.matched.length > 0 && (
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center gap-2 text-sm font-medium text-green-700 mb-2">
|
||||||
|
<CheckCircle2 className="h-4 w-4" />
|
||||||
|
Matched ({parseResults.matched.length})
|
||||||
|
</div>
|
||||||
|
<div className="rounded-md border border-green-200 bg-green-50 divide-y divide-green-100 text-sm">
|
||||||
|
{parseResults.matched.map(m => (
|
||||||
|
<div key={m.participantId} className="flex justify-between px-3 py-1.5">
|
||||||
|
<span className="text-muted-foreground">{m.inputName}</span>
|
||||||
|
<span className="font-medium">
|
||||||
|
{m.name} → {m.odds > 0 ? '+' : ''}{m.odds}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{parseResults.unmatched.length > 0 && (
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center gap-2 text-sm font-medium text-amber-700 mb-2">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
Not matched ({parseResults.unmatched.length}) — enter manually below
|
||||||
|
</div>
|
||||||
|
<div className="rounded-md border border-amber-200 bg-amber-50 divide-y divide-amber-100 text-sm">
|
||||||
|
{parseResults.unmatched.map((u, i) => (
|
||||||
|
<div key={i} className="flex justify-between px-3 py-1.5">
|
||||||
|
<span>{u.inputName}</span>
|
||||||
|
<span className="font-medium">{u.odds > 0 ? '+' : ''}{u.odds}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{parseResults.matched.length === 0 && parseResults.unmatched.length === 0 && (
|
||||||
|
<p className="text-sm text-muted-foreground">No odds found. Make sure each line ends with a value like +450 or -200.</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{parseResults.matched.length > 0 && (
|
||||||
|
<Button type="button" onClick={applyMatches}>
|
||||||
|
Apply {parseResults.matched.length} matched odds to form
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
<div className="grid gap-6 lg:grid-cols-2">
|
<div className="grid gap-6 lg:grid-cols-2">
|
||||||
<div>
|
<div>
|
||||||
<Card>
|
<Card>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue