2025-11-21 22:05:50 -08:00
|
|
|
import { Form, Link } from "react-router";
|
2025-11-17 22:19:46 -08:00
|
|
|
import type { Route } from "./+types/admin.sports-seasons.$id.expected-values";
|
2025-11-21 22:05:50 -08:00
|
|
|
import { loader, action } from "./admin.sports-seasons.$id.expected-values.server";
|
2025-11-17 22:19:46 -08:00
|
|
|
import { Button } from "~/components/ui/button";
|
|
|
|
|
import { Input } from "~/components/ui/input";
|
|
|
|
|
import {
|
|
|
|
|
Card,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardDescription,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
|
|
|
|
} from "~/components/ui/card";
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from "~/components/ui/table";
|
|
|
|
|
import { ArrowLeft, Save, Calculator } from "lucide-react";
|
|
|
|
|
|
2025-11-21 22:05:50 -08:00
|
|
|
export { loader, action };
|
2025-11-17 22:19:46 -08:00
|
|
|
|
|
|
|
|
export default function ExpectedValuesPage({ loaderData, actionData }: Route.ComponentProps) {
|
|
|
|
|
const { sportsSeason, participants, existingEVs } = loaderData;
|
|
|
|
|
|
2026-02-19 15:57:05 -08:00
|
|
|
const totalEV = Array.from(existingEVs.values()).reduce(
|
|
|
|
|
(sum, ev) => sum + parseFloat(ev.expectedValue),
|
|
|
|
|
0
|
|
|
|
|
);
|
|
|
|
|
|
2025-11-17 22:19:46 -08:00
|
|
|
return (
|
|
|
|
|
<div className="container mx-auto p-6 space-y-6">
|
|
|
|
|
<div className="flex items-center gap-4">
|
|
|
|
|
<Link to={`/admin/sports-seasons/${sportsSeason.id}`}>
|
|
|
|
|
<Button variant="ghost" size="sm">
|
|
|
|
|
<ArrowLeft className="h-4 w-4 mr-2" />
|
|
|
|
|
Back to Sports Season
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle className="flex items-center gap-2">
|
|
|
|
|
<Calculator className="h-5 w-5" />
|
|
|
|
|
Expected Values: {sportsSeason.sport.name} {sportsSeason.year}
|
|
|
|
|
</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
Manage probability distributions and expected values for participants
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent className="space-y-6">
|
|
|
|
|
{actionData?.error && (
|
2026-02-20 19:26:11 -08:00
|
|
|
<div className="p-4 bg-destructive/10 border border-destructive/30 rounded-md text-destructive">
|
2025-11-17 22:19:46 -08:00
|
|
|
{actionData.error}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{actionData?.success && (
|
2026-02-20 19:26:11 -08:00
|
|
|
<div className="p-4 bg-emerald-500/15 border border-emerald-500/30 rounded-md text-emerald-400">
|
2026-02-19 15:57:05 -08:00
|
|
|
All participants saved successfully!
|
2025-11-17 22:19:46 -08:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-02-20 19:26:11 -08:00
|
|
|
<div className="text-sm text-muted-foreground space-y-2">
|
2025-11-17 22:19:46 -08:00
|
|
|
<p><strong>Default Scoring Rules (for EV calculation):</strong></p>
|
|
|
|
|
<div className="grid grid-cols-4 gap-2">
|
|
|
|
|
<span>1st: 100 pts</span>
|
|
|
|
|
<span>2nd: 70 pts</span>
|
|
|
|
|
<span>3rd: 50 pts</span>
|
|
|
|
|
<span>4th: 40 pts</span>
|
|
|
|
|
<span>5th: 25 pts</span>
|
|
|
|
|
<span>6th: 25 pts</span>
|
|
|
|
|
<span>7th: 15 pts</span>
|
|
|
|
|
<span>8th: 15 pts</span>
|
|
|
|
|
</div>
|
2026-02-20 19:26:11 -08:00
|
|
|
<p className="text-xs text-muted-foreground italic">
|
2025-11-17 22:19:46 -08:00
|
|
|
Note: EVs will be recalculated with actual league scoring rules when used in fantasy leagues.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-19 15:57:05 -08:00
|
|
|
<Form method="post">
|
|
|
|
|
|
|
|
|
|
<Table>
|
|
|
|
|
<TableHeader>
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableHead>Participant</TableHead>
|
|
|
|
|
<TableHead className="text-center">1st %</TableHead>
|
|
|
|
|
<TableHead className="text-center">2nd %</TableHead>
|
|
|
|
|
<TableHead className="text-center">3rd %</TableHead>
|
|
|
|
|
<TableHead className="text-center">4th %</TableHead>
|
|
|
|
|
<TableHead className="text-center">5th %</TableHead>
|
|
|
|
|
<TableHead className="text-center">6th %</TableHead>
|
|
|
|
|
<TableHead className="text-center">7th %</TableHead>
|
|
|
|
|
<TableHead className="text-center">8th %</TableHead>
|
|
|
|
|
<TableHead className="text-center">EV</TableHead>
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{participants.map((participant: { id: string; name: string }) => {
|
|
|
|
|
const existingEV = existingEVs.get(participant.id);
|
|
|
|
|
const id = participant.id;
|
2025-11-17 22:19:46 -08:00
|
|
|
|
2026-02-19 15:57:05 -08:00
|
|
|
return (
|
|
|
|
|
<TableRow key={id}>
|
|
|
|
|
<TableCell className="font-medium">{participant.name}</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name={`probFirst_${id}`}
|
|
|
|
|
defaultValue={existingEV ? (parseFloat(existingEV.probFirst) * 100).toFixed(2) : "0"}
|
|
|
|
|
step="0.01"
|
|
|
|
|
min="0"
|
|
|
|
|
max="100"
|
|
|
|
|
className="w-20 text-center"
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name={`probSecond_${id}`}
|
|
|
|
|
defaultValue={existingEV ? (parseFloat(existingEV.probSecond) * 100).toFixed(2) : "0"}
|
|
|
|
|
step="0.01"
|
|
|
|
|
min="0"
|
|
|
|
|
max="100"
|
|
|
|
|
className="w-20 text-center"
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name={`probThird_${id}`}
|
|
|
|
|
defaultValue={existingEV ? (parseFloat(existingEV.probThird) * 100).toFixed(2) : "0"}
|
|
|
|
|
step="0.01"
|
|
|
|
|
min="0"
|
|
|
|
|
max="100"
|
|
|
|
|
className="w-20 text-center"
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name={`probFourth_${id}`}
|
|
|
|
|
defaultValue={existingEV ? (parseFloat(existingEV.probFourth) * 100).toFixed(2) : "0"}
|
|
|
|
|
step="0.01"
|
|
|
|
|
min="0"
|
|
|
|
|
max="100"
|
|
|
|
|
className="w-20 text-center"
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name={`probFifth_${id}`}
|
|
|
|
|
defaultValue={existingEV ? (parseFloat(existingEV.probFifth) * 100).toFixed(2) : "0"}
|
|
|
|
|
step="0.01"
|
|
|
|
|
min="0"
|
|
|
|
|
max="100"
|
|
|
|
|
className="w-20 text-center"
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name={`probSixth_${id}`}
|
|
|
|
|
defaultValue={existingEV ? (parseFloat(existingEV.probSixth) * 100).toFixed(2) : "0"}
|
|
|
|
|
step="0.01"
|
|
|
|
|
min="0"
|
|
|
|
|
max="100"
|
|
|
|
|
className="w-20 text-center"
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name={`probSeventh_${id}`}
|
|
|
|
|
defaultValue={existingEV ? (parseFloat(existingEV.probSeventh) * 100).toFixed(2) : "0"}
|
|
|
|
|
step="0.01"
|
|
|
|
|
min="0"
|
|
|
|
|
max="100"
|
|
|
|
|
className="w-20 text-center"
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name={`probEighth_${id}`}
|
|
|
|
|
defaultValue={existingEV ? (parseFloat(existingEV.probEighth) * 100).toFixed(2) : "0"}
|
|
|
|
|
step="0.01"
|
|
|
|
|
min="0"
|
|
|
|
|
max="100"
|
|
|
|
|
className="w-20 text-center"
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="text-center font-semibold">
|
|
|
|
|
{existingEV ? parseFloat(existingEV.expectedValue).toFixed(2) : "-"}
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
{existingEVs.size > 0 && (
|
|
|
|
|
<TableRow className="border-t-2 font-bold bg-muted/50">
|
|
|
|
|
<TableCell colSpan={9} className="text-right">Total EV</TableCell>
|
|
|
|
|
<TableCell className="text-center">{totalEV.toFixed(2)}</TableCell>
|
2025-11-17 22:19:46 -08:00
|
|
|
</TableRow>
|
2026-02-19 15:57:05 -08:00
|
|
|
)}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
2025-11-17 22:19:46 -08:00
|
|
|
|
2026-02-19 15:57:05 -08:00
|
|
|
{participants.length === 0 ? (
|
2026-02-20 19:26:11 -08:00
|
|
|
<p className="text-center text-muted-foreground py-8">
|
2026-02-19 15:57:05 -08:00
|
|
|
No participants found. Please add participants to this sports season first.
|
|
|
|
|
</p>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex justify-end pt-4">
|
|
|
|
|
<Button type="submit">
|
|
|
|
|
<Save className="h-4 w-4 mr-2" />
|
|
|
|
|
Save All
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</Form>
|
2025-11-17 22:19:46 -08:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|