Fix student performance freeze and search users in create entities
TODO: pagination in student performance freeze
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Module} from "@/interfaces";
|
||||
import { Module } from "@/interfaces";
|
||||
import {
|
||||
Exam,
|
||||
ReadingExam,
|
||||
@@ -70,9 +70,9 @@ export const getExamById = async (module: Module, id: string): Promise<Exam | un
|
||||
|
||||
export const defaultExamUserSolutions = (exam: Exam) => {
|
||||
if (exam.module === "reading" || exam.module === "listening" || exam.module === "level")
|
||||
return exam.parts.flatMap((x) => x.exercises).map((x) => defaultUserSolutions(x, exam));
|
||||
return (exam.parts.flatMap((x) => x.exercises) ?? []).map((x) => defaultUserSolutions(x, exam));
|
||||
|
||||
return exam.exercises.map((x) => defaultUserSolutions(x, exam));
|
||||
return (exam.exercises ?? []).map((x) => defaultUserSolutions(x, exam));
|
||||
};
|
||||
|
||||
export const defaultUserSolutions = (exercise: Exercise, exam: Exam): UserSolution => {
|
||||
@@ -88,26 +88,26 @@ export const defaultUserSolutions = (exercise: Exercise, exam: Exam): UserSoluti
|
||||
switch (exercise.type) {
|
||||
case "fillBlanks":
|
||||
total = exercise.text.match(/({{\d+}})/g)?.length || 0;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
return { ...defaultSettings, score: { correct: 0, total, missing: total } };
|
||||
case "matchSentences":
|
||||
total = exercise.sentences.length;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
return { ...defaultSettings, score: { correct: 0, total, missing: total } };
|
||||
case "multipleChoice":
|
||||
total = exercise.questions.length;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
return { ...defaultSettings, score: { correct: 0, total, missing: total } };
|
||||
case "writeBlanks":
|
||||
total = exercise.text.match(/({{\d+}})/g)?.length || 0;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
return { ...defaultSettings, score: { correct: 0, total, missing: total } };
|
||||
case "trueFalse":
|
||||
total = exercise.questions.length;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
return { ...defaultSettings, score: { correct: 0, total, missing: total } };
|
||||
case "writing":
|
||||
total = 1;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
return { ...defaultSettings, score: { correct: 0, total, missing: total } };
|
||||
case "speaking":
|
||||
total = 1;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
return { ...defaultSettings, score: { correct: 0, total, missing: total } };
|
||||
default:
|
||||
return {...defaultSettings, score: {correct: 0, total: 0, missing: 0}};
|
||||
return { ...defaultSettings, score: { correct: 0, total: 0, missing: 0 } };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {Module, Step} from "@/interfaces";
|
||||
import {Stat, User} from "@/interfaces/user";
|
||||
import { Module, Step } from "@/interfaces";
|
||||
import { Stat, User } from "@/interfaces/user";
|
||||
|
||||
type Type = "academic" | "general";
|
||||
|
||||
export const writingReverseMarking: {[key: number]: number} = {
|
||||
export const writingReverseMarking: { [key: number]: number } = {
|
||||
9: 90,
|
||||
8.5: 85,
|
||||
8: 80,
|
||||
@@ -25,7 +25,7 @@ export const writingReverseMarking: {[key: number]: number} = {
|
||||
0: 0,
|
||||
};
|
||||
|
||||
export const speakingReverseMarking: {[key: number]: number} = {
|
||||
export const speakingReverseMarking: { [key: number]: number } = {
|
||||
9: 90,
|
||||
8.5: 85,
|
||||
8: 80,
|
||||
@@ -47,7 +47,7 @@ export const speakingReverseMarking: {[key: number]: number} = {
|
||||
0: 0,
|
||||
};
|
||||
|
||||
export const writingMarking: {[key: number]: number} = {
|
||||
export const writingMarking: { [key: number]: number } = {
|
||||
90: 9,
|
||||
80: 8,
|
||||
70: 7,
|
||||
@@ -60,7 +60,7 @@ export const writingMarking: {[key: number]: number} = {
|
||||
0: 0,
|
||||
};
|
||||
|
||||
const readingGeneralMarking: {[key: number]: number} = {
|
||||
const readingGeneralMarking: { [key: number]: number } = {
|
||||
100: 9,
|
||||
97.5: 8.5,
|
||||
92.5: 8,
|
||||
@@ -77,7 +77,7 @@ const readingGeneralMarking: {[key: number]: number} = {
|
||||
15: 2.5,
|
||||
};
|
||||
|
||||
const academicMarking: {[key: number]: number} = {
|
||||
const academicMarking: { [key: number]: number } = {
|
||||
97.5: 9,
|
||||
92.5: 8.5,
|
||||
87.5: 8,
|
||||
@@ -94,7 +94,7 @@ const academicMarking: {[key: number]: number} = {
|
||||
10: 2.5,
|
||||
};
|
||||
|
||||
const levelMarking: {[key: number]: number} = {
|
||||
const levelMarking: { [key: number]: number } = {
|
||||
88: 9, // Advanced
|
||||
64: 8, // Upper-Intermediate
|
||||
52: 6, // Intermediate
|
||||
@@ -103,7 +103,7 @@ const levelMarking: {[key: number]: number} = {
|
||||
0: 0, // Beginner
|
||||
};
|
||||
|
||||
const moduleMarkings: {[key in Module | "overall"]: {[key in Type]: {[key: number]: number}}} = {
|
||||
const moduleMarkings: { [key in Module | "overall"]: { [key in Type]: { [key: number]: number } } } = {
|
||||
reading: {
|
||||
academic: academicMarking,
|
||||
general: readingGeneralMarking,
|
||||
@@ -147,7 +147,7 @@ export const calculateBandScore = (correct: number, total: number, module: Modul
|
||||
return 0;
|
||||
};
|
||||
|
||||
export const calculateAverageLevel = (levels: {[key in Module]: number}) => {
|
||||
export const calculateAverageLevel = (levels: { [key in Module]: number }) => {
|
||||
return (
|
||||
Object.keys(levels)
|
||||
.filter((x) => x !== "level")
|
||||
@@ -193,20 +193,21 @@ export const getGradingLabel = (score: number, grading: Step[]) => {
|
||||
return "N/A";
|
||||
};
|
||||
|
||||
export const averageLevelCalculator = (users: User[], studentStats: Stat[]) => {
|
||||
const formattedStats = studentStats
|
||||
export const averageLevelCalculator = (focus: Type, studentStats: Stat[]) => {
|
||||
/* const formattedStats = studentStats
|
||||
.map((s) => ({
|
||||
focus: users.find((u) => u.id === s.user)?.focus,
|
||||
focus: focus,
|
||||
score: s.score,
|
||||
module: s.module,
|
||||
}))
|
||||
.filter((f) => !!f.focus);
|
||||
const bandScores = formattedStats.map((s) => ({
|
||||
.filter((f) => !!f.focus); */
|
||||
|
||||
const bandScores = studentStats.map((s) => ({
|
||||
module: s.module,
|
||||
level: calculateBandScore(s.score.correct, s.score.total, s.module, s.focus!),
|
||||
level: calculateBandScore(s.score.correct, s.score.total, s.module, focus),
|
||||
}));
|
||||
|
||||
const levels: {[key in Module]: number} = {
|
||||
const levels: { [key in Module]: number } = {
|
||||
reading: 0,
|
||||
listening: 0,
|
||||
writing: 0,
|
||||
|
||||
@@ -6,7 +6,7 @@ import client from "@/lib/mongodb";
|
||||
import { EntityWithRoles, WithEntities } from "@/interfaces/entity";
|
||||
import { getEntity } from "./entities.be";
|
||||
import { getRole } from "./roles.be";
|
||||
import { groupAllowedEntitiesByPermissions } from "./permissions";
|
||||
import { groupAllowedEntitiesByPermissions } from "./permissions";
|
||||
import { mapBy } from ".";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
@@ -20,6 +20,15 @@ export async function getUsers(filter?: object, limit = 0, sort = {}, projection
|
||||
.toArray();
|
||||
}
|
||||
|
||||
export async function getUsersWithStats(filter?: object, projection = {}, limit = 0, sort = {}) {
|
||||
return await db
|
||||
.collection("usersWithStats")
|
||||
.find<User>(filter || {}, { projection: { _id: 0, ...projection } })
|
||||
.limit(limit)
|
||||
.sort(sort)
|
||||
.toArray();
|
||||
}
|
||||
|
||||
export async function searchUsers(searchInput?: string, limit = 50, page = 0, sort: object = { "name": 1 }, projection = {}, filter?: object) {
|
||||
const compoundFilter = {
|
||||
"compound": {
|
||||
|
||||
Reference in New Issue
Block a user