-
Notifications
You must be signed in to change notification settings - Fork 3
/
event.html
199 lines (193 loc) · 8.92 KB
/
event.html
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!--
Copyright 2018-2021 M. I. Bell
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/javascript">
RED.nodes.registerType('event',{
category: 'advanced',
color: '#AAAA66',
defaults: {
name: {value:""},
controlTopic: {value:"control"},
startCmd: {value:"start"},
stopCmd: {value:"stop"},
distribution: {value:"exponential"},
expMeanInterval: {value:1, validate:function(v){return v > 0}},
minInterval: {value:1, validate:function(v){return v > 0}},
maxInterval: {value:2, validate:function(v){return v > 0}},
gaussMeanInterval: {value:1, validate:function(v){return v > 0}},
stdDev: {value:1, validate:function(v){return v > 0}},
outputTopic: {value:"event"},
outputPayload: {validate:RED.validators.typedInput('outputPayloadType')},
outputPayloadType: {value:'date'},
maxEventCount: {value:0, validate:function(v){return Number.isInteger(Number(v))}}
},
inputs:1,
outputs:1,
icon: "arrow-out.png",
align: 'right',
paletteLabel: "event",
label: function() {
return this.name||"event";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
// var node = this
// configure event payload
$("#node-input-outputPayload").typedInput({
// type:"str",
default: 'date',
types: ['date','str','num','bool','json'],
typeField: $("#node-input-outputPayloadType")
});
// configure distribution parameters
$("#node-input-distribution").change(function() {
var distribution = $("#node-input-distribution").val();
switch (distribution) {
case "exponential":
$(".exponential-row").show();
$(".uniform-row").hide();
$(".gaussian-row").hide();
break;
case "uniform":
$(".exponential-row").hide();
$(".uniform-row").show();
$(".gaussian-row").hide();
break;
case "gaussian":
$(".exponential-row").hide();
$(".uniform-row").hide();
$(".gaussian-row").show();
break;
}
});
// configure version number
const version =
RED.nodes.registry.getModule("node-red-contrib-random-event-generator").version
$('#node-version').append(` ${version}`)
}
});
</script>
<script type="text/html" data-template-name="event">
<!-- controlTopic -->
<div class="form-row">
<label for="node-input-controlTopic"><i class="fa fa-cog"></i> Control Topic</label>
<input type="text" id="node-input-controlTopic" placeholder="control">
</div>
<br/>
<!-- commands -->
<div><b>Commands (case insensitive):</b></div>
<br/>
<div class="form-row">
<label for="node-input-startCmd" style = "width:auto"><i class="fa fa-play"></i> Start </label>
<input type="text" id="node-input-startCmd" placeholder="start" style="width:20%;">
<span>    </span>
<label for="node-input-stopCmd" style = "width:auto"><i class="fa fa-stop"></i> Stop </label>
<input type="text" id="node-input-stopCmd" placeholder="stop" style="width:20%;">
</div>
<div><i class="fa fa-arrows-v"></i>
Toggle: any payload other than a Start or Stop command
</div>
<!-- max event count -->
<div class="form-row">
<label for="node-input-maxEventCount" style = "width:auto"><i class="fa fa-exclamation-triangle"></i>
Stop after </label>
<input type="number" id="node-input-maxEventCount" placeholder="0" style="text-align:center; width:12%">
events (< 1, no limit)
<span>    </span>
</div>
<br/>
<!--distribution -->
<div><b>Distribution:</b></div>
<br/>
<div class="form-row">
<label for="node-input-distribution" style = "width:auto" ><i class="fa fa-area-chart"></i>
Type </label>
<select type="text" id="node-input-distribution" style="width:20%">
<option value="exponential">exponential</option>
<option value="uniform">uniform</option>
<option value="gaussian">gaussian</opton>
</select>
<!-- Exponential distribution: expMeanInterval-->
<span>    </span>
<span class="form-row exponential-row">
<label for="node-input-expMeanInterval" style="width:auto"><i class="fa fa-clock-o"></i>
Average interval </label>
<input type="number" id="node-input-expMeanInterval" placeholder="1" min = 0
style="text-align:center; width:10%"> seconds
</span>
</div>
<!--Uniform distribution: minInterval & maxInterval-->
<div class="form-row uniform-row">
<label for="node-input-minInterval" style="width:auto"><i class="fa fa-clock-o"></i>
Min interval </label>
<input type="number" id="node-input-minInterval" placeholder=1 min = 0
style="text-align:center; width:10%"> seconds
<span>    </span>
<label for="node-input-maxInterval" style="width:auto"><i class="fa fa-clock-o"></i>
Max interval </label>
<input type="number" id="node-input-maxInterval" placeholder=2 min = 0
style="text-align:center;width:10%"> seconds
</div>
<!-- Gaussian distribution: gaussMeanInterval and stdDev -->
<div class="form-row gaussian-row">
<label for="node-input-gaussMeanInterval" style="width:auto"><i class="fa fa-clock-o"></i>
Mean interval </label>
<input type="number" id="node-input-gaussMeanInterval" placeholder=1 min = 0
style="text-align:center; width:10%"> seconds
<span>    </span>
Standard deviation </label>
<input type="number" id="node-input-stdDev" placeholder=1 min = 0
style="text-align:center;width:10%"> seconds
</div>
<br/>
<div><b>Output:</b></div>
<br/>
<div class="form-row">
<label for="node-input-outputPayload"><i class="fa fa-envelope"></i> Payload</label>
<input type="text" id="node-input-outputPayload" style="width:70%">
<input type="hidden" id="node-input-outputPayloadType">
</div>
<div class="form-row">
<label for="node-input-outputTopic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-outputTopic" placeholder="event">
</div>
<br/>
<!-- Name & Version-->
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" style="width:50%">
<span>  </span>
<label id="node-version" style="width:auto" >Version</label>
</div>
</script>
<script type="text/html" data-help-name="event">
<p>Generates messages at random intervals.</p>
<h3>Details</h3>
<p>The interval between output messages is drawn from a random distribution that can
be selected to be exponential with a given average, uniform in a selected range, or
gaussian (normal) with specified mean and standard deviation.</p>
<p>Messages with the topic <code>Control Topic</code> are control messages, which start
or stop the generator or toggle its state. The generator can also be configured to stop after
a specified number of events.<p>
<p>The output messages have a user-defined topic and payload and two additional properties,
<code>msg.delay</code>, which is the time since the previous event, and <code>msg.count</code>,
which is the position of the event in the sequence sent since the generator was last started.
</p>
<h3>Examples</h3>
Flows illustrating the use of this node are provided in the <code>examples</code> tab
of the <span style="white-space:nowrap"><i class="fa fa-bars"></i> <b>Import</b></span>
sub-menu and can also be obtained from
<a href="https://github.com/drmibell/node-red-contrib-random-event-generator/tree/master/examples">
GitHub</a>.
</script>