Changeset - 972a54f99b2c
[Not reviewed]
default
0 11 0
drewp@bigasterisk.com - 20 months ago 2023-05-31 07:13:50
drewp@bigasterisk.com
reformat & clean up imports
10 files changed with 35 insertions and 42 deletions:
0 comments (0 inline, 0 general)
light9/effect/effect_function_library.py
Show inline comments
 
"""repo of the EffectFunctions in the graph. Includes URI->realPythonFunction"""
 
import logging
 
from dataclasses import dataclass, field
 
from typing import Callable, Dict, List, Optional, Tuple, cast
 
from typing import Callable, List, Optional, cast
 

	
 
from rdfdb.syncedgraph.syncedgraph import SyncedGraph
 
from rdflib import RDF, RDFS, Literal, Namespace, URIRef
 
from rdflib import RDF, RDFS, Literal
 

	
 
from light9.namespaces import DEV, FUNC, L9
 
from light9.newtypes import (DeviceAttr, DeviceUri, EffectAttr, EffectFunction, EffectUri, HexColor, VTUnion)
 
from light9.namespaces import FUNC, L9
 
from light9.newtypes import EffectAttr, EffectFunction, VTUnion
 
from light9.typedgraph import typedValue
 

	
 
log = logging.getLogger('effectfuncs')
 
from . import effect_functions
 

	
 
from . import effect_functions
 
log = logging.getLogger('effectfuncs')
 

	
 

	
 
@dataclass
light9/effect/effect_function_library_test.py
Show inline comments
 
from light9.effect.effect_function_library import EffectFunctionLibrary
 

	
 
from light9.mock_syncedgraph import MockSyncedGraph
 
from light9.namespaces import L9
 

	
 
PREFIXES = '''
 
@prefix : <http://light9.bigasterisk.com/> .
 
@@ -29,11 +27,11 @@ GRAPH = PREFIXES + '''
 
            [ :effectAttr :period; :defaultValue 0.5 ],
 
            [ :effectAttr :onTime; :defaultValue 0.1 ],
 
            [ :effectAttr :deviceSettings ] .
 
'''
 

	
 

	
 
'''
 
class TestParsesGraph:
 

	
 
class TestParsesGraph:
 
    def test(self):
 
        g = MockSyncedGraph(GRAPH)
 
        lib = EffectFunctionLibrary(g)
light9/effect/effecteval.py
Show inline comments
 
@@ -2,23 +2,14 @@ import logging
 
import math
 
import random
 
from colorsys import hsv_to_rgb
 
from dataclasses import dataclass, field
 
import time
 
from typing import Callable, Dict, List, Optional, Tuple, cast
 
from light9.effect.effect_function_library import EffectFunctionLibrary
 
from light9.typedgraph import typedValue
 

	
 
from noise import pnoise1
 
from PIL import Image
 
from rdfdb.syncedgraph.syncedgraph import SyncedGraph
 
from rdflib import RDF, RDFS, Literal, Namespace, URIRef
 
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, DeviceSettings, EffectSettings
 
from light9.namespaces import DEV, L9, FUNC
 
from light9.newtypes import (DeviceAttr, DeviceUri, EffectAttr, 
 
                             EffectFunction, EffectUri, HexColor, VTUnion)
 
from light9.namespaces import DEV, L9
 

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

	
light9/effect/effecteval2.py
Show inline comments
 
import inspect
 
import logging
 
from dataclasses import dataclass, field
 
from typing import Callable, Dict, List, Optional, Tuple, cast
 
from dataclasses import dataclass
 
from typing import Callable, List, Optional
 

	
 
from rdfdb.syncedgraph.syncedgraph import SyncedGraph
 
from rdflib import RDF, RDFS, Literal, Namespace, URIRef
 
from rdflib import RDF
 
from rdflib.term import Node
 

	
 
from light9.effect.effect_function_library import EffectFunctionLibrary
 
from light9.effect.settings import (BareEffectSettings, DeviceSettings, EffectSettings)
 
from light9.namespaces import DEV, FUNC, L9
 
from light9.newtypes import (DeviceAttr, DeviceUri, EffectAttr, EffectFunction, EffectUri, HexColor, VTUnion)
 
from light9.effect.settings import DeviceSettings, EffectSettings
 
from light9.namespaces import L9
 
from light9.newtypes import (DeviceAttr, DeviceUri, EffectAttr, EffectFunction, EffectUri, VTUnion)
 
from light9.typedgraph import typedValue
 
from rdflib.term import Node
 

	
 
log = logging.getLogger('effecteval')
 

	
 

	
 
@dataclass
 
class Config:
 
    effectFunction: EffectFunction
 
@@ -23,6 +24,7 @@ class Config:
 
    func: Callable
 
    funcArgs: List[inspect.Parameter]
 

	
 

	
 
@dataclass
 
class EffectEval2:
 
    """Runs one effect code to turn EffectSettings (e.g. strength) into DeviceSettings"""
 
@@ -75,7 +77,6 @@ class EffectEval2:
 
            log.error(f"while compiling {self.uri}")
 
            raise
 

	
 

	
 
    def compute(self, songTime: float, inputs: EffectSettings) -> DeviceSettings:
 
        """
 
        calls our function using inputs (publishedAttr attrs, e.g. :strength) 
 
@@ -102,7 +103,8 @@ class EffectEval2:
 

	
 
    def _getEffectAttrValue(self, attr: EffectAttr, inputs: EffectSettings) -> VTUnion:
 
        c=self.config
 
        if c is None: raise
 
        if c is None:
 
            raise
 
        try:
 
            return inputs.getValue(self.uri, attr, defaultToZero=False)
 
        except KeyError:
light9/effect/effecteval_test.py
Show inline comments
 
from typing import List, Tuple
 

	
 
import pytest
 

	
 
from light9.effect.effect_function_library import EffectFunctionLibrary
 
from light9.effect.effecteval2 import EffectEval2
 
from light9.effect.settings import DeviceSettings, EffectSettings
 
from light9.mock_syncedgraph import MockSyncedGraph
 
from light9.namespaces import DEV, L9
 
from light9.newtypes import (DeviceAttr, DeviceUri, EffectAttr, EffectUri, HexColor, VTUnion)
 
import pytest
 

	
 
PREFIX = '''
 
    @prefix : <http://light9.bigasterisk.com/> .
light9/effect/scale.py
Show inline comments
 
from decimal import Decimal
 

	
 
from webcolors import hex_to_rgb, rgb_to_hex
 

	
 
from light9.newtypes import VTUnion
 
from webcolors import hex_to_rgb, rgb_to_hex
 

	
 

	
 
def scale(value:VTUnion, strength:float):
light9/effect/sequencer/eval_faders.py
Show inline comments
 
@@ -4,15 +4,13 @@ from dataclasses import dataclass
 
from typing import List, Optional, cast
 

	
 
from prometheus_client import Summary
 
from light9.effect.effect_function_library import EffectFunctionLibrary
 
from light9.effect.effecteval2 import EffectEval2
 

	
 
from rdfdb import SyncedGraph
 
from rdflib import URIRef
 
from rdflib.term import Node
 

	
 
from light9.effect.effect_function_library import EffectFunctionLibrary
 
from light9.effect.effecteval2 import EffectEval2
 
from light9.effect.settings import DeviceSettings, EffectSettings
 
from light9.metrics import metrics
 
from light9.namespaces import L9, RDF
 
from light9.newtypes import EffectAttr, EffectUri, UnixTime
 
from light9.typedgraph import typedValue
 
@@ -21,6 +19,7 @@ log = logging.getLogger('seq.fader')
 

	
 
COMPILE=Summary('compile_graph_fader', '')
 

	
 

	
 
@dataclass
 
class Fader:
 
    graph: SyncedGraph
 
@@ -34,14 +33,13 @@ class Fader:
 
    def __post_init__(self):
 
        self.ee = EffectEval2(self.graph, self.effect, self.lib)
 

	
 

	
 
class FaderEval:
 
    """peer to Sequencer, but this one takes the current :Fader settings -> sendToCollector
 

	
 
    """
 
    def __init__(self,
 
                 graph: SyncedGraph,
 
                 lib: EffectFunctionLibrary
 
                 ):
 

	
 
    def __init__(self, graph: SyncedGraph, lib: EffectFunctionLibrary):
 
        self.graph = graph
 
        self.lib = lib
 
        self.faders: List[Fader] = []
light9/effect/sequencer/eval_faders_test.py
Show inline comments
 
from unittest import mock
 

	
 
from light9.effect.effect_function_library import EffectFunctionLibrary
 

	
 
from light9.effect.sequencer.eval_faders import FaderEval
 
from light9.effect.settings import DeviceSettings
 
from light9.mock_syncedgraph import MockSyncedGraph
light9/effect/sequencer/service.py
Show inline comments
 
@@ -6,7 +6,6 @@ import asyncio
 
import json
 
import logging
 
import time
 
from light9.effect.effect_function_library import EffectFunctionLibrary
 

	
 
from louie import dispatcher
 
from rdfdb.syncedgraph.syncedgraph import SyncedGraph
 
@@ -18,6 +17,7 @@ from starlette_exporter import Prometheu
 
from lib.background_loop import loop_forever
 
from light9 import networking
 
from light9.collector.collector_client_asyncio import sendToCollector
 
from light9.effect.effect_function_library import EffectFunctionLibrary
 
from light9.effect.sequencer.eval_faders import FaderEval
 
from light9.effect.sequencer.sequencer import Sequencer, StateUpdate
 
from light9.run_local import log
light9/effect/settings_test.py
Show inline comments
 
@@ -13,6 +13,7 @@ from light9.newtypes import DeviceAttr, 
 
def decimalLiteral(value):
 
    return Literal(value, datatype='http://www.w3.org/2001/XMLSchema#decimal')
 

	
 

	
 
class TestDeviceSettings(unittest.TestCase):
 

	
 
    def setUp(self):
0 comments (0 inline, 0 general)