From 4e1605207eb56342868ec3009b5c38814d4870aa Mon Sep 17 00:00:00 2001 From: Imggaggu Date: Sun, 25 May 2025 06:38:29 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20processWeeklyAttendance=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/admin/AdminStudentAttendance.jsx | 100 ++++++++---------- 1 file changed, 47 insertions(+), 53 deletions(-) diff --git a/frontend/src/pages/admin/AdminStudentAttendance.jsx b/frontend/src/pages/admin/AdminStudentAttendance.jsx index 3d0b1de..f21971d 100644 --- a/frontend/src/pages/admin/AdminStudentAttendance.jsx +++ b/frontend/src/pages/admin/AdminStudentAttendance.jsx @@ -64,64 +64,58 @@ const AdminStudentAttendance = () => { }, []); */ // 날짜 기반 주차-회차 구조로 변환 - const processWeeklyAttendance = (rawData) => { - const startDate = new Date("2025-06-24"); - const getWeekFromDate = (dateStr) => { - const d = new Date(dateStr); - const diffDays = Math.floor((d - startDate) / (1000 * 60 * 60 * 24)); - return Math.floor(diffDays / 7) + 1; - }; - - const weekSlotMap = new Map(); - const dateMap = new Map(); // 추가: 날짜 저장 - - rawData.forEach(({ date, order, status }) => { - const week = getWeekFromDate(date); - const statuses = [status ? "SUCCESS" : "FAILURE"]; - const existing = weekSlotMap.get(week) || []; - const existingDates = dateMap.get(week) || []; - - weekSlotMap.set(week, [...existing, ...statuses]); - dateMap.set(week, [...existingDates, date]); - - }); +const processWeeklyAttendance = (rawData) => { + const startDate = new Date("2025-06-24"); - return Array.from({ length: 5 }, (_, i) => { - const week = i + 1; - const all = weekSlotMap.get(week) || []; - const dates = dateMap.get(week) || []; - const classes = [0, 1, 2].map((classIdx) => { - const slice = all.slice(classIdx * 3, classIdx * 3 + 3); - const trueCount = slice.filter((s) => s === "SUCCESS").length; - - let status; - switch (trueCount) { - case 3: - status = "SUCCESS"; - break; - case 2: - status = "INSUFFICIENT"; - break; - case 1: - status = "FAILURE"; - break; - default: - status = "EMPTY"; - } - - return { - status, - date: dates[classIdx] || null, - }; - }); + const getWeekFromDate = (dateStr) => { + const d = new Date(dateStr); + const diffDays = Math.floor((d - startDate) / (1000 * 60 * 60 * 24)); + return Math.floor(diffDays / 7) + 1; + }; + // 주차별 출석 정보 묶기 + const weekMap = new Map(); + + rawData.forEach(({ date, order, status }) => { + const week = getWeekFromDate(date); + const entry = { date, order, status: status ? "SUCCESS" : "FAILURE" }; + + if (!weekMap.has(week)) weekMap.set(week, []); + weekMap.get(week).push(entry); + }); + + return Array.from({ length: 5 }, (_, i) => { + const week = i + 1; + const entries = (weekMap.get(week) || []).sort((a, b) => a.order - b.order); + + const classes = [0, 1, 2].map((classIdx) => { + const slice = entries.slice(classIdx * 3, classIdx * 3 + 3); + const trueCount = slice.filter((e) => e.status === "SUCCESS").length; + + let status; + switch (trueCount) { + case 3: + status = "SUCCESS"; + break; + case 2: + status = "INSUFFICIENT"; + break; + case 1: + status = "FAILURE"; + break; + default: + status = "EMPTY"; + } return { - week, - classes - }; + status, + date: entries[classIdx]?.date || null, + }; }); - }; + + return { week, classes }; + }); +}; return (