Statystyki: podstrona Statystyki profilu + tablica silowni REAL z opt-in nicku
Profil: GET /me/stats (ulubiona silownia/sprzet/cwiczenie, partie ciala, heatma, tonaz 12 tyg., rekordy Epley top5) + widok /profile/stats i podsumowanie na przegladzie. Tablica: GET /gyms/:id/board + PATCH /gyms/:id/stats-consent (GymMembership.statsOptIn, migracja gym_membership_stats_opt_in) — anonimowe agregaty, ranking i rekordy 1RM z atrybucja nicka tylko po zgodzie; /gyms/:id/board + pelnoekranowy tryb TV /gyms/:id/board/tv (TvShell, auto-refetch co 5 min); kafelek na GymDetail. Wspolne: api lib/strengthStats (Epley/efektywne obciazenie), app lib/stats-equiv + components/stats (MuscleSplit, WeeklyTonnageChart), storey stats-range/board-range. Testy: api 322 unit + 12 integracji (board, me-stats); app 285 unit; e2e gym-board 4, profile-stats 3.
This commit is contained in:
@@ -20,6 +20,7 @@ import type {
|
||||
FocusChain,
|
||||
HistorySession,
|
||||
Gym,
|
||||
GymBoardData,
|
||||
GymDetailResponse,
|
||||
GymException,
|
||||
GymRole,
|
||||
@@ -51,6 +52,7 @@ import type {
|
||||
DayMoveEntry,
|
||||
UserSearchResult,
|
||||
LatestExerciseResult,
|
||||
MeStats,
|
||||
} from './types';
|
||||
|
||||
// Zdjęcia siłowni renderuje komponent AuthImage (chroniony endpoint — blob przez apiBlob).
|
||||
@@ -126,6 +128,17 @@ export function useHistory(month?: string) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Statystyki osobiste (ulubione, partie ciała, heatma, rekordy).
|
||||
* `range`: '30' | '90' | '365' | 'all' — zakres kart; rekordy/tonaż always-all.
|
||||
*/
|
||||
export function useMeStats(range: string) {
|
||||
return useQuery({
|
||||
queryKey: ['me', 'stats', range],
|
||||
queryFn: () => api<MeStats>(`/me/stats?range=${range}`),
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- gyms ----------
|
||||
export interface UserGym extends Gym {
|
||||
roles: GymRole[];
|
||||
@@ -262,6 +275,29 @@ export function useGymStatsOverview(gymId: string | undefined, rangeDays: number
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tablica statystyk siłowni REAL (członkowie/admin): anonimowe agregaty +
|
||||
* ranking i rekordy z atrybucją nicka (opt-in). `range`: '7'|'30'|'90';
|
||||
* tryb TV: `refetchIntervalMs` (5 min). Zakres tnie ranking/agregaty,
|
||||
* rekordy always-all-time po stronie API.
|
||||
*/
|
||||
export function useGymBoard(gymId: string | undefined, range: string, refetchIntervalMs?: number) {
|
||||
return useQuery({
|
||||
queryKey: ['gyms', gymId, 'board', range],
|
||||
queryFn: () => api<GymBoardData>(`/gyms/${gymId}/board?range=${range}`),
|
||||
enabled: !!gymId,
|
||||
refetchInterval: refetchIntervalMs,
|
||||
});
|
||||
}
|
||||
|
||||
/** Zgoda na atrybucję nicka w rankingu/rekordach tablicy (per siłownia, członek). */
|
||||
export function setGymStatsConsent(gymId: string, enabled: boolean) {
|
||||
return api<{ statsOptIn: boolean }>(`/gyms/${gymId}/stats-consent`, {
|
||||
method: 'PATCH',
|
||||
body: { enabled },
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- bytność (check-in, live occupancy) ----------
|
||||
/** Aktywna bytność zalogowanego — podstawa przycisków „Idę ćwiczyć / Wychodzę / Wciąż tu jestem". */
|
||||
export function useActivePresence(refetchIntervalMs?: number) {
|
||||
|
||||
@@ -394,6 +394,44 @@ export interface GymStatsOverview {
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- tablica statystyk siłowni (GET /gyms/:id/board, REAL) ----------
|
||||
/** Wiersz rankingu: atrybuowani członkowie z opt-in; `sessions` = skuteczne sesje w zakresie. */
|
||||
export interface GymBoardRankingRow {
|
||||
userId: string;
|
||||
nickname: string | null;
|
||||
firstName: string | null;
|
||||
lastName: string | null;
|
||||
sessions: number;
|
||||
tonnageKg: number;
|
||||
days: number;
|
||||
}
|
||||
|
||||
/** Rekord 1RM (Epley, always-all-time); `author` null → render „anonim". */
|
||||
export interface GymBoardRecord {
|
||||
exerciseId: string;
|
||||
name: string;
|
||||
nameEn: string | null;
|
||||
muscle: string;
|
||||
oneRm: number;
|
||||
date: string;
|
||||
author: { nickname: string | null; firstName: string | null; lastName: string | null } | null;
|
||||
}
|
||||
|
||||
export interface GymBoardData {
|
||||
gym: { id: string; name: string };
|
||||
/** Zgoda zalogowanego (null = brak członkostwa, np. admin). */
|
||||
myStatsOptIn: boolean | null;
|
||||
rangeDays: number;
|
||||
ranking: GymBoardRankingRow[];
|
||||
aggregate: {
|
||||
tonnageKg: number;
|
||||
sessions: number;
|
||||
uniqueExercisers: number;
|
||||
muscles: { muscle: string; sets: number; volumeKg: number }[];
|
||||
};
|
||||
records: GymBoardRecord[];
|
||||
}
|
||||
|
||||
export interface Exercise {
|
||||
id: string;
|
||||
slug: string;
|
||||
@@ -679,6 +717,45 @@ export interface CircumferenceSeries {
|
||||
points: WeightPoint[];
|
||||
}
|
||||
|
||||
// ---------- statystyki osobiste (profile /stats) ----------
|
||||
export interface MeStats {
|
||||
/** Zakres kart (dni); null = pełna historia. Rekordy/tonaż all-time/tonaż tygodniowy zawsze all-time. */
|
||||
rangeDays: number | null;
|
||||
sessions: { count: number; sets: number; reps: number; avgMinutes: number | null };
|
||||
tonnageKg: number;
|
||||
tonnageAllTimeKg: number;
|
||||
/** Ulubiona siłownia wg planów sesji (TrainingPlan.gymId); null = brak atrybuowanych sesji. */
|
||||
topGym: { gymId: string; name: string; sessions: number } | null;
|
||||
/** Ulubiony sprzęt (serie na ćwiczeniach używających danego katalogu Equipment). */
|
||||
topEquipment: { equipmentId: string; name: string; nameEn: string | null; sets: number } | null;
|
||||
topExercise: {
|
||||
exerciseId: string;
|
||||
name: string;
|
||||
nameEn: string | null;
|
||||
muscle: string;
|
||||
sessions: number;
|
||||
sets: number;
|
||||
} | null;
|
||||
/** Serie i tonaż wg partii pierwotnej (malejąco). */
|
||||
muscles: { muscle: string; sets: number; volumeKg: number }[];
|
||||
/** Sesje wg dnia tygodnia (0 = pon … 6 = nd). */
|
||||
weekday: { dow: number; sessions: number }[];
|
||||
/** Heatma sesji: dzień (0=pon) × godzina startu; tylko komórki niezerowe. */
|
||||
heatmap: { day: number; hour: number; count: number }[];
|
||||
/** Tonaż w 12 ostatnich tygodniach ISO (od poniedziałku, rosnąco). */
|
||||
weeklyTonnage: { weekStart: string; volumeKg: number }[];
|
||||
/** Rekordy Epley 1RM (top 5): wartość + data sesji z rekordem. */
|
||||
records: {
|
||||
exerciseId: string;
|
||||
name: string;
|
||||
nameEn: string | null;
|
||||
muscle: string;
|
||||
oneRm: number;
|
||||
date: string;
|
||||
}[];
|
||||
plans: { completed: number; abandoned: number; daysCompleted: number; daysSkipped: number };
|
||||
}
|
||||
|
||||
// ---------- komunikator (messages) ----------
|
||||
export interface Conversation {
|
||||
coachingId: string;
|
||||
|
||||
Reference in New Issue
Block a user