-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoring.js
73 lines (68 loc) · 2.04 KB
/
scoring.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//Has scoring logic
//Updates the user's scores based on the result from the puzzle.
function updateScore(result) {
if (result==100) {
propagateEffect(1,userScores,currentLO);
}
else if (result == 50) {
propagateEffect(-.25,userScores,currentLO);
}
else {
propagateEffect(-.5,userScores,currentLO);
}
}
//Backpropagation of the user's result to earlier learning objectives.
function propagateEffect(effect, userScores,obj) {
var decayFactor = .5
var backPropObjects = [[obj,0]]
var objToAdjust;
var parent_ts;
while (backPropObjects.length > 0) {
objToAdjust = backPropObjects.splice(0,1);
objToAdjust = objToAdjust[0];
parent_ts = thresholds[objToAdjust[0]];
for (var t in parent_ts) {
if (parent_ts.hasOwnProperty(t)) {
backPropObjects.push([t,objToAdjust[1]+1]);
}
}
userScores[objToAdjust[0]] += effect*Math.pow(decayFactor,objToAdjust[1]);
}
return userScores;
}
//Given a set of scores, select learning objectives that
//are within this student's proficiency based on the thresholds.
function selectViableObjectives(userScores,objectivesList) {
var obj;
var objViable;
viableObjectives=[]
for (var i=0;i<objectivesList.length;i++) {
obj = objectivesList[i];
objViable=true;
current_ts = thresholds[obj];
for (var t in current_ts) {
if (current_ts.hasOwnProperty(t)) {
if (userScores[t]<current_ts[t]) {
objViable=false;
}
}
}
if (objViable) {
viableObjectives.push(obj);
}
}
return viableObjectives;
}
//Given a list of objectives, select one from the bottom three scores
function chooseRandomObjectiveFromList(objectives,userScores) {
var maxObjIndex = (objectives.length<2 ? objectives.length-1 : 1);
var chosenIdx = Math.round(Math.random()*maxObjIndex);
var scoreList = [];
for (var i=0;i<objectives.length;i++) {
scoreList.push([objectives[i],userScores[objectives[i]]]);
}
scoreList = scoreList.sort(function (a,b) { if (a[1]<b[1]) {return -1; } if (a[1]>b[1]) { return 1; } return 0; });
console.log(scoreList)
console.log(maxObjIndex)
return scoreList[chosenIdx][0];
}