@decidables/detectable-elements 0.2.16 → 0.3.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.
@@ -4,10 +4,100 @@ import SDTMath from '@decidables/detectable-math';
4
4
  import SDTExample from './sdt-example';
5
5
 
6
6
  /*
7
- SDTExample_Interactive element
7
+ SDTExampleInteractive element
8
8
  <sdt-example-interactive>
9
9
  */
10
10
  export default class SDTExampleInteractive extends SDTExample {
11
+ static get properties() {
12
+ return {
13
+ color: {
14
+ attribute: 'color',
15
+ type: String,
16
+ reflect: true,
17
+ },
18
+ zRoc: {
19
+ attribute: 'z-roc',
20
+ type: Boolean,
21
+ reflect: true,
22
+ },
23
+
24
+ h: {
25
+ attribute: 'hits',
26
+ type: Number,
27
+ reflect: true,
28
+ },
29
+ m: {
30
+ attribute: 'misses',
31
+ type: Number,
32
+ reflect: true,
33
+ },
34
+ fa: {
35
+ attribute: 'false-alarms',
36
+ type: Number,
37
+ reflect: true,
38
+ },
39
+ cr: {
40
+ attribute: 'correct-rejections',
41
+ type: Number,
42
+ reflect: true,
43
+ },
44
+
45
+ hr: {
46
+ attribute: 'hr',
47
+ type: Number,
48
+ reflect: true,
49
+ },
50
+ far: {
51
+ attribute: 'far',
52
+ type: Number,
53
+ reflect: true,
54
+ },
55
+
56
+ d: {
57
+ attribute: 'd',
58
+ type: Number,
59
+ reflect: true,
60
+ },
61
+ c: {
62
+ attribute: 'c',
63
+ type: Number,
64
+ reflect: true,
65
+ },
66
+ s: {
67
+ attribute: 's',
68
+ type: Number,
69
+ reflect: true,
70
+ },
71
+ };
72
+ }
73
+
74
+ constructor() {
75
+ super();
76
+
77
+ this.color = 'all';
78
+ this.zRoc = false;
79
+
80
+ this.h = undefined;
81
+ this.m = undefined;
82
+ this.fa = undefined;
83
+ this.cr = undefined;
84
+
85
+ this.hr = undefined;
86
+ this.far = undefined;
87
+
88
+ this.d = SDTMath.d.DEFAULT;
89
+ this.c = SDTMath.c.DEFAULT;
90
+ this.s = SDTMath.s.DEFAULT;
91
+
92
+ this.detectableControl = null;
93
+ this.detectableTable = null;
94
+ this.rocSpace = null;
95
+ this.sdtModel = null;
96
+ this.sdtParameters = null;
97
+
98
+ this.rocSpaces = [];
99
+ }
100
+
11
101
  connectedCallback() {
12
102
  super.connectedCallback();
13
103
 
@@ -15,118 +105,166 @@ export default class SDTExampleInteractive extends SDTExample {
15
105
  this.detectableTable = this.querySelector('detectable-table');
16
106
  this.rocSpace = this.querySelector('roc-space');
17
107
  this.sdtModel = this.querySelector('sdt-model');
108
+ this.sdtParameters = this.querySelector('sdt-parameters');
18
109
 
19
110
  this.rocSpaces = this.querySelectorAll('roc-space');
20
111
 
21
- if (this.detectableControl && this.detectableControl.hasAttribute('color')) {
22
- this.detectableControl.addEventListener('detectable-control-color', (event) => {
23
- if (this.sdtModel) {
24
- this.sdtModel.color = event.detail.color;
25
- }
112
+ if (
113
+ this.h !== undefined
114
+ && this.m !== undefined
115
+ && this.fa !== undefined
116
+ && this.cr !== undefined
117
+ ) {
118
+ this.hr = SDTMath.hM2Hr(this.h, this.m);
119
+ this.far = SDTMath.faCr2Far(this.fa, this.cr);
26
120
 
27
- if (this.detectableTable) {
28
- this.detectableTable.color = event.detail.color;
29
- }
30
- });
121
+ this.d = SDTMath.hrFar2D(this.hr, this.far, this.s);
122
+ this.c = SDTMath.hrFar2C(this.hr, this.far, this.s);
123
+ } else if (this.hr !== undefined && this.far !== undefined) {
124
+ this.d = SDTMath.hrFar2D(this.hr, this.far, this.s);
125
+ this.c = SDTMath.hrFar2C(this.hr, this.far, this.s);
126
+ } else if (this.d !== undefined && this.c !== undefined) {
127
+ this.hr = SDTMath.dC2Hr(this.d, this.c, this.s);
128
+ this.far = SDTMath.dC2Far(this.d, this.c, this.s);
129
+
130
+ const total = 100;
131
+ this.h = Math.round(total * this.hr);
132
+ this.m = total - this.h;
133
+ this.fa = Math.round(total * this.far);
134
+ this.cr = total - this.fa;
31
135
  }
32
136
 
33
137
  if (this.detectableControl) {
138
+ this.detectableControl.addEventListener('detectable-control-color', (event) => {
139
+ this.color = event.detail.color;
140
+ });
141
+
34
142
  this.detectableControl.addEventListener('detectable-control-z-roc', (event) => {
35
- if (this.rocSpaces.length > 0) {
36
- this.rocSpaces.forEach((rocSpace) => {
37
- rocSpace.zRoc = event.detail.zRoc;
38
- });
39
- }
143
+ this.zRoc = event.detail.zRoc;
40
144
  });
41
145
  }
42
146
 
43
147
  if (this.detectableTable) {
44
- if (this.rocSpace) {
45
- this.rocSpace.hr = SDTMath.hM2Hr(this.detectableTable.h, this.detectableTable.m);
46
- this.rocSpace.far = SDTMath.faCr2Far(this.detectableTable.fa, this.detectableTable.cr);
47
- }
48
-
49
- if (this.sdtModel) {
50
- this.sdtModel.d = SDTMath.hrFar2D(
51
- SDTMath.hM2Hr(this.detectableTable.h, this.detectableTable.m),
52
- SDTMath.faCr2Far(this.detectableTable.fa, this.detectableTable.cr),
53
- this.sdtModel.s,
54
- );
55
- this.sdtModel.c = SDTMath.hrFar2C(
56
- SDTMath.hM2Hr(this.detectableTable.h, this.detectableTable.m),
57
- SDTMath.faCr2Far(this.detectableTable.fa, this.detectableTable.cr),
58
- this.sdtModel.s,
59
- );
60
- }
61
-
62
148
  this.detectableTable.addEventListener('detectable-table-change', (event) => {
63
- if (this.rocSpace) {
64
- this.rocSpace.far = event.detail.far;
65
- this.rocSpace.hr = event.detail.hr;
66
- }
67
-
68
- if (this.sdtModel) {
69
- this.sdtModel.d = SDTMath.hrFar2D(event.detail.hr, event.detail.far, this.sdtModel.s);
70
- this.sdtModel.c = SDTMath.hrFar2C(event.detail.hr, event.detail.far, this.sdtModel.s);
71
- }
149
+ this.h = event.detail.h;
150
+ this.m = event.detail.m;
151
+ this.fa = event.detail.fa;
152
+ this.cr = event.detail.cr;
153
+
154
+ this.far = event.detail.far;
155
+ this.hr = event.detail.hr;
156
+
157
+ this.d = SDTMath.hrFar2D(this.hr, this.far, this.s);
158
+ this.c = SDTMath.hrFar2C(this.hr, this.far, this.s);
72
159
  });
73
160
  }
74
161
 
75
162
  if (this.rocSpace) {
76
- if (this.sdtModel && !this.detectableTable) {
77
- this.sdtModel.d = SDTMath.hrFar2D(this.rocSpace.hr, this.rocSpace.far, this.rocSpace.s);
78
- this.sdtModel.c = SDTMath.hrFar2C(this.rocSpace.hr, this.rocSpace.far, this.rocSpace.s);
79
- this.sdtModel.s = this.rocSpace.s;
80
- }
81
-
82
163
  this.rocSpace.addEventListener('roc-point-change', (event) => {
83
- if (this.sdtModel) {
84
- this.sdtModel.d = event.detail.d;
85
- this.sdtModel.c = event.detail.c;
86
- this.sdtModel.s = event.detail.s;
87
- }
88
-
89
- if (this.detectableTable) {
90
- const newh = Math.round(
91
- (this.detectableTable.h + this.detectableTable.m) * event.detail.hr,
92
- );
93
- const newm = (this.detectableTable.h + this.detectableTable.m) - newh;
94
- const newfa = Math.round(
95
- (this.detectableTable.fa + this.detectableTable.cr) * event.detail.far,
96
- );
97
- const newcr = (this.detectableTable.fa + this.detectableTable.cr) - newfa;
98
- this.detectableTable.h = newh;
99
- this.detectableTable.m = newm;
100
- this.detectableTable.fa = newfa;
101
- this.detectableTable.cr = newcr;
102
- }
164
+ this.d = event.detail.d;
165
+ this.c = event.detail.c;
166
+ this.s = event.detail.s;
167
+
168
+ this.hr = event.detail.hr;
169
+ this.far = event.detail.far;
170
+
171
+ const newh = Math.round((this.h + this.m) * this.hr);
172
+ const newm = (this.h + this.m) - newh;
173
+ const newfa = Math.round((this.fa + this.cr) * this.far);
174
+ const newcr = (this.fa + this.cr) - newfa;
175
+ this.h = newh;
176
+ this.m = newm;
177
+ this.fa = newfa;
178
+ this.cr = newcr;
103
179
  });
104
180
  }
105
181
 
106
182
  if (this.sdtModel) {
107
183
  this.sdtModel.addEventListener('sdt-model-change', (event) => {
108
- if (this.rocSpaces.length > 0) {
109
- this.rocSpaces.forEach((rocSpace) => {
110
- rocSpace.setWithSDT(event.detail.d, event.detail.c, 'default', '', event.detail.s);
111
- });
112
- }
113
-
114
- if (this.detectableTable) {
115
- const newh = Math.round(
116
- (this.detectableTable.h + this.detectableTable.m) * event.detail.hr,
117
- );
118
- const newm = (this.detectableTable.h + this.detectableTable.m) - newh;
119
- const newfa = Math.round(
120
- (this.detectableTable.fa + this.detectableTable.cr) * event.detail.far,
121
- );
122
- const newcr = (this.detectableTable.fa + this.detectableTable.cr) - newfa;
123
- this.detectableTable.h = newh;
124
- this.detectableTable.m = newm;
125
- this.detectableTable.fa = newfa;
126
- this.detectableTable.cr = newcr;
127
- }
184
+ this.d = event.detail.d;
185
+ this.c = event.detail.c;
186
+ this.s = event.detail.s;
187
+
188
+ this.hr = event.detail.hr;
189
+ this.far = event.detail.far;
190
+
191
+ const newh = Math.round((this.h + this.m) * this.hr);
192
+ const newm = (this.h + this.m) - newh;
193
+ const newfa = Math.round((this.fa + this.cr) * this.far);
194
+ const newcr = (this.fa + this.cr) - newfa;
195
+ this.h = newh;
196
+ this.m = newm;
197
+ this.fa = newfa;
198
+ this.cr = newcr;
128
199
  });
129
200
  }
201
+
202
+ if (this.sdtParameters) {
203
+ this.sdtParameters.addEventListener('sdt-parameters-d', (event) => {
204
+ this.d = event.detail.d;
205
+ });
206
+
207
+ this.sdtParameters.addEventListener('sdt-parameters-c', (event) => {
208
+ this.c = event.detail.c;
209
+ });
210
+
211
+ this.sdtParameters.addEventListener('sdt-parameters-s', (event) => {
212
+ this.s = event.detail.s;
213
+ });
214
+ }
215
+ }
216
+
217
+ update(changedProperties) {
218
+ super.update(changedProperties);
219
+
220
+ if (this.detectableControl) {
221
+ this.detectableControl.color = (this.detectableControl.color != null)
222
+ ? this.color
223
+ : undefined;
224
+ this.detectableControl.zRoc = (this.detectableControl.zRoc != null)
225
+ ? this.zRoc
226
+ : undefined;
227
+ }
228
+
229
+ if (this.detectableTable) {
230
+ this.detectableTable.color = this.color;
231
+ this.detectableTable.h = this.h;
232
+ this.detectableTable.m = this.m;
233
+ this.detectableTable.cr = this.cr;
234
+ this.detectableTable.fa = this.fa;
235
+ }
236
+
237
+ if (this.rocSpace) {
238
+ this.rocSpace.hr = this.hr;
239
+ this.rocSpace.far = this.far;
240
+ }
241
+
242
+ if (this.sdtModel) {
243
+ this.sdtModel.color = this.color;
244
+
245
+ this.sdtModel.d = this.d;
246
+ this.sdtModel.c = this.c;
247
+ this.sdtModel.s = this.s;
248
+ }
249
+
250
+ if (this.rocSpaces.length > 0) {
251
+ this.rocSpaces.forEach((rocSpace) => {
252
+ rocSpace.zRoc = this.zRoc;
253
+ rocSpace.setWithSDT(this.d, this.c, 'default', '', this.s);
254
+ });
255
+ }
256
+
257
+ if (this.sdtParameters) {
258
+ this.sdtParameters.d = (this.sdtParameters.d != null)
259
+ ? this.d
260
+ : undefined;
261
+ this.sdtParameters.c = (this.sdtParameters.c != null)
262
+ ? this.c
263
+ : undefined;
264
+ this.sdtParameters.s = (this.sdtParameters.s != null)
265
+ ? this.s
266
+ : undefined;
267
+ }
130
268
  }
131
269
  }
132
270