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.
Files changed (37) hide show
  1. package/CLAUDE.md +114 -114
  2. package/README.md +171 -147
  3. package/dist/cjs/common-interfaces.d.ts +33 -1
  4. package/dist/cjs/gonogo.js +89 -57
  5. package/dist/cjs/nback.d.ts +6 -2
  6. package/dist/cjs/nback.js +132 -2
  7. package/dist/cjs/spatial-cognition.js +0 -2
  8. package/dist/esm/common-interfaces.d.ts +33 -1
  9. package/dist/esm/gonogo.js +89 -57
  10. package/dist/esm/nback.d.ts +6 -2
  11. package/dist/esm/nback.js +128 -2
  12. package/dist/esm/spatial-cognition.js +0 -2
  13. package/example-data/emotions.json +807 -807
  14. package/example-data/gonogo.json +5392 -5392
  15. package/example-data/nback.json +892 -892
  16. package/example-data/participant.json +6 -6
  17. package/example-data/spatial-cognition.json +462 -462
  18. package/jest.config.js +13 -13
  19. package/original/emotion-recognition.R +39 -39
  20. package/original/gonogo.R +32 -32
  21. package/package.json +40 -40
  22. package/src/__tests__/integration/browserInfo.test.ts +16 -16
  23. package/src/__tests__/integration/emotions.test.ts +172 -172
  24. package/src/__tests__/integration/gonogo.test.ts +293 -183
  25. package/src/__tests__/integration/nback-versions.test.ts +182 -0
  26. package/src/__tests__/integration/nback.test.ts +148 -148
  27. package/src/__tests__/integration/spatial-cognition.test.ts +171 -171
  28. package/src/__tests__/test-utils/testData.ts +79 -79
  29. package/src/common-interfaces.ts +124 -78
  30. package/src/emotions.ts +98 -98
  31. package/src/getters.ts +21 -21
  32. package/src/gonogo.ts +149 -127
  33. package/src/index.ts +39 -39
  34. package/src/nback.ts +182 -61
  35. package/src/spatial-cognition.ts +110 -112
  36. package/tsconfig.cjs.json +12 -12
  37. package/tsconfig.esm.json +14 -14
@@ -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
- const missing_trials = obj.filter((o: any) => o.response === null || o.response === undefined);
29
-
30
- const total_rt = obj.reduce((a, b) => a + (b.rt || 0), 0);
31
- const correct_rt = correct_trials.reduce((a, b) => a + (b.rt || 0), 0);
32
- const incorrect_rt = incorrect_trials.reduce((a, b) => a + (b.rt || 0), 0);
33
- const missing_rt = missing_trials.reduce((a, b) => a + (b.rt || 0), 0);
34
-
35
- const avg_rt = obj.length > 0 ? total_rt / obj.length : 0;
36
- const avg_acc = obj.length > 0 ? correct_trials.length / obj.length : 0;
37
-
38
- const performance_score = calculate_performance_score(avg_rt, avg_acc);
39
-
40
- const common: CommonResults = {
41
- n_trials: obj.length,
42
- n_correct_trials: correct_trials.length,
43
- n_incorrect_trials: incorrect_trials.length,
44
- avg_rt_total: avg_rt,
45
- avg_rt_correct: correct_trials.length > 0 ? correct_rt / correct_trials.length : 0,
46
- avg_rt_incorrect: incorrect_trials.length > 0 ? incorrect_rt / incorrect_trials.length : 0,
47
- performance_score
48
- };
49
-
50
- // Group by distance, angle, and rotation for special results
51
- const by_distance = Object.values(obj.reduce((acc: any, trial: any) => {
52
- const key = trial.distance || 'unknown';
53
- if (!acc[key]) acc[key] = { distance: key, trials: [], avg_rt: 0, avg_acc: 0 };
54
- acc[key].trials.push(trial);
55
- return acc;
56
- }, {})).map((group: any) => {
57
- group.avg_rt = group.trials.reduce((a: number, b: any) => a + (b.rt || 0), 0) / group.trials.length;
58
- group.avg_acc = group.trials.reduce((a: number, b: any) => a + (b.correct ? 1 : 0), 0) / group.trials.length;
59
- return group;
60
- });
61
-
62
- const by_angle = Object.values(obj.reduce((acc: any, trial: any) => {
63
- const key = trial.angle || 'unknown';
64
- if (!acc[key]) acc[key] = { angle: key, trials: [], avg_rt: 0, avg_acc: 0 };
65
- acc[key].trials.push(trial);
66
- return acc;
67
- }, {})).map((group: any) => {
68
- group.avg_rt = group.trials.reduce((a: number, b: any) => a + (b.rt || 0), 0) / group.trials.length;
69
- group.avg_acc = group.trials.reduce((a: number, b: any) => a + (b.correct ? 1 : 0), 0) / group.trials.length;
70
- return group;
71
- });
72
-
73
- const by_rotation = Object.values(obj.reduce((acc: any, trial: any) => {
74
- const key = trial.rotation || 'unknown';
75
- if (!acc[key]) acc[key] = { rotation: key, trials: [], avg_rt: 0, avg_acc: 0 };
76
- acc[key].trials.push(trial);
77
- return acc;
78
- }, {})).map((group: any) => {
79
- group.avg_rt = group.trials.reduce((a: number, b: any) => a + (b.rt || 0), 0) / group.trials.length;
80
- group.avg_acc = group.trials.reduce((a: number, b: any) => a + (b.correct ? 1 : 0), 0) / group.trials.length;
81
- return group;
82
- });
83
-
84
- const special: SpatialSpecialResults = {
85
- by_distance,
86
- by_angle,
87
- by_rotation
88
- };
89
-
90
- return {
91
- common,
92
- special
93
- };
94
- }
95
-
96
- const spatial_extract_image_info = (obj: any[]) => {
97
- // from the following field, extract the final image name (map_left_1_90.png), and rotation from the class attribute (rotate_0)
98
- // "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\">",
99
- obj.forEach((o: any) => {
100
- // the image name is map_left_1_90.png
101
- o.image = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)?.[0];
102
- o.direction = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)?.[1];
103
- o.distance = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)?.[2];
104
- o.angle = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)?.[3];
105
- o.rotation = o.stimulus.match(/rotate_(\d+)/)?.[1];
106
- o.response = o.response === 1 ? "right" : "left";
107
- o.correct = o.response === o.direction;
108
- });
109
- return obj;
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
  }