-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
264 lines (264 loc) · 13.8 KB
/
test.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<section class="suite">
<h1>Authentication API</h1>
<dl>
<dt class="error">Sign-up</dt>
<dd class="error"><pre><code>var user = { username: "test", name: "Test User", password: "test1234", email: "[email protected]" };
request({ uri: baseurl + '/signup', method: 'POST', agentOptions: options, json: user }, function (error, response, body) {
expect(error).to.not.exists;
expect(response).to.exists;
expect(response.statusCode).to.equal(200);
done(error);
})</code></pre></dd>
<dd class="error">AssertionError: expected 400 to equal 200</dd>
<dt>Login</dt>
<dd><pre><code>var user = { username: "test", password: "test1234" };
request({ uri: baseurl + '/login', method: 'POST', agentOptions: options, json: user }, function (error, response, body) {
expect(error).to.not.exists;
expect(response).to.exists;
expect(response.statusCode).to.equal(200);
expect(response.body.token).to.exist();
expect(response.body.profile._id).to.equal(user.username);
done(error);
})</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>Time Series API</h1>
<dl>
<dt>Store</dt>
<dd><pre><code>var timeseries = { base: "2015-01-01T00:00+01:00", interval: "1h", vector: vector };
var url = baseurl + '/timeseries/' + id + '/timeseries'; // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.not.exists;
expect(response).to.exists;
expect(response.statusCode).to.equal(200);
done(error);
}
request({ uri: url, method: 'PUT', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Retrieve</dt>
<dd><pre><code>var timeseries = { base: "2015-01-01T00:00+01:00", interval: "1h", vector: vector };
var url = baseurl + '/timeseries/' + id + '/timeseries'; // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.not.exists;
expect(response).to.exists;
expect(response.statusCode).to.equal(200);
expect(body).to.deep.equal(timeseries);
done(error);
}
request({ uri: url, method: 'GET', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Retrieve Part</dt>
<dd><pre><code>var vector1 = [vector[0], vector[1]];
var timeseries = { base: "2015-01-01T00:00:00+01:00", interval: "1h", vector: vector1 };
var from = "2015-01-01T00:00:00+01:00"
var to = "2015-01-01T01:00:00+01:00"
var url = baseurl + '/timeseries/' + id + '/timeseries' + '?from=' + encodeURIComponent(from) + '&to=' + encodeURIComponent(to); // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.not.exists;
expect(response).to.exists;
expect(response.statusCode).to.equal(200);
expect(body).to.deep.equal(timeseries);
done(error);
}
request({ uri: url, method: 'GET', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Pad Emptiness</dt>
<dd><pre><code>var vector1 = [null, null].concat(vector).concat([null, null]);
var timeseries = { base: "2014-12-31T22:00:00+01:00", interval: "1h", vector: vector1 };
var from = "2014-12-31T22:00:00+01:00"
var to = "2015-01-01T05:00:00+01:00"
var url = baseurl + '/timeseries/' + id + '/timeseries' + '?from=' + encodeURIComponent(from) + '&to=' + encodeURIComponent(to); // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.not.exists;
expect(response).to.exists;
expect(response.statusCode).to.equal(200);
expect(body).to.deep.equal(timeseries);
done(error);
}
request({ uri: url, method: 'GET', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Overwrite</dt>
<dd><pre><code>var timeseries = { base: "2015-01-01T03:00+01:00", interval: "1h", vector: vector };
var url = baseurl + '/timeseries/' + id + '/timeseries'; // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.not.exists;
expect(response).to.exists;
expect(response.statusCode).to.equal(200);
done(error);
}
request({ uri: url, method: 'PUT', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Retrieve Again</dt>
<dd><pre><code>var timeseries = { base: "2015-01-01T00:00+01:00", interval: "1h", vector: vector.concat(vector) };
var url = baseurl + '/timeseries/' + id + '/timeseries'; // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.not.exists;
expect(response).to.exists;
expect(response.statusCode).to.equal(200);
expect(body).to.deep.equal(timeseries);
done(error);
}
request({ uri: url, method: 'GET', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Reject Incomplete</dt>
<dd><pre><code>var timeseries = { };
var url = baseurl + '/timeseries/' + id + '/timeseries'; // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.exists;
expect(response).to.exists;
expect(response.statusCode).to.not.equal(200);
done();
}
request({ uri: url, method: 'PUT', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Reject Base</dt>
<dd><pre><code>var timeseries = { base: "2 september 2015 om 15 over 12", interval: "1h", vector: vector };
var url = baseurl + '/timeseries/' + id + '/timeseries'; // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.exists;
expect(response).to.exists;
expect(response.statusCode).to.not.equal(200);
done();
}
request({ uri: url, method: 'PUT', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Reject Interval</dt>
<dd><pre><code>var timeseries = { base: "2015-01-01T00:00+01:00", interval: "2h", vector: vector };
var url = baseurl + '/timeseries/' + id + '/timeseries'; // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.exists;
expect(response).to.exists;
expect(response.statusCode).to.not.equal(200);
done();
}
request({ uri: url, method: 'PUT', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Reject Vector</dt>
<dd><pre><code>var timeseries = { base: "2015-01-01T00:00+01:00", interval: "1h", vector: [] };
var url = baseurl + '/timeseries/' + id + '/timeseries'; // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.exists;
expect(response).to.exists;
expect(response.statusCode).to.not.equal(200);
done();
}
request({ uri: url, method: 'PUT', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
<dt>Remove</dt>
<dd><pre><code>var timeseries = { base: "2015-01-01T00:00+01:00", interval: "1h", vector: vector };
var url = baseurl + '/timeseries/' + id + '/timeseries'; // + '/timeseries/timeseries';
var callback = function (error, response, body) {
expect(error).to.not.exists;
expect(response).to.exists;
expect(response.statusCode).to.equal(200);
done(error);
}
request({ uri: url, method: 'DELETE', agentOptions: options, json: timeseries }, callback)</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>Timeseries Library</h1>
<dl>
<section class="suite">
<h1>#overlay()</h1>
<dl>
<dt>should overwrite data points at correct location in vector</dt>
<dd><pre><code>var ts0 = { "base" : "2013-01-01T00:00:00+01:00", "interval" : "1h", "vector" : [ 1, 1, 1, 1 ] };
var ts1 = { "base" : "2013-01-01T02:00:00+01:00", "interval" : "1h", "vector" : [ 2, 2, 2, 2 ] };
var ts = new Timeseries(ts0).overlay(ts1);
ts.vector.toString().should.equal("1,1,2,2,2,2");</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>#isValid()</h1>
<dl>
<dt>should test if object is valid timeseries</dt>
<dd><pre><code>var ts = new Timeseries({ base: '2014-01-01T00:00+01:00', interval: '15m', vector: [1,2,3,4] });
ts.isValid().should.be.ok;</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>#length()</h1>
<dl>
<dt>should calculate correct hourly length</dt>
<dd><pre><code>Timeseries.prototype.length("2003-12-31T00:00+01:00", "2004-01-01T00:00+01:00", "1h").should.equal(25);</code></pre></dd>
<dt>should calculate correct hourly uneven-minute length</dt>
<dd><pre><code>Timeseries.prototype.length("2003-12-31T00:00+01:00", "2004-01-01T23:59+01:00", "1h").should.equal(48);</code></pre></dd>
<dt>should calculate correct zero length</dt>
<dd><pre><code>Timeseries.prototype.length("2004-02-01T00:00+01:00", "2004-01-01T00:00+01:00", "1h").should.equal(0);</code></pre></dd>
<dt>should calculate correct hourly uneven-minute length (2)</dt>
<dd><pre><code>Timeseries.prototype.length("2004-02-01T00:00+01:00", "2004-02-01T23:59+01:00", "1h").should.equal(24);</code></pre></dd>
<dt>should calculate correct 6 hourly length</dt>
<dd><pre><code>Timeseries.prototype.length("2014-01-01T00:00+01:00", "2014-01-01T23:59+01:00", "6h").should.equal(4);</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>#slice()</h1>
<dl>
<dt>calculate correct slice of array</dt>
<dd><pre><code>var ts = new Timeseries({ id: "ts", base: "2014-01-01T00:00+01:00", interval: "1d", vector: [1,2,3] })
ts.slice("2013-12-31", "2014-01-02").toString().should.equal("0,2");</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>#roundUp()</h1>
<dl>
<dt>should correctly round up to nearest interval</dt>
<dd><pre><code>var base = "2014-01-01T" + "00:01:00" + "+01:00";
var interval = '4m';
var date = "2013-01-04T" + "00:04:00" + "+01:00";
var ts = new Timeseries({base:base, interval:interval, vector:[]});
moment("2013-01-04T00:05:00+01:00").isSame(ts.roundUp(date)).should.be.ok;</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>#roundDown()</h1>
<dl>
<dt>should correctly round down to nearest interval</dt>
<dd><pre><code>var base = "2014-01-01T" + "00:01:00" + "+01:00";
var interval = '4m';
var date = "2013-01-04T" + "00:04:00" + "+01:00";
var ts = new Timeseries({base:base, interval:interval, vector:[]});
moment("2013-01-04T00:01:00+01:00").isSame(ts.roundDown(date)).should.be.ok;</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>#toCSV()</h1>
<dl>
<dt>should export correct CSV text in 15min interval</dt>
<dd><pre><code>var base = "2014-01-01T00:00:00+01:00";
var interval = '15m';
var ts = new Timeseries({base:base, interval:interval, vector:[1,2,3]});
ts.toCSV().should.equal("2014-01-01T00:00:00+01:00,1\n2014-01-01T00:15:00+01:00,2\n2014-01-01T00:30:00+01:00,3");</code></pre></dd>
<dt>should export correct CSV text in hourly interval</dt>
<dd><pre><code>var base = "2014-01-01T00:00:00+01:00";
var interval = '1h';
var ts = new Timeseries({base:base, interval:interval, vector:[1,2,3]});
ts.toCSV().should.equal("2014-01-01T00:00:00+01:00,1\n2014-01-01T01:00:00+01:00,2\n2014-01-01T02:00:00+01:00,3");</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>#reconstruct()</h1>
<dl>
<dt>should reconstruct timeseries vector from all changes</dt>
<dd><pre><code>var ts0 = new Timeseries({
base: "2015-01-01T00:00+01:00",
interval: "15m",
vector: []
});
ts0.change({ base: "2015-01-01T00:00+01:00", interval: "1m", vector: [ 0, 1, 2, 3, 4 ] });
ts0.change({ base: "2015-01-01T00:05+01:00", interval: "1m", vector: [ 5, 6, 7, 8, 9 ] });
ts0.change({ base: "2015-01-01T00:10+01:00", interval: "1m", vector: [10, 11, 12, 13, 14 ] });
ts0.reconstruct()
moment(ts0.base).isSame('2015-01-01T00:00+01:00').should.be.ok;
ts0.interval.should.equal('1m')
ts0.vector.join(',').should.equal([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ].join(','));</code></pre></dd>
</dl>
</section>
<section class="suite">
<h1>#pad()</h1>
<dl>
<dt>should padd timeseries with null value over a period</dt>
<dd><pre><code>var ts0 = new Timeseries({
base: "2015-01-01T00:00+01:00",
interval: "1h",
vector: [1,2,3]
});
var ts1 = ts0.pad("2014-12-31T22:00+01:00", "2015-01-01T05:00+01:00")
expect(ts1.vector).to.deep.equal([NaN, NaN, 1, 2, 3, NaN, NaN]);
expect(ts1.vector.length).to.equal(7);</code></pre></dd>
</dl>
</section>
</dl>
</section>