Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding stats for shirts, diet, schools #1773

Merged
merged 64 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
7797d8b
init school statistics
stormyy00 Aug 13, 2024
926a3bf
change
stormyy00 Aug 13, 2024
cff5847
colors
stormyy00 Aug 14, 2024
dd7b2e8
change
stormyy00 Aug 14, 2024
5cd4ee3
reworked stats data object
stormyy00 Aug 19, 2024
d5da8c5
update
stormyy00 Aug 23, 2024
c832267
fix
stormyy00 Aug 26, 2024
2c50825
clean up and added seeding
stormyy00 Sep 2, 2024
0dcc478
Merge branch 'dev' of https://github.com/acm-ucr/hackathon-website in…
stormyy00 Sep 2, 2024
49a5af4
clean up
stormyy00 Sep 2, 2024
6a2749b
clean up
stormyy00 Sep 2, 2024
13d5484
organized charting, added inner pir to signify status
stormyy00 Sep 5, 2024
604ca68
Merge branch 'dev' of https://github.com/acm-ucr/hackathon-website in…
stormyy00 Sep 5, 2024
358cb53
-rm comments
stormyy00 Sep 5, 2024
ab1a988
regen package lock
stormyy00 Sep 5, 2024
1df8f66
fixed var name
stormyy00 Sep 5, 2024
a65e882
rm fragments
stormyy00 Sep 5, 2024
793f63b
format smh
stormyy00 Sep 5, 2024
f41d357
forgot this
stormyy00 Sep 5, 2024
6c0b5df
rm code
stormyy00 Sep 6, 2024
dd28d8a
Addressed comments from previous PR
DannielK Sep 7, 2024
13e8bb3
Tag: div to badge
Derrick-Mao Sep 12, 2024
008f3d0
badge format
Derrick-Mao Sep 12, 2024
825b733
combined elif & rm console log
stormyy00 Sep 13, 2024
6a10b35
Merge branch 'dev' of https://github.com/acm-ucr/hackathon-website in…
stormyy00 Sep 13, 2024
ea9d511
rm stats api route
stormyy00 Sep 13, 2024
ec9c9a0
init setup for router visualizer
stormyy00 Sep 13, 2024
3ac63b1
init setup for router visualizer
stormyy00 Sep 13, 2024
f891771
reduced to 2 lines
stormyy00 Sep 14, 2024
fe9aaee
fix build error
stormyy00 Sep 14, 2024
90f9d3a
fix fix
stormyy00 Sep 14, 2024
dec4390
build did pass
stormyy00 Sep 14, 2024
d4e505a
build passed
stormyy00 Sep 14, 2024
ddd76d6
fix caps
shahdivyank Sep 14, 2024
c86ba09
remove ts config changes
shahdivyank Sep 14, 2024
359512a
Merge pull request #1819 from acm-ucr/stormyy00/visualizer
shahdivyank Sep 14, 2024
6b0221a
move parameters in className to be applied after to avoid override
Derrick-Mao Sep 15, 2024
f8f89d4
format
Derrick-Mao Sep 15, 2024
a878d04
Merge pull request #1813 from acm-ucr/derrick-mao/shadcn-badge
shahdivyank Sep 15, 2024
72cb79d
when you click on card link works
Shadow4324 Sep 16, 2024
6cc76c7
click the card boom
Shadow4324 Sep 16, 2024
692fecb
removed flex from cy
Shadow4324 Sep 16, 2024
00d6836
changed to ts
Shadow4324 Sep 16, 2024
6fe4855
added default message for user/find
chairfu Sep 17, 2024
aa0d013
Merge branch 'dev' of https://github.com/acm-ucr/hackathon-website in…
chairfu Sep 17, 2024
7f0a7d2
added default message for user/find
chairfu Sep 17, 2024
47126cd
rearranged
chairfu Sep 17, 2024
ff49546
forgot to commit the formatting :P
chairfu Sep 17, 2024
68ec0bc
Merge pull request #1846 from acm-ucr/Shadow/sitemap
shahdivyank Sep 17, 2024
919838b
Merge pull request #1848 from acm-ucr/chairfu/add-default-msg
shahdivyank Sep 17, 2024
b0b22cf
link contains description
Shadow-The-Dark-Knight Sep 17, 2024
2937494
last one fs this time
Shadow-The-Dark-Knight Sep 17, 2024
61af325
cypress be :(
Shadow-The-Dark-Knight Sep 17, 2024
f441406
Replaced cellProp with tanstack CellContext
DannielK Sep 17, 2024
208fb8b
Merge branch 'dev' of https://github.com/acm-ucr/hackathon-website in…
DannielK Sep 17, 2024
3688901
Weird, shouldve been deleted when i fixed merge conflict but ig it ju…
DannielK Sep 17, 2024
656a7bf
clickable text options
FelixMDM Sep 17, 2024
f1b0b72
converted js to ts
stormyy00 Sep 18, 2024
0a22447
Merge pull request #1851 from acm-ucr/stormyy00/contactsapi
shahdivyank Sep 18, 2024
3015deb
Merge pull request #1849 from acm-ucr/felix/enableclick
shahdivyank Sep 18, 2024
571eaed
Merge pull request #1845 from acm-ucr/Shadow/cardlink
shahdivyank Sep 18, 2024
2eea968
Merge pull request #1807 from acm-ucr/dk/col_helper_to_ts
shahdivyank Sep 18, 2024
0efa378
Merge branch 'stormyy00/schoolstats' of https://github.com/acm-ucr/ha…
stormyy00 Sep 18, 2024
529fca3
fix packge lock
stormyy00 Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cypress/component/user/Hackpack.cy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("HackPacks", () => {
cy.get('[data-cy="hackpack-link"]')
.should(
"have.class",
"flex items-center justify-between opacity-100 hover:opacity-70",
"items-center justify-between rounded-xl bg-white p-3 opacity-100 hover:opacity-70",
)
.should("have.attr", "href", link)
.should("have.attr", "target", "_black");
Expand Down
4,959 changes: 2,215 additions & 2,744 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@react-email/components": "^0.0.25",
"@shadcn/ui": "^0.0.4",
"@tailwindcss/typography": "^0.5.15",
"@tanstack/react-query": "^5.51.11",
"@tanstack/react-query-devtools": "^5.55.0",
Expand All @@ -58,13 +59,14 @@
"clsx": "^2.1.1",
"compressorjs": "^1.2.1",
"firebase": "^10.13.1",
"firebase-admin": "^11.4.1",
"firebase-admin": "^12.5.0",
"gray-matter": "^4.0.3",
"input-otp": "^1.2.4",
"jszip": "^3.10.1",
"lucide-react": "^0.438.0",
"next": "^14.2.7",
"next-auth": "^4.24.7",
"next-route-visualizer": "^1.1.3",
"qrcode.react": "^4.0.1",
"react": "^18.3.1",
"react-big-calendar": "^1.13.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { authenticate } from "@/utils/auth";
import { db } from "@/utils/firebase";
import { collection, getDocs, query, where } from "firebase/firestore";
import { NextResponse } from "next/server";
import { NextRequest, NextResponse } from "next/server";
import { contact } from "@/types/contacts";

export const GET = async (req) => {
export const GET = async (req: NextRequest) => {
const res = NextResponse;

const { auth, message } = await authenticate({
Expand All @@ -18,9 +19,9 @@ export const GET = async (req) => {
}

const role = req.nextUrl.searchParams.get("role");
const status = parseInt(req.nextUrl.searchParams.get("status"));
const status = parseInt(req.nextUrl.searchParams.get("status")!);

const output = [];
const output: contact[] = [];

try {
const snapshot = await getDocs(
Expand Down
30 changes: 22 additions & 8 deletions src/app/api/dashboard/[type]/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export const POST = async (req, { params }) => {
[`roles.${params.type}`]: 0,
}),
updateDoc(doc(db, "statistics", "statistics"), {
[`${params.type}.0`]: increment(1),
[`${params.type}.status.0`]: increment(1),
[`${params.type}.shirt.0.${element.size}`]: increment(1),
[`${params.type}.diet.0.${element.diet}`]: increment(1),
[`${params}.participants.school.0.${element.school}`]: increment(1),
}),
send({
email: user.email,
Expand Down Expand Up @@ -167,7 +170,6 @@ export const GET = async (req, { params }) => {
const total = countFromServer.data().count;
const lastDoc = output.length > 0 ? output[output.length - 1].uid : "";
const firstDoc = output.length > 0 ? output[0].uid : "";

return res.json(
{
message: "OK",
Expand Down Expand Up @@ -228,19 +230,31 @@ export const PUT = async (req, { params }) => {
});

const size = object.shirt;
const diet = object.diet;
const school = object.school;

status === 1 &&
(await updateDoc(doc(db, "statistics", "statistics"), {
[`${params.type}.1`]: increment(1),
[`${params.type}.0`]: increment(-1),
[`${params.type}.${size}`]: increment(1),
[`${params.type}.status.1`]: increment(1),
[`${params.type}.status.0`]: increment(-1),
[`${params.type}.shirt.1.${size}`]: increment(1),
[`${params.type}.shirt.0${size}`]: increment(-1),
[`${params.type}.diet.1.${diet}`]: increment(1),
[`${params.type}.diet.0${diet}`]: increment(-1),
[`${params}.participants.school.1.${school}`]: increment(1),
[`${params}.participants.school.0.${school}`]: increment(-1),
}));

status === -1 &&
(await updateDoc(doc(db, "statistics", "statistics"), {
[`${params.type}.-1`]: increment(1),
[`${params.type}.0`]: increment(-1),
[`${params.type}.${size}`]: increment(-1),
[`${params.type}.status.-1`]: increment(1),
[`${params.type}.status.0`]: increment(-1),
[`${params.type}.shirt.-1.${size}`]: increment(1),
[`${params.type}.shirt.0.${size}`]: increment(-1),
[`${params.type}.diet.-1.${diet}`]: increment(1),
[`${params.type}.diet.0.${diet}`]: increment(-1),
[`${params}.participants.school.-1.${school}`]: increment(1),
[`${params}.participants.school.0.${school}`]: increment(-1),
}));
}),
);
Expand Down
112 changes: 107 additions & 5 deletions src/app/api/settings/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,37 @@ const syncStatsWithDatabase = async () => {
updateRoleCounts("teams"),
]);
};
const getRoleCount = async (role, value) => {
const getRoleCount = async (role, value, subType, subValue) => {
if (role === "teams") {
return (
await getCountFromServer(
query(collection(db, "teams"), where(`status`, "==", value)),
)
).data().count;
}

if (subType) {
return (
await getCountFromServer(
query(
collection(db, "users"),
where(`${subType}`, "==", subValue),
where(`roles.${role}`, "==", value),
),
)
).data().count;
}
if (role === "participants" && subType === "school") {
return (
await getCountFromServer(
query(
collection(db, "users"),
where(`school`, "==", subValue),
where(`roles.${role}`, "==", value),
),
)
).data().count;
}
return (
await getCountFromServer(
query(collection(db, "users"), where(`roles.${role}`, "==", value)),
Expand All @@ -44,11 +67,90 @@ const updateRoleCounts = async (role) => {
getRoleCount(role, 1),
]);

await updateDoc(doc(db, "statistics", "statistics"), {
[`${role}.-1`]: roleMinusOneCount,
[`${role}.0`]: roleZeroCount,
[`${role}.1`]: roleOneCount,
const shirtSizes = ["XS", "S", "M", "L", "XL", "XXL"];
const dietOptions = [
"Halal",
"Vegan",
"Vegetarian",
"Nut Allergy",
"No Gluten",
"Lactose Intolerant",
];
const schoolOptions = [
"University of California, Riverside",
"New York University",
];

const [schoolMinusOneCount, schoolZeroCount, schoolOneCount] =
await Promise.all([
Promise.all(
schoolOptions.map((school) =>
getRoleCount("participants", -1, "school", school),
),
),
Promise.all(
schoolOptions.map((school) =>
getRoleCount("participants", 0, "school", school),
),
),
Promise.all(
schoolOptions.map((school) =>
getRoleCount("participants", 1, "school", school),
),
),
]);

const [shirtMinusOneCount, shirtZeroCount, shirtOneCount] = await Promise.all(
[
Promise.all(
shirtSizes.map((size) => getRoleCount(role, -1, "shirt", size)),
),
Promise.all(
shirtSizes.map((size) => getRoleCount(role, 0, "shirt", size)),
),
Promise.all(
shirtSizes.map((size) => getRoleCount(role, 1, "shirt", size)),
),
],
);

const [dietMinusOneCount, dietZeroCount, dietOneCount] = await Promise.all([
Promise.all(
dietOptions.map((option) => getRoleCount(role, -1, "diet", option)),
),
Promise.all(
dietOptions.map((option) => getRoleCount(role, 0, "diet", option)),
),
Promise.all(
dietOptions.map((option) => getRoleCount(role, 1, "diet", option)),
),
]);

const updateData = {
[`${role}.status.-1`]: roleMinusOneCount,
[`${role}.status.0`]: roleZeroCount,
[`${role}.status.1`]: roleOneCount,
};

schoolOptions.forEach((school, index) => {
updateData[`participants.school.-1.${school}`] = schoolMinusOneCount[index];
updateData[`participants.school.0.${school}`] = schoolZeroCount[index];
updateData[`participants.school.1.${school}`] = schoolOneCount[index];
});

shirtSizes.forEach((size, index) => {
updateData[`${role}.shirt.-1.${size}`] = shirtMinusOneCount[index];
updateData[`${role}.shirt.0.${size}`] = shirtZeroCount[index];
updateData[`${role}.shirt.1.${size}`] = shirtOneCount[index];
});

dietOptions.forEach((option, index) => {
updateData[`${role}.diet.-1.${option}`] = dietMinusOneCount[index];
updateData[`${role}.diet.0.${option}`] = dietZeroCount[index];
updateData[`${role}.diet.1.${option}`] = dietOneCount[index];
});

await updateDoc(doc(db, "statistics", "statistics"), updateData);
};
export const GET = async () => {
const res = NextResponse;
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions src/app/visualize/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Visualizer from "next-route-visualizer";

const Page = () => <Visualizer />;
export default Page;
2 changes: 1 addition & 1 deletion src/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Checkbox as Check } from "./ui/checkbox";

type checkbox = {
toggle: boolean;
text: string;
text?: string;
color?: string;
onClick?: () => void;
};
Expand Down
15 changes: 0 additions & 15 deletions src/components/admin/Tag.jsx

This file was deleted.

32 changes: 32 additions & 0 deletions src/components/admin/Tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { StatusMapping } from "@/data/Statuses";
import { Badge } from "../ui/badge";

type color = {
background: string;
text: string;
hover: string;
};

type props = {
color: color;
text: string;
onClick?: () => void;
classes?: string;
statuses?: StatusMapping;
};

const Tag = ({ color, text, onClick, classes, statuses }: props) => {
return (
<Badge
data-cy={`${text}-tag`}
className={`m-0 w-fit whitespace-nowrap rounded px-2 py-0.5 text-xs md:text-sm ${classes} ${color.background} ${color.text} ${
onClick && `hover:cursor-pointer ${color.hover}`
}`}
onClick={onClick}
>
{isNaN(Number(text)) ? text : statuses?.[text as keyof StatusMapping]}
</Badge>
);
};

export default Tag;
40 changes: 29 additions & 11 deletions src/components/admin/services/statistics/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as React from "react";
import { Label, Pie, PieChart } from "recharts";
import { ROLES, SIZES } from "@/data/admin/Statistics";
import { ROLES, SIZES, DIETS, SCHOOLS } from "@/data/admin/Statistics";

import { Card, CardContent } from "@/components/ui/card";
import {
Expand All @@ -11,17 +11,27 @@ import {
ChartTooltipContent,
} from "@/components/ui/chart";

const Chart = ({ title, data }) => {
const ITEMS = { ...ROLES, ...SIZES };
const Chart = ({ title, status = null, data }) => {
const ITEMS = { ...ROLES, ...SIZES, ...DIETS, ...SCHOOLS };

const chartData = Object.entries(data)
.filter(([type]) => ROLES[type])
.map(([type, value]) => ({
type: ITEMS[type].label,
value: value,
className: ITEMS[type].className,
fill: ITEMS[type].fill,
}));
const statusData =
status !== null
? [
{
type: ROLES[status].label,
value: 1,
className: ROLES[status].className,
fill: ROLES[status].fill,
},
]
: [];

const chartData = Object.entries(data).map(([type, value]) => ({
type: ITEMS[type].label,
value: value,
className: ITEMS[type].className,
fill: ITEMS[type].fill,
}));

const chartConfig = Object.entries(data).map(([type, value]) => {
const label = ITEMS[type].label;
Expand Down Expand Up @@ -103,6 +113,14 @@ const Chart = ({ title, data }) => {
}}
/>
</Pie>
<Pie
data={statusData}
dataKey="value"
nameKey="type"
innerRadius={55}
outerRadius={60}
strokeWidth={5}
/>
</PieChart>
</ChartContainer>
</CardContent>
Expand Down
Loading
Loading