feat(api): add timezone support for group fetching and increase page size

feat(attendance): refactor attendance summary logic and update tests

feat(analytics): extend GroupRiskSummary schema with absence and attendance counts

feat(groups): enhance group schema with attendee and waitlist counts

chore(skills): add frontend design skill with guidelines and license

feat(attendee-detail): implement AttendeePhoneLine component for phone display

feat(groups): create AttendanceBadge and CapacityIndicator components for group cards

feat(groups): add card utility functions for attendance alerts and capacity summaries

test(groups): implement tests for attendance alert and capacity summary logic
This commit is contained in:
Jose Selesan
2026-09-30 17:39:13 -03:00
parent 4e86096653
commit 454f20ed25
31 changed files with 1323 additions and 250 deletions

View File

@@ -12,6 +12,8 @@ import prisma from '@/lib/prisma';
import { buildGroupWhereForUser } from '@/modules/groups/lib';
import {
classifyRisk,
MIN_RISK_ABSENCE_STREAK,
MIN_RISK_MONTHLY_RATE,
monthlyAttendanceRate,
trailingAbsentStreak,
} from '../../lib/risk';
@@ -38,7 +40,8 @@ type AttendanceRow = {
// Resumen de semáforo de riesgo por grupo para la lista de grupos.
// Un grupo es HIGH si tiene al menos un alumno en riesgo alto, MEDIUM si
// alguno en riesgo moderado y NONE en caso contrario.
// alguno en riesgo moderado y NONE en caso contrario. Los contadores dicen el
// motivo (faltas seguidas o asistencia baja) para que la lista pueda nombrarlo.
export class GetGroupsRiskOverview {
constructor(private readonly deps: GetGroupsRiskOverviewDeps = {}) {}
@@ -90,6 +93,12 @@ export class GetGroupsRiskOverview {
const streamByAttendee = groupAttendanceByAttendee(attendances);
const worstRiskByGroup = new Map<string, GroupRiskLevel>();
// Por qué hay riesgo, en la misma pasada: un miembro con racha de faltas
// cuenta en el primero y solo en ese; el segundo agrupa a los que no llegan
// a racha y aun así quedan por debajo del mínimo de asistencia.
const absenceStreakCountByGroup = new Map<string, number>();
const lowAttendanceCountByGroup = new Map<string, number>();
for (const attendee of attendees) {
const groupId = attendeeGroup.get(attendee.id)!;
const stream = (streamByAttendee.get(attendee.id) ?? []).map((row) => ({
@@ -106,6 +115,12 @@ export class GetGroupsRiskOverview {
continue;
}
if (streak >= MIN_RISK_ABSENCE_STREAK) {
bump(absenceStreakCountByGroup, groupId);
} else if (monthlyRate < MIN_RISK_MONTHLY_RATE) {
bump(lowAttendanceCountByGroup, groupId);
}
const current = worstRiskByGroup.get(groupId) ?? 'NONE';
if (
riskLevel === 'HIGH' ||
@@ -119,12 +134,18 @@ export class GetGroupsRiskOverview {
groupId: group.id,
groupName: group.name,
riskLevel: worstRiskByGroup.get(group.id) ?? 'NONE',
absenceStreakCount: absenceStreakCountByGroup.get(group.id) ?? 0,
lowAttendanceCount: lowAttendanceCountByGroup.get(group.id) ?? 0,
}));
return ok({ items });
}
}
function bump(counter: Map<string, number>, key: string) {
counter.set(key, (counter.get(key) ?? 0) + 1);
}
function groupAttendanceByAttendee(rows: AttendanceRow[]): Map<string, AttendanceRow[]> {
const byAttendee = new Map<string, AttendanceRow[]>();
for (const row of rows) {