From 48573b69bc88d4a35a66b15f11ef340dbfc26052 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 22 Feb 2024 02:11:50 -0500 Subject: [PATCH 1/5] fixing cabin sorting --- ui/lib/answer.csv | 13 ++++++------ ui/lib/cabinTypes.csv | 2 +- ui/lib/questionNameMapping.csv | 4 ++-- .../SortedHackerApplicationDataService.ts | 20 +++++++++++-------- ui/models/HackerApplicationData.ts | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/ui/lib/answer.csv b/ui/lib/answer.csv index 01c6d0f..6b9a736 100644 --- a/ui/lib/answer.csv +++ b/ui/lib/answer.csv @@ -1,7 +1,6 @@ -question0,question1,question2,question3,question4,question5,question6,question7 -answer1,answer1,answer1,answer1,answer1,answer1,answer1,answer1 -answer2,answer2,answer2,answer2,answer2,answer2,answer2,answer2 -answer3,answer3,answer3,answer3,answer3,answer3,answer3,answer3 -answer4,answer4,answer4,answer4,answer4,answer4,answer4,answer4 -answer5,answer5,answer5,answer5,answer5,answer5,answer5,answer5 -answer6,answer6,answer6,answer6,answer6,answer6,answer6,answer6 +question0,question1,question2,question3,question4,question5,question6,question7,question8 +"Listening to what everyone has to say!","Water purifying water bottle","Use the strength of an empire to make this nation feel hopeless","Be well-liked. You want people to trust your judgment, and have as many friends as possible.","Ask upperclassmen for for tips and tricks","Find your RA’s Discord and call them immediately","Gardening!","I don’t have social media!","Do other class’s homework" +"Leading the conversation and planning another hangout","You already have an emergency backpack packed","Send someone to marry the heir to their throne to take over from the within","Be a ruler. You like it when people go to you for advice, when people look to you as their leader. You like to assign tasks, rather than do them.","Start a study group that meets daily","First tell all of your friends also stuck in the elevator to calm down and not panic and ask everyone to brainstorm a solution","Speech and Debate!","Instagram","always asking questions, when you’re not asking questions you’re talking to your friends" +"Thinking about what book you’re going to read when you get home","Survival for Dummies","Take the time to learn about the history of this nation and research its weaknesses to exploit them.","Be wise. Knowledge is your source of happiness. Nothing pleases you more but seeing your own intellectual growth.","Drill pass exams questions","Try to debug the elevator yourself","University Book Club!","Pinterest","Active listening and reflecting and making connections" +"Talking everyone’s ear off about your latest rock climbing experience","GoPro! Gotta vlog the journey","Stage a surprise attack on a sacred holiday of this nation.","Be a risk-taker. Exploring new things and taking on the challenges that others quiver from gives you unprecedented dopamine. You believe only great risks can there be great success","Trick your professor into giving you the topics and types of questions on the exam","Try to kick the door open","Outdoor Adventure Club!","Tiktok","Haha you’re kidding I won’t be in class" +"On a discord channel","Laptop. We’ll figure out the wifi later","Launch a cyber attack to nullify all communications inside and out.","Be remembered. You see leaving your mark on the world as the meaning in life. You want to leave a lasting impression on the world through the work you do!","Go to online office hours and ask for rundowns of potential topics","Pretend it didn’t happen and continue to game","Online Gaming Club!","Twitch","Game with mechanical keyboard" \ No newline at end of file diff --git a/ui/lib/cabinTypes.csv b/ui/lib/cabinTypes.csv index 69f81f2..e9612fb 100644 --- a/ui/lib/cabinTypes.csv +++ b/ui/lib/cabinTypes.csv @@ -1 +1 @@ -cabin0,cabin1,cabin2,cabin3,cabin4 +Finding Nemo,Sharknado,Northern Water Tribe,Bikini Bottom,Minecraft Ocean Monument \ No newline at end of file diff --git a/ui/lib/questionNameMapping.csv b/ui/lib/questionNameMapping.csv index db00c19..484d744 100644 --- a/ui/lib/questionNameMapping.csv +++ b/ui/lib/questionNameMapping.csv @@ -1,2 +1,2 @@ -hangingWithFriends,zombieApocalypse,takeOverNation,aspirations,study,stuckInElevator,socialMedia,duringClass -question0,question1,question2,question3,question4,question5,question6,question7 \ No newline at end of file +hangingWithFriends,zombieApocalypse,takeOverNation,aspirations,study,stuckInElevator,club,socialMedia,duringClass +question0,question1,question2,question3,question4,question5,question6,question7,question8 \ No newline at end of file diff --git a/ui/lib/service/SortedHackerApplicationDataService.ts b/ui/lib/service/SortedHackerApplicationDataService.ts index e892c75..7fbd3b0 100644 --- a/ui/lib/service/SortedHackerApplicationDataService.ts +++ b/ui/lib/service/SortedHackerApplicationDataService.ts @@ -24,7 +24,7 @@ let answerList: any[] let cabinList: any[] let questionNameMapping: { [key: string]: string } const CABIN_SIZE = 5 -const QUESTIONS_SIZE = 8 +const QUESTIONS_SIZE = 9 const getAllHackersWithAssignedCabins = async (): Promise< SortedHackersReturnType @@ -80,7 +80,7 @@ function formatRawData ( rawHackerData: HackerApplicationDataType[] ): FormattedHackerDataType[] { return rawHackerData - .filter((hackerData) => !!hackerData.postAcceptanceResponses) + .filter((hackerData) => hackerData.decisionStatus === "Admitted" && hackerData.rsvpStatus === "Confirmed" && !!hackerData.postAcceptanceResponses) .map((hackerData) => { const { email, postAcceptanceResponses } = hackerData @@ -130,7 +130,12 @@ function matchAnswers ( const cabinScore = Array(CABIN_SIZE).fill(0) hydrateCabinScore(hackerWithCabins, cabinScore) - + console.log(cabinScore) + let sum = 0 + cabinScore.forEach(score => sum += score) + if (sum != QUESTIONS_SIZE) { + console.log(hacker) + } // create extra column for hacker that determines the cabin they should // join (the one with the most points) const maxIndex: number = cabinScore.indexOf(Math.max(...cabinScore)) @@ -156,17 +161,16 @@ function hydrateCabinScore ( hacker: FormattedHackerWithCabinsDataType, cabinScore: number[] ) { - answerList.forEach((cabin: any, cabinIndex: number) => { - // skip first row of answerList because of question name - if (cabinIndex === 0) return + // skip first row of answerList because of question name + answerList.slice(1, -1).forEach((cabin: any, cabinIndex: number) => { for ( let questionIndex = 0; questionIndex < QUESTIONS_SIZE; questionIndex++ ) { if ( - cabin[questionIndex] === hacker['question' + questionIndex.toString()] - ) { + cabin[questionIndex].trim() === hacker['question' + questionIndex.toString()].trim() + ) { cabinScore[cabinIndex]++ } } diff --git a/ui/models/HackerApplicationData.ts b/ui/models/HackerApplicationData.ts index 0aa348b..04d08a8 100644 --- a/ui/models/HackerApplicationData.ts +++ b/ui/models/HackerApplicationData.ts @@ -48,7 +48,7 @@ export const HackerApplicationDataSchema = } }, { - collection: 'hacker_applications', + collection: 'applicant_data', versionKey: false } ) From a9146583400def8f085f7426a8f042d887f1b4a0 Mon Sep 17 00:00:00 2001 From: kzeng24 Date: Thu, 22 Feb 2024 02:16:56 -0500 Subject: [PATCH 2/5] updated cabin names in UI --- ui/pages/cabinSorting.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/pages/cabinSorting.tsx b/ui/pages/cabinSorting.tsx index da9f88c..e7d6b40 100644 --- a/ui/pages/cabinSorting.tsx +++ b/ui/pages/cabinSorting.tsx @@ -23,11 +23,11 @@ export default function CabinSorting ({ cabinData }: InferGetServerSidePropsType) { const cabinHeaders: string[] = [ - 'Cabin 0', - 'Cabin 1', - 'Cabin 2', - 'Cabin 3', - 'Cabin 4' + 'Finding Nemo', + 'Sharknado', + 'Northern Water Tribe', + 'Bikini Bottom', + 'Minecraft Ocean Monument' ] const cabinValues: string[][] = [] From 994c704dc6ce68d4d3f4ef460ded145d130a7e1b Mon Sep 17 00:00:00 2001 From: kzeng24 Date: Thu, 22 Feb 2024 19:14:05 -0500 Subject: [PATCH 3/5] fix eslint --- .../SortedHackerApplicationDataService.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ui/lib/service/SortedHackerApplicationDataService.ts b/ui/lib/service/SortedHackerApplicationDataService.ts index 7fbd3b0..19d0986 100644 --- a/ui/lib/service/SortedHackerApplicationDataService.ts +++ b/ui/lib/service/SortedHackerApplicationDataService.ts @@ -80,7 +80,8 @@ function formatRawData ( rawHackerData: HackerApplicationDataType[] ): FormattedHackerDataType[] { return rawHackerData - .filter((hackerData) => hackerData.decisionStatus === "Admitted" && hackerData.rsvpStatus === "Confirmed" && !!hackerData.postAcceptanceResponses) + .filter((hackerData) => hackerData.decisionStatus === 'Admitted' && + hackerData.rsvpStatus === 'Confirmed' && !!hackerData.postAcceptanceResponses) .map((hackerData) => { const { email, postAcceptanceResponses } = hackerData @@ -130,12 +131,12 @@ function matchAnswers ( const cabinScore = Array(CABIN_SIZE).fill(0) hydrateCabinScore(hackerWithCabins, cabinScore) - console.log(cabinScore) - let sum = 0 - cabinScore.forEach(score => sum += score) - if (sum != QUESTIONS_SIZE) { - console.log(hacker) - } + // console.log(cabinScore) + // let sum = 0 + // cabinScore.forEach(score => sum += score) + // if (sum != QUESTIONS_SIZE) { + // console.log(hacker) + // } // create extra column for hacker that determines the cabin they should // join (the one with the most points) const maxIndex: number = cabinScore.indexOf(Math.max(...cabinScore)) @@ -170,7 +171,7 @@ function hydrateCabinScore ( ) { if ( cabin[questionIndex].trim() === hacker['question' + questionIndex.toString()].trim() - ) { + ) { cabinScore[cabinIndex]++ } } From 65a28a465bb6b03a1c712123a9f1cea164d41c66 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 22 Feb 2024 19:17:58 -0500 Subject: [PATCH 4/5] eslinter errors --- .../SortedHackerApplicationDataService.ts | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/ui/lib/service/SortedHackerApplicationDataService.ts b/ui/lib/service/SortedHackerApplicationDataService.ts index 7fbd3b0..061df33 100644 --- a/ui/lib/service/SortedHackerApplicationDataService.ts +++ b/ui/lib/service/SortedHackerApplicationDataService.ts @@ -26,31 +26,30 @@ let questionNameMapping: { [key: string]: string } const CABIN_SIZE = 5 const QUESTIONS_SIZE = 9 -const getAllHackersWithAssignedCabins = async (): Promise< - SortedHackersReturnType -> => { - await fetch('http://localhost:3000/api/cabinSorting/answerList') - .then((response) => response.json()) - .then((data) => { - answerList = data.content - }) - - await fetch('http://localhost:3000/api/cabinSorting/cabinList') - .then((response) => response.json()) - .then((data) => { - cabinList = data.content[0] - }) - - await fetch('http://localhost:3000/api/cabinSorting/questionNameMapping') - .then((response) => response.json()) - .then((data) => { - questionNameMapping = data - }) - - const rawHackerData = await HackerApplicationDataDao.find() - const formattedHackerData = formatRawData(rawHackerData) - return matchAnswers(formattedHackerData) -} +const getAllHackersWithAssignedCabins = + async (): Promise => { + await fetch('http://localhost:3000/api/cabinSorting/answerList') + .then((response) => response.json()) + .then((data) => { + answerList = data.content + }) + + await fetch('http://localhost:3000/api/cabinSorting/cabinList') + .then((response) => response.json()) + .then((data) => { + cabinList = data.content[0] + }) + + await fetch('http://localhost:3000/api/cabinSorting/questionNameMapping') + .then((response) => response.json()) + .then((data) => { + questionNameMapping = data + }) + + const rawHackerData = await HackerApplicationDataDao.find() + const formattedHackerData = formatRawData(rawHackerData) + return matchAnswers(formattedHackerData) + } const pingServer = async (): Promise => { for (let i = 1; i <= 3; i++) { @@ -80,7 +79,12 @@ function formatRawData ( rawHackerData: HackerApplicationDataType[] ): FormattedHackerDataType[] { return rawHackerData - .filter((hackerData) => hackerData.decisionStatus === "Admitted" && hackerData.rsvpStatus === "Confirmed" && !!hackerData.postAcceptanceResponses) + .filter( + (hackerData) => + hackerData.decisionStatus === 'Admitted' && + hackerData.rsvpStatus === 'Confirmed' && + !!hackerData.postAcceptanceResponses + ) .map((hackerData) => { const { email, postAcceptanceResponses } = hackerData @@ -132,8 +136,8 @@ function matchAnswers ( hydrateCabinScore(hackerWithCabins, cabinScore) console.log(cabinScore) let sum = 0 - cabinScore.forEach(score => sum += score) - if (sum != QUESTIONS_SIZE) { + cabinScore.forEach((score) => (sum += score)) + if (sum !== QUESTIONS_SIZE) { console.log(hacker) } // create extra column for hacker that determines the cabin they should @@ -169,8 +173,9 @@ function hydrateCabinScore ( questionIndex++ ) { if ( - cabin[questionIndex].trim() === hacker['question' + questionIndex.toString()].trim() - ) { + cabin[questionIndex].trim() === + hacker['question' + questionIndex.toString()].trim() + ) { cabinScore[cabinIndex]++ } } From 15ad2c2f19c0f9357047851d4daa31908533aedf Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 22 Feb 2024 19:32:29 -0500 Subject: [PATCH 5/5] fixed bug in cabin matching algorithm --- ui/lib/service/SortedHackerApplicationDataService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/lib/service/SortedHackerApplicationDataService.ts b/ui/lib/service/SortedHackerApplicationDataService.ts index b5ed40c..c67b88d 100644 --- a/ui/lib/service/SortedHackerApplicationDataService.ts +++ b/ui/lib/service/SortedHackerApplicationDataService.ts @@ -161,7 +161,8 @@ function hydrateCabinScore ( cabinScore: number[] ) { // skip first row of answerList because of question name - answerList.slice(1, -1).forEach((cabin: any, cabinIndex: number) => { + answerList.slice(1).forEach((cabin: any, cabinIndex: number) => { + console.log(cabin, cabinIndex) for ( let questionIndex = 0; questionIndex < QUESTIONS_SIZE;