Changeset - 091909b4b727
[Not reviewed]
default
0 3 1
drewp@bigasterisk.com - 20 months ago 2023-05-22 08:08:31
drewp@bigasterisk.com
seems kind of important that effecteval return DeviceSettings, not more EffectSettings
4 files changed with 48 insertions and 8 deletions:
0 comments (0 inline, 0 general)
light9/collector/collector.py
Show inline comments
 
@@ -154,15 +154,15 @@ class Collector:
 
                staleClientSessions.append(clientSession)
 
        for clientSession in staleClientSessions:
 
            log.info('forgetting stale client %r', clientSession)
 
            del self.lastRequest[clientSession]
 

	
 
    # todo: move to settings.py
 
    def resolvedSettingsDict(self, settingsList: List[DeviceSetting]) -> Dict[Tuple[DeviceUri, DeviceAttr], VTUnion]:
 
    def _resolvedSettingsDict(self, settingsList: DeviceSettings) -> Dict[Tuple[DeviceUri, DeviceAttr], VTUnion]:
 
        out: Dict[Tuple[DeviceUri, DeviceAttr], VTUnion] = {}
 
        for devUri, devAttr, val in settingsList:
 
        for devUri, devAttr, val in settingsList.asList():
 
            if (devUri, devAttr) in out:
 
                existingVal = out[(devUri, devAttr)]
 
                out[(devUri, devAttr)] = resolve(self._deviceType[devUri], devAttr, [existingVal, val])
 
            else:
 
                out[(devUri, devAttr)] = val
 
        return out
light9/collector/service.py
Show inline comments
 
@@ -54,13 +54,13 @@ class Updates(WebSocketEndpoint, UiListe
 

	
 
    pass
 

	
 

	
 
async def PutAttrs(collector: Collector, request):
 
    with STAT_SETATTR.time():
 
        client, clientSession, settings, sendTime = parseJsonMessage(await request.body())
 
        client, clientSession, settings, sendTime = parseJsonMessage(collector.graph, await request.body())
 
        collector.setAttrs(client, clientSession, settings, sendTime)
 
        return Response('', status_code=202)
 

	
 

	
 
def main():
 
    logging.getLogger('autodepgraphapi').setLevel(logging.INFO)
light9/effect/effecteval.py
Show inline comments
 
@@ -9,13 +9,13 @@ from noise import pnoise1
 
from PIL import Image
 
from rdfdb.syncedgraph.syncedgraph import SyncedGraph
 
from rdflib import Literal, Namespace
 
from webcolors import hex_to_rgb, rgb_to_hex
 

	
 
from light9.effect.scale import scale
 
from light9.effect.settings import BareEffectSettings, EffectSettings
 
from light9.effect.settings import BareEffectSettings, DeviceSettings, EffectSettings
 
from light9.effect.simple_outputs import SimpleOutputs
 
from light9.namespaces import DEV, L9
 
from light9.newtypes import (DeviceAttr, DeviceUri, EffectAttr, EffectClass, VTUnion)
 

	
 
SKY = Namespace('http://light9.bigasterisk.com/theater/skyline/device/')
 

	
 
@@ -77,25 +77,27 @@ class EffectEval:
 
    device settings. No state; suitable for reload().
 
    """
 
    graph: SyncedGraph
 
    effect: EffectClass
 
    simpleOutputs: SimpleOutputs
 

	
 
    def outputFromEffect(self, effectSettings: BareEffectSettings, songTime: float, noteTime: float) -> Tuple[EffectSettings, Dict]:
 
    def outputFromEffect(self, effectSettings: BareEffectSettings, songTime: float, noteTime: float) -> Tuple[DeviceSettings, Dict]:
 
        """
 
        From effect attr settings, like strength=0.75, to output device
 
        settings like light1/bright=0.72;light2/bright=0.78. This runs
 
        the effect code.
 
        """
 
        # todo: what does the next comment line mean?
 
        # both callers need to apply note overrides
 

	
 
        strength = float(effectSettings.s[EffectAttr(L9['strength'])])
 
        if strength <= 0:
 
            return EffectSettings(self.graph, []), {'zero': True}
 
            return DeviceSettings(self.graph, []), {'zero': True}
 

	
 
        report = {}
 
        out: Dict[Tuple[DeviceUri, DeviceAttr], VTUnion] = {}  # (dev, attr): value
 
        out: Dict[Tuple[DeviceUri, DeviceAttr], VTUnion] = {}
 

	
 
        out.update(self.simpleOutputs.values(self.effect, strength, effectSettings.s.get(EffectAttr(L9['colorScale']), None)))
 

	
 
        if self.effect.startswith(L9['effect/']):
 
            tail = 'effect_' + self.effect[len(L9['effect/']):]
 
            try:
 
@@ -103,13 +105,13 @@ class EffectEval:
 
            except KeyError:
 
                report['error'] = 'effect code not found for %s' % self.effect
 
            else:
 
                out.update(func(effectSettings, strength, songTime, noteTime))
 

	
 
        outList = [(d, a, v) for (d, a), v in out.items()]
 
        return EffectSettings(self.graph, outList), report
 
        return DeviceSettings(self.graph, outList), report
 

	
 

	
 
def effect_Curtain(effectSettings, strength, songTime, noteTime):
 
    return {(L9['device/lowPattern%s' % n], L9['color']): literalColor(strength, strength, strength) for n in range(301, 308 + 1)}
 

	
 

	
light9/effect/effecteval_test.py
Show inline comments
 
new file 100644
 
import time
 
import unittest
 

	
 
from freezegun import freeze_time
 
from light9.effect.effecteval import EffectEval
 
from light9.effect.settings import BareEffectSettings, DeviceSettings, EffectSettings
 
from light9.effect.simple_outputs import SimpleOutputs
 
from rdflib import Namespace
 

	
 
from light9.collector.collector import Collector
 
from light9.collector.output import Output
 
from light9.collector.weblisteners import WebListeners
 
from light9.mock_syncedgraph import MockSyncedGraph
 
from light9.namespaces import DEV, L9
 
from light9.newtypes import (ClientSessionType, ClientType, DeviceAttr, DeviceUri, EffectAttr, EffectClass, HexColor, UnixTime)
 

	
 
PREFIX = '''
 
    @prefix : <http://light9.bigasterisk.com/> .
 
    @prefix dev: <http://light9.bigasterisk.com/device/> .
 
'''
 

	
 
THEATER = '''
 

	
 
    :effectClass1 a :EffectClass .
 
#add light to here
 
'''
 
effectClass1 = EffectClass(L9['effectClass1'])
 

	
 

	
 
class TestEffectEval:
 

	
 
    def test_scalesColors(self):
 
        g = MockSyncedGraph(THEATER)
 
        so = SimpleOutputs(g)
 
        ee = EffectEval(g, effectClass1, so)
 
        s = BareEffectSettings(s={EffectAttr(L9['strength']): 0.5})
 
        ds,report = ee.outputFromEffect(s, songTime=0, noteTime=0)
 
        assert ds == DeviceSettings(g, [(DeviceUri(L9['light1']), DeviceAttr(L9['color']), HexColor('#888888'))])
0 comments (0 inline, 0 general)