diff --git a/components/common/ExpandableSearchGrid/expandableSearchGrid.tsx b/components/common/ExpandableSearchGrid/expandableSearchGrid.tsx index f571fcc8..d5e956ae 100644 --- a/components/common/ExpandableSearchGrid/expandableSearchGrid.tsx +++ b/components/common/ExpandableSearchGrid/expandableSearchGrid.tsx @@ -12,6 +12,7 @@ import { SearchTermCard } from '../SearchTermCard/searchTermCard'; type ExpandableSearchGridProps = { onChange: (searchTerms: SearchQuery[]) => void; studentTotals: number[]; + averageData: number[]; }; /** @@ -22,6 +23,7 @@ type ExpandableSearchGridProps = { export const ExpandableSearchGrid = ({ onChange, studentTotals, + averageData, }: ExpandableSearchGridProps) => { const router = useRouter(); @@ -87,34 +89,38 @@ export const ExpandableSearchGrid = ({ {searchTerms.map((option: SearchQuery, index: number) => ( ))} {searchTerms.length < 3 ? ( - - - - + + ) : null} ); }; -function studentTotalFormatter(total: number) { - if (total === -1) { - return 'Loading...'; - } - return total.toLocaleString('en-US') + ' grades'; +function secondaryTextFormatter(total: number, gpa: number) { + return ( + total.toLocaleString('en-US') + + ' grades | ' + + Number(gpa).toFixed(2) + + ' average GPA' + ); } function searchQueriesLabel(queries: SearchQuery[]): string { diff --git a/components/common/SearchTermCard/searchTermCard.tsx b/components/common/SearchTermCard/searchTermCard.tsx index a5a3a8ab..b6e61b7a 100644 --- a/components/common/SearchTermCard/searchTermCard.tsx +++ b/components/common/SearchTermCard/searchTermCard.tsx @@ -1,5 +1,5 @@ -import { Close } from '@mui/icons-material'; -import { Box, IconButton, Typography } from '@mui/material'; +import { Close, Help } from '@mui/icons-material'; +import { Box, IconButton, Tooltip, Typography } from '@mui/material'; import Card from '@mui/material/Card'; import * as React from 'react'; @@ -12,6 +12,7 @@ type SearchTermCardProps = { index: number; onCloseButtonClicked: (index: number) => void; legendColor: string; + loading: boolean; }; /** @@ -25,35 +26,27 @@ export const SearchTermCard = (props: SearchTermCardProps) => { } return ( - +
- - {props.primaryText} - - {props.secondaryText} +
+ + {props.primaryText} + + + {props.loading ? 'Loading...' : props.secondaryText} - + {props.loading ? null : ( + + + + )} +
diff --git a/pages/dashboard/index.tsx b/pages/dashboard/index.tsx index e21bb567..e23cf845 100644 --- a/pages/dashboard/index.tsx +++ b/pages/dashboard/index.tsx @@ -113,9 +113,7 @@ export const Dashboard: NextPage = () => { const [fullGradesData, setFullGradesData] = useState([]); const [gradesData, setGradesData] = useState([]); - const [GPAData, setGPAData] = useState([]); - const [averageData, setAverageData] = useState([]); - const [stdevData, setStdevData] = useState([]); + const [averageData, setAverageData] = useState([-1, -1, -1]); const [studentTotals, setStudentTotals] = useState([-1, -1, -1]); const [professorInvolvingSearchTerms, setProfessorInvolvingSearchTerms] = @@ -265,8 +263,9 @@ export const Dashboard: NextPage = () => { }; }); - const newDat: gradesType[] = []; + const newGradesData: gradesType[] = []; const newStudentTotals = [-1, -1, -1]; + const newAverageData: number[] = []; for (let i = 0; i < partialGradesData.length; i++) { const total: number = partialGradesData[i].data.reduce( (accumulator, currentValue) => accumulator + currentValue, @@ -276,47 +275,28 @@ export const Dashboard: NextPage = () => { const normalized: number[] = partialGradesData[i].data.map( (value) => (value / total) * 100, ); - newDat[i] = { + newGradesData[i] = { name: partialGradesData[i].name, data: normalized, }; - } - setGradesData(newDat); - setStudentTotals(newStudentTotals); - const newGPADat: gradesType[] = []; - const newAverageDat: gradesType[] = []; - const newStdevDat: gradesType[] = []; - for (let i = 0; i < partialGradesData.length; i++) { const GPALookup = [ 4, 4, 3.67, 3.33, 3, 2.67, 2.33, 2, 1.67, 1.33, 1, 0.67, 0, ]; - let GPAGrades: number[] = []; - for (let j = 0; j < partialGradesData[i].data.length - 1; j++) { - GPAGrades = GPAGrades.concat( - Array(partialGradesData[i].data[j]).fill(GPALookup[j]), - ); - } - newGPADat.push({ name: partialGradesData[i].name, data: GPAGrades }); - const mean = - GPAGrades.reduce((partialSum, a) => partialSum + a, 0) / - GPAGrades.length; - newAverageDat.push({ - name: partialGradesData[i].name, - data: [mean], - }); - const stdev = Math.sqrt( - GPAGrades.reduce((partialSum, a) => partialSum + (a - mean) ** 2, 0) / - GPAGrades.length, + + newAverageData.push( + GPALookup.reduce( + (accumulator, currentValue, index) => + accumulator + currentValue * partialGradesData[i].data[index], + 0, + ) / + (total - + partialGradesData[i].data[partialGradesData[i].data.length - 1]), ); - newStdevDat.push({ - name: partialGradesData[i].name, - data: [stdev], - }); } - setGPAData(newGPADat); - setAverageData(newAverageDat); - setStdevData(newStdevDat); + setGradesData(newGradesData); + setStudentTotals(newStudentTotals); + setAverageData(newAverageData); }, [fullGradesData, startingSession, endingSession]); let gradesPage; @@ -408,34 +388,6 @@ export const Dashboard: NextPage = () => { series={gradesData} /> - - Number(value).toFixed(2)} - series={GPAData} - /> - -
- - Number(value).toFixed(2)} - series={averageData} - /> - - - Number(value).toFixed(2)} - series={stdevData} - /> - -
); @@ -583,6 +535,7 @@ export const Dashboard: NextPage = () => {