From 7988d784e9a25918713fa8f3b2158f87ab72de4c Mon Sep 17 00:00:00 2001 From: DonaldKLee Date: Sat, 8 Mar 2025 01:39:59 -0800 Subject: [PATCH 1/2] raffle wip --- pages/[id]/HackerInfo.js | 21 +++++++++++++++++- utility/firebase.js | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/pages/[id]/HackerInfo.js b/pages/[id]/HackerInfo.js index 1d89d784..99ce02b6 100644 --- a/pages/[id]/HackerInfo.js +++ b/pages/[id]/HackerInfo.js @@ -1,7 +1,7 @@ import { useState, useEffect, useRef, useMemo } from 'react' import styled from 'styled-components' import { CSVLink } from 'react-csv' -import { getHackathonPaths, getHackathons, getHackerInfo } from '../../utility/firebase' +import { getHackathonPaths, getHackathons, getHackerInfo, getRaffleWheelEmails } from '../../utility/firebase' import Page from '../../components/page' import Button from '../../components/button' import Menu from '../../components/menu' @@ -102,6 +102,7 @@ const Calculate = styled.select` export default function HackerInfo({ id, hackathons }) { const [unfilteredData, setUnfilteredData] = useState([]) const [filteredData, setFilteredData] = useState([]) + const [raffleData, setRaffleData] = useState([]) const [currTable, setCurrTable] = useState('Applicants') const [unfilteredTableKeys, setUnfilteredTableKeys] = useState([]) const [filteredTableKeys, setFilteredTableKeys] = useState([]) @@ -122,6 +123,7 @@ export default function HackerInfo({ id, hackathons }) { const [filter, setFilter] = useState({}) const [calculate, setCalculate] = useState({}) const downloadLink = useRef() + const raffleDownloadLink = useRef() const clearFilters = () => { setGroupBy({ col1: '', func: '', col2: '' }) @@ -198,6 +200,7 @@ export default function HackerInfo({ id, hackathons }) { }) } + const HackerInfoRow = ({ data }) => { return ( @@ -298,6 +301,22 @@ export default function HackerInfo({ id, hackathons }) { + + {/* TODO raffle */} + + + + + + diff --git a/utility/firebase.js b/utility/firebase.js index dfd7f799..f0617446 100644 --- a/utility/firebase.js +++ b/utility/firebase.js @@ -754,6 +754,54 @@ export const getCSVData = async () => { return CSV } + +export const getRaffleWheelEmails = async () => { + const apps = await db + .collection('Hackathons') + .doc(HackerEvaluationHackathon) + .collection('Applicants') + .where('dayOf.checkedIn', '==', true) + .get() + const CSV = apps.docs.map(doc => { + const { + basicInfo: { + legalFirstName, + legalLastName, + preferredName, + email, + phoneNumber, + } + } = doc.data() + // TODO - Raffle + const totalPoints = email + const totalRaffleEntries = "4000" + + return [ + legalFirstName, + legalLastName, + preferredName, + email, + phoneNumber, + totalPoints, + totalRaffleEntries, + ] + }) + CSV.unshift([ + 'First Name', + 'Last Name', + 'Preferred Name', + 'Email', + 'Phone Number', + 'Events', + 'Total Points', + 'Raffle Entries' + ]) + + console.log(CSV) + + return CSV +} + export const getResumeFile = async userId => { try { const ref = storage.ref(`applicantResumes/${userId}`) From 5a89ac40e3ff63113ccf272342d169bb98923468 Mon Sep 17 00:00:00 2001 From: DonaldKLee Date: Sat, 8 Mar 2025 01:56:02 -0800 Subject: [PATCH 2/2] raffle yolo --- utility/firebase.js | 164 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 128 insertions(+), 36 deletions(-) diff --git a/utility/firebase.js b/utility/firebase.js index f0617446..d53c10e2 100644 --- a/utility/firebase.js +++ b/utility/firebase.js @@ -755,52 +755,144 @@ export const getCSVData = async () => { } +// export const getRaffleNumbers = async () => { +// const apps = await db +// .collection('Hackathons') +// .doc(HackerEvaluationHackathon) +// .collection('Applicants') +// .where('dayOf.checkedIn', '==', true) +// .get(); + +// // Use Promise.all to handle asynchronous logic for each applicant +// const CSV = await Promise.all( +// apps.docs.map(async (doc) => { +// const { +// basicInfo: { +// legalFirstName, +// legalLastName, +// preferredName, +// email, +// phoneNumber, +// }, +// dayOf, +// } = doc.data(); + +// // Ensure dayOf.events exists before proceeding +// if (!dayOf?.events || !Array.isArray(dayOf.events)) return null; + +// // Fetch event documents for each event in dayOf.events +// const dayOfDocsPromises = dayOf.events.map((e) => +// db +// .collection('Hackathons') +// .doc(HackerEvaluationHackathon) +// .collection('DayOf') +// .doc(e.eventId) +// .get() +// ); + +// // Wait for all dayOfDocs to resolve +// const dayOfDocs = await Promise.all(dayOfDocsPromises); + +// // Calculate total points from events +// const totalPoints = dayOfDocs.reduce( +// (acc, curr) => acc + Number(curr.data()?.points ?? 0), +// 0 +// ); + +// // Calculate raffle entries based on total points +// const totalRaffleEntries = Math.floor(totalPoints / 15); + +// return [ +// legalFirstName, +// legalLastName, +// preferredName, +// email, +// phoneNumber, +// totalPoints.toString(), +// totalRaffleEntries.toString(), +// ]; +// }) +// ); + +// // Filter out null results (in case any docs didn't have events or checked-in status) +// const validCSV = CSV.filter((entry) => entry !== null); + +// // Add headers to CSV +// validCSV.unshift([ +// 'First Name', +// 'Last Name', +// 'Preferred Name', +// 'Email', +// 'Phone Number', +// 'Total Points', +// 'Raffle Entries', +// ]); + +// console.log(validCSV); + +// return validCSV; +// }; + + export const getRaffleWheelEmails = async () => { const apps = await db .collection('Hackathons') .doc(HackerEvaluationHackathon) .collection('Applicants') .where('dayOf.checkedIn', '==', true) - .get() - const CSV = apps.docs.map(doc => { + .get(); + + // Create an array to hold all rows for the raffle entries + const raffleEntries = []; + + // Iterate over the documents and calculate raffle entries for each user + for (const doc of apps.docs) { const { - basicInfo: { - legalFirstName, - legalLastName, - preferredName, - email, - phoneNumber, - } - } = doc.data() - // TODO - Raffle - const totalPoints = email - const totalRaffleEntries = "4000" + basicInfo: { email }, + dayOf, + } = doc.data(); + + if (!dayOf?.events || !Array.isArray(dayOf.events)) continue; + + // Fetch event documents for each event in dayOf.events + const dayOfDocsPromises = dayOf.events.map((e) => + db + .collection('Hackathons') + .doc(HackerEvaluationHackathon) + .collection('DayOf') + .doc(e.eventId) + .get() + ); + + const dayOfDocs = await Promise.all(dayOfDocsPromises); + + // Calculate total points from events + // +15 is from check in : cmd-f 2025 + const totalPoints = 15 + dayOfDocs.reduce( + (acc, curr) => acc + Number(curr.data()?.points ?? 0), + 0 + ); + + // Calculate raffle entries based on total points + const totalRaffleEntries = Math.floor(totalPoints / 15); + + // Add the user's email multiple times based on raffle entries + for (let i = 0; i < totalRaffleEntries; i++) { + raffleEntries.push(email); // Repeat the email for each raffle entry + } + } - return [ - legalFirstName, - legalLastName, - preferredName, - email, - phoneNumber, - totalPoints, - totalRaffleEntries, - ] - }) - CSV.unshift([ - 'First Name', - 'Last Name', - 'Preferred Name', - 'Email', - 'Phone Number', - 'Events', - 'Total Points', - 'Raffle Entries' - ]) + // Prepare CSV with only the "Raffle Entries" column + const CSV = [ + ['Raffle Entries'], + ...raffleEntries.map(email => [email]), // Convert to array format for CSV + ]; - console.log(CSV) + console.log(CSV); + + return CSV; +}; - return CSV -} export const getResumeFile = async userId => { try {