|
- // Interface for testing, provides testing data, and dynamic updates, etc.
-
- // WebSocket emulation class for testing
- function WebSocketTest(actions) {
- this.actions = actions.slice(); // copy
- this.actions.reverse()
- this.processNextItem()
- }
-
- // WebSocketTest.prototype.send = function ()
- // WebSocketTest.prototype.close = function ()
-
- // Internal
- WebSocketTest.prototype.processNextItem = function () {
- var item = this.actions.pop()
- if (item === undefined) {
- console.log("WebSocketTest finished running");
- return;
- }
-
- var wst = this;
- setTimeout(function() {
- item[1](wst);
- wst.processNextItem();
- }, item[0]);
-
- return this;
- }
-
- fakeData = [
- [ 1578544199000, 0.3934 ],
- [ 1578544209000, 0.4934 ],
- [ 1578544219000, 0.5234 ],
- [ 1578544229000, 0.4734 ],
- [ 1578544239000, 0.4334 ],
- [ 1578544249000, 0.2334 ],
- [ 1578544259000, 0.1034 ],
- [ 1578544269000, -0.4334 ],
- [ 1578544279000, -0.6334 ],
- [ 1578544289000, -0.2334 ],
- ]
-
- fakeConData = [
- [ 1578544199000, 0.3934 ],
- [ 1578544209000, 0.4934 ],
- [ 1578544219000, 0.5234 ],
- [ 1578544229000, 0.4734 ],
- [ 1578544239000, 0.4334 ],
- [ 1578544249000, 0.2334 ],
- [ 1578544259000, 0.1034 ],
- [ 1578544269000, 0.4334 ],
- [ 1578544279000, 0.6334 ],
- [ 1578544289000, 0.2334 ],
- ]
-
- fakeOverviewData = {
- grid: fakeData,
- consumption: fakeConData,
- production: fakeConData,
- }
-
-
- // Setup the socket that will be used
- var socket = new WebSocketTest([
- [ 10, function(a) { a.onopen(new Object()) } ],
- [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
- data : 'o ' + JSON.stringify(fakeOverviewData)
- })) } ],
- [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
- data : 'p .123'
- })) } ],
- [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
- data : 'c .302'
- })) } ],
- [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
- data : 'ng .758'
- })) } ],
- [ 2000, function(a) { a.onmessage(new MessageEvent('websockettest', {
- data : 'p .234'
- })) } ],
- [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
- data : 'ng -.584'
- })) } ],
- ]);
|