diff --git a/app/admin/districtstats/page.js b/app/admin/districtstats/page.js new file mode 100644 index 0000000..ec11e9c --- /dev/null +++ b/app/admin/districtstats/page.js @@ -0,0 +1,424 @@ +"use client"; +import { useEffect, useState, useMemo } from "react"; +import { useRouter } from "next/navigation"; +import { auth } from "@/app/_util/initApp"; +import { getRegistrationData } from "@/app/_util/data"; +import secureLocalStorage from "react-secure-storage"; + +export default function DistrictStats() { + const router = useRouter(); + const [user, setUser] = useState(null); + const [data, setData] = useState(null); + const [filteredData, setFilteredData] = useState([]); + + const [districts, setDistricts] = useState([]); + const [districtData, setDistrictData] = useState([]); + + const [checkInDateOptions, setCheckInDateOptions] = useState([]); + const [filterCheckInDate, setFilterCheckInDate] = useState(""); + + const [checkOutDateOptions, setCheckOutDateOptions] = useState([]); + const [filterCheckOutDate, setFilterCheckOutDate] = useState(""); + + useEffect(() => { + const savedUser = secureLocalStorage.getItem("user"); + if (!savedUser) { + router.push("/"); + return; + } + + const parsedUser = JSON.parse(savedUser); + setUser(parsedUser); + + getRegistrationData().then((_data) => { + if (!_data || _data.length !== 8) { + router.push("/"); + return; + } + + setData(_data[0]); + setDistricts(_data[1]); + setCheckInDateOptions(_data[6]); + setCheckOutDateOptions(_data[7]); + + const organizedData = _data[1].map((district) => ({ + district, + rows: _data[0].filter((row) => row.district === district), + })); + + setDistrictData(organizedData); + }); + }, [router]); + + useEffect(() => { + const filtered = districtData.map((item) => ({ + district: item.district, + rows: item.rows.filter( + (row) => + (filterCheckInDate === "" || row.checkInDate === filterCheckInDate) && + (filterCheckOutDate === "" || row.checkOutDate === filterCheckOutDate) + ), + })); + + setFilteredData(filtered); + }, [districtData, filterCheckInDate, filterCheckOutDate]); + + return user && data ? ( +
{user.email}
+Total Registrations
++ Participants +
+Male
++ {rows.reduce( + (acc, row) => + acc + parseInt((row.gender == "Male" ? 1 : 0) ?? 0), + 0 + )} +
+Female
++ {rows.reduce( + (acc, row) => + acc + parseInt((row.gender == "Female" ? 1 : 0) ?? 0), + 0 + )} +
+Total
++ {rows.reduce( + (acc, row) => + acc + parseInt((row.gender == "Male" ? 1 : 0) ?? 0), + 0 + ) + + rows.reduce( + (acc, row) => + acc + parseInt((row.gender == "Female" ? 1 : 0) ?? 0), + 0 + )} +
+Total Accompanying Adults
++ Non-Participants +
+Male
++ {rows.reduce( + (acc, row) => + acc + parseInt(row.numMaleAccompanying ?? 0), + 0 + )} +
+Female
++ {rows.reduce( + (acc, row) => + acc + parseInt(row.numFemaleAccompanying ?? 0), + 0 + )} +
+Children
++ {rows.reduce( + (acc, row) => + acc + parseInt(row.numNonParticipatingSiblings ?? 0), + 0 + )} +
+Total
++ {rows.reduce( + (acc, row) => + acc + parseInt(row.numMaleAccompanying ?? 0), + 0 + ) + + rows.reduce( + (acc, row) => + acc + parseInt(row.numFemaleAccompanying ?? 0), + 0 + ) + + rows.reduce( + (acc, row) => + acc + parseInt(row.numNonParticipatingSiblings ?? 0), + 0 + )} +
+Accommodation Logistics
++ Non-Participants +
+Male
++ {rows.reduce( + (acc, row) => + acc + + parseInt( + row.numMaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + )} +
+Female
++ {rows.reduce( + (acc, row) => + acc + + parseInt( + row.numFemaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + )} +
++ Participants +
+Male
++ {rows.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Male" + ? 1 + : 0) ?? 0 + ), + 0 + )} +
+Female
++ {rows.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Female" + ? 1 + : 0) ?? 0 + ), + 0 + )} +
+Accommodation
+Overall
+Male
++ {rows.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Male" + ? 1 + : 0) ?? 0 + ), + 0 + ) + + rows.reduce( + (acc, row) => + acc + + parseInt( + row.numMaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + )} +
+Female
++ {rows.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Female" + ? 1 + : 0) ?? 0 + ), + 0 + ) + + rows.reduce( + (acc, row) => + acc + + parseInt( + row.numFemaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + )} +
+Total
++ {rows.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Male" + ? 1 + : 0) ?? 0 + ), + 0 + ) + + rows.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Female" + ? 1 + : 0) ?? 0 + ), + 0 + ) + + rows.reduce( + (acc, row) => + acc + + parseInt( + row.numMaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + ) + + rows.reduce( + (acc, row) => + acc + + parseInt( + row.numFemaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + )} +
+Loading...
+{user.email}
+{user.email}
-Total Registrations
+Participants
+Male
++ {filteredData.reduce( + (acc, row) => + acc + parseInt((row.gender == "Male" ? 1 : 0) ?? 0), + 0 + )} +
+Female
++ {filteredData.reduce( + (acc, row) => + acc + parseInt((row.gender == "Female" ? 1 : 0) ?? 0), + 0 + )} +
+Total
++ {filteredData.reduce( + (acc, row) => + acc + parseInt((row.gender == "Male" ? 1 : 0) ?? 0), + 0 + ) + + filteredData.reduce( + (acc, row) => + acc + parseInt((row.gender == "Female" ? 1 : 0) ?? 0), + 0 + )} +
+Total Accompanying Adults
+Non-Participants
+Male
++ {filteredData.reduce( + (acc, row) => acc + parseInt(row.numMaleAccompanying ?? 0), + 0 + )} +
+Female
++ {filteredData.reduce( + (acc, row) => + acc + parseInt(row.numFemaleAccompanying ?? 0), + 0 + )} +
+Children
++ {filteredData.reduce( + (acc, row) => + acc + parseInt(row.numNonParticipatingSiblings ?? 0), + 0 + )} +
+Total
++ {filteredData.reduce( + (acc, row) => acc + parseInt(row.numMaleAccompanying ?? 0), + 0 + ) + + filteredData.reduce( + (acc, row) => + acc + parseInt(row.numFemaleAccompanying ?? 0), + 0 + ) + + filteredData.reduce( + (acc, row) => + acc + parseInt(row.numNonParticipatingSiblings ?? 0), + 0 + )} +
+Accommodation Logistics
+Non-Participants
+Male
++ {filteredData.reduce( + (acc, row) => + acc + + parseInt( + row.numMaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + )} +
+Female
++ {filteredData.reduce( + (acc, row) => + acc + + parseInt( + row.numFemaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + )} +
+Total
++ {filteredData.reduce( + (acc, row) => + acc + + parseInt( + row.numMaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + ) + + filteredData.reduce( + (acc, row) => + acc + + parseInt( + row.numFemaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + )} +
+Participants
+Male
++ {filteredData.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Male" + ? 1 + : 0) ?? 0 + ), + 0 + )} +
+Female
++ {filteredData.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Female" + ? 1 + : 0) ?? 0 + ), + 0 + )} +
+Total
++ {filteredData.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Male" + ? 1 + : 0) ?? 0 + ), + 0 + ) + + filteredData.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Female" + ? 1 + : 0) ?? 0 + ), + 0 + )} +
+Overall
+Total
++ {filteredData.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Male" + ? 1 + : 0) ?? 0 + ), + 0 + ) + + filteredData.reduce( + (acc, row) => + acc + + parseInt( + (row.needsAccommodation == "Yes" && + row.gender == "Female" + ? 1 + : 0) ?? 0 + ), + 0 + ) + + filteredData.reduce( + (acc, row) => + acc + + parseInt( + row.numMaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + ) + + filteredData.reduce( + (acc, row) => + acc + + parseInt( + row.numFemaleAccompanyingNeedAccommodation ?? 0 + ), + 0 + )} +
+Total Registrations
-Participants
-Male
-{filteredData.reduce((acc, row) => acc + parseInt((row.gender == "Male" ? 1 : 0) ?? 0), 0)}
-Female
-{filteredData.reduce((acc, row) => acc + parseInt((row.gender == "Female" ? 1 : 0) ?? 0), 0)}
-Total
-- {filteredData.reduce((acc, row) => acc + parseInt((row.gender == "Male" ? 1 : 0) ?? 0), 0) + filteredData.reduce((acc, row) => acc + parseInt((row.gender == "Female" ? 1 : 0) ?? 0), 0)} -
-Student Details | +BalVikas Details | ++ Arrival & Departure Logistics + | +Accompany Details | +Accommodation Details | +||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
+ {row.studentFullName ?? "-"} ++ {row.gender ?? "-"} - {row.dateOfBirth ?? "-"} + +
+
- + {row.studentId ?? "-"} + ++ {row.studentGroup ?? "-"} +
-
-
- Total Accompanying Adults -Non-Participants -
-
+
-
- Male -{filteredData.reduce((acc, row) => acc + parseInt(row.numMaleAccompanying ?? 0), 0)} -
-
- Female -{filteredData.reduce((acc, row) => acc + parseInt(row.numFemaleAccompanying ?? 0), 0)} -
-
- Children -{filteredData.reduce((acc, row) => acc + parseInt(row.numNonParticipatingSiblings ?? 0), 0)} -
-
- Total -- {filteredData.reduce((acc, row) => acc + parseInt(row.numMaleAccompanying ?? 0), 0) + - filteredData.reduce((acc, row) => acc + parseInt(row.numFemaleAccompanying ?? 0), 0) + - filteredData.reduce((acc, row) => acc + parseInt(row.numNonParticipatingSiblings ?? 0), 0)} - - |
+
+ {row.district ?? "-"} +{row.samithiName ?? "-"} ++ DOJ BV: {row.dateOfJoiningBalvikas ?? "-"}{" "} + {row.yearOfJoiningBalvikas ?? "-"} + + {row.studentGroup === "Group 3" && ( ++ Passed group 2: {row.hasPassedGroup2Exam ?? "-"} + + )} +
+ {row.registeredEvents.map((event, index) => (
+
- + {event ?? "-"} + + ))}
- Accommodation Logistics -
-
+
-
-
-
- Non-Participants -
-
-
-
- Male -{filteredData.reduce((acc, row) => acc + parseInt(row.numMaleAccompanyingNeedAccommodation ?? 0), 0)} -
-
- Female -{filteredData.reduce((acc, row) => acc + parseInt(row.numFemaleAccompanyingNeedAccommodation ?? 0), 0)} -
-
- Total -- {filteredData.reduce((acc, row) => acc + parseInt(row.numMaleAccompanyingNeedAccommodation ?? 0), 0) + - filteredData.reduce((acc, row) => acc + parseInt(row.numFemaleAccompanyingNeedAccommodation ?? 0), 0)} - -
-
-
-
- Participants -
-
-
-
- Male -{filteredData.reduce((acc, row) => acc + parseInt((row.needsAccommodation == "Yes" && row.gender == "Male" ? 1 : 0) ?? 0), 0)} -
-
- Female -{filteredData.reduce((acc, row) => acc + parseInt((row.needsAccommodation == "Yes" && row.gender == "Female" ? 1 : 0) ?? 0), 0)} -
-
- Total -- {filteredData.reduce((acc, row) => acc + parseInt((row.needsAccommodation == "Yes" && row.gender == "Male" ? 1 : 0) ?? 0), 0) + - filteredData.reduce((acc, row) => acc + parseInt((row.needsAccommodation == "Yes" && row.gender == "Female" ? 1 : 0) ?? 0), 0)} - -
-
-
-
- Overall -
-
- Total -- {filteredData.reduce((acc, row) => acc + parseInt((row.needsAccommodation == "Yes" && row.gender == "Male" ? 1 : 0) ?? 0), 0) + - filteredData.reduce((acc, row) => acc + parseInt((row.needsAccommodation == "Yes" && row.gender == "Female" ? 1 : 0) ?? 0), 0) + filteredData.reduce((acc, row) => acc + parseInt(row.numMaleAccompanyingNeedAccommodation ?? 0), 0) + - filteredData.reduce((acc, row) => acc + parseInt(row.numFemaleAccompanyingNeedAccommodation ?? 0), 0)} - - |
+
+
+
-
-
-
+
+ {"Arrival"} ++ {row.arrivalDate ?? "-"} - {row.arrivalTime ?? "-"} + ++ {row.needsPickup === "Yes" + ? "Needs pickup." + : "Pickup not needed."} + + {row.needsPickup === "Yes" && ( +
+
+ )}
+ + Mode: {row.modeOfTravel ?? "-"} + ++ Pickup Point: {row.pickupPoint ?? "-"} + +
+
{"Departure"} ++ {row.departureDate ?? "-"} -{" "} + {row.departureTime ?? "-"} + ++ {row.needsDrop === "Yes" + ? "Needs drop." + : "Drop not needed."} + + {row.needsDrop === "Yes" && ( +
+
+ )}
+ + Mode: {row.modeOfTravelForDrop ?? "-"} + ++ Drop Point: {row.dropOffPoint ?? "-"} + +
-
-
- >
- ) : (
-
-
+ Loading... ++ For student: {row.needsAccommodation ?? "-"} + ++ Allergies: {row.foodAllergies ?? "-"} + +
+
+ + {row.numMaleAccompanyingNeedAccommodation ?? "0"} male + ++ {row.numFemaleAccompanyingNeedAccommodation ?? "0"}{" "} + female + + |
+
Loading...
+