Skip to content

Commit

Permalink
Merge pull request #65 from polyglot-edu/learning-analytics
Browse files Browse the repository at this point in the history
LP grade definition and integration
  • Loading branch information
tmaog authored Jan 13, 2025
2 parents 5e09dfd + cb817f2 commit 663b3e7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/controllers/learningAnalysis.controllers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Request, Response } from "express";
import * as Models from "../models/learningData.models";
import * as Types from "../types/LearningData";
import { flowGradeUpdate } from "../learningAnalyticsAlgorithms";

export const createAction = async (req: Request, res: Response) => {
try {
Expand Down Expand Up @@ -250,18 +251,23 @@ export const createAction = async (req: Request, res: Response) => {
action = await Models.SubmitAnswerActionModel.create(SubmitAnswer);
break;

case "grade_LP": //TO CHECK!
case "GradeAction": //TO CHECK!
const GradeLP = req.body;
if (
!GradeLP.action.flowId ||
!GradeLP.action.grade
) {
return res.status(400).json({
error:
"Missing fields for grade_LP: flowId or grade.",
"Missing fields for GradeAction: flowId or grade.",
});
}

action = await Models.GradeActionModel.create(GradeLP);

//update LP grade
flowGradeUpdate(GradeLP.action.flowId)

break;

default:
Expand Down Expand Up @@ -704,7 +710,7 @@ export const calculateGradeMetrics = async (req: Request, res: Response) => {
{
$match: {
"action.flowId": flowId,
actionType: "grade_LP",
actionType: "GradeAction",
},
},
{
Expand Down Expand Up @@ -741,18 +747,18 @@ export const getGradeByUserId = async (req: Request, res: Response) => {
error: "Missing required parameters: userId and flowId",
});
}

console.log('check1')
const gradeAction = await Models.BaseActionModel.findOne({
userId,
"action.flowId": flowId,
actionType: "grade_LP",
actionType: "GradeAction",
});
if (!gradeAction) {
return res.status(404).json({
error: "No grade found for the given user and learning path.",
});
}

console.log('check2')
res.status(200).send(gradeAction);
} catch (error: any) {
console.error("Error getting grade:", error);
Expand Down
14 changes: 14 additions & 0 deletions src/learningAnalyticsAlgorithms/flowGrading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import PolyglotFlowModel from "../models/flow.model";
import * as Models from "../models/learningData.models";

export async function flowGradeUpdate(flowId: string){
const gradeAction = await Models.BaseActionModel.find({actionType: "GradeAction",
"action.flowId": flowId,});
let gradeSum=0;
gradeAction.map((grade : any)=>{if(grade.action.grade) gradeSum+= grade.action.grade})
const newGrade= gradeSum/gradeAction.length;
const flow = await PolyglotFlowModel.findByIdAndUpdate(flowId,{$set: {overallGrade: newGrade, executedTimes: gradeAction.length}}, {new: true});
if(!flow) return false;

return true;
}
1 change: 1 addition & 0 deletions src/learningAnalyticsAlgorithms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./flowGrading";
2 changes: 2 additions & 0 deletions src/models/flow.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export const flowSchema = new mongoose.Schema<PolyglotFlow>({
algo: { type: String, default: "Random Execution" },
},
},
overallGrade: { type: Number, required: false, default: null },
executedTimes: { type: Number, required: false, default: null }
});

export interface PolyglotFlowModel extends Model<PolyglotFlow> {}
Expand Down
7 changes: 2 additions & 5 deletions src/types/PolyglotFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ export type PolyglotFlowInfo = {
learningContext: string;
duration: number;
topics: string[];
/* to be discussed: do we want to save in the database the last summarized material of the professor?
sourceMaterial?: string;
levelMaterial?: string;
generatedMaterial?: string;
noW?: number;*/
tags: string[];
execution: PolyglotExecutionData;
overallGrade?: number;
executedTimes?: number;
};

export type PolyglotFlow = PolyglotFlowInfo & {
Expand Down

0 comments on commit 663b3e7

Please sign in to comment.