compileprofile-spacetests 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +115 -0
- package/README.md +147 -34
- package/dist/cjs/common-interfaces.d.ts +60 -0
- package/dist/cjs/common-interfaces.js +2 -0
- package/dist/cjs/emotions.d.ts +4 -9
- package/dist/cjs/emotions.js +56 -22
- package/dist/cjs/gonogo.d.ts +4 -9
- package/dist/cjs/gonogo.js +61 -14
- package/dist/cjs/index.d.ts +6 -5
- package/dist/cjs/index.js +11 -1
- package/dist/cjs/nback.d.ts +4 -14
- package/dist/cjs/nback.js +27 -13
- package/dist/cjs/spatial-cognition.d.ts +4 -9
- package/dist/cjs/spatial-cognition.js +69 -14
- package/dist/esm/common-interfaces.d.ts +60 -0
- package/dist/esm/common-interfaces.js +1 -0
- package/dist/esm/emotions.d.ts +4 -9
- package/dist/esm/emotions.js +55 -21
- package/dist/esm/gonogo.d.ts +4 -9
- package/dist/esm/gonogo.js +61 -14
- package/dist/esm/index.d.ts +6 -5
- package/dist/esm/index.js +9 -1
- package/dist/esm/nback.d.ts +4 -14
- package/dist/esm/nback.js +27 -13
- package/dist/esm/spatial-cognition.d.ts +4 -9
- package/dist/esm/spatial-cognition.js +69 -14
- package/example-data/emotions.json +807 -807
- package/example-data/gonogo.json +5392 -5392
- package/example-data/nback.json +892 -892
- package/example-data/participant.json +6 -6
- package/example-data/spatial-cognition.json +462 -462
- package/jest.config.js +13 -13
- package/original/emotion-recognition.R +39 -39
- package/original/gonogo.R +32 -32
- package/package.json +40 -40
- package/src/__tests__/integration/browserInfo.test.ts +16 -16
- package/src/__tests__/integration/emotions.test.ts +172 -64
- package/src/__tests__/integration/gonogo.test.ts +183 -80
- package/src/__tests__/integration/nback.test.ts +148 -55
- package/src/__tests__/integration/spatial-cognition.test.ts +171 -66
- package/src/__tests__/test-utils/testData.ts +79 -79
- package/src/common-interfaces.ts +79 -0
- package/src/emotions.ts +98 -59
- package/src/getters.ts +21 -21
- package/src/gonogo.ts +127 -76
- package/src/index.ts +39 -12
- package/src/nback.ts +61 -53
- package/src/spatial-cognition.ts +113 -55
- package/tsconfig.cjs.json +12 -12
- package/tsconfig.esm.json +14 -14
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
var BEST_SCORE = 1000;
|
|
2
|
+
var WORST_SCORE = 10000;
|
|
1
3
|
var spatial_calculate_results = function (obj) {
|
|
2
4
|
var trials = spatial_extract_trials(obj);
|
|
3
5
|
return spatial_results(trials);
|
|
4
6
|
};
|
|
7
|
+
var calculate_performance_score = function (avg_rt, avg_acc) {
|
|
8
|
+
var performance = avg_rt / (avg_acc + 0.001);
|
|
9
|
+
performance = Math.min(Math.max(performance, BEST_SCORE), WORST_SCORE);
|
|
10
|
+
var performance_score = (1 - ((performance - BEST_SCORE) / (WORST_SCORE - BEST_SCORE))) * 100;
|
|
11
|
+
return performance_score;
|
|
12
|
+
};
|
|
5
13
|
var spatial_extract_trials = function (obj) {
|
|
6
14
|
var trials = obj.filter(function (o) { return 'stimulus' in o &&
|
|
7
15
|
o.stimulus.startsWith("<img src="); });
|
|
@@ -9,21 +17,68 @@ var spatial_extract_trials = function (obj) {
|
|
|
9
17
|
return trials;
|
|
10
18
|
};
|
|
11
19
|
var spatial_results = function (obj) {
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
var correct_trials = obj.filter(function (o) { return o.correct === 1 || o.correct === true; });
|
|
21
|
+
var incorrect_trials = obj.filter(function (o) { return o.correct === 0 || o.correct === false; });
|
|
22
|
+
var missing_trials = obj.filter(function (o) { return o.response === null || o.response === undefined; });
|
|
23
|
+
var total_rt = obj.reduce(function (a, b) { return a + (b.rt || 0); }, 0);
|
|
24
|
+
var correct_rt = correct_trials.reduce(function (a, b) { return a + (b.rt || 0); }, 0);
|
|
25
|
+
var incorrect_rt = incorrect_trials.reduce(function (a, b) { return a + (b.rt || 0); }, 0);
|
|
26
|
+
var missing_rt = missing_trials.reduce(function (a, b) { return a + (b.rt || 0); }, 0);
|
|
27
|
+
var avg_rt = obj.length > 0 ? total_rt / obj.length : 0;
|
|
28
|
+
var avg_acc = obj.length > 0 ? correct_trials.length / obj.length : 0;
|
|
29
|
+
var performance_score = calculate_performance_score(avg_rt, avg_acc);
|
|
30
|
+
var common = {
|
|
31
|
+
n_trials: obj.length,
|
|
32
|
+
n_correct_trials: correct_trials.length,
|
|
33
|
+
n_incorrect_trials: incorrect_trials.length,
|
|
34
|
+
avg_rt_total: avg_rt,
|
|
35
|
+
avg_rt_correct: correct_trials.length > 0 ? correct_rt / correct_trials.length : 0,
|
|
36
|
+
avg_rt_incorrect: incorrect_trials.length > 0 ? incorrect_rt / incorrect_trials.length : 0,
|
|
37
|
+
performance_score: performance_score
|
|
38
|
+
};
|
|
39
|
+
// Group by distance, angle, and rotation for special results
|
|
40
|
+
var by_distance = Object.values(obj.reduce(function (acc, trial) {
|
|
41
|
+
var key = trial.distance || 'unknown';
|
|
42
|
+
if (!acc[key])
|
|
43
|
+
acc[key] = { distance: key, trials: [], avg_rt: 0, avg_acc: 0 };
|
|
44
|
+
acc[key].trials.push(trial);
|
|
45
|
+
return acc;
|
|
46
|
+
}, {})).map(function (group) {
|
|
47
|
+
group.avg_rt = group.trials.reduce(function (a, b) { return a + (b.rt || 0); }, 0) / group.trials.length;
|
|
48
|
+
group.avg_acc = group.trials.reduce(function (a, b) { return a + (b.correct ? 1 : 0); }, 0) / group.trials.length;
|
|
49
|
+
return group;
|
|
50
|
+
});
|
|
51
|
+
var by_angle = Object.values(obj.reduce(function (acc, trial) {
|
|
52
|
+
var key = trial.angle || 'unknown';
|
|
53
|
+
if (!acc[key])
|
|
54
|
+
acc[key] = { angle: key, trials: [], avg_rt: 0, avg_acc: 0 };
|
|
55
|
+
acc[key].trials.push(trial);
|
|
56
|
+
return acc;
|
|
57
|
+
}, {})).map(function (group) {
|
|
58
|
+
group.avg_rt = group.trials.reduce(function (a, b) { return a + (b.rt || 0); }, 0) / group.trials.length;
|
|
59
|
+
group.avg_acc = group.trials.reduce(function (a, b) { return a + (b.correct ? 1 : 0); }, 0) / group.trials.length;
|
|
60
|
+
return group;
|
|
61
|
+
});
|
|
62
|
+
var by_rotation = Object.values(obj.reduce(function (acc, trial) {
|
|
63
|
+
var key = trial.rotation || 'unknown';
|
|
64
|
+
if (!acc[key])
|
|
65
|
+
acc[key] = { rotation: key, trials: [], avg_rt: 0, avg_acc: 0 };
|
|
66
|
+
acc[key].trials.push(trial);
|
|
67
|
+
return acc;
|
|
68
|
+
}, {})).map(function (group) {
|
|
69
|
+
group.avg_rt = group.trials.reduce(function (a, b) { return a + (b.rt || 0); }, 0) / group.trials.length;
|
|
70
|
+
group.avg_acc = group.trials.reduce(function (a, b) { return a + (b.correct ? 1 : 0); }, 0) / group.trials.length;
|
|
71
|
+
return group;
|
|
72
|
+
});
|
|
73
|
+
var special = {
|
|
74
|
+
by_distance: by_distance,
|
|
75
|
+
by_angle: by_angle,
|
|
76
|
+
by_rotation: by_rotation
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
common: common,
|
|
80
|
+
special: special
|
|
17
81
|
};
|
|
18
|
-
var best_score = 1000;
|
|
19
|
-
var worst_score = 10000;
|
|
20
|
-
// results.avg_acc to the power of 5
|
|
21
|
-
//let performance = results.avg_rt / (Math.pow(results.avg_acc, 5) + 0.001);
|
|
22
|
-
var performance = results.avg_rt / (results.avg_acc + 0.001);
|
|
23
|
-
performance = Math.min(Math.max(performance, best_score), worst_score);
|
|
24
|
-
// convert to 0-100 where 100 is the best (200)
|
|
25
|
-
results.performance = (1 - ((performance - best_score) / (worst_score - best_score))) * 100;
|
|
26
|
-
return results;
|
|
27
82
|
};
|
|
28
83
|
var spatial_extract_image_info = function (obj) {
|
|
29
84
|
// from the following field, extract the final image name (map_left_1_90.png), and rotation from the class attribute (rotate_0)
|