-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathworker.coffee
164 lines (131 loc) · 4.03 KB
/
worker.coffee
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
Transformation = require("../components/transform/label.json")
FIT_LABEL = require('../../engine/labels.json').FIT_LABEL
CROSS_LABEL = require('../../engine/labels.json').CROSS_LABEL
VALIDATION_LABEL = require('../../engine/labels.json').VALIDATION_LABEL
SILENT_MESSAGE_TYPES = [ "progress" ]
class ME
constructor: ( ) ->
@listeners = { }
undefined
reset: ( ) ->
@listners = { }
on: ( target, listener ) ->
(@listeners[target] or= [ ]).push listener
undefined
fire: ( target, message ) ->
unless target in SILENT_MESSAGE_TYPES
console.debug "ME/fire", target
if listeners = @listeners[target]
for listener in listeners
listener.call this, message
undefined
# eventually have Adapter class extending ME
module.exports = new class WorkerAdapter extends ME
constructor: ( ) ->
super()
@worker = new Worker "engine-worker.js"
@worker.onerror = ( error ) =>
console.debug "Worker/res [error]", error
@fire "error", error
@worker.onmessage = ( { data: message } ) =>
if message._subworker
return
{ type, data } = message
unless type in SILENT_MESSAGE_TYPES
console.debug "Worker/res [#{type}]", data
@fire type, data
post: ( target, message ) ->
console.debug "Worker/req [#{target}]", message
@worker.postMessage({
type: target,
data: message
})
# Send data to engine-worker.js
stopCalc: ( ) ->
console.error("Stopped/cancelled calc");
@post "stopCalc"
sendPsig: ( x ) ->
console.debug("Sending PSIG" + x)
@post "sendPsig", x
setData: ( x, label ) ->
@post "setData", { data: x, label }
setExponents: ( x ) ->
@post "setExponents", x
setMultiplicands: ( x ) ->
@post "setMultiplicands", x
setDependent: ( x ) ->
@post "setDependent", x
setLags: ( x ) ->
@post "setLags", x
addTerm: ( x ) ->
@post "addTerm", x
removeTerm: ( x ) ->
@post "removeTerm", x
transformDelete: ( x ) ->
if x
@post("transformData", {
label: Transformation.Transform.delete,
index: x.index,
data_labels: x.labels || [FIT_LABEL, CROSS_LABEL, VALIDATION_LABEL]
})
transformLog: ( x ) ->
if x
@post("transformData", {
label: Transformation.Transform.log,
index: x.index,
data_labels: x.labels || [FIT_LABEL, CROSS_LABEL, VALIDATION_LABEL]
})
kOrderTransform: ( x ) ->
if x
@post("transformData", {
label: Transformation.Transform.k_order_diff,
index: x.index,
k: x.k,
data_labels: x.labels || [FIT_LABEL, CROSS_LABEL, VALIDATION_LABEL]
})
transformStandardize: ( x ) ->
if x
@post("transformData", {
label: Transformation.Transform.standardize,
index: x.index,
data_labels: x.labels || [FIT_LABEL, CROSS_LABEL, VALIDATION_LABEL]
})
transformRescale: ( x ) ->
if x
@post("transformData", {
label: Transformation.Transform.rescale,
index: x.index,
data_labels: x.labels || [FIT_LABEL, CROSS_LABEL, VALIDATION_LABEL]
})
requestStatisticsMetadata: ( ) ->
@post "getStatisticsMetadata"
subscribeToChanges: ( ) ->
@post "subscribeToChanges"
unsubscribeToChanges: ( ) ->
@post "unsubscribeToChanges"
getSensitivity: ( x ) ->
@post "getSensitivity", x
deleteSensitivity: ( x ) ->
@post "deleteSensitivity", x
updateSensitivity: ( x ) ->
@post "updateSensitivity", x
getConfidence: ( x ) ->
@post "getConfidence", x
deleteConfidence: ( x ) ->
@post "deleteConfidence", x
updateConfidence: ( x ) ->
@post "updateConfidence", x
getPrediction: ( x ) ->
@post "getPrediction", x
deletePrediction: ( x ) ->
@post "deletePrediction", x
updatePrediction: ( x ) ->
@post "updatePrediction", x
getImportanceRatio: ( x ) ->
@post "getImportanceRatio", x
deleteImportanceRatio: ( x ) ->
@post "deleteImportanceRatio", x
updateImportanceRatio: ( x ) ->
@post "updateImportanceRatio", x
clear: ( ) ->
@post "clear"