Skip to content
Merged
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
6 changes: 6 additions & 0 deletions server/mongodb/actions/AggregatedAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const getAggregatedAnalytics = async (
throw new Error("User Analytics record not found");
}

console.log("p");
const out: Partial<IAggregatedAnalyticsAll>[] = [];

const lastMonday = new Date(getCurrentMonday().getDate() - 7);
Expand Down Expand Up @@ -254,6 +255,7 @@ export const getAggregatedAnalytics = async (
}
});
});
console.log("o");
const excludedProperties = new Set([
"totalNum",
"questionsCompleted",
Expand Down Expand Up @@ -286,6 +288,7 @@ export const getAggregatedAnalytics = async (
});
});

console.log("j");
const allDateVars = Array.from(dbDateVars).reverse();

// PADDING
Expand Down Expand Up @@ -408,12 +411,14 @@ export const getAggregatedAnalytics = async (
}
});

console.log("sd");
const excludedProperties2 = new Set([
"totalNum",
"questionsCompleted",
"questionsCorrect",
"avgSessionsAttempted",
]);
console.log("s2");
allDateVars.forEach((month) => {
Object.entries(groupSumDict[month]).forEach(([type, monthTypeDict]) => {
Object.keys(monthTypeDict).forEach((property) => {
Expand Down Expand Up @@ -472,6 +477,7 @@ export const getAggregatedAnalytics = async (
});
});

console.log(analyticsRecord.lastSessionMetrics);
// if overshoot, remove last element
// const groupSumArray = Object.values(groupSumDict)
// if ((groupSumArray.length === 4 && range === "quarter") ||
Expand Down
102 changes: 51 additions & 51 deletions server/mongodb/actions/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,57 @@ const checkNewDate = async (userID: string): Promise<null> => {
analytics?.lastSessionMetrics.date.getFullYear() !== today.getFullYear()
) {
await Analytics.findOneAndUpdate({ userID }, [
{
$set: {
lastSessionsMetrics: {
$cond: {
if: { $gt: [{ $size: "$lastSessionsMetrics" }, 1] },
then: { $slice: ["$lastSessionsMetrics", 1] },
else: "$lastSessionsMetrics",
},
},
},
},
{
$set: {
lastSessionsMetrics: {
$concatArrays: [
[
{
date: today,
math: {
attempted: false,
questionsAttempted: 0,
questionsCorrect: 0,
finalDifficultyScore: 0,
timePerQuestion: 0,
},
trivia: {
attempted: false,
questionsAttempted: 0,
questionsCorrect: 0,
timePerQuestion: 0,
},
reading: {
attempted: false,
passagesRead: 0,
timePerPassage: 0,
wordsPerMinute: 0,
skipped: true,
},
writing: {
attempted: false,
questionsAnswered: 0,
timePerQuestion: 0,
skipped: true,
},
},
],
"$lastSessionsMetrics",
],
},
},
},
// {
// $set: {
// lastSessionsMetrics: {
// $cond: {
// if: { $gt: [{ $size: "$lastSessionsMetrics" }, 1] },
// then: { $slice: ["$lastSessionsMetrics", 1] },
// else: "$lastSessionsMetrics",
// },
// },
// },
// },
// {
// $set: {
// lastSessionsMetrics: {
// $concatArrays: [
// [
// {
// date: today,
// math: {
// attempted: false,
// questionsAttempted: 0,
// questionsCorrect: 0,
// finalDifficultyScore: 0,
// timePerQuestion: 0,
// },
// trivia: {
// attempted: false,
// questionsAttempted: 0,
// questionsCorrect: 0,
// timePerQuestion: 0,
// },
// reading: {
// attempted: false,
// passagesRead: 0,
// timePerPassage: 0,
// wordsPerMinute: 0,
// skipped: true,
// },
// writing: {
// attempted: false,
// questionsAnswered: 0,
// timePerQuestion: 0,
// skipped: true,
// },
// },
// ],
// "$lastSessionsMetrics",
// ],
// },
// },
// },
]);
}
return null;
Expand Down
5 changes: 5 additions & 0 deletions server/mongodb/actions/Chapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { ObjectId, PipelineStage, Promise } from "mongoose";
import Chapter from "../models/Chapter";
import User from "../models/User";

export const getChapters = async (): Promise<IChapter[] | null> => {
const chapters = await Chapter.find<IChapter>();
return chapters;
};

export const getChapterByName = async (
name: string,
): Promise<IChapter | null> => {
Expand Down
4 changes: 2 additions & 2 deletions server/mongodb/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ type UParam = {
"location.state"?: object;
"location.city"?: object;
additionalAffiliation?: object;
beiChapter?: object;
chapter?: object;
"analyticsRecords.active"?: boolean;
};

Expand Down Expand Up @@ -201,7 +201,7 @@ export const getUsersFiltered = async ({
};
}
if (paramsObject.beiChapters) {
userParamsObject.beiChapter = { $in: paramsObject.beiChapters };
userParamsObject.chapter = { $in: paramsObject.beiChapters };
}
if (paramsObject.active !== undefined) {
userParamsObject["analyticsRecords.active"] = paramsObject.active;
Expand Down
119 changes: 58 additions & 61 deletions server/mongodb/models/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,66 @@ const AnalyticsSchema = new Schema({
},
default: [],
},
lastSessionsMetrics: {
type: [
{
date: Date,
math: {
attempted: Boolean,
questionsAttempted: Number,
questionsCorrect: Number,
finalDifficultyScore: Number,
timePerQuestion: Number,
},
trivia: {
attempted: Boolean,
questionsAttempted: Number,
questionsCorrect: Number,
timePerQuestion: Number,
},
reading: {
attempted: Boolean,
passagesRead: Number,
timePerPassage: Number,
wordsPerMinute: Number,
skipped: Boolean, // should be true even if the user attempts the section but skips without completing
},
writing: {
attempted: Boolean,
questionsAnswered: Number,
timePerQuestion: Number,
skipped: Boolean, // should be true even if the user attempts the section but skips without completing
},
lastSessionMetrics: {
type: {
date: Date,
math: {
attempted: Boolean,
questionsAttempted: Number,
questionsCorrect: Number,
finalDifficultyScore: Number,
timePerQuestion: Number,
},
],
default: [
{
date: Date(),
math: {
attempted: false,
questionsAttempted: 0,
questionsCorrect: 0,
finalDifficultyScore: 0,
timePerQuestion: 0,
},
trivia: {
attempted: false,
questionsAttempted: 0,
questionsCorrect: 0,
timePerQuestion: 0,
},
reading: {
attempted: false,
passagesRead: 0,
timePerPassage: 0,
wordsPerMinute: 0,
skipped: true,
},
writing: {
attempted: false,
questionsAnswered: 0,
timePerQuestion: 0,
skipped: true,
},
trivia: {
attempted: Boolean,
questionsAttempted: Number,
questionsCorrect: Number,
timePerQuestion: Number,
},
],
reading: {
attempted: Boolean,
passagesRead: Number,
timePerPassage: Number,
wordsPerMinute: Number,
skipped: Boolean, // should be true even if the user attempts the section but skips without completing
},
writing: {
attempted: Boolean,
questionsAnswered: Number,
timePerQuestion: Number,
skipped: Boolean, // should be true even if the user attempts the section but skips without completing
},
},

default: {
date: Date(),
math: {
attempted: false,
questionsAttempted: 0,
questionsCorrect: 0,
finalDifficultyScore: 0,
timePerQuestion: 0,
},
trivia: {
attempted: false,
questionsAttempted: 0,
questionsCorrect: 0,
timePerQuestion: 0,
},
reading: {
attempted: false,
passagesRead: 0,
timePerPassage: 0,
wordsPerMinute: 0,
skipped: true,
},
writing: {
attempted: false,
questionsAnswered: 0,
timePerQuestion: 0,
skipped: true,
},
},
},
weeklyMetrics: {
type: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default function Page({ params }: { params: { id: string } }) {
const retrieveAnalytics = useCallback(
async <T,>(range: DateRangeEnum, sections: AnalyticsSectionEnum[]) => {
setLoading(true);
console.log(params.id);
try {
const data = await internalRequest<T>({
url: "/api/patient/analytics",
Expand Down
14 changes: 14 additions & 0 deletions src/app/api/chapter/get-chapters/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getChapters } from "@server/mongodb/actions/Chapter";
import APIWrapper from "@server/utils/APIWrapper";

export const GET = APIWrapper({
config: {
requireToken: true,
requireAdmin: true,
},
handler: async () => {
const chapters = await getChapters();

return chapters;
},
});
Loading
Loading