@decidables/accumulable-elements 0.1.3 → 0.2.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.
@@ -41,9 +41,9 @@ export default class DDMEquationAZV2PC extends DDMEquation {
41
41
 
42
42
  constructor() {
43
43
  super();
44
- this.a = 1.5;
45
- this.z = 0.5;
46
- this.v = 0.1;
44
+ this.a = DDMMath.a.DEFAULT;
45
+ this.z = DDMMath.z.DEFAULT;
46
+ this.v = DDMMath.v.DEFAULT;
47
47
  this.alignState();
48
48
  }
49
49
 
@@ -92,19 +92,46 @@ export default class DDMEquationAZV2PC extends DDMEquation {
92
92
  let s;
93
93
  let accuracy;
94
94
  if (this.numeric) {
95
- a = html`<decidables-spinner class="a bottom" ?disabled=${!this.interactive} min="0.1" max="2" step="0.01" .value="${this.a}" @input=${this.aInput.bind(this)}>
95
+ a = html`<decidables-spinner class="a bottom"
96
+ ?disabled=${!this.interactive}
97
+ min=${DDMMath.a.MIN}
98
+ max=${DDMMath.a.MAX}
99
+ step=${DDMMath.a.STEP}
100
+ .value=${this.a}
101
+ @input=${this.aInput.bind(this)}
102
+ >
96
103
  <var class="math-var">a</var>
97
104
  </decidables-spinner>`;
98
- z = html`<decidables-spinner class="z bottom" ?disabled=${!this.interactive} min="0.01" max="0.99" step="0.01" .value="${this.z}" @input=${this.zInput.bind(this)}>
105
+ z = html`<decidables-spinner class="z bottom"
106
+ ?disabled=${!this.interactive}
107
+ min=${DDMMath.z.MIN}
108
+ max=${DDMMath.z.MAX}
109
+ step=${DDMMath.z.STEP}
110
+ .value=${this.z}
111
+ @input=${this.zInput.bind(this)}
112
+ >
99
113
  <var class="math-var">z</var>
100
114
  </decidables-spinner>`;
101
- v = html`<decidables-spinner class="v bottom" ?disabled=${!this.interactive} min="0.01" max="5" step="0.01" .value="${this.v}" @input=${this.vInput.bind(this)}>
115
+ v = html`<decidables-spinner class="v bottom"
116
+ ?disabled=${!this.interactive}
117
+ min=${DDMMath.v.MIN}
118
+ max=${DDMMath.v.MAX}
119
+ step=${DDMMath.v.STEP}
120
+ .value=${this.v}
121
+ @input=${this.vInput.bind(this)}
122
+ >
102
123
  <var class="math-var">v</var>
103
124
  </decidables-spinner>`;
104
- s = html`<decidables-spinner class="s bottom" disabled min="0.01" max="1" step="0.01" .value="${DDMMath.s}">
125
+ s = html`<decidables-spinner class="s bottom"
126
+ disabled
127
+ .value=${DDMMath.s.DEFAULT}
128
+ >
105
129
  <var class="math-var">s</var>
106
130
  </decidables-spinner>`;
107
- accuracy = html`<decidables-spinner class="accuracy bottom" disabled min="0" max="1" step="0.01" .value="${+this.accuracy.toFixed(2)}">
131
+ accuracy = html`<decidables-spinner class="accuracy bottom"
132
+ disabled
133
+ .value=${+this.accuracy.toFixed(2)}
134
+ >
108
135
  <var>Accuracy</var>
109
136
  </decidables-spinner>`;
110
137
  } else {
@@ -46,10 +46,10 @@ export default class DDMEquationAZVT02M extends DDMEquation {
46
46
 
47
47
  constructor() {
48
48
  super();
49
- this.a = 1.5;
50
- this.z = 0.5;
51
- this.v = 0.1;
52
- this.t0 = 200;
49
+ this.a = DDMMath.a.DEFAULT;
50
+ this.z = DDMMath.z.DEFAULT;
51
+ this.v = DDMMath.v.DEFAULT;
52
+ this.t0 = DDMMath.t0.DEFAULT;
53
53
  this.alignState();
54
54
  }
55
55
 
@@ -106,22 +106,56 @@ export default class DDMEquationAZVT02M extends DDMEquation {
106
106
  let s;
107
107
  let meanRT;
108
108
  if (this.numeric) {
109
- a = html`<decidables-spinner class="a bottom" ?disabled=${!this.interactive} min="0.1" max="2" step="0.01" .value="${this.a}" @input=${this.aInput.bind(this)}>
109
+ a = html`<decidables-spinner class="a bottom"
110
+ ?disabled=${!this.interactive}
111
+ min=${DDMMath.a.MIN}
112
+ max=${DDMMath.a.MAX}
113
+ step=${DDMMath.a.STEP}
114
+ .value=${this.a}
115
+ @input=${this.aInput.bind(this)}
116
+ >
110
117
  <var class="math-var">a</var>
111
118
  </decidables-spinner>`;
112
- z = html`<decidables-spinner class="z bottom" ?disabled=${!this.interactive} min="0.01" max="0.99" step="0.01" .value="${this.z}" @input=${this.zInput.bind(this)}>
119
+ z = html`<decidables-spinner class="z bottom"
120
+ ?disabled=${!this.interactive}
121
+ min=${DDMMath.z.MIN}
122
+ max=${DDMMath.z.MAX}
123
+ step=${DDMMath.z.STEP}
124
+ .value=${this.z}
125
+ @input=${this.zInput.bind(this)}
126
+ >
113
127
  <var class="math-var">z</var>
114
128
  </decidables-spinner>`;
115
- v = html`<decidables-spinner class="v bottom" ?disabled=${!this.interactive} min="0.01" max="5" step="0.01" .value="${this.v}" @input=${this.vInput.bind(this)}>
129
+ v = html`<decidables-spinner class="v bottom"
130
+ ?disabled=${!this.interactive}
131
+ min=${DDMMath.v.MIN}
132
+ max=${DDMMath.v.MAX}
133
+ step=${DDMMath.v.STEP}
134
+ .value=${this.v}
135
+ @input=${this.vInput.bind(this)}
136
+ >
116
137
  <var class="math-var">v</var>
117
138
  </decidables-spinner>`;
118
- t0 = html`<decidables-spinner class="t0 bottom" ?disabled=${!this.interactive} min="0" max="500" step="1" .value="${this.t0}" @input=${this.t0Input.bind(this)}>
139
+ t0 = html`<decidables-spinner class="t0 bottom"
140
+ ?disabled=${!this.interactive}
141
+ min=${DDMMath.t0.MIN}
142
+ max=${DDMMath.t0.MAX}
143
+ step=${DDMMath.t0.STEP}
144
+ .value=${this.t0}
145
+ @input=${this.t0Input.bind(this)}
146
+ >
119
147
  <var class="math-var">t<sub>0</sub></var>
120
148
  </decidables-spinner>`;
121
- s = html`<decidables-spinner class="s bottom" disabled min="0.01" max="1" step="0.01" .value="${DDMMath.s}">
149
+ s = html`<decidables-spinner class="s bottom"
150
+ disabled
151
+ .value=${DDMMath.s.DEFAULT}
152
+ >
122
153
  <var class="math-var">s</var>
123
154
  </decidables-spinner>`;
124
- meanRT = html`<decidables-spinner class="mean-rt bottom" disabled min="0" max="1" step="0.01" .value="${+this.meanRT.toFixed(0)}">
155
+ meanRT = html`<decidables-spinner class="mean-rt bottom"
156
+ disabled
157
+ .value=${+this.meanRT.toFixed(0)}
158
+ >
125
159
  <var>Mean RT</var>
126
160
  </decidables-spinner>`;
127
161
  } else {
@@ -1,5 +1,5 @@
1
1
 
2
- // import DDMMath from '@decidables/accumulable-math';
2
+ import DDMMath from '@decidables/accumulable-math';
3
3
 
4
4
  import DDMExample from './ddm-example';
5
5
 
@@ -8,10 +8,75 @@ import DDMExample from './ddm-example';
8
8
  <ddm-example-human>
9
9
  */
10
10
  export default class DDMExampleHuman extends DDMExample {
11
+ static get properties() {
12
+ return {
13
+ trials: {
14
+ attribute: 'trials',
15
+ type: Number,
16
+ reflect: true,
17
+ },
18
+ duration: {
19
+ attribute: 'duration',
20
+ type: Number,
21
+ reflect: true,
22
+ },
23
+ coherence: {
24
+ attribute: 'coherence',
25
+ type: Number,
26
+ reflect: true,
27
+ },
28
+ color: {
29
+ attribute: 'color',
30
+ type: String,
31
+ reflect: true,
32
+ },
33
+
34
+ a: {
35
+ attribute: false,
36
+ type: Number,
37
+ reflect: false,
38
+ },
39
+ z: {
40
+ attribute: false,
41
+ type: Number,
42
+ reflect: false,
43
+ },
44
+ v: {
45
+ attribute: false,
46
+ type: Number,
47
+ reflect: false,
48
+ },
49
+ t0: {
50
+ attribute: false,
51
+ type: Number,
52
+ reflect: false,
53
+ },
54
+ };
55
+ }
56
+
11
57
  constructor() {
12
58
  super();
13
59
 
14
- this.trialCount = 0;
60
+ this.trials = 10;
61
+ this.duration = 2000;
62
+ this.coherence = 0.5;
63
+ this.colors = ['none', 'measure', 'outcome', 'all'];
64
+ this.color = 'outcome';
65
+
66
+ this.a = DDMMath.a.DEFAULT;
67
+ this.z = DDMMath.z.DEFAULT;
68
+ this.v = DDMMath.v.DEFAULT;
69
+ this.t0 = DDMMath.t0.DEFAULT;
70
+
71
+ this.accumulableControl = null;
72
+ this.rdkTask = null;
73
+ this.accumulableResponse = null;
74
+ this.accumulableTable = null;
75
+ this.ddmParameters = null;
76
+ this.ddmModel = null;
77
+ this.ddmFit = null;
78
+
79
+ this.data = undefined;
15
80
  }
16
81
 
17
82
  connectedCallback() {
@@ -28,61 +93,35 @@ export default class DDMExampleHuman extends DDMExample {
28
93
  // Initialize
29
94
  this.ddmModel.clear();
30
95
 
31
- if (this.accumulableControl && this.accumulableControl.hasAttribute('trials')) {
96
+ if (this.accumulableControl) {
32
97
  this.accumulableControl.addEventListener('accumulable-control-trials', (event) => {
33
- if (this.rdkTask) {
34
- this.rdkTask.trials = event.detail.trials;
35
- }
36
-
37
- if (this.accumulableResponse) {
38
- this.accumulableResponse.trialTotal = event.detail.trials;
39
- }
98
+ this.trials = event.detail.trials;
40
99
  });
41
- }
42
100
 
43
- if (this.accumulableControl && this.accumulableControl.hasAttribute('duration')) {
44
101
  this.accumulableControl.addEventListener('accumulable-control-duration', (event) => {
45
- if (this.rdkTask) {
46
- this.rdkTask.duration = event.detail.duration;
47
- this.rdkTask.wait = event.detail.duration;
48
- this.rdkTask.iti = event.detail.duration;
49
- }
102
+ this.duration = event.detail.duration;
50
103
  });
51
- }
52
104
 
53
- if (this.accumulableControl && this.accumulableControl.hasAttribute('coherence')) {
54
105
  this.accumulableControl.addEventListener('accumulable-control-coherence', (event) => {
55
- if (this.rdkTask) {
56
- this.rdkTask.coherence = event.detail.coherence;
57
- }
106
+ this.coherence = event.detail.coherence;
58
107
  });
59
- }
60
108
 
61
- if (this.accumulableControl && this.accumulableControl.hasAttribute('color')) {
62
109
  this.accumulableControl.addEventListener('accumulable-control-color', (event) => {
63
- if (this.accumulableTable) {
64
- this.accumulableTable.color = event.detail.color;
65
- }
110
+ this.color = event.detail.color;
66
111
  });
67
- }
68
112
 
69
- if (this.accumulableControl && this.accumulableControl.hasAttribute('run')) {
70
113
  this.accumulableControl.addEventListener('accumulable-control-run', (/* event */) => {
71
114
  if (this.rdkTask) {
72
115
  this.rdkTask.running = true;
73
116
  }
74
117
  });
75
- }
76
118
 
77
- if (this.accumulableControl && this.accumulableControl.hasAttribute('pause')) {
78
119
  this.accumulableControl.addEventListener('accumulable-control-pause', (/* event */) => {
79
120
  if (this.rdkTask) {
80
121
  this.rdkTask.running = false;
81
122
  }
82
123
  });
83
- }
84
124
 
85
- if (this.accumulableControl && this.accumulableControl.hasAttribute('reset')) {
86
125
  this.accumulableControl.addEventListener('accumulable-control-reset', (/* event */) => {
87
126
  if (this.rdkTask) {
88
127
  this.rdkTask.reset();
@@ -118,12 +157,6 @@ export default class DDMExampleHuman extends DDMExample {
118
157
  });
119
158
  }
120
159
 
121
- if (this.rdkTask) {
122
- if (this.accumulableResponse) {
123
- this.accumulableResponse.trialTotal = this.rdkTask.trials;
124
- }
125
- }
126
-
127
160
  if (this.rdkTask) {
128
161
  this.rdkTask.addEventListener('rdk-trial-start', (event) => {
129
162
  if (this.accumulableResponse) {
@@ -150,18 +183,7 @@ export default class DDMExampleHuman extends DDMExample {
150
183
 
151
184
  if (this.accumulableResponse) {
152
185
  this.accumulableResponse.addEventListener('accumulable-response', (event) => {
153
- if (this.accumulableTable) {
154
- this.accumulableTable.correctCount = event.detail.correctCount;
155
- this.accumulableTable.errorCount = event.detail.errorCount;
156
- this.accumulableTable.nrCount = event.detail.nrCount;
157
- this.accumulableTable.accuracy = event.detail.accuracy;
158
- this.accumulableTable.correctMeanRT = event.detail.correctMeanRT;
159
- this.accumulableTable.errorMeanRT = event.detail.errorMeanRT;
160
- this.accumulableTable.meanRT = event.detail.meanRT;
161
- this.accumulableTable.correctSDRT = event.detail.correctSDRT;
162
- this.accumulableTable.errorSDRT = event.detail.errorSDRT;
163
- this.accumulableTable.sdRT = event.detail.sdRT;
164
- }
186
+ this.data = event.detail.data;
165
187
 
166
188
  if (this.ddmModel) {
167
189
  this.ddmModel.trial({
@@ -173,36 +195,99 @@ export default class DDMExampleHuman extends DDMExample {
173
195
 
174
196
  if (this.ddmFit) {
175
197
  this.ddmFit.set({
176
- accuracy: event.detail.accuracy,
177
- correctMeanRT: event.detail.correctMeanRT,
178
- errorMeanRT: event.detail.errorMeanRT,
179
- meanRT: event.detail.meanRT,
180
- correctSDRT: event.detail.correctSDRT,
181
- errorSDRT: event.detail.errorSDRT,
182
- sdRT: event.detail.sdRT,
198
+ accuracy: event.detail.data.accuracy,
199
+ correctMeanRT: event.detail.data.correctMeanRT,
200
+ errorMeanRT: event.detail.data.errorMeanRT,
201
+ meanRT: event.detail.data.meanRT,
202
+ correctSDRT: event.detail.data.correctSDRT,
203
+ errorSDRT: event.detail.data.errorSDRT,
204
+ sdRT: event.detail.data.sdRT,
183
205
  });
184
206
  }
207
+
208
+ this.requestUpdate();
185
209
  });
186
210
  }
187
211
 
188
212
  if (this.ddmFit) {
189
213
  this.ddmFit.addEventListener('ddm-fit-update', (event) => {
190
- if (this.ddmParameters) {
191
- this.ddmParameters.a = event.detail.a;
192
- this.ddmParameters.z = 0.5; // event.detail.z;
193
- this.ddmParameters.v = event.detail.v;
194
- this.ddmParameters.t0 = event.detail.t0;
195
- }
196
-
197
- if (this.ddmModel) {
198
- this.ddmModel.a = event.detail.a;
199
- this.ddmModel.z = 0.5; // event.detail.z;
200
- this.ddmModel.v = event.detail.v;
201
- this.ddmModel.t0 = event.detail.t0;
202
- }
214
+ this.a = event.detail.a;
215
+ this.z = 0.5; // event.detail.z;
216
+ this.v = event.detail.v;
217
+ this.t0 = event.detail.t0;
203
218
  });
204
219
  }
205
220
  }
221
+
222
+ update(changedProperties) {
223
+ super.update(changedProperties);
224
+
225
+ if (this.accumulableControl) {
226
+ this.accumulableControl.trials = (this.accumulableControl.trials != null)
227
+ ? this.trials
228
+ : undefined;
229
+ this.accumulableControl.duration = (this.accumulableControl.duration != null)
230
+ ? this.duration
231
+ : undefined;
232
+ this.accumulableControl.coherence = (this.accumulableControl.coherence != null)
233
+ ? this.coherence
234
+ : undefined;
235
+ this.accumulableControl.color = (this.accumulableControl.color != null)
236
+ ? this.color
237
+ : undefined;
238
+ }
239
+
240
+ if (this.rdkTask) {
241
+ this.rdkTask.trials = this.trials;
242
+ this.rdkTask.duration = this.duration;
243
+ this.rdkTask.wait = this.duration;
244
+ this.rdkTask.iti = this.duration;
245
+ this.rdkTask.coherence = this.coherence;
246
+ }
247
+
248
+ if (this.ddmParameters) {
249
+ this.ddmParameters.a = (this.ddmParameters.a != null)
250
+ ? this.a
251
+ : undefined;
252
+ this.ddmParameters.z = (this.ddmParameters.z != null)
253
+ ? this.z
254
+ : undefined;
255
+ this.ddmParameters.v = (this.ddmParameters.a != null)
256
+ ? this.v
257
+ : undefined;
258
+ this.ddmParameters.t0 = (this.ddmParameters.t0 != null)
259
+ ? this.t0
260
+ : undefined;
261
+ }
262
+
263
+ if (this.ddmModel) {
264
+ this.ddmModel.a = +this.a;
265
+ this.ddmModel.z = +this.z;
266
+ this.ddmModel.v = +this.v;
267
+ this.ddmModel.t0 = +this.t0;
268
+ }
269
+
270
+ if (this.accumulableResponse) {
271
+ this.accumulableResponse.trialTotal = this.trials;
272
+ }
273
+
274
+ if (this.accumulableTable) {
275
+ this.accumulableTable.color = this.color;
276
+ }
277
+
278
+ if (this.accumulableTable && this.data) {
279
+ this.accumulableTable.correctCount = this.data.correctCount;
280
+ this.accumulableTable.errorCount = this.data.errorCount;
281
+ this.accumulableTable.nrCount = this.data.nrCount;
282
+ this.accumulableTable.accuracy = this.data.accuracy;
283
+ this.accumulableTable.correctMeanRT = this.data.correctMeanRT;
284
+ this.accumulableTable.errorMeanRT = this.data.errorMeanRT;
285
+ this.accumulableTable.meanRT = this.data.meanRT;
286
+ this.accumulableTable.correctSDRT = this.data.correctSDRT;
287
+ this.accumulableTable.errorSDRT = this.data.errorSDRT;
288
+ this.accumulableTable.sdRT = this.data.sdRT;
289
+ }
290
+ }
206
291
  }
207
292
 
208
293
  customElements.define('ddm-example-human', DDMExampleHuman);
@@ -1,4 +1,6 @@
1
1
 
2
+ import DDMMath from '@decidables/accumulable-math';
3
+
2
4
  import DDMExample from './ddm-example';
3
5
 
4
6
  /*
@@ -13,6 +15,11 @@ export default class DDMExampleInteractive extends DDMExample {
13
15
  type: Number,
14
16
  reflect: true,
15
17
  },
18
+ color: {
19
+ attribute: 'color',
20
+ type: String,
21
+ reflect: true,
22
+ },
16
23
  a: {
17
24
  attribute: 'boundary-separation',
18
25
  type: Number,
@@ -40,10 +47,13 @@ export default class DDMExampleInteractive extends DDMExample {
40
47
  super();
41
48
 
42
49
  this.trials = 10;
43
- this.a = 1.2;
44
- this.z = 0.35;
45
- this.v = 1.5;
46
- this.t0 = 150;
50
+ this.colors = ['none', 'measure', 'outcome', 'all'];
51
+ this.color = 'outcome';
52
+
53
+ this.a = DDMMath.a.DEFAULT;
54
+ this.z = DDMMath.z.DEFAULT;
55
+ this.v = DDMMath.v.DEFAULT;
56
+ this.t0 = DDMMath.t0.DEFAULT;
47
57
 
48
58
  this.accumulableControl = null;
49
59
  this.accumulableTable = null;
@@ -70,6 +80,9 @@ export default class DDMExampleInteractive extends DDMExample {
70
80
  this.accumulableControl.addEventListener('accumulable-control-trials', (event) => {
71
81
  this.trials = event.detail.trials;
72
82
  });
83
+ this.accumulableControl.addEventListener('accumulable-control-color', (event) => {
84
+ this.color = event.detail.color;
85
+ });
73
86
  }
74
87
 
75
88
  if (this.ddmParameters) {
@@ -114,7 +127,16 @@ export default class DDMExampleInteractive extends DDMExample {
114
127
  super.update(changedProperties);
115
128
 
116
129
  if (this.accumulableControl) {
117
- this.accumulableControl.trials = this.trials;
130
+ this.accumulableControl.trials = (this.accumulableControl.trials != null)
131
+ ? this.trials
132
+ : undefined;
133
+ this.accumulableControl.color = (this.accumulableControl.color != null)
134
+ ? this.color
135
+ : undefined;
136
+ }
137
+
138
+ if (this.accumulableTable) {
139
+ this.accumulableTable.color = this.color;
118
140
  }
119
141
 
120
142
  if (this.accumulableTable && this.data) {
@@ -131,10 +153,18 @@ export default class DDMExampleInteractive extends DDMExample {
131
153
  }
132
154
 
133
155
  if (this.ddmParameters) {
134
- this.ddmParameters.a = this.a;
135
- this.ddmParameters.z = this.z;
136
- this.ddmParameters.v = this.v;
137
- this.ddmParameters.t0 = this.t0;
156
+ this.ddmParameters.a = (this.ddmParameters.a != null)
157
+ ? this.a
158
+ : undefined;
159
+ this.ddmParameters.z = (this.ddmParameters.z != null)
160
+ ? this.z
161
+ : undefined;
162
+ this.ddmParameters.v = (this.ddmParameters.a != null)
163
+ ? this.v
164
+ : undefined;
165
+ this.ddmParameters.t0 = (this.ddmParameters.t0 != null)
166
+ ? this.t0
167
+ : undefined;
138
168
  }
139
169
 
140
170
  if (this.ddmModel) {