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
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
import { nback_extract_trials, nback_results,
|
|
2
|
-
nback_calculate_results } from '../../nback';
|
|
3
|
-
import { loadTestData } from '../test-utils/testData';
|
|
4
|
-
|
|
5
|
-
describe('N-Back Task Integration Tests', () => {
|
|
6
|
-
const testData = loadTestData('nback');
|
|
7
|
-
|
|
8
|
-
// Mock data for predictable testing
|
|
9
|
-
const mockNbackData = [
|
|
10
|
-
{
|
|
11
|
-
"stimulus": "",
|
|
12
|
-
"trial_index": 25,
|
|
13
|
-
"nbackimage": "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/nback//final/nback_final_fractals_4.png",
|
|
14
|
-
"is_target": false,
|
|
15
|
-
"rt": null,
|
|
16
|
-
"response": null,
|
|
17
|
-
"trial_type": "html-button-response",
|
|
18
|
-
"plugin_version": "2.0.0",
|
|
19
|
-
"time_elapsed": 70759,
|
|
20
|
-
"attempted": false,
|
|
21
|
-
"correct": true
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"stimulus": "",
|
|
25
|
-
"trial_index": 26,
|
|
26
|
-
"nbackimage": "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/nback//final/nback_final_fractals_2.png",
|
|
27
|
-
"is_target": false,
|
|
28
|
-
"rt": null,
|
|
29
|
-
"response": null,
|
|
30
|
-
"trial_type": "html-button-response",
|
|
31
|
-
"plugin_version": "2.0.0",
|
|
32
|
-
"time_elapsed": 73325,
|
|
33
|
-
"attempted": false,
|
|
34
|
-
"correct": true
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"stimulus": "",
|
|
38
|
-
"trial_index": 27,
|
|
39
|
-
"nbackimage": "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/nback//final/nback_final_fractals_4.png",
|
|
40
|
-
"is_target": true,
|
|
41
|
-
"rt": 1000,
|
|
42
|
-
"response": 0,
|
|
43
|
-
"trial_type": "html-button-response",
|
|
44
|
-
"plugin_version": "2.0.0",
|
|
45
|
-
"time_elapsed": 74928,
|
|
46
|
-
"attempted": false,
|
|
47
|
-
"correct": true
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"stimulus": "",
|
|
51
|
-
"trial_index": 28,
|
|
52
|
-
"nbackimage": "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/nback//final/nback_final_fractals_3.png",
|
|
53
|
-
"is_target": false,
|
|
54
|
-
"rt": 2000,
|
|
55
|
-
"response": 0,
|
|
56
|
-
"trial_type": "html-button-response",
|
|
57
|
-
"plugin_version": "2.0.0",
|
|
58
|
-
"time_elapsed": 77512,
|
|
59
|
-
"attempted": false,
|
|
60
|
-
"correct": false
|
|
61
|
-
},
|
|
62
|
-
// Non-trial data that should be filtered out
|
|
63
|
-
{ trial_type: 'browser-check', browser: 'chrome' },
|
|
64
|
-
{ trial_type: 'instructions', text: 'Press space when...' }
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
describe('nback_extract_trials', () => {
|
|
68
|
-
it('should extract only trials with is_target field', () => {
|
|
69
|
-
const trials = nback_extract_trials(testData.nback);
|
|
70
|
-
expect(trials.every(trial => trial.is_target !== null)).toBe(true);
|
|
71
|
-
expect(trials.length).toBe(60);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should extract mock data correctly', () => {
|
|
75
|
-
const trials = nback_extract_trials(mockNbackData);
|
|
76
|
-
expect(trials.length).toBe(4); // Only trials with is_target field
|
|
77
|
-
expect(trials.every(trial => 'is_target' in trial)).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('nback_results', () => {
|
|
82
|
-
const trials = nback_extract_trials(testData.nback);
|
|
83
|
-
const results = nback_results(trials);
|
|
84
|
-
|
|
85
|
-
it('should calculate correct common metrics', () => {
|
|
86
|
-
expect(results.common).toHaveProperty('n_trials');
|
|
87
|
-
expect(results.common).toHaveProperty('n_correct_trials');
|
|
88
|
-
expect(results.common).toHaveProperty('n_incorrect_trials');
|
|
89
|
-
expect(results.common).toHaveProperty('avg_rt_total');
|
|
90
|
-
expect(results.common).toHaveProperty('avg_rt_correct');
|
|
91
|
-
expect(results.common).toHaveProperty('avg_rt_incorrect');
|
|
92
|
-
expect(results.common).toHaveProperty('performance_score');
|
|
93
|
-
expect(results.common.n_trials).toBeGreaterThan(0);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should calculate correct target trials metrics', () => {
|
|
97
|
-
expect(results.special.target_trials).toHaveProperty('n');
|
|
98
|
-
expect(results.special.target_trials).toHaveProperty('avg_rt');
|
|
99
|
-
expect(results.special.target_trials).toHaveProperty('avg_acc');
|
|
100
|
-
expect(results.special.target_trials.n).toBeGreaterThan(0);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should calculate correct non-target trials metrics', () => {
|
|
104
|
-
expect(results.special.non_target_trials).toHaveProperty('n');
|
|
105
|
-
expect(results.special.non_target_trials).toHaveProperty('avg_rt');
|
|
106
|
-
expect(results.special.non_target_trials).toHaveProperty('avg_acc');
|
|
107
|
-
expect(results.special.non_target_trials.n).toBeGreaterThan(0);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should calculate performance score', () => {
|
|
111
|
-
expect(results.common.performance_score).not.toBeNaN();
|
|
112
|
-
expect(results.common.performance_score).toBeGreaterThanOrEqual(0);
|
|
113
|
-
expect(results.common.performance_score).toBeLessThanOrEqual(100);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should calculate mock data results correctly', () => {
|
|
117
|
-
const mockTrials = nback_extract_trials(mockNbackData);
|
|
118
|
-
const mockResults = nback_results(mockTrials);
|
|
119
|
-
|
|
120
|
-
// Expected: 6 trials total, 4 correct, 2 incorrect, 1 missing (counting false as incorrect, not missing)
|
|
121
|
-
expect(mockResults.common.n_trials).toBe(4);
|
|
122
|
-
expect(mockResults.common.n_correct_trials).toBe(3);
|
|
123
|
-
expect(mockResults.common.n_incorrect_trials).toBe(1);
|
|
124
|
-
|
|
125
|
-
expect(mockResults.common.performance_score).toEqual(75);
|
|
126
|
-
|
|
127
|
-
expect(mockResults.common.avg_rt_total).toEqual(1500);
|
|
128
|
-
|
|
129
|
-
expect(mockResults.special.target_trials.n).toBe(1);
|
|
130
|
-
expect(mockResults.special.target_trials.avg_acc).toEqual(100);
|
|
131
|
-
|
|
132
|
-
expect(mockResults.special.non_target_trials.n).toBe(3);
|
|
133
|
-
expect(mockResults.special.non_target_trials.avg_acc).toBeCloseTo(66.67, 1);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe('nback_calculate_results', () => {
|
|
138
|
-
it('should calculate results correctly', () => {
|
|
139
|
-
const results = nback_calculate_results(testData.nback);
|
|
140
|
-
expect(results).toBeDefined();
|
|
141
|
-
expect(results).toHaveProperty('common');
|
|
142
|
-
expect(results).toHaveProperty('special');
|
|
143
|
-
expect(results.common).toHaveProperty('n_trials');
|
|
144
|
-
expect(results.common).toHaveProperty('performance_score');
|
|
145
|
-
expect(results.special).toHaveProperty('target_trials');
|
|
146
|
-
expect(results.special).toHaveProperty('non_target_trials');
|
|
147
|
-
});
|
|
148
|
-
});
|
|
1
|
+
import { nback_extract_trials, nback_results,
|
|
2
|
+
nback_calculate_results } from '../../nback';
|
|
3
|
+
import { loadTestData } from '../test-utils/testData';
|
|
4
|
+
|
|
5
|
+
describe('N-Back Task Integration Tests', () => {
|
|
6
|
+
const testData = loadTestData('nback');
|
|
7
|
+
|
|
8
|
+
// Mock data for predictable testing
|
|
9
|
+
const mockNbackData = [
|
|
10
|
+
{
|
|
11
|
+
"stimulus": "",
|
|
12
|
+
"trial_index": 25,
|
|
13
|
+
"nbackimage": "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/nback//final/nback_final_fractals_4.png",
|
|
14
|
+
"is_target": false,
|
|
15
|
+
"rt": null,
|
|
16
|
+
"response": null,
|
|
17
|
+
"trial_type": "html-button-response",
|
|
18
|
+
"plugin_version": "2.0.0",
|
|
19
|
+
"time_elapsed": 70759,
|
|
20
|
+
"attempted": false,
|
|
21
|
+
"correct": true
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"stimulus": "",
|
|
25
|
+
"trial_index": 26,
|
|
26
|
+
"nbackimage": "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/nback//final/nback_final_fractals_2.png",
|
|
27
|
+
"is_target": false,
|
|
28
|
+
"rt": null,
|
|
29
|
+
"response": null,
|
|
30
|
+
"trial_type": "html-button-response",
|
|
31
|
+
"plugin_version": "2.0.0",
|
|
32
|
+
"time_elapsed": 73325,
|
|
33
|
+
"attempted": false,
|
|
34
|
+
"correct": true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"stimulus": "",
|
|
38
|
+
"trial_index": 27,
|
|
39
|
+
"nbackimage": "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/nback//final/nback_final_fractals_4.png",
|
|
40
|
+
"is_target": true,
|
|
41
|
+
"rt": 1000,
|
|
42
|
+
"response": 0,
|
|
43
|
+
"trial_type": "html-button-response",
|
|
44
|
+
"plugin_version": "2.0.0",
|
|
45
|
+
"time_elapsed": 74928,
|
|
46
|
+
"attempted": false,
|
|
47
|
+
"correct": true
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"stimulus": "",
|
|
51
|
+
"trial_index": 28,
|
|
52
|
+
"nbackimage": "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/nback//final/nback_final_fractals_3.png",
|
|
53
|
+
"is_target": false,
|
|
54
|
+
"rt": 2000,
|
|
55
|
+
"response": 0,
|
|
56
|
+
"trial_type": "html-button-response",
|
|
57
|
+
"plugin_version": "2.0.0",
|
|
58
|
+
"time_elapsed": 77512,
|
|
59
|
+
"attempted": false,
|
|
60
|
+
"correct": false
|
|
61
|
+
},
|
|
62
|
+
// Non-trial data that should be filtered out
|
|
63
|
+
{ trial_type: 'browser-check', browser: 'chrome' },
|
|
64
|
+
{ trial_type: 'instructions', text: 'Press space when...' }
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
describe('nback_extract_trials', () => {
|
|
68
|
+
it('should extract only trials with is_target field', () => {
|
|
69
|
+
const trials = nback_extract_trials(testData.nback);
|
|
70
|
+
expect(trials.every(trial => trial.is_target !== null)).toBe(true);
|
|
71
|
+
expect(trials.length).toBe(60);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should extract mock data correctly', () => {
|
|
75
|
+
const trials = nback_extract_trials(mockNbackData);
|
|
76
|
+
expect(trials.length).toBe(4); // Only trials with is_target field
|
|
77
|
+
expect(trials.every(trial => 'is_target' in trial)).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('nback_results', () => {
|
|
82
|
+
const trials = nback_extract_trials(testData.nback);
|
|
83
|
+
const results = nback_results(trials);
|
|
84
|
+
|
|
85
|
+
it('should calculate correct common metrics', () => {
|
|
86
|
+
expect(results.common).toHaveProperty('n_trials');
|
|
87
|
+
expect(results.common).toHaveProperty('n_correct_trials');
|
|
88
|
+
expect(results.common).toHaveProperty('n_incorrect_trials');
|
|
89
|
+
expect(results.common).toHaveProperty('avg_rt_total');
|
|
90
|
+
expect(results.common).toHaveProperty('avg_rt_correct');
|
|
91
|
+
expect(results.common).toHaveProperty('avg_rt_incorrect');
|
|
92
|
+
expect(results.common).toHaveProperty('performance_score');
|
|
93
|
+
expect(results.common.n_trials).toBeGreaterThan(0);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should calculate correct target trials metrics', () => {
|
|
97
|
+
expect(results.special.target_trials).toHaveProperty('n');
|
|
98
|
+
expect(results.special.target_trials).toHaveProperty('avg_rt');
|
|
99
|
+
expect(results.special.target_trials).toHaveProperty('avg_acc');
|
|
100
|
+
expect(results.special.target_trials.n).toBeGreaterThan(0);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should calculate correct non-target trials metrics', () => {
|
|
104
|
+
expect(results.special.non_target_trials).toHaveProperty('n');
|
|
105
|
+
expect(results.special.non_target_trials).toHaveProperty('avg_rt');
|
|
106
|
+
expect(results.special.non_target_trials).toHaveProperty('avg_acc');
|
|
107
|
+
expect(results.special.non_target_trials.n).toBeGreaterThan(0);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should calculate performance score', () => {
|
|
111
|
+
expect(results.common.performance_score).not.toBeNaN();
|
|
112
|
+
expect(results.common.performance_score).toBeGreaterThanOrEqual(0);
|
|
113
|
+
expect(results.common.performance_score).toBeLessThanOrEqual(100);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should calculate mock data results correctly', () => {
|
|
117
|
+
const mockTrials = nback_extract_trials(mockNbackData);
|
|
118
|
+
const mockResults = nback_results(mockTrials);
|
|
119
|
+
|
|
120
|
+
// Expected: 6 trials total, 4 correct, 2 incorrect, 1 missing (counting false as incorrect, not missing)
|
|
121
|
+
expect(mockResults.common.n_trials).toBe(4);
|
|
122
|
+
expect(mockResults.common.n_correct_trials).toBe(3);
|
|
123
|
+
expect(mockResults.common.n_incorrect_trials).toBe(1);
|
|
124
|
+
|
|
125
|
+
expect(mockResults.common.performance_score).toEqual(75);
|
|
126
|
+
|
|
127
|
+
expect(mockResults.common.avg_rt_total).toEqual(1500);
|
|
128
|
+
|
|
129
|
+
expect(mockResults.special.target_trials.n).toBe(1);
|
|
130
|
+
expect(mockResults.special.target_trials.avg_acc).toEqual(100);
|
|
131
|
+
|
|
132
|
+
expect(mockResults.special.non_target_trials.n).toBe(3);
|
|
133
|
+
expect(mockResults.special.non_target_trials.avg_acc).toBeCloseTo(66.67, 1);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('nback_calculate_results', () => {
|
|
138
|
+
it('should calculate results correctly', () => {
|
|
139
|
+
const results = nback_calculate_results(testData.nback);
|
|
140
|
+
expect(results).toBeDefined();
|
|
141
|
+
expect(results).toHaveProperty('common');
|
|
142
|
+
expect(results).toHaveProperty('special');
|
|
143
|
+
expect(results.common).toHaveProperty('n_trials');
|
|
144
|
+
expect(results.common).toHaveProperty('performance_score');
|
|
145
|
+
expect(results.special).toHaveProperty('target_trials');
|
|
146
|
+
expect(results.special).toHaveProperty('non_target_trials');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
149
|
});
|
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
// test out the spatial_extract_image_info function
|
|
2
|
-
import { spatial_extract_trials, spatial_extract_image_info, spatial_calculate_results,
|
|
3
|
-
spatial_results } from '../../spatial-cognition';
|
|
4
|
-
import { loadTestData } from '../test-utils/testData';
|
|
5
|
-
|
|
6
|
-
const ImageInfoTestData = [
|
|
7
|
-
{
|
|
8
|
-
stimulus: "<img src=\"https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/spatialcognition/map_left_1_90.png\" class=\"max-w-none rotate_90\" width=\"512\" height=\"512\" alt=\"Mapa\">",
|
|
9
|
-
rt: 1411,
|
|
10
|
-
response: 0,
|
|
11
|
-
plugin_version: "2.0.0",
|
|
12
|
-
time_elapsed: 73045,
|
|
13
|
-
attempted: false
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
stimulus: "<img src=\"https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/spatialcognition/map_left_3_180.png\" class=\"max-w-none rotate_270\" width=\"512\" height=\"512\" alt=\"Mapa\">",
|
|
17
|
-
rt: 1411,
|
|
18
|
-
response: 1,
|
|
19
|
-
plugin_version: "2.0.0",
|
|
20
|
-
time_elapsed: 73045,
|
|
21
|
-
}
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
// Enhanced mock data for comprehensive testing
|
|
25
|
-
const mockSpatialData = [
|
|
26
|
-
{
|
|
27
|
-
stimulus: "<img src=\"https://example.com/map_left_1_90.png\" class=\"max-w-none rotate_0\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
28
|
-
rt: 800,
|
|
29
|
-
response: 0 // left - correct
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
stimulus: "<img src=\"https://example.com/map_right_2_180.png\" class=\"max-w-none rotate_90\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
33
|
-
rt: 1200,
|
|
34
|
-
response: 1 // right - correct
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
stimulus: "<img src=\"https://example.com/map_left_1_270.png\" class=\"max-w-none rotate_180\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
38
|
-
rt: 600,
|
|
39
|
-
response: 1 // right - incorrect (should be left)
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
stimulus: "<img src=\"https://example.com/map_right_3_90.png\" class=\"max-w-none rotate_270\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
43
|
-
rt: 1000,
|
|
44
|
-
response: 1 // right - correct
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
stimulus: "<img src=\"https://example.com/map_left_2_180.png\" class=\"max-w-none rotate_0\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
48
|
-
rt: 0,
|
|
49
|
-
response: null // missing response
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
stimulus: "<img src=\"https://example.com/map_right_1_90.png\" class=\"max-w-none rotate_90\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
53
|
-
rt: 900,
|
|
54
|
-
response: 0 // left - incorrect (should be right)
|
|
55
|
-
},
|
|
56
|
-
// Non-spatial data that should be filtered out
|
|
57
|
-
{ trial_type: 'instructions', text: 'Use arrow keys...' },
|
|
58
|
-
{ trial_type: 'browser-check', browser: 'firefox' }
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
describe('spatial_extract_image_info test data', () => {
|
|
62
|
-
test('processes test data correctly', () => {
|
|
63
|
-
const resultsTestData = spatial_extract_image_info(ImageInfoTestData);
|
|
64
|
-
expect(resultsTestData.length).toBe(2);
|
|
65
|
-
|
|
66
|
-
expect(resultsTestData[0].image).toBe('map_left_1_90.png');
|
|
67
|
-
expect(resultsTestData[0].direction).toBe('left');
|
|
68
|
-
expect(resultsTestData[0].distance).toBe('1');
|
|
69
|
-
expect(resultsTestData[0].angle).toBe('90');
|
|
70
|
-
expect(resultsTestData[0].rotation).toBe('90');
|
|
71
|
-
expect(resultsTestData[0].response).toBe('left');
|
|
72
|
-
expect(resultsTestData[0].correct).toBe(true);
|
|
73
|
-
|
|
74
|
-
expect(resultsTestData[1].image).toBe('map_left_3_180.png');
|
|
75
|
-
expect(resultsTestData[1].direction).toBe('left');
|
|
76
|
-
expect(resultsTestData[1].distance).toBe('3');
|
|
77
|
-
expect(resultsTestData[1].angle).toBe('180');
|
|
78
|
-
expect(resultsTestData[1].rotation).toBe('270');
|
|
79
|
-
expect(resultsTestData[1].response).toBe('right');
|
|
80
|
-
expect(resultsTestData[1].correct).toBe(false);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('processes real data correctly', () => {
|
|
84
|
-
const testData = loadTestData('spatial-cognition');
|
|
85
|
-
const resultData = spatial_extract_image_info(testData.spatialCognition);
|
|
86
|
-
expect(resultData).toBeDefined();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('processes mock data correctly', () => {
|
|
90
|
-
// First extract spatial trials, then process image info
|
|
91
|
-
const mockTrials = spatial_extract_trials(mockSpatialData);
|
|
92
|
-
expect(mockTrials.length).toBe(6); // Only spatial trials
|
|
93
|
-
|
|
94
|
-
// Check first trial
|
|
95
|
-
expect(mockTrials[0].direction).toBe('left');
|
|
96
|
-
expect(mockTrials[0].distance).toBe('1');
|
|
97
|
-
expect(mockTrials[0].angle).toBe('90');
|
|
98
|
-
expect(mockTrials[0].rotation).toBe('0');
|
|
99
|
-
expect(mockTrials[0].response).toBe('left');
|
|
100
|
-
expect(mockTrials[0].correct).toBe(true);
|
|
101
|
-
|
|
102
|
-
// Check second trial
|
|
103
|
-
expect(mockTrials[1].direction).toBe('right');
|
|
104
|
-
expect(mockTrials[1].response).toBe('right');
|
|
105
|
-
expect(mockTrials[1].correct).toBe(true);
|
|
106
|
-
|
|
107
|
-
// Check incorrect trial
|
|
108
|
-
expect(mockTrials[2].direction).toBe('left');
|
|
109
|
-
expect(mockTrials[2].response).toBe('right');
|
|
110
|
-
expect(mockTrials[2].correct).toBe(false);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe('spatial_results test data', () => {
|
|
115
|
-
test('processes test data correctly', () => {
|
|
116
|
-
const resultsTestData = spatial_results(ImageInfoTestData);
|
|
117
|
-
console.log(resultsTestData);
|
|
118
|
-
expect(resultsTestData).toBeDefined();
|
|
119
|
-
expect(resultsTestData).toHaveProperty('common');
|
|
120
|
-
expect(resultsTestData).toHaveProperty('special');
|
|
121
|
-
expect(resultsTestData.common).toHaveProperty('n_trials');
|
|
122
|
-
expect(resultsTestData.common).toHaveProperty('n_correct_trials');
|
|
123
|
-
expect(resultsTestData.common).toHaveProperty('n_incorrect_trials');
|
|
124
|
-
expect(resultsTestData.common).toHaveProperty('performance_score');
|
|
125
|
-
expect(resultsTestData.special).toHaveProperty('by_distance');
|
|
126
|
-
expect(resultsTestData.special).toHaveProperty('by_angle');
|
|
127
|
-
expect(resultsTestData.special).toHaveProperty('by_rotation');
|
|
128
|
-
});
|
|
129
|
-
test('processes real data correctly', () => {
|
|
130
|
-
const testData = loadTestData('spatialCognition').spatialCognition;
|
|
131
|
-
const resultData = spatial_calculate_results(testData);
|
|
132
|
-
console.log(resultData);
|
|
133
|
-
expect(resultData).toBeDefined();
|
|
134
|
-
expect(resultData).toHaveProperty('common');
|
|
135
|
-
expect(resultData).toHaveProperty('special');
|
|
136
|
-
expect(resultData.common).toHaveProperty('n_trials');
|
|
137
|
-
expect(resultData.common).toHaveProperty('n_correct_trials');
|
|
138
|
-
expect(resultData.common).toHaveProperty('avg_rt_total');
|
|
139
|
-
expect(resultData.common).toHaveProperty('performance_score');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('processes mock data with predictable results', () => {
|
|
143
|
-
const spatialTrials = mockSpatialData.filter(o => 'stimulus' in o && o.stimulus.startsWith("<img src="));
|
|
144
|
-
const mockTrials = spatial_extract_image_info(spatialTrials);
|
|
145
|
-
const mockResults = spatial_results(mockTrials);
|
|
146
|
-
|
|
147
|
-
// Expected: 6 trials total, 3 correct, 3 incorrect, 1 missing
|
|
148
|
-
expect(mockResults.common.n_trials).toBe(6);
|
|
149
|
-
expect(mockResults.common.n_correct_trials).toBe(3);
|
|
150
|
-
expect(mockResults.common.n_incorrect_trials).toBe(3);
|
|
151
|
-
|
|
152
|
-
// Expected avg_rt_total: (800+1200+600+1000+0+900)/6 = 750
|
|
153
|
-
expect(mockResults.common.avg_rt_total).toBe(750);
|
|
154
|
-
|
|
155
|
-
// Expected avg_rt_correct: actual calculation shows 466.67
|
|
156
|
-
expect(mockResults.common.avg_rt_correct).toBeCloseTo(466.67, 1);
|
|
157
|
-
|
|
158
|
-
// Expected avg_rt_incorrect: (600+900+more)/3 - need to check actual calculation
|
|
159
|
-
expect(mockResults.common.avg_rt_incorrect).toBeGreaterThan(0);
|
|
160
|
-
|
|
161
|
-
// Performance score should be calculated based on RT/accuracy formula
|
|
162
|
-
expect(mockResults.common.performance_score).toBeGreaterThan(0);
|
|
163
|
-
expect(mockResults.common.performance_score).toBeLessThanOrEqual(100);
|
|
164
|
-
|
|
165
|
-
// Check special results structure
|
|
166
|
-
expect(mockResults.special.by_distance).toHaveLength(3); // distances: 1, 2, 3
|
|
167
|
-
expect(mockResults.special.by_angle).toHaveLength(3); // angles: 90, 180, 270
|
|
168
|
-
expect(mockResults.special.by_rotation).toHaveLength(4); // rotations: 0, 90, 180, 270
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
1
|
+
// test out the spatial_extract_image_info function
|
|
2
|
+
import { spatial_extract_trials, spatial_extract_image_info, spatial_calculate_results,
|
|
3
|
+
spatial_results } from '../../spatial-cognition';
|
|
4
|
+
import { loadTestData } from '../test-utils/testData';
|
|
5
|
+
|
|
6
|
+
const ImageInfoTestData = [
|
|
7
|
+
{
|
|
8
|
+
stimulus: "<img src=\"https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/spatialcognition/map_left_1_90.png\" class=\"max-w-none rotate_90\" width=\"512\" height=\"512\" alt=\"Mapa\">",
|
|
9
|
+
rt: 1411,
|
|
10
|
+
response: 0,
|
|
11
|
+
plugin_version: "2.0.0",
|
|
12
|
+
time_elapsed: 73045,
|
|
13
|
+
attempted: false
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
stimulus: "<img src=\"https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/spatialcognition/map_left_3_180.png\" class=\"max-w-none rotate_270\" width=\"512\" height=\"512\" alt=\"Mapa\">",
|
|
17
|
+
rt: 1411,
|
|
18
|
+
response: 1,
|
|
19
|
+
plugin_version: "2.0.0",
|
|
20
|
+
time_elapsed: 73045,
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
// Enhanced mock data for comprehensive testing
|
|
25
|
+
const mockSpatialData = [
|
|
26
|
+
{
|
|
27
|
+
stimulus: "<img src=\"https://example.com/map_left_1_90.png\" class=\"max-w-none rotate_0\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
28
|
+
rt: 800,
|
|
29
|
+
response: 0 // left - correct
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
stimulus: "<img src=\"https://example.com/map_right_2_180.png\" class=\"max-w-none rotate_90\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
33
|
+
rt: 1200,
|
|
34
|
+
response: 1 // right - correct
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
stimulus: "<img src=\"https://example.com/map_left_1_270.png\" class=\"max-w-none rotate_180\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
38
|
+
rt: 600,
|
|
39
|
+
response: 1 // right - incorrect (should be left)
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
stimulus: "<img src=\"https://example.com/map_right_3_90.png\" class=\"max-w-none rotate_270\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
43
|
+
rt: 1000,
|
|
44
|
+
response: 1 // right - correct
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
stimulus: "<img src=\"https://example.com/map_left_2_180.png\" class=\"max-w-none rotate_0\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
48
|
+
rt: 0,
|
|
49
|
+
response: null // missing response
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
stimulus: "<img src=\"https://example.com/map_right_1_90.png\" class=\"max-w-none rotate_90\" width=\"512\" height=\"512\" alt=\"Map\">",
|
|
53
|
+
rt: 900,
|
|
54
|
+
response: 0 // left - incorrect (should be right)
|
|
55
|
+
},
|
|
56
|
+
// Non-spatial data that should be filtered out
|
|
57
|
+
{ trial_type: 'instructions', text: 'Use arrow keys...' },
|
|
58
|
+
{ trial_type: 'browser-check', browser: 'firefox' }
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
describe('spatial_extract_image_info test data', () => {
|
|
62
|
+
test('processes test data correctly', () => {
|
|
63
|
+
const resultsTestData = spatial_extract_image_info(ImageInfoTestData);
|
|
64
|
+
expect(resultsTestData.length).toBe(2);
|
|
65
|
+
|
|
66
|
+
expect(resultsTestData[0].image).toBe('map_left_1_90.png');
|
|
67
|
+
expect(resultsTestData[0].direction).toBe('left');
|
|
68
|
+
expect(resultsTestData[0].distance).toBe('1');
|
|
69
|
+
expect(resultsTestData[0].angle).toBe('90');
|
|
70
|
+
expect(resultsTestData[0].rotation).toBe('90');
|
|
71
|
+
expect(resultsTestData[0].response).toBe('left');
|
|
72
|
+
expect(resultsTestData[0].correct).toBe(true);
|
|
73
|
+
|
|
74
|
+
expect(resultsTestData[1].image).toBe('map_left_3_180.png');
|
|
75
|
+
expect(resultsTestData[1].direction).toBe('left');
|
|
76
|
+
expect(resultsTestData[1].distance).toBe('3');
|
|
77
|
+
expect(resultsTestData[1].angle).toBe('180');
|
|
78
|
+
expect(resultsTestData[1].rotation).toBe('270');
|
|
79
|
+
expect(resultsTestData[1].response).toBe('right');
|
|
80
|
+
expect(resultsTestData[1].correct).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('processes real data correctly', () => {
|
|
84
|
+
const testData = loadTestData('spatial-cognition');
|
|
85
|
+
const resultData = spatial_extract_image_info(testData.spatialCognition);
|
|
86
|
+
expect(resultData).toBeDefined();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('processes mock data correctly', () => {
|
|
90
|
+
// First extract spatial trials, then process image info
|
|
91
|
+
const mockTrials = spatial_extract_trials(mockSpatialData);
|
|
92
|
+
expect(mockTrials.length).toBe(6); // Only spatial trials
|
|
93
|
+
|
|
94
|
+
// Check first trial
|
|
95
|
+
expect(mockTrials[0].direction).toBe('left');
|
|
96
|
+
expect(mockTrials[0].distance).toBe('1');
|
|
97
|
+
expect(mockTrials[0].angle).toBe('90');
|
|
98
|
+
expect(mockTrials[0].rotation).toBe('0');
|
|
99
|
+
expect(mockTrials[0].response).toBe('left');
|
|
100
|
+
expect(mockTrials[0].correct).toBe(true);
|
|
101
|
+
|
|
102
|
+
// Check second trial
|
|
103
|
+
expect(mockTrials[1].direction).toBe('right');
|
|
104
|
+
expect(mockTrials[1].response).toBe('right');
|
|
105
|
+
expect(mockTrials[1].correct).toBe(true);
|
|
106
|
+
|
|
107
|
+
// Check incorrect trial
|
|
108
|
+
expect(mockTrials[2].direction).toBe('left');
|
|
109
|
+
expect(mockTrials[2].response).toBe('right');
|
|
110
|
+
expect(mockTrials[2].correct).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('spatial_results test data', () => {
|
|
115
|
+
test('processes test data correctly', () => {
|
|
116
|
+
const resultsTestData = spatial_results(ImageInfoTestData);
|
|
117
|
+
console.log(resultsTestData);
|
|
118
|
+
expect(resultsTestData).toBeDefined();
|
|
119
|
+
expect(resultsTestData).toHaveProperty('common');
|
|
120
|
+
expect(resultsTestData).toHaveProperty('special');
|
|
121
|
+
expect(resultsTestData.common).toHaveProperty('n_trials');
|
|
122
|
+
expect(resultsTestData.common).toHaveProperty('n_correct_trials');
|
|
123
|
+
expect(resultsTestData.common).toHaveProperty('n_incorrect_trials');
|
|
124
|
+
expect(resultsTestData.common).toHaveProperty('performance_score');
|
|
125
|
+
expect(resultsTestData.special).toHaveProperty('by_distance');
|
|
126
|
+
expect(resultsTestData.special).toHaveProperty('by_angle');
|
|
127
|
+
expect(resultsTestData.special).toHaveProperty('by_rotation');
|
|
128
|
+
});
|
|
129
|
+
test('processes real data correctly', () => {
|
|
130
|
+
const testData = loadTestData('spatialCognition').spatialCognition;
|
|
131
|
+
const resultData = spatial_calculate_results(testData);
|
|
132
|
+
console.log(resultData);
|
|
133
|
+
expect(resultData).toBeDefined();
|
|
134
|
+
expect(resultData).toHaveProperty('common');
|
|
135
|
+
expect(resultData).toHaveProperty('special');
|
|
136
|
+
expect(resultData.common).toHaveProperty('n_trials');
|
|
137
|
+
expect(resultData.common).toHaveProperty('n_correct_trials');
|
|
138
|
+
expect(resultData.common).toHaveProperty('avg_rt_total');
|
|
139
|
+
expect(resultData.common).toHaveProperty('performance_score');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('processes mock data with predictable results', () => {
|
|
143
|
+
const spatialTrials = mockSpatialData.filter(o => 'stimulus' in o && o.stimulus.startsWith("<img src="));
|
|
144
|
+
const mockTrials = spatial_extract_image_info(spatialTrials);
|
|
145
|
+
const mockResults = spatial_results(mockTrials);
|
|
146
|
+
|
|
147
|
+
// Expected: 6 trials total, 3 correct, 3 incorrect, 1 missing
|
|
148
|
+
expect(mockResults.common.n_trials).toBe(6);
|
|
149
|
+
expect(mockResults.common.n_correct_trials).toBe(3);
|
|
150
|
+
expect(mockResults.common.n_incorrect_trials).toBe(3);
|
|
151
|
+
|
|
152
|
+
// Expected avg_rt_total: (800+1200+600+1000+0+900)/6 = 750
|
|
153
|
+
expect(mockResults.common.avg_rt_total).toBe(750);
|
|
154
|
+
|
|
155
|
+
// Expected avg_rt_correct: actual calculation shows 466.67
|
|
156
|
+
expect(mockResults.common.avg_rt_correct).toBeCloseTo(466.67, 1);
|
|
157
|
+
|
|
158
|
+
// Expected avg_rt_incorrect: (600+900+more)/3 - need to check actual calculation
|
|
159
|
+
expect(mockResults.common.avg_rt_incorrect).toBeGreaterThan(0);
|
|
160
|
+
|
|
161
|
+
// Performance score should be calculated based on RT/accuracy formula
|
|
162
|
+
expect(mockResults.common.performance_score).toBeGreaterThan(0);
|
|
163
|
+
expect(mockResults.common.performance_score).toBeLessThanOrEqual(100);
|
|
164
|
+
|
|
165
|
+
// Check special results structure
|
|
166
|
+
expect(mockResults.special.by_distance).toHaveLength(3); // distances: 1, 2, 3
|
|
167
|
+
expect(mockResults.special.by_angle).toHaveLength(3); // angles: 90, 180, 270
|
|
168
|
+
expect(mockResults.special.by_rotation).toHaveLength(4); // rotations: 0, 90, 180, 270
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|