compileprofile-spacetests 0.2.1 → 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 +115 -0
- package/README.md +152 -15
- package/dist/cjs/common-interfaces.d.ts +92 -0
- package/dist/cjs/common-interfaces.js +2 -0
- package/dist/cjs/emotions.d.ts +2 -7
- package/dist/cjs/emotions.js +56 -22
- package/dist/cjs/gonogo.d.ts +1 -6
- package/dist/cjs/gonogo.js +125 -46
- package/dist/cjs/index.d.ts +2 -5
- package/dist/cjs/nback.d.ts +6 -12
- package/dist/cjs/nback.js +159 -15
- package/dist/cjs/spatial-cognition.d.ts +1 -6
- package/dist/cjs/spatial-cognition.js +67 -14
- package/dist/esm/common-interfaces.d.ts +92 -0
- package/dist/esm/common-interfaces.js +1 -0
- package/dist/esm/emotions.d.ts +2 -7
- package/dist/esm/emotions.js +55 -21
- package/dist/esm/gonogo.d.ts +1 -6
- package/dist/esm/gonogo.js +125 -46
- package/dist/esm/index.d.ts +2 -5
- package/dist/esm/nback.d.ts +6 -12
- package/dist/esm/nback.js +155 -15
- package/dist/esm/spatial-cognition.d.ts +1 -6
- package/dist/esm/spatial-cognition.js +67 -14
- package/package.json +2 -2
- package/src/__tests__/integration/emotions.test.ts +122 -14
- package/src/__tests__/integration/gonogo.test.ts +240 -27
- package/src/__tests__/integration/nback-versions.test.ts +182 -0
- package/src/__tests__/integration/nback.test.ts +113 -20
- package/src/__tests__/integration/spatial-cognition.test.ts +106 -1
- package/src/common-interfaces.ts +125 -0
- package/src/emotions.ts +68 -29
- package/src/gonogo.ts +128 -55
- package/src/index.ts +22 -6
- package/src/nback.ts +160 -31
- package/src/spatial-cognition.ts +77 -21
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
This is a TypeScript package that evaluates cognitive test results from "Vzhuru do vesmiru" (To Space) cognitive testing platform. The package analyzes performance data from four different cognitive tests: N-back memory tests, spatial cognition tests, Go/No-Go response inhibition tests, and emotion recognition tests.
|
|
8
|
+
|
|
9
|
+
## Build Commands
|
|
10
|
+
|
|
11
|
+
- `npm run build` - Build both CommonJS and ESM distributions
|
|
12
|
+
- `npm run build:csj` - Build CommonJS distribution only
|
|
13
|
+
- `npm run build:esm` - Build ESM distribution only
|
|
14
|
+
- `npm test` - Run all tests using Jest
|
|
15
|
+
- `npm run prepare` - Automatically builds before publishing
|
|
16
|
+
|
|
17
|
+
## Testing
|
|
18
|
+
|
|
19
|
+
- Jest is configured with TypeScript support
|
|
20
|
+
- Test files should follow patterns: `**/__tests__/**/*.ts` or `**/?(*.)+(spec|test).ts`
|
|
21
|
+
- Tests are located in `src/__tests__/integration/`
|
|
22
|
+
- Test utilities and shared data are in `src/__tests__/test-utils/`
|
|
23
|
+
- Run single test: `npm test -- --testNamePattern="test_name"`
|
|
24
|
+
- Run tests for specific file: `npm test -- emotions.test.ts`
|
|
25
|
+
|
|
26
|
+
## Architecture
|
|
27
|
+
|
|
28
|
+
### Core Structure
|
|
29
|
+
|
|
30
|
+
The package exports four main calculation functions from `src/index.ts`:
|
|
31
|
+
- `NbackResults(data)` - Analyzes N-back memory test performance
|
|
32
|
+
- `SpatialCognitionResults(data)` - Evaluates spatial cognition test results
|
|
33
|
+
- `GonogoResults(data)` - Processes Go/No-Go inhibition test data
|
|
34
|
+
- `EmotionResults(data)` - Analyzes emotion recognition test performance
|
|
35
|
+
|
|
36
|
+
### Data Processing Pipeline
|
|
37
|
+
|
|
38
|
+
Each cognitive test follows a consistent three-step processing pattern:
|
|
39
|
+
|
|
40
|
+
1. **Extract Trials**: Filter raw test data to identify relevant trial records
|
|
41
|
+
- `nback_extract_trials()` - Filters for records with `is_target` field
|
|
42
|
+
- `spatial_extract_trials()` - Filters for records with image stimulus data
|
|
43
|
+
- `gonogo_extract_trials()` - Filters for records with image responses
|
|
44
|
+
- `emotion_extract_trials()` - Filters for records with emotion response data
|
|
45
|
+
|
|
46
|
+
2. **Calculate Results**: Compute accuracy, reaction time, and derived metrics
|
|
47
|
+
- All tests calculate: trial count (`n`), average accuracy (`avg_acc`), average reaction time (`avg_rt`)
|
|
48
|
+
- Each test has specific performance scoring algorithms
|
|
49
|
+
|
|
50
|
+
- the results should have a uniform structure
|
|
51
|
+
- common - should be common structure for all tests
|
|
52
|
+
- n_trials (number of trials)
|
|
53
|
+
- n_correct_trials (number of correct trials)
|
|
54
|
+
- n_incorrect_trials (number of incorrect trials)
|
|
55
|
+
- n_missing_trials (number of missing trials)
|
|
56
|
+
- avg_rt_total (in ms)
|
|
57
|
+
- avg_rt_correct (in ms)
|
|
58
|
+
- avg_rt_incorrect (in ms)
|
|
59
|
+
- avg_rt_missing (in ms)
|
|
60
|
+
- performance_score - score calculated as per test instruction - differs for each test slightly
|
|
61
|
+
- special - special results inherent for the test itself
|
|
62
|
+
|
|
63
|
+
3. **Performance Scoring**: Convert raw metrics to normalized 0-100 performance scores
|
|
64
|
+
- Go/No-Go: Uses RT/(accuracy^5) with 300-5000ms bounds; RT = mean RT of hits, accuracy = balanced (hit rate and correct-rejection rate weighted equally), 0 when there is no hit
|
|
65
|
+
- Emotions: Uses RT/(accuracy^5) with 1000-10000ms bounds
|
|
66
|
+
- Spatial: Uses RT/accuracy with 1000-10000ms bounds
|
|
67
|
+
- N-back: Uses raw accuracy as performance score
|
|
68
|
+
|
|
69
|
+
### Key Implementation Details
|
|
70
|
+
|
|
71
|
+
**N-back Test** (`src/nback.ts`):
|
|
72
|
+
- Processes target vs non-target trials separately
|
|
73
|
+
- Returns comprehensive breakdown of both trial types
|
|
74
|
+
- Performance score is simply average accuracy
|
|
75
|
+
|
|
76
|
+
**Spatial Cognition Test** (`src/spatial-cognition.ts`):
|
|
77
|
+
- Extracts map direction (left/right), distance, angle, and rotation from image URLs
|
|
78
|
+
- Compares user response direction against correct answer
|
|
79
|
+
- Uses simpler RT/accuracy performance formula
|
|
80
|
+
|
|
81
|
+
**Go/No-Go Test** (`src/gonogo.ts`):
|
|
82
|
+
- Determines correct response based on block number and stimulus type
|
|
83
|
+
- Block 1: respond to astronaut, Block 2: respond to alien, Block 3: respond to rocket, Block 4: respond to non-rocket
|
|
84
|
+
- Extracts stimulus type from image URL patterns
|
|
85
|
+
|
|
86
|
+
**Emotion Recognition Test** (`src/emotions.ts`):
|
|
87
|
+
- Maps numeric responses (0-4) to emotion labels: neutral, sad, happy, surprised, angry
|
|
88
|
+
- Extracts emotion type and image number from file paths
|
|
89
|
+
- Compares recognized emotion against correct emotion
|
|
90
|
+
|
|
91
|
+
### Data Formats
|
|
92
|
+
|
|
93
|
+
All tests expect arrays of trial objects with specific fields:
|
|
94
|
+
- N-back: `is_target`, `rt`, `correct`
|
|
95
|
+
- Spatial: `stimulus` (HTML img tag), `response`, `rt`
|
|
96
|
+
- Go/No-Go: `image` (URL), `response`, `rt`, `block_number`
|
|
97
|
+
- Emotions: `emotion` (URL), `response`, `rt`
|
|
98
|
+
|
|
99
|
+
## Utilities
|
|
100
|
+
|
|
101
|
+
**Browser Information** (`src/getters.ts`):
|
|
102
|
+
- `getBrowserInformation(data)` extracts browser/system info from test data
|
|
103
|
+
- Returns OS, browser version, screen dimensions, hardware capabilities
|
|
104
|
+
|
|
105
|
+
**Normative Data** (`src/norms/`):
|
|
106
|
+
- JSON files contain normative performance data for each test type
|
|
107
|
+
- Used for percentile calculations and age/gender adjustments
|
|
108
|
+
|
|
109
|
+
## Development Notes
|
|
110
|
+
|
|
111
|
+
- Package supports both CommonJS and ESM exports
|
|
112
|
+
- TypeScript configurations: `tsconfig.cjs.json` and `tsconfig.esm.json`
|
|
113
|
+
- All calculation functions include comprehensive TypeScript interfaces
|
|
114
|
+
- Console logging is used in some functions for debugging
|
|
115
|
+
- Error handling throws descriptive errors for empty trial datasets
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# compileprofile-spacetests
|
|
2
2
|
|
|
3
|
-
A package for evaluating cognitive test results
|
|
3
|
+
A package for evaluating cognitive test results from "Vzhuru do vesmiru" (To Space) cognitive testing platform. This package analyzes performance data from four different cognitive tests: N-back memory tests, spatial cognition tests, Go/No-Go response inhibition tests, and emotion recognition tests.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -11,25 +11,162 @@ npm install compileprofile-spacetests
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
import {
|
|
15
|
+
NbackResults,
|
|
16
|
+
SpatialCognitionResults,
|
|
17
|
+
GonogoResults,
|
|
18
|
+
EmotionResults
|
|
19
|
+
} from 'compileprofile-spacetests';
|
|
20
|
+
|
|
21
|
+
// Analyze N-back memory test
|
|
22
|
+
const nbackResults = NbackResults(nbackData);
|
|
23
|
+
|
|
24
|
+
// Analyze spatial cognition test
|
|
25
|
+
const spatialResults = SpatialCognitionResults(spatialData);
|
|
26
|
+
|
|
27
|
+
// Analyze Go/No-Go test
|
|
28
|
+
const gonogoResults = GonogoResults(gonogoData);
|
|
29
|
+
|
|
30
|
+
// Analyze emotion recognition test
|
|
31
|
+
const emotionResults = EmotionResults(emotionData);
|
|
18
32
|
```
|
|
19
33
|
|
|
34
|
+
## Test Results
|
|
20
35
|
|
|
21
|
-
|
|
36
|
+
All cognitive tests return results in two parts: **common metrics** (same for all tests) and **special metrics** (specific to each test type).
|
|
37
|
+
|
|
38
|
+
### Common Metrics (All Tests)
|
|
39
|
+
|
|
40
|
+
Every test provides these basic performance measures:
|
|
41
|
+
|
|
42
|
+
- **n_trials** - Total number of test trials completed
|
|
43
|
+
- **n_correct_trials** - How many responses were correct
|
|
44
|
+
- **n_incorrect_trials** - How many responses were wrong
|
|
45
|
+
- **avg_rt_total** - Average reaction time across all trials (milliseconds)
|
|
46
|
+
- **avg_rt_correct** - Average reaction time for correct answers only
|
|
47
|
+
- **avg_rt_incorrect** - Average reaction time for wrong answers only
|
|
48
|
+
- **performance_score** - Overall performance score (0-100, higher is better)
|
|
49
|
+
|
|
50
|
+
### Special Metrics by Test Type
|
|
51
|
+
|
|
52
|
+
#### N-back Memory Test
|
|
53
|
+
|
|
54
|
+
Analyzes working memory by comparing performance on different trial types:
|
|
55
|
+
|
|
56
|
+
- **target_trials** - Performance when participant should respond (saw matching stimulus)
|
|
57
|
+
- Number of target trials, average reaction time, accuracy rate
|
|
58
|
+
- **non_target_trials** - Performance when participant should not respond
|
|
59
|
+
- Number of non-target trials, average reaction time, accuracy rate
|
|
60
|
+
|
|
61
|
+
Version 2 data (trials carry `n_back`, `block` and `block_index`) also gets:
|
|
62
|
+
|
|
63
|
+
- **by_block** - Results for each block, in block order, with its `block`, `block_index` and `n_back`
|
|
64
|
+
- **by_nback** - Results for each N level, pooling all blocks with that N, sorted by N
|
|
65
|
+
|
|
66
|
+
Each entry of both has `n_trials`, `n_correct_trials`, `performance_score`, `n_targets`,
|
|
67
|
+
`n_non_targets`, `hits`, `misses`, `false_alarms`, `correct_rejections`, `hit_rate`,
|
|
68
|
+
`false_alarm_rate`, `d_prime`, `n_lures`, `lure_false_alarms`, `lure_false_alarm_rate`,
|
|
69
|
+
`avg_rt_hits` and `avg_rt_false_alarms`. Lures (`is_lure: true`) are non-targets repeating an image
|
|
70
|
+
from a distance other than N; their false alarms also count in `false_alarms` and `d_prime`, and a
|
|
71
|
+
high `lure_false_alarm_rate` means the participant responds to familiarity rather than position. `d_prime` uses the
|
|
72
|
+
log-linear correction (Hautus 1995), so it stays finite at 0 % or 100 % rates; it is `null` for a
|
|
73
|
+
group without targets or without non-targets. Version 1 data has neither field, and its results are
|
|
74
|
+
unchanged from 0.3.0.
|
|
75
|
+
|
|
76
|
+
About 80 % of trials are non-targets, so not responding at all already gives a high
|
|
77
|
+
`performance_score`. Compare levels by `hit_rate` or `d_prime`.
|
|
78
|
+
|
|
79
|
+
#### Spatial Cognition Test
|
|
80
|
+
|
|
81
|
+
Analyzes spatial reasoning by breaking down performance across map characteristics:
|
|
82
|
+
|
|
83
|
+
- **by_distance** - Performance grouped by how far the destination is (1, 2, 3 units)
|
|
84
|
+
- **by_angle** - Performance grouped by map rotation angle (90°, 180°, 270°)
|
|
85
|
+
- **by_rotation** - Performance grouped by how much the view was rotated
|
|
86
|
+
|
|
87
|
+
Each group shows number of trials, average reaction time, and accuracy rate.
|
|
88
|
+
|
|
89
|
+
#### Go/No-Go Response Inhibition Test
|
|
90
|
+
|
|
91
|
+
Analyzes impulse control by examining when to respond vs. when to inhibit:
|
|
92
|
+
|
|
93
|
+
- **balanced_acc** - Mean of the go hit rate and the no-go correct-rejection rate
|
|
94
|
+
- **by_block** - Performance in each test phase (blocks 1-4 have different rules)
|
|
95
|
+
- Average RT of hits, accuracy, hit rate, correct-rejection rate, balanced accuracy
|
|
96
|
+
- **go_trials** - Trials where participant should press the button
|
|
97
|
+
- Number of trials, average RT of hits, hit rate, number of omissions (misses)
|
|
98
|
+
- **nogo_trials** - Trials where participant should NOT press the button
|
|
99
|
+
- Number of trials, average RT of false alarms, correct-rejection rate, number of commissions (false alarms)
|
|
22
100
|
|
|
23
|
-
|
|
101
|
+
Reaction times are averaged only over trials with a response; a trial without a click has no RT.
|
|
24
102
|
|
|
25
|
-
|
|
103
|
+
#### Emotion Recognition Test
|
|
26
104
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
|
|
105
|
+
Analyzes emotion processing by examining recognition patterns:
|
|
106
|
+
|
|
107
|
+
- **by_emotion** - Performance for each emotion type (neutral, sad, happy, surprised, angry)
|
|
108
|
+
- For each emotion: number of trials, average reaction time, accuracy rate
|
|
109
|
+
- **confusion_matrix** - Shows which emotions get confused with which others
|
|
110
|
+
- Rows = actual emotion, columns = what participant guessed
|
|
111
|
+
|
|
112
|
+
## Performance Scoring
|
|
113
|
+
|
|
114
|
+
Each test uses a specific algorithm to calculate the performance score (0-100):
|
|
115
|
+
|
|
116
|
+
- **N-back**: Raw accuracy percentage
|
|
117
|
+
- **Spatial Cognition**: RT/(accuracy) formula with 1000-10000ms bounds
|
|
118
|
+
- **Go/No-Go**: RT/(accuracy^5) formula with 300-5000ms bounds, where RT is the mean RT of hits and accuracy is the balanced accuracy; 0 when there is no hit
|
|
119
|
+
- **Emotions**: RT/(accuracy^5) formula with 1000-10000ms bounds
|
|
120
|
+
|
|
121
|
+
## Input Data Format
|
|
122
|
+
|
|
123
|
+
Each test expects an array of trial objects with specific fields:
|
|
124
|
+
|
|
125
|
+
### N-back Test Data
|
|
126
|
+
|
|
127
|
+
Each trial object should have:
|
|
128
|
+
- **is_target** - `true` if participant should respond, `false` if they shouldn't
|
|
129
|
+
- **rt** - Reaction time in milliseconds
|
|
130
|
+
- **correct** - `true` if response was correct, `false` if wrong
|
|
131
|
+
- **response** - What the participant pressed (0 or 1, or null if no response)
|
|
132
|
+
- **n_back**, **block**, **block_index** - Version 2 only: N, block name and block position
|
|
133
|
+
- **is_lure** - Version 2 only: `true` for a non-target repeating an image from a distance other than N
|
|
134
|
+
|
|
135
|
+
### Spatial Cognition Test Data
|
|
136
|
+
|
|
137
|
+
Each trial object should have:
|
|
138
|
+
- **stimulus** - HTML image tag containing the map image
|
|
139
|
+
- **rt** - Reaction time in milliseconds
|
|
140
|
+
- **response** - Direction chosen (0 = left, 1 = right)
|
|
141
|
+
|
|
142
|
+
### Go/No-Go Test Data
|
|
143
|
+
|
|
144
|
+
Each trial object should have:
|
|
145
|
+
- **image** - URL to the stimulus image (astronaut, alien, or rocket)
|
|
146
|
+
- **rt** - Reaction time in milliseconds
|
|
147
|
+
- **response** - Button press (any number = pressed, null = no press)
|
|
148
|
+
- **block_number** - Which test phase (1, 2, 3, or 4)
|
|
149
|
+
|
|
150
|
+
### Emotion Recognition Test Data
|
|
151
|
+
|
|
152
|
+
Each trial object should have:
|
|
153
|
+
- **emotion** - URL to the emotion face image
|
|
154
|
+
- **rt** - Reaction time in milliseconds
|
|
155
|
+
- **response** - Emotion chosen (0=neutral, 1=sad, 2=happy, 3=surprised, 4=angry)
|
|
156
|
+
|
|
157
|
+
## Development
|
|
158
|
+
|
|
159
|
+
Build the package:
|
|
160
|
+
```bash
|
|
161
|
+
npm run build # Build both CommonJS and ESM
|
|
162
|
+
npm run build:cjs # Build CommonJS only
|
|
163
|
+
npm run build:esm # Build ESM only
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Run tests:
|
|
167
|
+
```bash
|
|
168
|
+
npm test # Run all tests
|
|
169
|
+
npm test -- emotions.test.ts # Run specific test file
|
|
170
|
+
```
|
|
34
171
|
|
|
35
172
|
## License
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
interface CommonResults {
|
|
2
|
+
n_trials: number;
|
|
3
|
+
n_correct_trials: number;
|
|
4
|
+
n_incorrect_trials: number;
|
|
5
|
+
avg_rt_total: number;
|
|
6
|
+
avg_rt_correct: number;
|
|
7
|
+
avg_rt_incorrect: number;
|
|
8
|
+
performance_score: number;
|
|
9
|
+
}
|
|
10
|
+
interface NbackGroupResults {
|
|
11
|
+
n_trials: number;
|
|
12
|
+
n_correct_trials: number;
|
|
13
|
+
performance_score: number;
|
|
14
|
+
n_targets: number;
|
|
15
|
+
n_non_targets: number;
|
|
16
|
+
hits: number;
|
|
17
|
+
misses: number;
|
|
18
|
+
false_alarms: number;
|
|
19
|
+
correct_rejections: number;
|
|
20
|
+
hit_rate: number | null;
|
|
21
|
+
false_alarm_rate: number | null;
|
|
22
|
+
d_prime: number | null;
|
|
23
|
+
n_lures: number;
|
|
24
|
+
lure_false_alarms: number;
|
|
25
|
+
lure_false_alarm_rate: number | null;
|
|
26
|
+
avg_rt_hits: number | null;
|
|
27
|
+
avg_rt_false_alarms: number | null;
|
|
28
|
+
}
|
|
29
|
+
interface NbackBlockResults extends NbackGroupResults {
|
|
30
|
+
block: string;
|
|
31
|
+
block_index: number;
|
|
32
|
+
n_back: number;
|
|
33
|
+
}
|
|
34
|
+
interface NbackLevelResults extends NbackGroupResults {
|
|
35
|
+
n_back: number;
|
|
36
|
+
}
|
|
37
|
+
interface NbackSpecialResults {
|
|
38
|
+
target_trials: {
|
|
39
|
+
n: number;
|
|
40
|
+
avg_rt: number;
|
|
41
|
+
avg_acc: number;
|
|
42
|
+
};
|
|
43
|
+
non_target_trials: {
|
|
44
|
+
n: number;
|
|
45
|
+
avg_rt: number;
|
|
46
|
+
avg_acc: number;
|
|
47
|
+
};
|
|
48
|
+
by_block?: NbackBlockResults[];
|
|
49
|
+
by_nback?: NbackLevelResults[];
|
|
50
|
+
}
|
|
51
|
+
interface SpatialSpecialResults {
|
|
52
|
+
by_distance: any[];
|
|
53
|
+
by_angle: any[];
|
|
54
|
+
by_rotation: any[];
|
|
55
|
+
}
|
|
56
|
+
interface GonogoSpecialResults {
|
|
57
|
+
balanced_acc: number;
|
|
58
|
+
by_block: any[];
|
|
59
|
+
go_trials: {
|
|
60
|
+
n: number;
|
|
61
|
+
avg_rt: number;
|
|
62
|
+
avg_acc: number;
|
|
63
|
+
n_omissions: number;
|
|
64
|
+
};
|
|
65
|
+
nogo_trials: {
|
|
66
|
+
n: number;
|
|
67
|
+
avg_rt: number;
|
|
68
|
+
avg_acc: number;
|
|
69
|
+
n_commissions: number;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
interface EmotionSpecialResults {
|
|
73
|
+
by_emotion: any[];
|
|
74
|
+
confusion_matrix: any;
|
|
75
|
+
}
|
|
76
|
+
interface NbackResultsStructure {
|
|
77
|
+
common: CommonResults;
|
|
78
|
+
special: NbackSpecialResults;
|
|
79
|
+
}
|
|
80
|
+
interface SpatialResultsStructure {
|
|
81
|
+
common: CommonResults;
|
|
82
|
+
special: SpatialSpecialResults;
|
|
83
|
+
}
|
|
84
|
+
interface GonogoResultsStructure {
|
|
85
|
+
common: CommonResults;
|
|
86
|
+
special: GonogoSpecialResults;
|
|
87
|
+
}
|
|
88
|
+
interface EmotionResultsStructure {
|
|
89
|
+
common: CommonResults;
|
|
90
|
+
special: EmotionSpecialResults;
|
|
91
|
+
}
|
|
92
|
+
export { CommonResults, NbackResultsStructure, SpatialResultsStructure, GonogoResultsStructure, EmotionResultsStructure, NbackSpecialResults, NbackGroupResults, NbackBlockResults, NbackLevelResults, SpatialSpecialResults, GonogoSpecialResults, EmotionSpecialResults };
|
package/dist/cjs/emotions.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
n: number;
|
|
3
|
-
avg_rt: number;
|
|
4
|
-
avg_acc: number;
|
|
5
|
-
performance: number;
|
|
6
|
-
}
|
|
1
|
+
import { EmotionResultsStructure } from './common-interfaces';
|
|
7
2
|
declare const emotion_calculate_results: (obj: any[]) => EmotionResultsStructure;
|
|
8
|
-
declare const emotion_results: (obj: any[]) => EmotionResultsStructure;
|
|
9
3
|
declare const emotion_extract_trials: (obj: any[]) => any[];
|
|
4
|
+
declare const emotion_results: (obj: any[]) => EmotionResultsStructure;
|
|
10
5
|
export { EmotionResultsStructure, emotion_calculate_results, emotion_extract_trials, emotion_results };
|
package/dist/cjs/emotions.js
CHANGED
|
@@ -1,36 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.emotion_results = exports.emotion_extract_trials = exports.emotion_calculate_results = void 0;
|
|
4
|
+
var EMOTION_MAP = ["neutral", "sad", "happy", "surprised", "angry"];
|
|
4
5
|
var emotion_calculate_results = function (obj) {
|
|
5
6
|
var trials = emotion_extract_trials(obj);
|
|
6
|
-
// throw if trials is empty
|
|
7
7
|
if (trials.length === 0) {
|
|
8
8
|
throw new Error("No trials found");
|
|
9
9
|
}
|
|
10
10
|
return emotion_results(trials);
|
|
11
11
|
};
|
|
12
12
|
exports.emotion_calculate_results = emotion_calculate_results;
|
|
13
|
-
var emotion_results = function (obj) {
|
|
14
|
-
// throw error if obj is empty
|
|
15
|
-
if (obj.length === 0) {
|
|
16
|
-
throw new Error("No trials found");
|
|
17
|
-
}
|
|
18
|
-
var results = {
|
|
19
|
-
n: obj.length,
|
|
20
|
-
avg_rt: obj.reduce(function (a, b) { return a + b.rt; }, 0) / obj.length,
|
|
21
|
-
avg_acc: obj.reduce(function (a, b) { return a + b.correct; }, 0) / obj.length,
|
|
22
|
-
performance: NaN
|
|
23
|
-
};
|
|
24
|
-
var best_score = 1000;
|
|
25
|
-
var worst_score = 10000;
|
|
26
|
-
var performance = results.avg_rt / (Math.pow(results.avg_acc, 5) + 0.001);
|
|
27
|
-
performance = Math.min(Math.max(performance, best_score), worst_score);
|
|
28
|
-
results.performance = (1 - ((performance - best_score) / (worst_score - best_score))) * 100;
|
|
29
|
-
return results;
|
|
30
|
-
};
|
|
31
|
-
exports.emotion_results = emotion_results;
|
|
32
13
|
var emotion_extract_trials = function (obj) {
|
|
33
|
-
var emotionMap = ["neutral", "sad", "happy", "surprised", "angry"];
|
|
34
14
|
// filter trials where response and rt are defined and not null
|
|
35
15
|
var trials = obj.filter(function (o) { return 'response' in o && 'rt' in o && 'emotion' in o; });
|
|
36
16
|
trials = trials.filter(function (o) { return o.response !== null && o.rt !== null; });
|
|
@@ -45,10 +25,64 @@ var emotion_extract_trials = function (obj) {
|
|
|
45
25
|
}
|
|
46
26
|
});
|
|
47
27
|
trials.forEach(function (o) {
|
|
48
|
-
o.emotion_response =
|
|
28
|
+
o.emotion_response = EMOTION_MAP[o.response] || "unknown";
|
|
49
29
|
o.correct = o.emotion === o.emotion_response;
|
|
50
30
|
// in the older ones there were 15 trials per rotation
|
|
51
31
|
});
|
|
52
32
|
return trials;
|
|
53
33
|
};
|
|
54
34
|
exports.emotion_extract_trials = emotion_extract_trials;
|
|
35
|
+
var emotion_results = function (obj) {
|
|
36
|
+
if (obj.length === 0) {
|
|
37
|
+
throw new Error("No trials found");
|
|
38
|
+
}
|
|
39
|
+
var correct_trials = obj.filter(function (o) { return o.correct === true; });
|
|
40
|
+
var incorrect_trials = obj.filter(function (o) { return o.correct === false; });
|
|
41
|
+
var total_rt = obj.reduce(function (a, b) { return a + (b.rt || 0); }, 0);
|
|
42
|
+
var correct_rt = correct_trials.reduce(function (a, b) { return a + (b.rt || 0); }, 0);
|
|
43
|
+
var incorrect_rt = incorrect_trials.reduce(function (a, b) { return a + (b.rt || 0); }, 0);
|
|
44
|
+
var avg_rt = total_rt / obj.length;
|
|
45
|
+
var avg_acc = correct_trials.length / obj.length;
|
|
46
|
+
// Calculate performance score using the existing formula
|
|
47
|
+
var best_score = 1000;
|
|
48
|
+
var worst_score = 10000;
|
|
49
|
+
var performance = avg_rt / (Math.pow(avg_acc, 5) + 0.001);
|
|
50
|
+
performance = Math.min(Math.max(performance, best_score), worst_score);
|
|
51
|
+
var performance_score = (1 - ((performance - best_score) / (worst_score - best_score))) * 100;
|
|
52
|
+
var common = {
|
|
53
|
+
n_trials: obj.length,
|
|
54
|
+
n_correct_trials: correct_trials.length,
|
|
55
|
+
n_incorrect_trials: incorrect_trials.length,
|
|
56
|
+
avg_rt_total: avg_rt,
|
|
57
|
+
avg_rt_correct: correct_trials.length > 0 ? correct_rt / correct_trials.length : 0,
|
|
58
|
+
avg_rt_incorrect: incorrect_trials.length > 0 ? incorrect_rt / incorrect_trials.length : 0,
|
|
59
|
+
performance_score: performance_score
|
|
60
|
+
};
|
|
61
|
+
// Group by emotion for special results
|
|
62
|
+
var by_emotion = EMOTION_MAP.map(function (emotion) {
|
|
63
|
+
var emotion_trials = obj.filter(function (o) { return o.emotion === emotion; });
|
|
64
|
+
return {
|
|
65
|
+
emotion: emotion,
|
|
66
|
+
n: emotion_trials.length,
|
|
67
|
+
avg_rt: emotion_trials.length > 0 ? emotion_trials.reduce(function (a, b) { return a + (b.rt || 0); }, 0) / emotion_trials.length : 0,
|
|
68
|
+
avg_acc: emotion_trials.length > 0 ? emotion_trials.reduce(function (a, b) { return a + (b.correct ? 1 : 0); }, 0) / emotion_trials.length : 0,
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
// Create confusion matrix
|
|
72
|
+
var confusion_matrix = EMOTION_MAP.reduce(function (matrix, actual) {
|
|
73
|
+
matrix[actual] = EMOTION_MAP.reduce(function (row, predicted) {
|
|
74
|
+
row[predicted] = obj.filter(function (o) { return o.emotion === actual && o.emotion_response === predicted; }).length;
|
|
75
|
+
return row;
|
|
76
|
+
}, {});
|
|
77
|
+
return matrix;
|
|
78
|
+
}, {});
|
|
79
|
+
var special = {
|
|
80
|
+
by_emotion: by_emotion,
|
|
81
|
+
confusion_matrix: confusion_matrix
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
common: common,
|
|
85
|
+
special: special
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
exports.emotion_results = emotion_results;
|
package/dist/cjs/gonogo.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
n: number;
|
|
3
|
-
avg_rt: number;
|
|
4
|
-
avg_acc: number;
|
|
5
|
-
performance: number;
|
|
6
|
-
}
|
|
1
|
+
import { GonogoResultsStructure } from './common-interfaces';
|
|
7
2
|
declare const gonogo_calculate_results: (data: any[]) => GonogoResultsStructure;
|
|
8
3
|
declare const gonogo_extract_trials: (obj: any[]) => any[];
|
|
9
4
|
declare const gonogo_results: (data: any[]) => GonogoResultsStructure;
|