-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* internal/static: js cosmetics * internal/static: convert to ES6 modules * _example: ignore dev directory * _example: minor test log improvements * internal/static: in ui.js switch to const where possible * Update CHANGELOG.md
- Loading branch information
Showing
7 changed files
with
547 additions
and
605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,67 @@ | ||
(function() { | ||
function $(id) { | ||
return document.getElementById(id); | ||
} | ||
|
||
function buildWebsocketURI() { | ||
var loc = window.location, | ||
ws_prot = "ws:"; | ||
if (loc.protocol === "https:") { | ||
ws_prot = "wss:"; | ||
} | ||
return ws_prot + "//" + loc.host + loc.pathname + "ws" | ||
} | ||
import * as stats from './stats.js'; | ||
import * as ui from './ui.js'; | ||
|
||
const dataRetentionSeconds = 60; | ||
var timeout = 250; | ||
const $ = id => { | ||
return document.getElementById(id); | ||
} | ||
|
||
function clamp(val, min, max) { | ||
if (val < min) return min; | ||
if (val > max) return max; | ||
return val; | ||
const buildWebsocketURI = () => { | ||
var loc = window.location, | ||
ws_prot = "ws:"; | ||
if (loc.protocol === "https:") { | ||
ws_prot = "wss:"; | ||
} | ||
return ws_prot + "//" + loc.host + loc.pathname + "ws" | ||
} | ||
|
||
/* WebSocket connection handling */ | ||
const dataRetentionSeconds = 60; | ||
var timeout = 250; | ||
|
||
function connect() { | ||
let ws = new WebSocket(buildWebsocketURI()); | ||
console.log("Attempting websocket connection to statsviz server..."); | ||
const clamp = (val, min, max) => { | ||
if (val < min) return min; | ||
if (val > max) return max; | ||
return val; | ||
} | ||
|
||
ws.onopen = () => { | ||
console.log("Successfully connected"); | ||
timeout = 250; // reset connection timeout for next time | ||
}; | ||
/* WebSocket connection handling */ | ||
|
||
ws.onclose = event => { | ||
console.log("Closed websocket connection: ", event); | ||
setTimeout(connect, clamp(timeout += timeout, 250, 5000)); | ||
}; | ||
const connect = () => { | ||
let ws = new WebSocket(buildWebsocketURI()); | ||
console.log("Attempting websocket connection to statsviz server..."); | ||
|
||
ws.onerror = error => { | ||
console.log("Websocket error: ", error); | ||
ws.close(); | ||
}; | ||
ws.onopen = () => { | ||
console.log("Successfully connected"); | ||
timeout = 250; // reset connection timeout for next time | ||
}; | ||
|
||
var initDone = false; | ||
ws.onmessage = event => { | ||
let allStats = JSON.parse(event.data) | ||
if (!initDone) { | ||
stats.init(dataRetentionSeconds, allStats); | ||
stats.pushData(new Date(), allStats); | ||
initDone = true; | ||
let data = stats.slice(dataRetentionSeconds); | ||
ui.createPlots(data); | ||
return; | ||
} | ||
ws.onclose = event => { | ||
console.log("Closed websocket connection: ", event); | ||
setTimeout(connect, clamp(timeout += timeout, 250, 5000)); | ||
}; | ||
|
||
ws.onerror = error => { | ||
console.log("Websocket error: ", error); | ||
ws.close(); | ||
}; | ||
|
||
var initDone = false; | ||
ws.onmessage = event => { | ||
let allStats = JSON.parse(event.data) | ||
if (!initDone) { | ||
stats.init(dataRetentionSeconds, allStats); | ||
stats.pushData(new Date(), allStats); | ||
if (ui.isPaused()) { | ||
return | ||
} | ||
initDone = true; | ||
let data = stats.slice(dataRetentionSeconds); | ||
ui.updatePlots(data); | ||
ui.createPlots(data); | ||
return; | ||
} | ||
|
||
stats.pushData(new Date(), allStats); | ||
if (ui.isPaused()) { | ||
return | ||
} | ||
let data = stats.slice(dataRetentionSeconds); | ||
ui.updatePlots(data); | ||
} | ||
connect(); | ||
}()); | ||
} | ||
connect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,46 @@ | ||
// Buffer declares the Buffer class. | ||
var Buffer = (function() { | ||
class Buffer { | ||
constructor(len, cap) { | ||
if (cap - len < 0) { | ||
console.Error("cap - len must be positive"); | ||
} | ||
|
||
// TODO(arl): value using TypedArray rather than Array here | ||
this._buf = new Array(cap); | ||
this._pos = 0; | ||
this._len = len; | ||
this._cap = cap; | ||
export default class Buffer { | ||
constructor(len, cap) { | ||
if (cap - len < 0) { | ||
console.Error("cap - len must be positive"); | ||
} | ||
last() { | ||
if (this.length() == 0) { | ||
throw 'Cannot call last() on an empty Buffer'; | ||
} | ||
return this._buf[this._pos]; | ||
// TODO(arl): value using TypedArray rather than Array here | ||
this._buf = new Array(cap); | ||
this._pos = 0; | ||
this._len = len; | ||
this._cap = cap; | ||
} | ||
last() { | ||
if (this.length() == 0) { | ||
throw 'Cannot call last() on an empty Buffer'; | ||
} | ||
push(pt) { | ||
if (this._pos >= this._cap) { | ||
// move data to the beggining of the buffer, effectively discarding | ||
// the cap-len oldest elements | ||
this._buf.copyWithin(0, this._cap - this._len); | ||
this._pos = this._len; | ||
} | ||
|
||
this._buf[this._pos] = pt; | ||
this._pos++; | ||
return this._buf[this._pos]; | ||
} | ||
push(pt) { | ||
if (this._pos >= this._cap) { | ||
// move data to the beggining of the buffer, effectively discarding | ||
// the cap-len oldest elements | ||
this._buf.copyWithin(0, this._cap - this._len); | ||
this._pos = this._len; | ||
} | ||
length() { | ||
if (this._pos > this._len) { | ||
return this._len; | ||
} | ||
|
||
return this._pos; | ||
} | ||
// slice returns a slice of the len latest datapoints present in the buffer. | ||
slice(len) { | ||
// Cap the dimension of the returned slice to the data available | ||
if (len > this.length()) { | ||
len = this.length(); | ||
} | ||
|
||
let start = this._pos - len; | ||
return this._buf.slice(start, start + len); | ||
this._buf[this._pos] = pt; | ||
this._pos++; | ||
} | ||
length() { | ||
if (this._pos > this._len) { | ||
return this._len; | ||
} | ||
return this._pos; | ||
} | ||
|
||
// slice returns a slice of the len latest datapoints present in the buffer. | ||
slice(len) { | ||
// Cap the dimension of the returned slice to the data available | ||
if (len > this.length()) { | ||
len = this.length(); | ||
} | ||
|
||
return Buffer; | ||
}()); | ||
let start = this._pos - len; | ||
return this._buf.slice(start, start + len); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.