Timeline now show pillows in order of light
This commit is contained in:
parent
e3481a58ad
commit
fe0b67aed4
2 changed files with 44 additions and 12 deletions
|
@ -293,6 +293,14 @@ def getVoiceHandler(voiceStorage):
|
||||||
self.finish()
|
self.finish()
|
||||||
return VoiceHandler
|
return VoiceHandler
|
||||||
|
|
||||||
|
class InfoHandler(tornado.web.RequestHandler):
|
||||||
|
def initialize(self, command):
|
||||||
|
self.command = command
|
||||||
|
|
||||||
|
async def get(self):
|
||||||
|
self.write(json.dumps(self.command.hugvey_ids))
|
||||||
|
|
||||||
|
|
||||||
class StaticFileWithHeaderHandler(tornado.web.StaticFileHandler):
|
class StaticFileWithHeaderHandler(tornado.web.StaticFileHandler):
|
||||||
def set_extra_headers(self, path):
|
def set_extra_headers(self, path):
|
||||||
"""For subclass to add extra headers to the response"""
|
"""For subclass to add extra headers to the response"""
|
||||||
|
@ -314,6 +322,7 @@ class Panopticon(object):
|
||||||
{"path": config['web']['files_dir']}),
|
{"path": config['web']['files_dir']}),
|
||||||
(r"/upload", getUploadHandler(self.command)),
|
(r"/upload", getUploadHandler(self.command)),
|
||||||
(r"/voice", getVoiceHandler(self.voiceStorage)),
|
(r"/voice", getVoiceHandler(self.voiceStorage)),
|
||||||
|
(r"/count", InfoHandler, {'command': self.command}),
|
||||||
(r"/(.*)", StaticFileWithHeaderHandler,
|
(r"/(.*)", StaticFileWithHeaderHandler,
|
||||||
{"path": web_dir, "default_filename": 'index.html'}),
|
{"path": web_dir, "default_filename": 'index.html'}),
|
||||||
], debug=True)
|
], debug=True)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
var ws = new ReconnectingWebSocket( window.location.origin.replace('http', 'ws') +'/ws', null, { debug: false, reconnectInterval: 3000 } );
|
var ws = new ReconnectingWebSocket( window.location.origin.replace('http', 'ws') +'/ws', null, { debug: false, reconnectInterval: 3000 } );
|
||||||
|
|
||||||
var seeme = true;
|
var seeme = true;
|
||||||
|
var tl ;
|
||||||
|
|
||||||
var error_audio = new Audio('siren.wav');
|
var error_audio = new Audio('siren.wav');
|
||||||
var playSoundOnError = true;
|
var playSoundOnError = true;
|
||||||
|
@ -34,6 +35,8 @@ class Timeline{
|
||||||
]);
|
]);
|
||||||
// console.log('init timeline');
|
// console.log('init timeline');
|
||||||
|
|
||||||
|
this.lightMap = {};
|
||||||
|
|
||||||
let groups = [];
|
let groups = [];
|
||||||
for(let hid = 1; hid<=this.count; hid++) {
|
for(let hid = 1; hid<=this.count; hid++) {
|
||||||
groups.push({id: parseInt(hid), content: 'Hugvey #'+hid});
|
groups.push({id: parseInt(hid), content: 'Hugvey #'+hid});
|
||||||
|
@ -107,12 +110,25 @@ class Timeline{
|
||||||
}
|
}
|
||||||
|
|
||||||
if(msg['action'] == 'status') {
|
if(msg['action'] == 'status') {
|
||||||
|
// reconstruct mapping of lights to hugveys
|
||||||
|
this.lightMap = {}
|
||||||
for(let hv of msg['hugveys']){
|
for(let hv of msg['hugveys']){
|
||||||
console.log(hv['language'], hv['status']);
|
if(!this.lightMap.hasOwnProperty(hv['light_id'])) {
|
||||||
let evenOdd = parseInt(hv['id'])%2 ? 'odd': 'even';
|
this.lightMap[hv['light_id']] = [];
|
||||||
|
}
|
||||||
|
this.lightMap[hv['light_id']].push(hv['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop over statusses of hugveys and show them at the appropriate lights
|
||||||
|
for(let hv of msg['hugveys']){
|
||||||
|
// console.log(hv['language'], hv['status']);
|
||||||
|
let evenOdd = parseInt(hv['light_id'])%2 ? 'odd': 'even';
|
||||||
let availableClass = hv['available'] ? 'is-available' : 'is-not-available';
|
let availableClass = hv['available'] ? 'is-available' : 'is-not-available';
|
||||||
let realHugveyId = hv['id'] == hv['light_id'] ? "" : `(#${hv['id']})`;
|
let realHugveyId = "";
|
||||||
this.dataGroups.update({id: parseInt(hv['id']), content: `<div class='title'>Hugvey ${hv['light_id']} ${realHugveyId}</div><div class='times'><span class='${hv['time_since_hugvey_spoke_state']}'>${hv['time_since_hugvey_spoke']}</span><span class='${hv['time_since_visitor_spoke_state']}'>${hv['time_since_visitor_spoke']}</span></div>`, className: `status-${hv['status']} ${availableClass} lang-${hv['language']} ${evenOdd}`})
|
if(this.lightMap[hv['light_id']].length > 1 || this.lightMap[hv['light_id']][0] != hv['light_id']) {
|
||||||
|
realHugveyId = '(#' + this.lightMap[hv['light_id']].join(' #') + ')';
|
||||||
|
}
|
||||||
|
this.dataGroups.update({id: parseInt(hv['light_id']), content: `<div class='title'>Hugvey ${hv['light_id']} ${realHugveyId}</div><div class='times'><span class='${hv['time_since_hugvey_spoke_state']}'>${hv['time_since_hugvey_spoke']}</span><span class='${hv['time_since_visitor_spoke_state']}'>${hv['time_since_visitor_spoke']}</span></div>`, className: `status-${hv['status']} ${availableClass} lang-${hv['language']} ${evenOdd}`})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +136,13 @@ class Timeline{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug(msg, this);
|
|
||||||
|
|
||||||
let hv_id = parseInt(msg['id']);
|
// let hv_id = parseInt(msg['id']);
|
||||||
|
let hv_machine_id = parseInt(msg['id']);
|
||||||
|
// map to light id:
|
||||||
|
let hv_id = Object.keys(this.lightMap).find(key => this.lightMap[key].indexOf(hv_machine_id) >= 0);
|
||||||
|
|
||||||
|
console.debug(msg, hv_id);
|
||||||
// {'action': 'log', 'id':hugvey_id, 'type': items[0], 'info', 'args'}
|
// {'action': 'log', 'id':hugvey_id, 'type': items[0], 'info', 'args'}
|
||||||
let d, parts;
|
let d, parts;
|
||||||
switch(msg['type']){
|
switch(msg['type']){
|
||||||
|
@ -135,11 +155,11 @@ class Timeline{
|
||||||
let msgContent = parts.join(' ');
|
let msgContent = parts.join(' ');
|
||||||
let mId = 'm-'+msgUuid+'-'+hv_id;
|
let mId = 'm-'+msgUuid+'-'+hv_id;
|
||||||
d = this.eventDataSet.get(mId);
|
d = this.eventDataSet.get(mId);
|
||||||
console.log(msgId, msgEvent, msgContent);
|
// console.log(msgId, msgEvent, msgContent);
|
||||||
if(d !== null && msgEvent == 'done'){
|
if(d !== null && msgEvent == 'done'){
|
||||||
d['end'] = new Date();
|
d['end'] = new Date();
|
||||||
this.eventDataSet.update(d);
|
this.eventDataSet.update(d);
|
||||||
console.log('update', d);
|
// console.log('update', d);
|
||||||
} else {
|
} else {
|
||||||
this.eventDataSet.add({id: mId, content: msgContent, title: `${msgContent} (${msgId})`, start: new Date(), end: new Date(Date.now()+5000), group: hv_id, 'className': 'message'});
|
this.eventDataSet.add({id: mId, content: msgContent, title: `${msgContent} (${msgId})`, start: new Date(), end: new Date(Date.now()+5000), group: hv_id, 'className': 'message'});
|
||||||
}
|
}
|
||||||
|
@ -158,13 +178,13 @@ class Timeline{
|
||||||
if(info.startsWith('content')){
|
if(info.startsWith('content')){
|
||||||
d = this.eventDataSet.get(scId);
|
d = this.eventDataSet.get(scId);
|
||||||
if(d !== null){
|
if(d !== null){
|
||||||
console.log('alter');
|
// console.log('alter');
|
||||||
d['content'] = content;
|
d['content'] = content;
|
||||||
d['end']= new Date();
|
d['end']= new Date();
|
||||||
d['title'] = content;
|
d['title'] = content;
|
||||||
this.eventDataSet.update(d);
|
this.eventDataSet.update(d);
|
||||||
} else {
|
} else {
|
||||||
console.log('add');
|
// console.log('add');
|
||||||
this.eventDataSet.add({id: scId, content: content, title: content, start: new Date(), end: new Date(Date.now() + 1000), group: hv_id, 'className': 'speech'});
|
this.eventDataSet.add({id: scId, content: content, title: content, start: new Date(), end: new Date(Date.now() + 1000), group: hv_id, 'className': 'speech'});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,12 +220,15 @@ class Timeline{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tl = new Timeline(ws, document.getElementById('line'), 29);
|
let req = new Request('/count');
|
||||||
|
fetch(req).then(response => response.json()).then(function(data) {
|
||||||
|
tl = new Timeline(ws, document.getElementById('line'), data.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener('keypress', function(e){
|
window.addEventListener('keypress', function(e){
|
||||||
console.log(e.keyCode)
|
// console.log(e.keyCode)
|
||||||
if(e.keyCode==46){
|
if(e.keyCode==46){
|
||||||
if(seeme){
|
if(seeme){
|
||||||
seeme = false;
|
seeme = false;
|
||||||
|
|
Loading…
Reference in a new issue