compileprofile-spacetests 0.1.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 (45) hide show
  1. package/README.md +35 -0
  2. package/dist/cjs/getters.d.ts +2 -0
  3. package/dist/cjs/getters.js +22 -0
  4. package/dist/cjs/gonogo.d.ts +3 -0
  5. package/dist/cjs/gonogo.js +30 -0
  6. package/dist/cjs/index.d.ts +5 -0
  7. package/dist/cjs/index.js +13 -0
  8. package/dist/cjs/nback.d.ts +15 -0
  9. package/dist/cjs/nback.js +40 -0
  10. package/dist/cjs/spatial-cognition.d.ts +11 -0
  11. package/dist/cjs/spatial-cognition.js +54 -0
  12. package/dist/esm/getters.d.ts +2 -0
  13. package/dist/esm/getters.js +20 -0
  14. package/dist/esm/gonogo.d.ts +3 -0
  15. package/dist/esm/gonogo.js +30 -0
  16. package/dist/esm/index.d.ts +5 -0
  17. package/dist/esm/index.js +9 -0
  18. package/dist/esm/nback.d.ts +15 -0
  19. package/dist/esm/nback.js +35 -0
  20. package/dist/esm/spatial-cognition.d.ts +11 -0
  21. package/dist/esm/spatial-cognition.js +48 -0
  22. package/example-data/emotions.json +808 -0
  23. package/example-data/gonogo.json +5393 -0
  24. package/example-data/nback.json +893 -0
  25. package/example-data/participant.json +7 -0
  26. package/example-data/spatial-cognition.json +463 -0
  27. package/jest.config.js +14 -0
  28. package/original/emotion-recognition.R +39 -0
  29. package/original/gonogo.R +32 -0
  30. package/package.json +40 -0
  31. package/src/__tests__/integration/browserInfo.test.ts +17 -0
  32. package/src/__tests__/integration/nback.test.ts +56 -0
  33. package/src/__tests__/integration/spatial-cognition.test.ts +59 -0
  34. package/src/__tests__/test-utils/testData.ts +80 -0
  35. package/src/getters.ts +21 -0
  36. package/src/gonogo.ts +37 -0
  37. package/src/index.ts +12 -0
  38. package/src/nback.ts +53 -0
  39. package/src/norms/emotions.json +0 -0
  40. package/src/norms/gonogo.json +0 -0
  41. package/src/norms/nback.json +0 -0
  42. package/src/norms/spatial-cognition.json +0 -0
  43. package/src/spatial-cognition.ts +59 -0
  44. package/tsconfig.cjs.json +13 -0
  45. package/tsconfig.esm.json +15 -0
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # compileprofile-spacetests
2
+
3
+ A package for evaluating cognitive test results, specifically designed for memory tests.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install compileprofile-spacetests
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { evaluateMemoryTest, MemoryTestData, SubjectParameters } from 'compileprofile-spacetests';
15
+ // Evaluate the test results
16
+ const results = evaluateMemoryTest(testData, subjectParams);
17
+ console.log(results);
18
+ ```
19
+
20
+
21
+ ## Development
22
+
23
+ Basic js distribution
24
+
25
+ ## API
26
+
27
+ Evaluates memory test results and returns a comprehensive analysis including:
28
+ - Overall accuracy
29
+ - Average reaction time
30
+ - Total correct responses
31
+ - Total number of trials
32
+ - Age-adjusted score (for subjects between 18-65)
33
+ - Gender-specific percentile (when gender is specified)
34
+
35
+ ## License
@@ -0,0 +1,2 @@
1
+ declare function getBrowserInformation(data: any[]): any;
2
+ export { getBrowserInformation };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBrowserInformation = getBrowserInformation;
4
+ function getBrowserInformation(data) {
5
+ var browserInfo = data.find(function (row) { return row.trial_type === "browser-check"; });
6
+ if (!browserInfo) {
7
+ return null;
8
+ }
9
+ return {
10
+ os: browserInfo.os,
11
+ mobile: browserInfo.mobile,
12
+ fullscreen: browserInfo.fullscreen,
13
+ vsync_rate: browserInfo.vsync_rate,
14
+ webcam: browserInfo.webcam,
15
+ microphone: browserInfo.microphone,
16
+ browser: browserInfo.browser,
17
+ browser_version: browserInfo.browser_version,
18
+ webaudio: browserInfo.webaudio,
19
+ width: browserInfo.width,
20
+ height: browserInfo.height
21
+ };
22
+ }
@@ -0,0 +1,3 @@
1
+ declare const gonogo_calculate_results: (data: any) => void;
2
+ declare const gonogo_extract_trials: (data: any) => void;
3
+ declare const gonogo_results: (data: any) => void;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ // gonogo_create_trial_table <- function(txt) {
3
+ // arr <- fromJSON(txt)
4
+ // df <- as.data.frame(fromJSON(arr[[1]]))
5
+ // GONOGO_IMAGE_PATH <- "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/gonogo/"
6
+ // df <- filter(df, !is.na(image))
7
+ // df <- select(df, trial_index, time_elapsed, rt,
8
+ // response, block_number, image)
9
+ // df$image <- gsub(GONOGO_IMAGE_PATH, "", df$image)
10
+ // df$image <- gsub(".png", "", df$image)
11
+ // df <- df %>%
12
+ // mutate(
13
+ // should_go = case_when(
14
+ // block_number == 1 & grepl("astronaut_trans_1", image) ~ TRUE,
15
+ // block_number == 2 & grepl("alien_trans_1", image) ~ TRUE,
16
+ // block_number == 3 & grepl("rocket_trans_1", image) ~ TRUE,
17
+ // block_number == 4 & !grepl("rocket_trans_1", image) ~ TRUE,
18
+ // TRUE ~ FALSE),
19
+ // did_go = !is.na(response),
20
+ // correct = should_go == did_go
21
+ // )
22
+ // return(df)
23
+ // }
24
+ var gonogo_calculate_results = function (data) {
25
+ };
26
+ var gonogo_extract_trials = function (data) {
27
+ // GONOGO_IMAGE_PATH <- "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/gonogo/"
28
+ };
29
+ var gonogo_results = function (data) {
30
+ };
@@ -0,0 +1,5 @@
1
+ import { NBackResults } from './nback';
2
+ import { SpatialResults } from './spatial-cognition';
3
+ declare const NbackResults: (obj: any[]) => NBackResults;
4
+ declare const SpatialCognitionResults: (obj: any[]) => SpatialResults;
5
+ export { NbackResults, SpatialCognitionResults };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpatialCognitionResults = exports.NbackResults = void 0;
4
+ var nback_1 = require("./nback");
5
+ var spatial_cognition_1 = require("./spatial-cognition");
6
+ var NbackResults = function (obj) {
7
+ return (0, nback_1.nback_calculate_results)(obj);
8
+ };
9
+ exports.NbackResults = NbackResults;
10
+ var SpatialCognitionResults = function (obj) {
11
+ return (0, spatial_cognition_1.spatial_calculate_results)(obj);
12
+ };
13
+ exports.SpatialCognitionResults = SpatialCognitionResults;
@@ -0,0 +1,15 @@
1
+ declare const nback_calculate_results: (obj: any[]) => NBackResults;
2
+ declare const nback_extract_trials: (obj: any[]) => any[];
3
+ interface NbackTrialResults {
4
+ n: number;
5
+ avg_rt: number;
6
+ avg_acc: number;
7
+ }
8
+ interface NBackResults {
9
+ total_trials: NbackTrialResults;
10
+ target_trials: NbackTrialResults;
11
+ non_target_trials: NbackTrialResults;
12
+ performance: number;
13
+ }
14
+ declare const nback_results: (trials: any[]) => NBackResults;
15
+ export { nback_extract_trials, nback_results, nback_calculate_results, NBackResults };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nback_calculate_results = exports.nback_results = exports.nback_extract_trials = void 0;
4
+ // from the passed json extract those objects that have field is_target
5
+ var nback_calculate_results = function (obj) {
6
+ var trials = nback_extract_trials(obj);
7
+ return nback_results(trials);
8
+ };
9
+ exports.nback_calculate_results = nback_calculate_results;
10
+ var nback_extract_trials = function (obj) {
11
+ var trials = obj.filter(function (o) { return 'is_target' in o; });
12
+ return trials;
13
+ };
14
+ exports.nback_extract_trials = nback_extract_trials;
15
+ var nback_results = function (trials) {
16
+ var target_trials = trials.filter(function (o) { return o.is_target; });
17
+ var non_target_trials = trials.filter(function (o) { return !o.is_target; });
18
+ var results = {
19
+ total_trials: {
20
+ n: trials.length,
21
+ avg_rt: trials.reduce(function (a, b) { return a + b.rt; }, 0) / trials.length,
22
+ avg_acc: trials.reduce(function (a, b) { return a + b.correct; }, 0) / trials.length,
23
+ },
24
+ target_trials: {
25
+ n: target_trials.length,
26
+ avg_rt: target_trials.reduce(function (a, b) { return a + b.rt; }, 0) / target_trials.length,
27
+ avg_acc: target_trials.reduce(function (a, b) { return a + b.correct; }, 0) / target_trials.length,
28
+ },
29
+ non_target_trials: {
30
+ n: non_target_trials.length,
31
+ avg_rt: non_target_trials.reduce(function (a, b) { return a + b.rt; }, 0) / non_target_trials.length,
32
+ avg_acc: non_target_trials.reduce(function (a, b) { return a + b.correct; }, 0) / non_target_trials.length,
33
+ },
34
+ performance: NaN
35
+ };
36
+ results.performance = results.total_trials.avg_acc;
37
+ console.log(results);
38
+ return results;
39
+ };
40
+ exports.nback_results = nback_results;
@@ -0,0 +1,11 @@
1
+ interface SpatialResults {
2
+ n: number;
3
+ avg_rt: number;
4
+ avg_acc: number;
5
+ performance: number;
6
+ }
7
+ declare const spatial_calculate_results: (obj: any[]) => SpatialResults;
8
+ declare const spatial_extract_trials: (obj: any[]) => any[];
9
+ declare const spatial_results: (obj: any[]) => SpatialResults;
10
+ declare const spatial_extract_image_info: (obj: any[]) => any[];
11
+ export { spatial_extract_image_info, spatial_extract_trials, spatial_results, spatial_calculate_results, SpatialResults };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spatial_calculate_results = exports.spatial_results = exports.spatial_extract_trials = exports.spatial_extract_image_info = void 0;
4
+ var spatial_calculate_results = function (obj) {
5
+ var trials = spatial_extract_trials(obj);
6
+ return spatial_results(trials);
7
+ };
8
+ exports.spatial_calculate_results = spatial_calculate_results;
9
+ var spatial_extract_trials = function (obj) {
10
+ var trials = obj.filter(function (o) { return 'stimulus' in o &&
11
+ o.stimulus.startsWith("<img src="); });
12
+ trials = spatial_extract_image_info(trials);
13
+ return trials;
14
+ };
15
+ exports.spatial_extract_trials = spatial_extract_trials;
16
+ var spatial_results = function (obj) {
17
+ var results = {
18
+ n: obj.length,
19
+ avg_rt: obj.reduce(function (a, b) { return a + b.rt; }, 0) / obj.length,
20
+ avg_acc: obj.reduce(function (a, b) { return a + b.correct; }, 0) / obj.length,
21
+ performance: NaN
22
+ };
23
+ var best_score = 1000;
24
+ var worst_score = 10000;
25
+ // results.avg_acc to the power of 5
26
+ var performance = results.avg_rt / (Math.pow(results.avg_acc, 5) + 0.001);
27
+ if (performance < best_score) {
28
+ performance = best_score;
29
+ }
30
+ if (performance > worst_score) {
31
+ performance = worst_score;
32
+ }
33
+ // convert to 0-100 where 100 is the best (200)
34
+ results.performance = (1 - ((performance - best_score) / (worst_score - best_score))) * 100;
35
+ return results;
36
+ };
37
+ exports.spatial_results = spatial_results;
38
+ var spatial_extract_image_info = function (obj) {
39
+ // from the following field, extract the final image name (map_left_1_90.png), and rotation from the class attribute (rotate_0)
40
+ // "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\">",
41
+ obj.forEach(function (o) {
42
+ var _a, _b, _c, _d, _e;
43
+ // the image name is map_left_1_90.png
44
+ o.image = (_a = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)) === null || _a === void 0 ? void 0 : _a[0];
45
+ o.direction = (_b = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)) === null || _b === void 0 ? void 0 : _b[1];
46
+ o.distance = (_c = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)) === null || _c === void 0 ? void 0 : _c[2];
47
+ o.angle = (_d = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)) === null || _d === void 0 ? void 0 : _d[3];
48
+ o.rotation = (_e = o.stimulus.match(/rotate_(\d+)/)) === null || _e === void 0 ? void 0 : _e[1];
49
+ o.response = o.response === 1 ? "right" : "left";
50
+ o.correct = o.response === o.direction;
51
+ });
52
+ return obj;
53
+ };
54
+ exports.spatial_extract_image_info = spatial_extract_image_info;
@@ -0,0 +1,2 @@
1
+ declare function getBrowserInformation(data: any[]): any;
2
+ export { getBrowserInformation };
@@ -0,0 +1,20 @@
1
+ function getBrowserInformation(data) {
2
+ var browserInfo = data.find(function (row) { return row.trial_type === "browser-check"; });
3
+ if (!browserInfo) {
4
+ return null;
5
+ }
6
+ return {
7
+ os: browserInfo.os,
8
+ mobile: browserInfo.mobile,
9
+ fullscreen: browserInfo.fullscreen,
10
+ vsync_rate: browserInfo.vsync_rate,
11
+ webcam: browserInfo.webcam,
12
+ microphone: browserInfo.microphone,
13
+ browser: browserInfo.browser,
14
+ browser_version: browserInfo.browser_version,
15
+ webaudio: browserInfo.webaudio,
16
+ width: browserInfo.width,
17
+ height: browserInfo.height
18
+ };
19
+ }
20
+ export { getBrowserInformation };
@@ -0,0 +1,3 @@
1
+ declare const gonogo_calculate_results: (data: any) => void;
2
+ declare const gonogo_extract_trials: (data: any) => void;
3
+ declare const gonogo_results: (data: any) => void;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ // gonogo_create_trial_table <- function(txt) {
3
+ // arr <- fromJSON(txt)
4
+ // df <- as.data.frame(fromJSON(arr[[1]]))
5
+ // GONOGO_IMAGE_PATH <- "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/gonogo/"
6
+ // df <- filter(df, !is.na(image))
7
+ // df <- select(df, trial_index, time_elapsed, rt,
8
+ // response, block_number, image)
9
+ // df$image <- gsub(GONOGO_IMAGE_PATH, "", df$image)
10
+ // df$image <- gsub(".png", "", df$image)
11
+ // df <- df %>%
12
+ // mutate(
13
+ // should_go = case_when(
14
+ // block_number == 1 & grepl("astronaut_trans_1", image) ~ TRUE,
15
+ // block_number == 2 & grepl("alien_trans_1", image) ~ TRUE,
16
+ // block_number == 3 & grepl("rocket_trans_1", image) ~ TRUE,
17
+ // block_number == 4 & !grepl("rocket_trans_1", image) ~ TRUE,
18
+ // TRUE ~ FALSE),
19
+ // did_go = !is.na(response),
20
+ // correct = should_go == did_go
21
+ // )
22
+ // return(df)
23
+ // }
24
+ var gonogo_calculate_results = function (data) {
25
+ };
26
+ var gonogo_extract_trials = function (data) {
27
+ // GONOGO_IMAGE_PATH <- "https://unyavwofnmwihnpvkjji.supabase.co/storage/v1/object/public/test-stimuli/gonogo/"
28
+ };
29
+ var gonogo_results = function (data) {
30
+ };
@@ -0,0 +1,5 @@
1
+ import { NBackResults } from './nback';
2
+ import { SpatialResults } from './spatial-cognition';
3
+ declare const NbackResults: (obj: any[]) => NBackResults;
4
+ declare const SpatialCognitionResults: (obj: any[]) => SpatialResults;
5
+ export { NbackResults, SpatialCognitionResults };
@@ -0,0 +1,9 @@
1
+ import { nback_calculate_results } from './nback';
2
+ import { spatial_calculate_results } from './spatial-cognition';
3
+ var NbackResults = function (obj) {
4
+ return nback_calculate_results(obj);
5
+ };
6
+ var SpatialCognitionResults = function (obj) {
7
+ return spatial_calculate_results(obj);
8
+ };
9
+ export { NbackResults, SpatialCognitionResults };
@@ -0,0 +1,15 @@
1
+ declare const nback_calculate_results: (obj: any[]) => NBackResults;
2
+ declare const nback_extract_trials: (obj: any[]) => any[];
3
+ interface NbackTrialResults {
4
+ n: number;
5
+ avg_rt: number;
6
+ avg_acc: number;
7
+ }
8
+ interface NBackResults {
9
+ total_trials: NbackTrialResults;
10
+ target_trials: NbackTrialResults;
11
+ non_target_trials: NbackTrialResults;
12
+ performance: number;
13
+ }
14
+ declare const nback_results: (trials: any[]) => NBackResults;
15
+ export { nback_extract_trials, nback_results, nback_calculate_results, NBackResults };
@@ -0,0 +1,35 @@
1
+ // from the passed json extract those objects that have field is_target
2
+ var nback_calculate_results = function (obj) {
3
+ var trials = nback_extract_trials(obj);
4
+ return nback_results(trials);
5
+ };
6
+ var nback_extract_trials = function (obj) {
7
+ var trials = obj.filter(function (o) { return 'is_target' in o; });
8
+ return trials;
9
+ };
10
+ var nback_results = function (trials) {
11
+ var target_trials = trials.filter(function (o) { return o.is_target; });
12
+ var non_target_trials = trials.filter(function (o) { return !o.is_target; });
13
+ var results = {
14
+ total_trials: {
15
+ n: trials.length,
16
+ avg_rt: trials.reduce(function (a, b) { return a + b.rt; }, 0) / trials.length,
17
+ avg_acc: trials.reduce(function (a, b) { return a + b.correct; }, 0) / trials.length,
18
+ },
19
+ target_trials: {
20
+ n: target_trials.length,
21
+ avg_rt: target_trials.reduce(function (a, b) { return a + b.rt; }, 0) / target_trials.length,
22
+ avg_acc: target_trials.reduce(function (a, b) { return a + b.correct; }, 0) / target_trials.length,
23
+ },
24
+ non_target_trials: {
25
+ n: non_target_trials.length,
26
+ avg_rt: non_target_trials.reduce(function (a, b) { return a + b.rt; }, 0) / non_target_trials.length,
27
+ avg_acc: non_target_trials.reduce(function (a, b) { return a + b.correct; }, 0) / non_target_trials.length,
28
+ },
29
+ performance: NaN
30
+ };
31
+ results.performance = results.total_trials.avg_acc;
32
+ console.log(results);
33
+ return results;
34
+ };
35
+ export { nback_extract_trials, nback_results, nback_calculate_results };
@@ -0,0 +1,11 @@
1
+ interface SpatialResults {
2
+ n: number;
3
+ avg_rt: number;
4
+ avg_acc: number;
5
+ performance: number;
6
+ }
7
+ declare const spatial_calculate_results: (obj: any[]) => SpatialResults;
8
+ declare const spatial_extract_trials: (obj: any[]) => any[];
9
+ declare const spatial_results: (obj: any[]) => SpatialResults;
10
+ declare const spatial_extract_image_info: (obj: any[]) => any[];
11
+ export { spatial_extract_image_info, spatial_extract_trials, spatial_results, spatial_calculate_results, SpatialResults };
@@ -0,0 +1,48 @@
1
+ var spatial_calculate_results = function (obj) {
2
+ var trials = spatial_extract_trials(obj);
3
+ return spatial_results(trials);
4
+ };
5
+ var spatial_extract_trials = function (obj) {
6
+ var trials = obj.filter(function (o) { return 'stimulus' in o &&
7
+ o.stimulus.startsWith("<img src="); });
8
+ trials = spatial_extract_image_info(trials);
9
+ return trials;
10
+ };
11
+ var spatial_results = function (obj) {
12
+ var results = {
13
+ n: obj.length,
14
+ avg_rt: obj.reduce(function (a, b) { return a + b.rt; }, 0) / obj.length,
15
+ avg_acc: obj.reduce(function (a, b) { return a + b.correct; }, 0) / obj.length,
16
+ performance: NaN
17
+ };
18
+ var best_score = 1000;
19
+ var worst_score = 10000;
20
+ // results.avg_acc to the power of 5
21
+ var performance = results.avg_rt / (Math.pow(results.avg_acc, 5) + 0.001);
22
+ if (performance < best_score) {
23
+ performance = best_score;
24
+ }
25
+ if (performance > worst_score) {
26
+ performance = worst_score;
27
+ }
28
+ // convert to 0-100 where 100 is the best (200)
29
+ results.performance = (1 - ((performance - best_score) / (worst_score - best_score))) * 100;
30
+ return results;
31
+ };
32
+ var spatial_extract_image_info = function (obj) {
33
+ // from the following field, extract the final image name (map_left_1_90.png), and rotation from the class attribute (rotate_0)
34
+ // "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\">",
35
+ obj.forEach(function (o) {
36
+ var _a, _b, _c, _d, _e;
37
+ // the image name is map_left_1_90.png
38
+ o.image = (_a = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)) === null || _a === void 0 ? void 0 : _a[0];
39
+ o.direction = (_b = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)) === null || _b === void 0 ? void 0 : _b[1];
40
+ o.distance = (_c = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)) === null || _c === void 0 ? void 0 : _c[2];
41
+ o.angle = (_d = o.stimulus.match(/map_(left|right)_(\d+)_(\d+)\.png/)) === null || _d === void 0 ? void 0 : _d[3];
42
+ o.rotation = (_e = o.stimulus.match(/rotate_(\d+)/)) === null || _e === void 0 ? void 0 : _e[1];
43
+ o.response = o.response === 1 ? "right" : "left";
44
+ o.correct = o.response === o.direction;
45
+ });
46
+ return obj;
47
+ };
48
+ export { spatial_extract_image_info, spatial_extract_trials, spatial_results, spatial_calculate_results };