Changeset - c8cffe82b537
[Not reviewed]
default
0 4 0
Drew Perttula - 8 years ago 2017-05-19 07:33:11
drewp@bigasterisk.com
collector gui updates
Ignore-this: d8ab8247884e674a2332684297920c6a
4 files changed with 9 insertions and 2 deletions:
0 comments (0 inline, 0 general)
bin/collector
Show inline comments
 
@@ -42,59 +42,62 @@ def startZmq(port, collector):
 
            # front and then use small ints to refer to devices and
 
            # attributes in subsequent requests.
 
            client, clientSession, settings, sendTime = parseJsonMessage(message[0])
 
            collector.setAttrs(client, clientSession, settings, sendTime)
 
    s.onPull = onPull
 

	
 
class WebListeners(object):
 
    def __init__(self):
 
        self.clients = []
 

	
 
    def addClient(self, client):
 
        self.clients.append([client, {}])
 
        log.info('added client %s', client)
 

	
 
    def delClient(self, client):
 
        self.clients = [[c, t] for c, t in self.clients if c != client]
 
        log.info('delClient %s, %s left', client, len(self.clients))
 
        
 
    def outputAttrsSet(self, dev, attrs, outputMap):
 
        now = time.time()
 

	
 
        msg = self.makeMsg(dev, attrs, outputMap)
 
        
 
        for client, seen in self.clients:
 
            for m, t in seen.items():
 
                if t < now - 5:
 
                    del seen[m]
 
            if msg in seen:
 
                continue
 
            seen[msg] = now
 
            client.sendMessage(msg)
 

	
 
    def makeMsg(self, dev, attrs, outputMap):
 
        attrRows = []
 
        for attr, val in attrs.items():
 
            output, index = outputMap[(dev, attr)]
 
            attrRows.append({'attr': attr.rsplit('/')[-1],
 
                             'val': val,
 
                             'chan': (output.shortId(), index)})
 
                             'chan': (output.shortId(), index + 1)})
 
        attrRows.sort(key=lambda r: r['chan'])
 
        for row in attrRows:
 
            row['chan'] = '%s %s' % (row['chan'][0], row['chan'][1])
 

	
 
        msg = json.dumps({'outputAttrsSet': {'dev': dev, 'attrs': attrRows}}, sort_keys=True)
 
        return msg
 
    
 
class Updates(cyclone.websocket.WebSocketHandler):
 

	
 
    def connectionMade(self, *args, **kwargs):
 
        log.info('socket connect %s', self)
 
        self.settings.listeners.addClient(self)
 

	
 
    def connectionLost(self, reason):
 
        self.settings.listeners.delClient(self)
 

	
 
    def messageReceived(self, message):
 
        json.loads(message)
 

	
 
stats = scales.collection('/webServer', scales.PmfStat('setAttr'))
 

	
 
class Attrs(PrettyErrorHandler, cyclone.web.RequestHandler):
 
    def put(self):
bin/homepageConfig
Show inline comments
 
@@ -19,24 +19,25 @@ print "listen %s;" % splitport(urlparse(
 

	
 
def location(path, server):
 
    print """
 
    location /%(path)s/ {
 

	
 
      # for websocket
 
      proxy_http_version 1.1;
 
      proxy_set_header Upgrade $http_upgrade;
 
      proxy_set_header Connection "upgrade";
 
      proxy_set_header Host $host;
 

	
 
      proxy_pass %(server)s;
 
      proxy_buffering off;
 
      rewrite /[^/]+/(.*) /$1 break;
 
    }""" % vars()
 

	
 
for role, server in sorted(graph.predicate_objects(netHome)):
 
    if not server.startswith('http') or role == L9['webServer']:
 
        continue
 
    path = graph.value(role, L9['urlPath'])
 
    if not path:
 
        continue
 
    server = server.rstrip('/')
 
    location(path, server)
 

	
light9/collector/web/index.html
Show inline comments
 
@@ -3,24 +3,27 @@
 
  <head>
 
    <title>collector</title>
 
    <meta charset="utf-8" />
 
    <script src="/lib/webcomponentsjs/webcomponents-lite.min.js"></script>
 
    <link rel="import" href="/lib/polymer/polymer.html">
 
    <link rel="import" href="/lib/iron-ajax/iron-ajax.html">
 
    <link rel="import" href="../rdfdb-synced-graph.html">
 
    <script src="/lib/N3.js-pull61/browser/n3-browser.js"></script>
 
    <script src="/lib/async/dist/async.js"></script>
 
    <script src="/lib/underscore/underscore-min.js"></script>
 

	
 
    <link rel="stylesheet"  href="/style.css">
 
    <style>
 
     td { white-space: nowrap; }
 
    </style>
 
  </head>
 
  <body>
 

	
 
    <dom-module id="light9-collector-device">
 
      <template>
 
        <style>
 
         :host {
 
             display: block;
 
             break-inside: avoid-column;
 
         }
 
         td.nonzero {
 
             background: #310202;
makefile
Show inline comments
 
NOSEARGS="--no-path-adjustment light9.rdfdb.rdflibpatch light9.rdfdb.patch light9.effecteval.test_effect light9.collector light9.rdfdb.graphfile_test light9.paint"
 
NOSEARGS="--no-path-adjustment light9.rdfdb.rdflibpatch light9.rdfdb.patch light9.effecteval.test_effect light9.collector light9.rdfdb.graphfile_test light9.paint light9.effect"
 

	
 
tests:
 
	eval env/bin/nosetests -x $(NOSEARGS)
 

	
 
tests_watch:
 
	eval env/bin/nosetests --with-watcher $(NOSEARGS)
 

	
 

	
 
tests_coverage:
 
	eval env/bin/nosetests --with-coverage --cover-erase --cover-html --cover-html-dir=/tmp/light9-cov/  --cover-package=light9 --cover-branches $(NOSEARGS)
 

	
 
test_js_init:
0 comments (0 inline, 0 general)