stats reorg, upcoming refinement

This commit is contained in:
yohlo
2025-09-14 23:10:05 -05:00
parent 8efc0a7a4b
commit 9a105b30c6
18 changed files with 703 additions and 373 deletions

View File

@@ -1,11 +1,12 @@
import { Box } from "@mantine/core";
import Header from "./header";
import { Player } from "@/features/players/types";
import { Player, PlayerStats } from "@/features/players/types";
import SwipeableTabs from "@/components/swipeable-tabs";
import { usePlayer, usePlayerMatches } from "../../queries";
import { usePlayer, usePlayerMatches, usePlayerStats } from "../../queries";
import TeamList from "@/features/teams/components/team-list";
import StatsOverview from "../stats-overview";
import StatsOverview from "@/shared/components/stats-overview";
import MatchList from "@/features/matches/components/match-list";
import { BaseStats } from "@/shared/types/stats";
interface ProfileProps {
id: string;
@@ -14,11 +15,24 @@ interface ProfileProps {
const Profile = ({ id }: ProfileProps) => {
const { data: player } = usePlayer(id);
const { data: matches } = usePlayerMatches(id);
const { data: stats, isLoading: statsLoading } = usePlayerStats(id);
// Aggregate player stats from multiple tournaments into a single BaseStats object
const aggregatedStats: BaseStats | null = stats && stats.length > 0 ? {
id: `player_${id}_aggregate`,
matches: stats.reduce((acc, stat) => acc + stat.matches, 0),
wins: stats.reduce((acc, stat) => acc + stat.wins, 0),
losses: stats.reduce((acc, stat) => acc + stat.losses, 0),
total_cups_made: stats.reduce((acc, stat) => acc + stat.total_cups_made, 0),
total_cups_against: stats.reduce((acc, stat) => acc + stat.total_cups_against, 0),
margin_of_victory: stats.filter(s => s.margin_of_victory > 0).reduce((acc, stat, _, arr) => acc + stat.margin_of_victory / arr.length, 0),
margin_of_loss: stats.filter(s => s.margin_of_loss > 0).reduce((acc, stat, _, arr) => acc + stat.margin_of_loss / arr.length, 0),
} : null;
const tabs = [
{
label: "Overview",
content: <StatsOverview playerId={id} />,
content: <StatsOverview statsData={aggregatedStats} isLoading={statsLoading} />,
},
{
label: "Matches",