API+App+Admin: telemetria bytnosci w ogolnym widoku sirowni - GET /gyms/:id/presence-stats (heatmapa dzien×godzina, sredni pobyt, wizyty/dzien, szczyt, teraz w srodku, top urzadzenia; stale 30 dni), wspoldzielony komponent PresenceHeatmap, telemetria wyciagnieta z podstrony statystyk; pasek godzin w forma zegarowa z minutami, usuniete karta Dane i filtr okresu; swagger + testy integracyjne, unit i e2e
This commit is contained in:
74
admin/src/components/gyms/PresenceHeatmap.tsx
Normal file
74
admin/src/components/gyms/PresenceHeatmap.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { dayName } from '../../lib/format';
|
||||
import { dayShort } from '../../lib/availability';
|
||||
|
||||
export interface PresenceHeatCell {
|
||||
day: number;
|
||||
hour: number;
|
||||
count: number;
|
||||
}
|
||||
|
||||
/* Mapa ciepła bytności 7 (dzień 0=pon) × 24 (godzina) — natężenie ~ udział w szczycie,
|
||||
styl kafli jak mapa urządzeń. Lustrzana kopia komponentu z app (identyczny widok
|
||||
w obu pakietach). Etykiety dni skrócone (pełna nazwa w tytulu wiersza), siatka
|
||||
skaluje się do szerokosci kolumny — bez minimalnej szerokosci i przewijania. */
|
||||
export function PresenceHeatmapGrid({ cells }: { cells: PresenceHeatCell[] }) {
|
||||
const max = cells.reduce((m, c) => Math.max(m, c.count), 0);
|
||||
return (
|
||||
<div className="min-w-0">
|
||||
<div
|
||||
className="grid gap-[3px]"
|
||||
style={{ gridTemplateColumns: 'minmax(2.4rem, 3.4rem) repeat(24, minmax(0, 1fr))' }}
|
||||
>
|
||||
<span />
|
||||
{Array.from({ length: 24 }, (_, hour) => (
|
||||
<span
|
||||
key={hour}
|
||||
className="min-w-0 truncate text-center text-[0.6rem] font-bold tabular-nums text-dim"
|
||||
>
|
||||
{hour % 3 === 0 ? String(hour).padStart(2, '0') : ''}
|
||||
</span>
|
||||
))}
|
||||
{Array.from({ length: 7 }, (_, day) => (
|
||||
<HeatmapRow key={day} day={day} cells={cells} max={max} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function HeatmapRow({ day, cells, max }: { day: number; cells: PresenceHeatCell[]; max: number }) {
|
||||
const { t } = useTranslation('gyms');
|
||||
return (
|
||||
<>
|
||||
<span
|
||||
title={dayName(day + 1)}
|
||||
className="flex min-w-0 items-center pr-1 text-[0.68rem] font-semibold text-dim"
|
||||
>
|
||||
<span className="truncate">{dayShort(day)}</span>
|
||||
</span>
|
||||
{Array.from({ length: 24 }, (_, hour) => {
|
||||
const cell = cells.find((c) => c.day === day && c.hour === hour);
|
||||
const count = cell?.count ?? 0;
|
||||
const intensity = max > 0 ? count / max : 0;
|
||||
return (
|
||||
<span
|
||||
key={hour}
|
||||
title={t('stats.cellTitle', {
|
||||
day: dayName(day + 1),
|
||||
hour: String(hour).padStart(2, '0'),
|
||||
count,
|
||||
})}
|
||||
className="aspect-square rounded-[2px] border border-line/40"
|
||||
style={{
|
||||
background:
|
||||
intensity > 0
|
||||
? `color-mix(in srgb, var(--accent) ${Math.round(18 + intensity * 82)}%, var(--bg-input))`
|
||||
: 'var(--bg-input)',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user