Mercurial > code > home > repos > light9
annotate src/light9/collector/collector.py @ 2410:44fc477970bf
cleanup imports, reformats
author | drewp@bigasterisk.com |
---|---|
date | Sat, 18 May 2024 23:19:04 -0700 |
parents | 4556eebe5d73 |
children |
rev | line source |
---|---|
2154 | 1 import logging |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
2 import time |
2162 | 3 from typing import Dict, List, Set, Tuple, cast |
1884
5cde72dfdc22
change collector output code to use very specific types. Might fix bugs too.
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
4 |
2357 | 5 from prometheus_client import Summary |
2154 | 6 from rdfdb.syncedgraph.syncedgraph import SyncedGraph |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
7 |
2154 | 8 from light9.collector.device import resolve, toOutputAttrs |
1884
5cde72dfdc22
change collector output code to use very specific types. Might fix bugs too.
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
9 from light9.collector.output import Output as OutputInstance |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
10 from light9.collector.weblisteners import WebListeners |
2193
f79fff92990b
collector.output use asyncio loop, not twisted loop. other cleanups.
drewp@bigasterisk.com
parents:
2183
diff
changeset
|
11 from light9.effect.settings import DeviceSettings |
1884
5cde72dfdc22
change collector output code to use very specific types. Might fix bugs too.
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
12 from light9.namespaces import L9, RDF |
2410 | 13 from light9.newtypes import ( |
14 ClientSessionType, | |
15 ClientType, | |
16 DeviceAttr, | |
17 DeviceClass, | |
18 DeviceUri, | |
19 DmxIndex, | |
20 DmxMessageIndex, | |
21 OutputAttr, | |
22 OutputRange, | |
23 OutputUri, | |
24 OutputValue, | |
25 UnixTime, | |
26 VTUnion, | |
27 uriTail, | |
28 ) | |
29 from light9.typedgraph import typedValue | |
2072 | 30 |
1289
5a4e74f1e36a
Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents:
1288
diff
changeset
|
31 log = logging.getLogger('collector') |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
32 |
2357 | 33 STAT_SETATTR = Summary('set_attr', 'setAttr calls') |
1858 | 34 |
2410 | 35 |
2155
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
36 def makeDmxMessageIndex(base: DmxIndex, offset: DmxIndex) -> DmxMessageIndex: |
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
37 return DmxMessageIndex(base + offset - 1) |
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
38 |
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
39 |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
40 def _outputMap(graph: SyncedGraph, outputs: Set[OutputUri]) -> Dict[Tuple[DeviceUri, OutputAttr], Tuple[OutputUri, DmxMessageIndex]]: |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
41 """From rdf config graph, compute a map of |
1416
ab7b40d20af0
rewrite theaterConfig to a better data format
Drew Perttula <drewp@bigasterisk.com>
parents:
1412
diff
changeset
|
42 (device, outputattr) : (output, index) |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
43 that explains which output index to set for any device update. |
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
44 """ |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
45 ret = cast(Dict[Tuple[DeviceUri, OutputAttr], Tuple[OutputUri, DmxMessageIndex]], {}) |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
46 |
1416
ab7b40d20af0
rewrite theaterConfig to a better data format
Drew Perttula <drewp@bigasterisk.com>
parents:
1412
diff
changeset
|
47 for dc in graph.subjects(RDF.type, L9['DeviceClass']): |
2252 | 48 log.info(' mapping devices of class %s', dc) |
1416
ab7b40d20af0
rewrite theaterConfig to a better data format
Drew Perttula <drewp@bigasterisk.com>
parents:
1412
diff
changeset
|
49 for dev in graph.subjects(RDF.type, dc): |
1884
5cde72dfdc22
change collector output code to use very specific types. Might fix bugs too.
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
50 dev = cast(DeviceUri, dev) |
2252 | 51 log.info(' 💡 mapping device %s', dev) |
2155
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
52 universe = typedValue(OutputUri, graph, dev, L9['dmxUniverse']) |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
53 if universe not in outputs: |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
54 raise ValueError(f'{dev=} is configured to be in {universe=}, but we have no Output for that universe') |
2155
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
55 try: |
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
56 dmxBase = typedValue(DmxIndex, graph, dev, L9['dmxBase']) |
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
57 except ValueError: |
1966 | 58 raise ValueError('no :dmxBase for %s' % dev) |
2155
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
59 |
2193
f79fff92990b
collector.output use asyncio loop, not twisted loop. other cleanups.
drewp@bigasterisk.com
parents:
2183
diff
changeset
|
60 for row in sorted(graph.objects(dc, L9['attr']), key=str): |
2155
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
61 outputAttr = typedValue(OutputAttr, graph, row, L9['outputAttr']) |
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
62 offset = typedValue(DmxIndex, graph, row, L9['dmxOffset']) |
092967f313e1
attempt to make things more typesafe and readable (untested)
drewp@bigasterisk.com
parents:
2154
diff
changeset
|
63 index = makeDmxMessageIndex(dmxBase, offset) |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
64 ret[(dev, outputAttr)] = (universe, index) |
2193
f79fff92990b
collector.output use asyncio loop, not twisted loop. other cleanups.
drewp@bigasterisk.com
parents:
2183
diff
changeset
|
65 log.info(f' {uriTail(outputAttr):15} maps to {uriTail(universe)} index {index}') |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
66 return ret |
1858 | 67 |
68 | |
1884
5cde72dfdc22
change collector output code to use very specific types. Might fix bugs too.
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
69 class Collector: |
2193
f79fff92990b
collector.output use asyncio loop, not twisted loop. other cleanups.
drewp@bigasterisk.com
parents:
2183
diff
changeset
|
70 """receives setAttrs calls; combines settings; renders them into what outputs like; calls Output.update""" |
1858 | 71 |
2072 | 72 def __init__(self, graph: SyncedGraph, outputs: List[OutputInstance], listeners: WebListeners, clientTimeoutSec: float = 10): |
1307
8863b4485fd4
collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1302
diff
changeset
|
73 self.graph = graph |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
74 self.outputs = outputs |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1506
diff
changeset
|
75 self.listeners = listeners |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
76 self.clientTimeoutSec = clientTimeoutSec |
2194 | 77 |
78 self._initTime = time.time() | |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
79 self._outputByUri: Dict[OutputUri, OutputInstance] = {} |
2194 | 80 self._deviceType: Dict[DeviceUri, DeviceClass] = {} |
81 self.remapOut: Dict[Tuple[DeviceUri, OutputAttr], OutputRange] = {} | |
1307
8863b4485fd4
collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1302
diff
changeset
|
82 |
2194 | 83 self.graph.addHandler(self._compile) |
1506
37cbb245d93c
fix tests. add logging, some mypy types.
Drew Perttula <drewp@bigasterisk.com>
parents:
1492
diff
changeset
|
84 |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
85 # rename to activeSessons ? |
2170
066f05ad7900
collector: even stronger types; repair test code (some are failing)
drewp@bigasterisk.com
parents:
2162
diff
changeset
|
86 self.lastRequest: Dict[Tuple[ClientType, ClientSessionType], Tuple[UnixTime, Dict[Tuple[DeviceUri, DeviceAttr], VTUnion]]] = {} |
1506
37cbb245d93c
fix tests. add logging, some mypy types.
Drew Perttula <drewp@bigasterisk.com>
parents:
1492
diff
changeset
|
87 |
37cbb245d93c
fix tests. add logging, some mypy types.
Drew Perttula <drewp@bigasterisk.com>
parents:
1492
diff
changeset
|
88 # (dev, devAttr): value to use instead of 0 |
2170
066f05ad7900
collector: even stronger types; repair test code (some are failing)
drewp@bigasterisk.com
parents:
2162
diff
changeset
|
89 self.stickyAttrs: Dict[Tuple[DeviceUri, DeviceAttr], VTUnion] = {} |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
90 |
2194 | 91 def _compile(self): |
2252 | 92 log.info('Collector._compile:') |
2194 | 93 self._outputByUri = self._compileOutputByUri() |
94 self._outputMap = _outputMap(self.graph, set(self._outputByUri.keys())) | |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
95 |
2194 | 96 self._deviceType.clear() |
97 self.remapOut.clear() | |
1416
ab7b40d20af0
rewrite theaterConfig to a better data format
Drew Perttula <drewp@bigasterisk.com>
parents:
1412
diff
changeset
|
98 for dc in self.graph.subjects(RDF.type, L9['DeviceClass']): |
2072 | 99 dc = cast(DeviceClass, dc) |
100 for dev in self.graph.subjects(RDF.type, dc): | |
101 dev = cast(DeviceUri, dev) | |
2194 | 102 self._deviceType[dev] = dc |
103 self._compileRemapForDevice(dev) | |
1307
8863b4485fd4
collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1302
diff
changeset
|
104 |
2194 | 105 def _compileOutputByUri(self) -> Dict[OutputUri, OutputInstance]: |
106 ret = {} | |
107 for output in self.outputs: | |
108 ret[OutputUri(output.uri)] = output | |
109 return ret | |
110 | |
111 def _compileRemapForDevice(self, dev: DeviceUri): | |
112 for remap in self.graph.objects(dev, L9['outputAttrRange']): | |
113 attr = typedValue(OutputAttr, self.graph, remap, L9['outputAttr']) | |
114 start = typedValue(float, self.graph, remap, L9['start']) | |
115 end = typedValue(float, self.graph, remap, L9['end']) | |
116 self.remapOut[(dev, attr)] = OutputRange((start, end)) | |
1448
931d2dafca12
new feature: values can have their range remapped in the device processing
drewp@bigasterisk.com
parents:
1446
diff
changeset
|
117 |
2357 | 118 @STAT_SETATTR.time() |
2204 | 119 def setAttrs(self, client: ClientType, clientSession: ClientSessionType, settings: DeviceSettings, sendTime: UnixTime): |
120 """ | |
121 Given DeviceSettings, we resolve conflicting values, | |
122 process them into output attrs, and call Output.update | |
123 to send the new outputs. | |
124 | |
125 client is a string naming the type of client. | |
126 (client, clientSession) is a unique client instance. | |
127 clientSession is deprecated. | |
128 | |
129 Each client session's last settings will be forgotten | |
130 after clientTimeoutSec. | |
131 """ | |
132 # todo: cleanup session code if we really don't want to be able to run multiple sessions of one client | |
133 clientSession = ClientSessionType("no_longer_used") | |
134 | |
135 now = UnixTime(time.time()) | |
136 self._warnOnLateRequests(client, now, sendTime) | |
137 | |
138 self._forgetStaleClients(now) | |
139 | |
140 self.lastRequest[(client, clientSession)] = (now, self._resolvedSettingsDict(settings)) | |
141 | |
142 deviceAttrs = self._merge(iter(self.lastRequest.values())) | |
143 | |
144 outputAttrsByDevice = self._convertToOutputAttrsPerDevice(deviceAttrs) | |
145 pendingOut = self._flattenDmxOutput(outputAttrsByDevice) | |
146 | |
2217 | 147 t2 = time.time() |
2204 | 148 |
149 self._updateOutputs(pendingOut) | |
150 | |
2217 | 151 t3 = time.time() |
152 if t2 - now > .030 or t3 - t2 > .030: | |
153 log.warning("slow setAttrs: prepare %.1fms -> updateOutputs %.1fms" % ((t2 - now) * 1000, (t3 - t2) * 1000)) | |
2204 | 154 |
155 def _warnOnLateRequests(self, client, now, sendTime): | |
156 requestLag = now - sendTime | |
157 if requestLag > .1 and now > self._initTime + 10 and getattr(self, '_lastWarnTime', 0) < now - 3: | |
158 self._lastWarnTime = now | |
159 log.warning('collector.setAttrs from %s is running %.1fms after the request was made', client, requestLag * 1000) | |
160 | |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
161 def _forgetStaleClients(self, now): |
1602
0fc61e701347
collector: don't confuse two clients with the same name- use the session
Drew Perttula <drewp@bigasterisk.com>
parents:
1596
diff
changeset
|
162 staleClientSessions = [] |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
163 for clientSession, (reqTime, _) in self.lastRequest.items(): |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
164 if reqTime < now - self.clientTimeoutSec: |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
165 staleClientSessions.append(clientSession) |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
166 for clientSession in staleClientSessions: |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
167 log.info('forgetting stale client %r', clientSession) |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
168 del self.lastRequest[clientSession] |
1300
d51014267bfd
move device-specific code out of collector. resolver isn't done yet. live.html can edit colors
Drew Perttula <drewp@bigasterisk.com>
parents:
1289
diff
changeset
|
169 |
1602
0fc61e701347
collector: don't confuse two clients with the same name- use the session
Drew Perttula <drewp@bigasterisk.com>
parents:
1596
diff
changeset
|
170 # todo: move to settings.py |
2208
091909b4b727
seems kind of important that effecteval return DeviceSettings, not more EffectSettings
drewp@bigasterisk.com
parents:
2204
diff
changeset
|
171 def _resolvedSettingsDict(self, settingsList: DeviceSettings) -> Dict[Tuple[DeviceUri, DeviceAttr], VTUnion]: |
2170
066f05ad7900
collector: even stronger types; repair test code (some are failing)
drewp@bigasterisk.com
parents:
2162
diff
changeset
|
172 out: Dict[Tuple[DeviceUri, DeviceAttr], VTUnion] = {} |
2208
091909b4b727
seems kind of important that effecteval return DeviceSettings, not more EffectSettings
drewp@bigasterisk.com
parents:
2204
diff
changeset
|
173 for devUri, devAttr, val in settingsList.asList(): |
2183
081f36506ad3
address a bunch of type errors and loose types
drewp@bigasterisk.com
parents:
2173
diff
changeset
|
174 if (devUri, devAttr) in out: |
081f36506ad3
address a bunch of type errors and loose types
drewp@bigasterisk.com
parents:
2173
diff
changeset
|
175 existingVal = out[(devUri, devAttr)] |
2194 | 176 out[(devUri, devAttr)] = resolve(self._deviceType[devUri], devAttr, [existingVal, val]) |
1372
f427801da9f6
collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents:
1307
diff
changeset
|
177 else: |
2183
081f36506ad3
address a bunch of type errors and loose types
drewp@bigasterisk.com
parents:
2173
diff
changeset
|
178 out[(devUri, devAttr)] = val |
1372
f427801da9f6
collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents:
1307
diff
changeset
|
179 return out |
f427801da9f6
collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents:
1307
diff
changeset
|
180 |
1602
0fc61e701347
collector: don't confuse two clients with the same name- use the session
Drew Perttula <drewp@bigasterisk.com>
parents:
1596
diff
changeset
|
181 def _merge(self, lastRequests): |
2170
066f05ad7900
collector: even stronger types; repair test code (some are failing)
drewp@bigasterisk.com
parents:
2162
diff
changeset
|
182 deviceAttrs: Dict[DeviceUri, Dict[DeviceAttr, VTUnion]] = {} # device: {deviceAttr: value} |
1602
0fc61e701347
collector: don't confuse two clients with the same name- use the session
Drew Perttula <drewp@bigasterisk.com>
parents:
1596
diff
changeset
|
183 for _, lastSettings in lastRequests: |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
184 for (device, deviceAttr), value in lastSettings.items(): |
1448
931d2dafca12
new feature: values can have their range remapped in the device processing
drewp@bigasterisk.com
parents:
1446
diff
changeset
|
185 if (device, deviceAttr) in self.remapOut: |
931d2dafca12
new feature: values can have their range remapped in the device processing
drewp@bigasterisk.com
parents:
1446
diff
changeset
|
186 start, end = self.remapOut[(device, deviceAttr)] |
2170
066f05ad7900
collector: even stronger types; repair test code (some are failing)
drewp@bigasterisk.com
parents:
2162
diff
changeset
|
187 value = start + float(value) * (end - start) |
1450
ddb7622698a8
don't mix remapped values with unremapped ones
drewp@bigasterisk.com
parents:
1448
diff
changeset
|
188 |
ddb7622698a8
don't mix remapped values with unremapped ones
drewp@bigasterisk.com
parents:
1448
diff
changeset
|
189 attrs = deviceAttrs.setdefault(device, {}) |
ddb7622698a8
don't mix remapped values with unremapped ones
drewp@bigasterisk.com
parents:
1448
diff
changeset
|
190 if deviceAttr in attrs: |
2072 | 191 value = resolve(device, deviceAttr, [attrs[deviceAttr], value]) |
1416
ab7b40d20af0
rewrite theaterConfig to a better data format
Drew Perttula <drewp@bigasterisk.com>
parents:
1412
diff
changeset
|
192 attrs[deviceAttr] = value |
1470
b1d8abc96f06
don't run rotations to zero when no one is requesting them.
drewp@bigasterisk.com
parents:
1450
diff
changeset
|
193 # list should come from the graph. these are attrs |
b1d8abc96f06
don't run rotations to zero when no one is requesting them.
drewp@bigasterisk.com
parents:
1450
diff
changeset
|
194 # that should default to holding the last position, |
b1d8abc96f06
don't run rotations to zero when no one is requesting them.
drewp@bigasterisk.com
parents:
1450
diff
changeset
|
195 # not going to 0. |
1475 | 196 if deviceAttr in [L9['rx'], L9['ry'], L9['zoom'], L9['focus']]: |
2072 | 197 self.stickyAttrs[(device, deviceAttr)] = cast(float, value) |
1300
d51014267bfd
move device-specific code out of collector. resolver isn't done yet. live.html can edit colors
Drew Perttula <drewp@bigasterisk.com>
parents:
1289
diff
changeset
|
198 |
1470
b1d8abc96f06
don't run rotations to zero when no one is requesting them.
drewp@bigasterisk.com
parents:
1450
diff
changeset
|
199 # e.g. don't let an unspecified rotation go to 0 |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
200 for (d, da), v in self.stickyAttrs.items(): |
1470
b1d8abc96f06
don't run rotations to zero when no one is requesting them.
drewp@bigasterisk.com
parents:
1450
diff
changeset
|
201 daDict = deviceAttrs.setdefault(d, {}) |
b1d8abc96f06
don't run rotations to zero when no one is requesting them.
drewp@bigasterisk.com
parents:
1450
diff
changeset
|
202 if da not in daDict: |
b1d8abc96f06
don't run rotations to zero when no one is requesting them.
drewp@bigasterisk.com
parents:
1450
diff
changeset
|
203 daDict[da] = v |
1858 | 204 |
1602
0fc61e701347
collector: don't confuse two clients with the same name- use the session
Drew Perttula <drewp@bigasterisk.com>
parents:
1596
diff
changeset
|
205 return deviceAttrs |
0fc61e701347
collector: don't confuse two clients with the same name- use the session
Drew Perttula <drewp@bigasterisk.com>
parents:
1596
diff
changeset
|
206 |
2204 | 207 def _convertToOutputAttrsPerDevice(self, deviceAttrs): |
208 ret: Dict[DeviceUri, Dict[OutputAttr, OutputValue]] = {} | |
2194 | 209 for d, devType in self._deviceType.items(): |
1809
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1799
diff
changeset
|
210 try: |
2204 | 211 ret[d] = toOutputAttrs(devType, deviceAttrs.get(d, {})) |
212 self.listeners.outputAttrsSet(d, ret[d], self._outputMap) | |
1809
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1799
diff
changeset
|
213 except Exception as e: |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1799
diff
changeset
|
214 log.error('failing toOutputAttrs on %s: %r', d, e) |
2204 | 215 return ret |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
216 |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
217 def _flattenDmxOutput(self, outputAttrs: Dict[DeviceUri, Dict[OutputAttr, OutputValue]]) -> Dict[OutputUri, bytearray]: |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
218 pendingOut = cast(Dict[OutputUri, bytearray], {}) |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
219 for outUri in self._outputByUri.keys(): |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
220 pendingOut[outUri] = bytearray(512) |
1506
37cbb245d93c
fix tests. add logging, some mypy types.
Drew Perttula <drewp@bigasterisk.com>
parents:
1492
diff
changeset
|
221 |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
222 for device, attrs in outputAttrs.items(): |
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
223 for outputAttr, value in attrs.items(): |
2194 | 224 outputUri, _index = self._outputMap[(device, outputAttr)] |
1884
5cde72dfdc22
change collector output code to use very specific types. Might fix bugs too.
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
225 index = DmxMessageIndex(_index) |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
226 outArray = pendingOut[outputUri] |
1884
5cde72dfdc22
change collector output code to use very specific types. Might fix bugs too.
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
227 if outArray[index] != 0: |
2202 | 228 log.warning(f'conflict: {outputUri} output array was already nonzero at 0-based index {index}') |
1884
5cde72dfdc22
change collector output code to use very specific types. Might fix bugs too.
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
229 raise ValueError(f"someone already wrote to index {index}") |
5cde72dfdc22
change collector output code to use very specific types. Might fix bugs too.
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
230 outArray[index] = value |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
231 return pendingOut |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
232 |
2173
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
233 def _updateOutputs(self, pendingOut: Dict[OutputUri, bytearray]): |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
234 for uri, buf in pendingOut.items(): |
f239dedb025a
disable collector client sessions- we prob don't need them. refactor collector.py
drewp@bigasterisk.com
parents:
2170
diff
changeset
|
235 self._outputByUri[uri].update(bytes(buf)) |