-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluationScene.ts
More file actions
79 lines (63 loc) · 2.13 KB
/
Copy pathevaluationScene.ts
File metadata and controls
79 lines (63 loc) · 2.13 KB
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
namespace micro_ml {
import Screen = user_interface_base.Screen
import Scene = user_interface_base.Scene
import AppInterface = user_interface_base.AppInterface
import font = user_interface_base.font
import Button = user_interface_base.Button
import CursorScene = user_interface_base.CursorScene
import Sensor = sensors.Sensor
const intraSampleFrequencyMS: number = 100;
const intraSampleQuantity: number = 10;
const sampleFrequencyMS: number = (intraSampleFrequencyMS * intraSampleFrequencyMS) - 1000 + 100;
export class EvaluationScene extends Scene {
private sensors: Sensor[];
private samplingIntervalID: number;
private lastSample: number[];
private lastNNPredLabel: string;
constructor(app: AppInterface) {
super(app);
}
startup() {
super.startup()
}
activate() {
super.activate()
const uBitSensors: sensors.MicrobitSensors[] = DatasetManager.getSensors();
this.sensors = uBitSensors.map(s => sensors.getMicrobitSensor(s));
this.samplingIntervalID = control.setInterval(
() => {
this.lastSample = sensors.getSamples(this.sensors, intraSampleQuantity, intraSampleFrequencyMS);
const pred = evaluate_nn(Buffer.fromArray(this.lastSample));
this.lastNNPredLabel = DatasetManager.getLabelNameFromPred(pred);
},
sampleFrequencyMS,
control.IntervalMode.Interval
);
}
deactivate(): void {
super.deactivate()
control.clearInterval(this.samplingIntervalID, control.IntervalMode.Interval)
}
draw() {
Screen.drawTransparentImage(
trainingSceneBackground,
-Screen.HALF_WIDTH,
-Screen.HALF_HEIGHT
);
const s: string = this.lastSample[0] + ", " + this.lastSample[1] + ", " + this.lastSample[2]
Screen.print(
s,
0 - (s.length * font.charWidth >> 1),
-20
)
if (this.lastNNPredLabel !== undefined) {
Screen.print(
this.lastNNPredLabel,
0 - (this.lastNNPredLabel.length * font.charWidth >> 1),
20
)
}
super.draw()
}
}
}