compileprofile-spacetests 0.3.0 → 0.4.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 +114 -114
- package/README.md +171 -147
- package/dist/cjs/common-interfaces.d.ts +33 -1
- package/dist/cjs/gonogo.js +89 -57
- package/dist/cjs/nback.d.ts +6 -2
- package/dist/cjs/nback.js +132 -2
- package/dist/cjs/spatial-cognition.js +0 -2
- package/dist/esm/common-interfaces.d.ts +33 -1
- package/dist/esm/gonogo.js +89 -57
- package/dist/esm/nback.d.ts +6 -2
- package/dist/esm/nback.js +128 -2
- package/dist/esm/spatial-cognition.js +0 -2
- 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 -172
- package/src/__tests__/integration/gonogo.test.ts +293 -183
- package/src/__tests__/integration/nback-versions.test.ts +182 -0
- package/src/__tests__/integration/nback.test.ts +148 -148
- package/src/__tests__/integration/spatial-cognition.test.ts +171 -171
- package/src/__tests__/test-utils/testData.ts +79 -79
- package/src/common-interfaces.ts +124 -78
- package/src/emotions.ts +98 -98
- package/src/getters.ts +21 -21
- package/src/gonogo.ts +149 -127
- package/src/index.ts +39 -39
- package/src/nback.ts +182 -61
- package/src/spatial-cognition.ts +110 -112
- package/tsconfig.cjs.json +12 -12
- package/tsconfig.esm.json +14 -14
package/src/spatial-cognition.ts
CHANGED
|
@@ -1,113 +1,111 @@
|
|
|
1
|
-
import { SpatialResultsStructure, CommonResults, SpatialSpecialResults } from './common-interfaces';
|
|
2
|
-
|
|
3
|
-
const BEST_SCORE = 1000;
|
|
4
|
-
const WORST_SCORE = 10000;
|
|
5
|
-
|
|
6
|
-
const spatial_calculate_results = (obj: any[]): SpatialResultsStructure => {
|
|
7
|
-
const trials = spatial_extract_trials(obj);
|
|
8
|
-
return spatial_results(trials);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const calculate_performance_score = (avg_rt: number, avg_acc: number): number => {
|
|
12
|
-
let performance = avg_rt / (avg_acc + 0.001);
|
|
13
|
-
performance = Math.min(Math.max(performance, BEST_SCORE), WORST_SCORE);
|
|
14
|
-
const performance_score = (1 - ((performance - BEST_SCORE) / (WORST_SCORE - BEST_SCORE))) * 100;
|
|
15
|
-
return performance_score;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const spatial_extract_trials = (obj: any[]) => {
|
|
19
|
-
let trials = obj.filter((o: any) => 'stimulus' in o &&
|
|
20
|
-
o.stimulus.startsWith("<img src="));
|
|
21
|
-
trials = spatial_extract_image_info(trials);
|
|
22
|
-
return trials;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const spatial_results = (obj: any[]): SpatialResultsStructure => {
|
|
26
|
-
const correct_trials = obj.filter((o: any) => o.correct === 1 || o.correct === true);
|
|
27
|
-
const incorrect_trials = obj.filter((o: any) => o.correct === 0 || o.correct === false);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
o.
|
|
102
|
-
o.
|
|
103
|
-
o.
|
|
104
|
-
o.
|
|
105
|
-
o.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
export { spatial_extract_image_info, spatial_extract_trials,
|
|
1
|
+
import { SpatialResultsStructure, CommonResults, SpatialSpecialResults } from './common-interfaces';
|
|
2
|
+
|
|
3
|
+
const BEST_SCORE = 1000;
|
|
4
|
+
const WORST_SCORE = 10000;
|
|
5
|
+
|
|
6
|
+
const spatial_calculate_results = (obj: any[]): SpatialResultsStructure => {
|
|
7
|
+
const trials = spatial_extract_trials(obj);
|
|
8
|
+
return spatial_results(trials);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const calculate_performance_score = (avg_rt: number, avg_acc: number): number => {
|
|
12
|
+
let performance = avg_rt / (avg_acc + 0.001);
|
|
13
|
+
performance = Math.min(Math.max(performance, BEST_SCORE), WORST_SCORE);
|
|
14
|
+
const performance_score = (1 - ((performance - BEST_SCORE) / (WORST_SCORE - BEST_SCORE))) * 100;
|
|
15
|
+
return performance_score;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const spatial_extract_trials = (obj: any[]) => {
|
|
19
|
+
let trials = obj.filter((o: any) => 'stimulus' in o &&
|
|
20
|
+
o.stimulus.startsWith("<img src="));
|
|
21
|
+
trials = spatial_extract_image_info(trials);
|
|
22
|
+
return trials;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const spatial_results = (obj: any[]): SpatialResultsStructure => {
|
|
26
|
+
const correct_trials = obj.filter((o: any) => o.correct === 1 || o.correct === true);
|
|
27
|
+
const incorrect_trials = obj.filter((o: any) => o.correct === 0 || o.correct === false);
|
|
28
|
+
|
|
29
|
+
const total_rt = obj.reduce((a, b) => a + (b.rt || 0), 0);
|
|
30
|
+
const correct_rt = correct_trials.reduce((a, b) => a + (b.rt || 0), 0);
|
|
31
|
+
const incorrect_rt = incorrect_trials.reduce((a, b) => a + (b.rt || 0), 0);
|
|
32
|
+
|
|
33
|
+
const avg_rt = obj.length > 0 ? total_rt / obj.length : 0;
|
|
34
|
+
const avg_acc = obj.length > 0 ? correct_trials.length / obj.length : 0;
|
|
35
|
+
|
|
36
|
+
const performance_score = calculate_performance_score(avg_rt, avg_acc);
|
|
37
|
+
|
|
38
|
+
const common: CommonResults = {
|
|
39
|
+
n_trials: obj.length,
|
|
40
|
+
n_correct_trials: correct_trials.length,
|
|
41
|
+
n_incorrect_trials: incorrect_trials.length,
|
|
42
|
+
avg_rt_total: avg_rt,
|
|
43
|
+
avg_rt_correct: correct_trials.length > 0 ? correct_rt / correct_trials.length : 0,
|
|
44
|
+
avg_rt_incorrect: incorrect_trials.length > 0 ? incorrect_rt / incorrect_trials.length : 0,
|
|
45
|
+
performance_score
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Group by distance, angle, and rotation for special results
|
|
49
|
+
const by_distance = Object.values(obj.reduce((acc: any, trial: any) => {
|
|
50
|
+
const key = trial.distance || 'unknown';
|
|
51
|
+
if (!acc[key]) acc[key] = { distance: key, trials: [], avg_rt: 0, avg_acc: 0 };
|
|
52
|
+
acc[key].trials.push(trial);
|
|
53
|
+
return acc;
|
|
54
|
+
}, {})).map((group: any) => {
|
|
55
|
+
group.avg_rt = group.trials.reduce((a: number, b: any) => a + (b.rt || 0), 0) / group.trials.length;
|
|
56
|
+
group.avg_acc = group.trials.reduce((a: number, b: any) => a + (b.correct ? 1 : 0), 0) / group.trials.length;
|
|
57
|
+
return group;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const by_angle = Object.values(obj.reduce((acc: any, trial: any) => {
|
|
61
|
+
const key = trial.angle || 'unknown';
|
|
62
|
+
if (!acc[key]) acc[key] = { angle: key, trials: [], avg_rt: 0, avg_acc: 0 };
|
|
63
|
+
acc[key].trials.push(trial);
|
|
64
|
+
return acc;
|
|
65
|
+
}, {})).map((group: any) => {
|
|
66
|
+
group.avg_rt = group.trials.reduce((a: number, b: any) => a + (b.rt || 0), 0) / group.trials.length;
|
|
67
|
+
group.avg_acc = group.trials.reduce((a: number, b: any) => a + (b.correct ? 1 : 0), 0) / group.trials.length;
|
|
68
|
+
return group;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const by_rotation = Object.values(obj.reduce((acc: any, trial: any) => {
|
|
72
|
+
const key = trial.rotation || 'unknown';
|
|
73
|
+
if (!acc[key]) acc[key] = { rotation: key, trials: [], avg_rt: 0, avg_acc: 0 };
|
|
74
|
+
acc[key].trials.push(trial);
|
|
75
|
+
return acc;
|
|
76
|
+
}, {})).map((group: any) => {
|
|
77
|
+
group.avg_rt = group.trials.reduce((a: number, b: any) => a + (b.rt || 0), 0) / group.trials.length;
|
|
78
|
+
group.avg_acc = group.trials.reduce((a: number, b: any) => a + (b.correct ? 1 : 0), 0) / group.trials.length;
|
|
79
|
+
return group;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const special: SpatialSpecialResults = {
|
|
83
|
+
by_distance,
|
|
84
|
+
by_angle,
|
|
85
|
+
by_rotation
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
common,
|
|
90
|
+
special
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const spatial_extract_image_info = (obj: any[]) => {
|
|
95
|
+
// from the following field, extract the final image name (map_left_1_90.png), and rotation from the class attribute (rotate_0)
|
|
96
|
+
// "stimulus": "<img src=\"https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/spatialcognition/map_left_1_90.png\" class=\"max-w-none rotate_0\" width=\"512\" height=\"512\" alt=\"Mapa\">",
|
|
97
|
+
obj.forEach((o: any) => {
|
|
98
|
+
// the image name is map_left_1_90.png
|
|
99
|
+
o.image = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)?.[0];
|
|
100
|
+
o.direction = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)?.[1];
|
|
101
|
+
o.distance = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)?.[2];
|
|
102
|
+
o.angle = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)?.[3];
|
|
103
|
+
o.rotation = o.stimulus.match(/rotate_(\d+)/)?.[1];
|
|
104
|
+
o.response = o.response === 1 ? "right" : "left";
|
|
105
|
+
o.correct = o.response === o.direction;
|
|
106
|
+
});
|
|
107
|
+
return obj;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { spatial_extract_image_info, spatial_extract_trials,
|
|
113
111
|
spatial_results, spatial_calculate_results, SpatialResultsStructure };
|
package/tsconfig.cjs.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"outDir": "./dist/cjs",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true
|
|
10
|
-
},
|
|
11
|
-
"include": ["src"],
|
|
12
|
-
"exclude": ["node_modules", "**/__tests__/*"]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"outDir": "./dist/cjs",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["src"],
|
|
12
|
+
"exclude": ["node_modules", "**/__tests__/*"]
|
|
13
13
|
}
|
package/tsconfig.esm.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
// tsconfig.esm.json - For ES modules
|
|
2
|
-
{
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "esnext",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"outDir": "./dist/esm",
|
|
7
|
-
"strict": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"forceConsistentCasingInFileNames": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["src"],
|
|
14
|
-
"exclude": ["node_modules", "**/__tests__/*"]
|
|
1
|
+
// tsconfig.esm.json - For ES modules
|
|
2
|
+
{
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist/esm",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"moduleResolution": "node",
|
|
11
|
+
"forceConsistentCasingInFileNames": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"],
|
|
14
|
+
"exclude": ["node_modules", "**/__tests__/*"]
|
|
15
15
|
}
|