Changeset - 931d2dafca12
[Not reviewed]
default
0 3 0
drewp@bigasterisk.com - 9 years ago 2016-06-11 22:08:37
drewp@bigasterisk.com
new feature: values can have their range remapped in the device processing
Ignore-this: 542047e6307a304f2aa52a69d134ba21
3 files changed with 22 insertions and 1 deletions:
0 comments (0 inline, 0 general)
light9/collector/collector.py
Show inline comments
 
from __future__ import division
 
import time
 
import logging
 
from rdflib import Literal
 
from light9.namespaces import L9, RDF, DEV
 
from light9.collector.output import setListElem
 
from light9.collector.device import toOutputAttrs, resolve
 
@@ -42,10 +43,17 @@ class Collector(object):
 
    def rebuildOutputMap(self):
 
        self.outputMap = outputMap(self.graph, self.outputs) # (device, attr) : (output, index)
 
        self.deviceType = {} # uri: type that's a subclass of Device
 
        self.remapOut = {} # (device, deviceAttr) : (start, end)
 
        for dc in self.graph.subjects(RDF.type, L9['DeviceClass']):
 
            for dev in self.graph.subjects(RDF.type, dc):
 
                self.deviceType[dev] = dc
 

	
 
                for remap in self.graph.objects(dev, L9['outputAttrRange']):
 
                    attr = self.graph.value(remap, L9['outputAttr'])
 
                    start = float(self.graph.value(remap, L9['start']))
 
                    end = float(self.graph.value(remap, L9['end']))
 
                    self.remapOut[(dev, attr)] = start, end
 

	
 
    def _forgetStaleClients(self, now):
 
        staleClients = []
 
        for c, (_, t, _) in self.lastRequest.iteritems():
 
@@ -90,7 +98,9 @@ class Collector(object):
 
        prevClientSettings.update(self.resolvedSettingsDict(settings))
 
        self.lastRequest[client] = (clientSession, now, prevClientSettings)
 

	
 

	
 
        # inputs that are omitted, implying a zero, should be added
 
        # back here if they would remap to something nonzero.
 
        
 
        deviceAttrs = {} # device: {deviceAttr: value}
 
        for _, _, lastSettings in self.lastRequest.itervalues():
 
            for (device, deviceAttr), value in lastSettings.iteritems():
 
@@ -98,6 +108,9 @@ class Collector(object):
 
                if deviceAttr in attrs:
 
                    value = resolve(device, deviceAttr, [attrs[deviceAttr],
 
                                                         value])
 
                if (device, deviceAttr) in self.remapOut:
 
                    start, end = self.remapOut[(device, deviceAttr)]
 
                    value = Literal(start + float(value) * (end - start))
 
                attrs[deviceAttr] = value
 

	
 
        outputAttrs = {} # device: {outputAttr: value}
light9/collector/device.py
Show inline comments
 
@@ -58,6 +58,8 @@ def toOutputAttrs(deviceType, deviceAttr
 
    Given device attr settings like {L9['color']: Literal('#ff0000')},
 
    return a similar dict where the keys are output attrs (like
 
    L9['red']) and the values are suitable for Collector.setAttr
 

	
 
    :outputAttrRange happens before we get here.
 
    """
 
    def floatAttr(attr, default=0):
 
        out = deviceAttrSettings.get(attr)
show/dance2016/theaterLightConfig.n3
Show inline comments
 
@@ -21,8 +21,14 @@ dev:cycR a :SimpleDimmer; :dmxUniverse d
 
dev:cycL a :SimpleDimmer; :dmxUniverse dmxA:; :dmxBase 44 .
 

	
 
dev:q1 a :MacQuantum; :dmxUniverse udmxB:; :dmxBase 325 .
 
dev:q1 :outputAttrRange dev:q1rx . dev:q1rx :outputAttr :rx; :start 0.143; :end 0.271 .
 
dev:q1 :outputAttrRange dev:q1ry . dev:q1ry :outputAttr :ry; :start 0.71; :end 0.821 .
 
dev:q2 a :MacQuantum; :dmxUniverse udmxB:; :dmxBase 352 .
 
dev:q2 :outputAttrRange dev:q2rx . dev:q2rx :outputAttr :rx; :start 0.097; :end 0.227 .
 
dev:q2 :outputAttrRange dev:q2ry . dev:q2ry :outputAttr :ry; :start 0.739; :end 0.824 .
 
dev:q3 a :MacQuantum; :dmxUniverse udmxB:; :dmxBase 379 .
 
dev:q3 :outputAttrRange dev:q3rx . dev:q3rx :outputAttr :rx; :start 0.064; :end 0.198 .
 
dev:q3 :outputAttrRange dev:q3ry . dev:q3ry :outputAttr :ry; :start 0.765; :end 0.822 .
 

	
 
dev:aura1 a :MacAura; :dmxUniverse udmxB:; :dmxBase 406 .
 
dev:aura2 a :MacAura; :dmxUniverse udmxB:; :dmxBase 420 .
0 comments (0 inline, 0 general)