Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file removed public/assets/logo-netlify-large.png
Binary file not shown.
141 changes: 73 additions & 68 deletions server/mongodb/actions/AggregatedAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export const getAggregatedAnalytics = async (

let counter = 0;
const lenOfMetrics = analyticsRecord.weeklyMetrics.length;
const groupSize = Math.floor(lenOfMetrics / 12);

// reversing the list
const reversedWeeklyMetrics = analyticsRecord.weeklyMetrics.reverse();
Expand All @@ -106,10 +105,6 @@ export const getAggregatedAnalytics = async (
reversedWeeklyMetrics.length === 0
? lastMonday
: new Date(reversedWeeklyMetrics[0].date);
let lastDateMax =
reversedWeeklyMetrics.length === 0
? lastMonday
: new Date(reversedWeeklyMetrics[0].date);

const dbDateVars = new Set<string>();

Expand All @@ -121,13 +116,14 @@ export const getAggregatedAnalytics = async (
dateVar = formatDateByRangeEnum(lastDate, range);
}

// group into groups of 12 and put everything into the last object once it goes over
if (range === DateRangeEnum.MAX) {
if (counter % groupSize === 0 && counter < groupSize * 12) {
lastDateMax = item.date;
if (lenOfMetrics > 12) {
dateVar = formatDateByRangeEnum(item.date, range, true);
} else {
dateVar = formatDateByRangeEnum(item.date, range);
}
dateVar = formatDateByRangeEnum(lastDateMax, range);
}

counter += 1;
lastDate = item.date;

Expand Down Expand Up @@ -231,6 +227,7 @@ export const getAggregatedAnalytics = async (
"questionsCompleted",
"questionsCorrect",
]);

Object.values(groupSumDict).forEach((monthDict) => {
Object.values(monthDict).forEach((monthTypeDict) => {
Object.keys(monthTypeDict).forEach((property) => {
Expand Down Expand Up @@ -260,70 +257,78 @@ export const getAggregatedAnalytics = async (
const allDateVars = Array.from(dbDateVars).reverse();

// PADDING
if (range !== DateRangeEnum.MAX) {
let len = Object.keys(groupSumDict).length;

let totalWeeks = numOfWeeks;
if (range === DateRangeEnum.HALF) {
totalWeeks = 13;
} else if (range === DateRangeEnum.YEAR) {
totalWeeks = 12;
}
if (
userIDs.length === 1 &&
(analyticsRecords[0].weeklyMetrics as []).length === 0
) {
let len = Object.keys(groupSumDict).length;

let totalWeeks = numOfWeeks;
if (range === DateRangeEnum.HALF) {
totalWeeks = 13;
} else if (range === DateRangeEnum.YEAR) {
totalWeeks = 12;
} else if (range === DateRangeEnum.MAX) {
if (lenOfMetrics === 1) {
totalWeeks = 6;
} else {
totalWeeks = 0;
}
}

while (len < totalWeeks) {
if (range === DateRangeEnum.RECENT || range === DateRangeEnum.QUARTER) {
paddingDate.setDate(paddingDate.getDate() - 7);
} else if (range === DateRangeEnum.HALF) {
paddingDate.setDate(paddingDate.getDate() - 14);
} else if (range === DateRangeEnum.YEAR) {
paddingDate.setMonth(paddingDate.getMonth() - 1);
}

const tempDateString = formatDateByRangeEnum(paddingDate, range);

allDateVars.push(tempDateString);
groupSumDict[tempDateString] = Object.fromEntries(
Object.entries({
overall: {
streakLength: 0,
streakHistory: 0,
},
math: {
avgAccuracy: 0,
avgDifficultyScore: 0,
avgQuestionsCompleted: 0,
avgTimePerQuestion: 0,
},
reading: {
avgSessionsCompleted: 0,
avgSessionsAttempted: 0,
avgWordsPerMin: 0,
avgPassagesRead: 0,
avgTimePerPassage: 0,
},
writing: {
avgSessionsCompleted: 0,
avgSessionsAttempted: 0,
avgPromptsAnswered: 0,
avgTimePerQuestion: 0,
},
trivia: {
avgAccuracy: 0,
avgQuestionsCompleted: 0,
avgTimePerQuestion: 0,
},
}).filter(([k]) => sections.includes(k as AnalyticsSectionEnum)),
);
if (
userIDs.length === 1 &&
(analyticsRecords[0].weeklyMetrics as []).length === 0
) {
totalWeeks = 0;
}

len += 1;
while (len < totalWeeks) {
if (range === DateRangeEnum.RECENT || range === DateRangeEnum.QUARTER) {
paddingDate.setDate(paddingDate.getDate() - 7);
} else if (range === DateRangeEnum.HALF) {
paddingDate.setDate(paddingDate.getDate() - 14);
} else if (range === DateRangeEnum.YEAR) {
paddingDate.setMonth(paddingDate.getMonth() - 1);
} else if (range === DateRangeEnum.MAX) {
paddingDate.setDate(paddingDate.getDate() - 7);
}

const tempDateString = formatDateByRangeEnum(paddingDate, range);

allDateVars.push(tempDateString);
groupSumDict[tempDateString] = Object.fromEntries(
Object.entries({
overall: {
streakLength: 0,
streakHistory: 0,
},
math: {
avgAccuracy: 0,
avgDifficultyScore: 0,
avgQuestionsCompleted: 0,
avgTimePerQuestion: 0,
},
reading: {
avgSessionsCompleted: 0,
avgSessionsAttempted: 0,
avgWordsPerMin: 0,
avgPassagesRead: 0,
avgTimePerPassage: 0,
},
writing: {
avgSessionsCompleted: 0,
avgSessionsAttempted: 0,
avgPromptsAnswered: 0,
avgTimePerQuestion: 0,
},
trivia: {
avgAccuracy: 0,
avgQuestionsCompleted: 0,
avgTimePerQuestion: 0,
},
}).filter(([k]) => sections.includes(k as AnalyticsSectionEnum)),
);

len += 1;
}
// }

const result: Result = {};
sections.forEach((type) => {
Expand Down Expand Up @@ -416,7 +421,7 @@ export const getAggregatedAnalytics = async (
};
const obj = result.overall;
if (obj) {
obj.streakHistory.push(dr);
obj.streakHistory.unshift(dr);
}
}

Expand Down
16 changes: 12 additions & 4 deletions server/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export function getCurrentSunday() {
return new Date(date.toDateString());
}

export function formatDateByRangeEnum(date: Date, range: DateRangeEnum) {
export function formatDateByRangeEnum(
date: Date,
range: DateRangeEnum,
month?: boolean,
) {
const monthName = date.toLocaleString("default", {
timeZone: "UTC",
month: "short",
Expand All @@ -28,9 +32,13 @@ export function formatDateByRangeEnum(date: Date, range: DateRangeEnum) {
const year = String(date.getUTCFullYear());

if (
[DateRangeEnum.RECENT, DateRangeEnum.QUARTER, DateRangeEnum.HALF].includes(
range,
)
[
DateRangeEnum.RECENT,
DateRangeEnum.QUARTER,
DateRangeEnum.HALF,
DateRangeEnum.MAX,
].includes(range) &&
!month
) {
return `${monthName} ${day}`;
}
Expand Down
1 change: 0 additions & 1 deletion src/app/(management-portal)/chapter/[name]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export default function Page({ params }: { params: { name: string } }) {
chapter={chapter}
chapterPresident={chapterPresident}
refreshUsers={fetchUsers}
refreshInfo={fetchChapterAndPresident}
/>
<Divider />
</div>
Expand Down
11 changes: 2 additions & 9 deletions src/app/(management-portal)/chapter/search/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
flex-direction: column;
align-items: center;
row-gap: 30px;
position: relative;
}

.search-container {
Expand Down Expand Up @@ -42,14 +41,14 @@
max-height: 0px;
z-index: 1;
opacity: 1;
overflow: visible;
overflow: hidden;
}

.table-container-show {
max-height: 10000px;
z-index: 1;
opacity: 1;
overflow: visible;
overflow: auto;
}

.arrowButton {
Expand All @@ -64,9 +63,3 @@
width: 100%;
height: 100%;
}

.netlify {
position: absolute;
bottom: 20px;
right: 20px;
}
4 changes: 0 additions & 4 deletions src/app/(management-portal)/chapter/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import firebaseInit from "@src/firebase/config";

import { RootState } from "@src/redux/rootReducer";
import { internalRequest } from "@src/utils/requests";
import NetlifyLogo from "@src/components/NetlifyLogo/NetlifyLogo";
import styles from "./page.module.css";

firebaseInit();
Expand Down Expand Up @@ -94,9 +93,6 @@ export default function Page() {
currentPage={currentPage}
/>
</div>
<div className={styles.netlify}>
<NetlifyLogo></NetlifyLogo>
</div>
</div>
);
}
11 changes: 2 additions & 9 deletions src/app/(management-portal)/patient/search/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
flex-direction: column;
align-items: center;
row-gap: 30px;
position: relative;
}

.search-container {
Expand Down Expand Up @@ -42,14 +41,14 @@
max-height: 0px;
z-index: 1;
opacity: 1;
overflow: visible;
overflow: hidden;
}

.table-container-show {
max-height: 10000px;
z-index: 1;
opacity: 1;
overflow: visible;
overflow: auto;
}

.arrowButton {
Expand All @@ -64,9 +63,3 @@
width: 100%;
height: 100%;
}

.netlify {
position: absolute;
bottom: 20px;
right: 40px;
}
4 changes: 0 additions & 4 deletions src/app/(management-portal)/patient/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Modal from "@src/components/Modal/Modal";
import firebaseInit from "@src/firebase/config";

import { RootState } from "@src/redux/rootReducer";
import NetlifyLogo from "@src/components/NetlifyLogo/NetlifyLogo";
import styles from "./page.module.css";

firebaseInit();
Expand Down Expand Up @@ -142,9 +141,6 @@ export default function Page() {
currentPage={currentPage}
/>
</div>
<div className={styles.netlify}>
<NetlifyLogo></NetlifyLogo>
</div>
</div>
);
}
11 changes: 2 additions & 9 deletions src/app/(management-portal)/volunteer/approval/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
flex-direction: column;
align-items: center;
row-gap: 30px;
position: relative;
}

.search-container {
Expand Down Expand Up @@ -42,14 +41,14 @@
max-height: 0px;
z-index: 1;
opacity: 1;
overflow: visible;
overflow: hidden;
}

.table-container-show {
max-height: 10000px;
z-index: 1;
opacity: 1;
overflow: visible;
overflow: auto;
}

.arrowButton {
Expand All @@ -64,9 +63,3 @@
width: 100%;
height: 100%;
}

.netlify {
position: absolute;
right: 5%;
bottom: 5%;
}
4 changes: 0 additions & 4 deletions src/app/(management-portal)/volunteer/approval/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {

import firebaseInit from "@src/firebase/config";
import { RootState } from "@src/redux/rootReducer";
import NetlifyLogo from "@src/components/NetlifyLogo/NetlifyLogo";
import styles from "./page.module.css";

firebaseInit();
Expand Down Expand Up @@ -146,9 +145,6 @@ export default function Page() {
refreshUsers={fetchUsers}
/>
</div>
<div className={styles.netlify}>
<NetlifyLogo></NetlifyLogo>
</div>
</div>
);
}
Loading
Loading