-
Notifications
You must be signed in to change notification settings - Fork 2
/
TrialHistoryController.j
81 lines (67 loc) · 2.46 KB
/
TrialHistoryController.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
This file is part of FrACT10, a vision test battery.
Copyright © 2021 Michael Bach, [email protected], <https://michaelbach.de>
TrialHistoryController.j
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import "Globals.j"
/**
2021-01-06 This class manages the FrACT10 trial history that collects the full run info
*/
@implementation TrialHistoryController: CPObject {
id _trialHistory;
int _currentIndex, _nTrials;
CPDate _dateStart;
float value @accessors;
int presented @accessors;
int responded @accessors;
BOOL correct @accessors;
CPString resultsHistoryString @accessors;
}
- (id) initWithNumTrials: (int) nTrials { //console.info("TrialHistoryController>initWithNumTrials");
self = [super init];
if (self) { // console.info("TrialHistory>initWithNumTrials: success");
_trialHistory = [];
_currentIndex = 0;
_nTrials = nTrials;
_dateStart = [CPDate date];
[self setResultsHistoryString: ""];
}
return self;
}
- (void) trialEnded { //console.info("TrialHistoryController>trialEnded, value: ", value);
if (_currentIndex > _nTrials) return; // just for safety, should not occur
_trialHistory[_currentIndex] = {};
_trialHistory[_currentIndex].value = value;
_trialHistory[_currentIndex].presented = presented;
_trialHistory[_currentIndex].responded = responded;
_trialHistory[_currentIndex].correct = correct;
_trialHistory[_currentIndex].reactionTimeInMs = Math.round(-[_dateStart timeIntervalSinceNow] * 1000.0);
_currentIndex++;
_dateStart = [CPDate date];
}
- (void) runEnded { //console.info("TrialHistoryController>trialEnded");
let s = "trial" + tab + "value" + tab + "choicePresented" + tab + "choiceResponded" + tab + "correct" + tab + "reactionTimeInMs" + crlf;
for (let i = 0; i < _trialHistory.length; ++i) {
const th = _trialHistory[i];
s += [Misc stringFromInteger: i + 1] + tab;
s += [Misc stringFromNumber: th.value decimals: 3 localised: YES] + tab;
s += th.presented + tab;
s += th.responded + tab;
s += th.correct + tab;
s += th.reactionTimeInMs + crlf;
}
[self setResultsHistoryString: s];
}
/**
Here we collect all info in a dataframe that is needed for the CI95 calculation
*/
- (id) composeInfo4CI {
const trialsDF = [];
for (const thi of _trialHistory) {
trialsDF.push({lMar: thi.value, correct: thi.correct});
}
return trialsDF;
}
@end