worker_specs

This commit is contained in:
merijn 2019-11-01 18:56:00 +01:00
parent 34199c394c
commit 9a1aa0312a

View file

@ -27,6 +27,7 @@ spec_names.forEach(function(name){
let request_time = timeStamp(), let request_time = timeStamp(),
hit_started = false,
elapsed_time, elapsed_time,
hit_finished = false hit_finished = false
@ -36,15 +37,6 @@ let request_time = timeStamp(),
let ws = new ReconnectingWebSocket('ws://localhost:8888/status/ws') let ws = new ReconnectingWebSocket('ws://localhost:8888/status/ws')
let test = `{"property": "os", "value": "213.127.20.197"}`
// fakeWs(test)
//
// function fakeWs(json){
//
//
// }
ws.addEventListener('open', () => { ws.addEventListener('open', () => {
// ws.send('hi server') // ws.send('hi server')
@ -56,14 +48,21 @@ ws.addEventListener('message', (event) => {
let data = JSON.parse(event.data) let data = JSON.parse(event.data)
if(data.property === 'hit_opened') { if(data.property === 'hit_opened') {
if(data.value != null){
hit_started = true
hit_finished = false hit_finished = false
request_time = timeStamp() request_time = timeStamp()
divs[data.property].innerHTML = `${request_time.format('dd mmm HH:MM:ss')}` divs[data.property].innerHTML = `${request_time.format('dd mmm HH:MM:ss')}`
}else{
hit_started = false
}
} }
else if(data.property === 'hit_submitted'){ else if(data.property === 'hit_submitted'){
hit_finished = true; hit_finished = true;
} }
else if(divs[data.property]) divs[data.property].innerHTML = `${data.value}` else if(divs[data.property]){
data.value === null ? divs[data.property].innerHTML = `—` : divs[data.property].innerHTML = `${data.value}`
}
}) })
@ -103,8 +102,11 @@ function makeAnimation(){
function update(step){ function update(step){
if(!hit_finished) elapsed_time = `${new Date((Date.now() - request_time)).format('MM"m "ss"s"')}` if(!hit_finished) elapsed_time = `${new Date((Date.now() - request_time)).format('MM"m "ss"s"')}`
if(hit_started){
divs['elapsed_time'].innerHTML = elapsed_time divs['elapsed_time'].innerHTML = elapsed_time
}else{
divs['elapsed_time'].innerHTML = `—`
}
} }
@ -112,3 +114,4 @@ makeAnimation()
function timeStamp(){return window.performance && window.performance.now ? window.performance.now() : new Date().getTime()} function timeStamp(){return window.performance && window.performance.now ? window.performance.now() : new Date().getTime()}