-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscore.js
57 lines (50 loc) · 1.24 KB
/
score.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
import { NORMS } from './norms.js';
class Score {
#FORWARD = 0;
#BACKWARD = 0;
#SEQUENCING = 0;
#OVERALL = 0;
constructor() {
return new Proxy(this, this);
}
updateOverall() {
this.#OVERALL = this.#FORWARD + this.#BACKWARD + this.#SEQUENCING;
}
getIQ(years, which) {
const ageRange = NORMS['age-ranges'].find(([from, to]) => {
return years >= from && years <= to;
});
const i = NORMS['age-ranges'].indexOf(ageRange);
const mean = NORMS[which].means[i];
const sd = NORMS[which].sds[i];
const iq = 100 + ((this[which] - mean) / sd) * 15;
return iq.toFixed(1);
}
get(target, prop) {
return {
FORWARD: this.#FORWARD,
BACKWARD: this.#BACKWARD,
SEQUENCING: this.#SEQUENCING,
OVERALL: this.#OVERALL,
getIQ: this.getIQ,
}[prop];
}
set(target, prop, val) {
if (prop === 'FORWARD') {
this.#FORWARD = val;
}
if (prop === 'BACKWARD') {
this.#BACKWARD = val;
}
if (prop === 'SEQUENCING') {
this.#SEQUENCING = val;
}
this.updateOverall();
return {
FORWARD: this.#FORWARD || true,
BACKWARD: this.#BACKWARD || true,
SEQUENCING: this.#SEQUENCING || true,
}[prop];
}
}
export const SCORE = new Score();