# HG changeset patch # User drewp # Date 1555829763 25200 # Node ID 87d7a14073a24d8caa78509a0d3849f8564bc7bd # Parent b4004739640e71942fab0746b62bf4d18d843790 last version of colplay, which i hope won't need a custom service soon Ignore-this: dd6799d5eba9854538e56c791e9f836a darcs-hash:25d151e3431e1d6c2237c203feeb9ab1f017ecfa diff -r b4004739640e -r 87d7a14073a2 service/colplay/colplay.py --- a/service/colplay/colplay.py Sat Apr 20 23:54:11 2019 -0700 +++ b/service/colplay/colplay.py Sat Apr 20 23:56:03 2019 -0700 @@ -15,18 +15,22 @@ from cyclone.httpclient import fetch from webcolors import rgb_to_hex from influxdb import InfluxDBClient +from rdflib import Namespace, Graph +from rdflib.parser import StringInputSource + +ROOM = Namespace('http://projects.bigasterisk.com/room/') influx = InfluxDBClient('bang', 9060, 'root', 'root', 'main') -def currentAudio(location='brace'): +def currentAudio(location='frontbed'): t = time.time() row = list(influx.query("""SELECT mean(value) FROM audioLevel WHERE "location" = '%s' AND time > %ds""" % (location, t - 30)))[0][0] log.debug("query took %.03fms", 1000 * (time.time() - t)) - base = {'brace': .020, + base = {'frontbed': .015, 'living': .03, }[location] high = { - 'brace': .1, + 'frontbed': .40, 'living': .3, }[location] return max(0.0, min(1.0, (row['mean'] - base) / high)) @@ -139,7 +143,7 @@ x = int(((hr - 12) % 24) * pxPerHour) % 2400 log.debug("x = %s", x) - audioLevel = currentAudio('brace') + audioLevel = currentAudio('frontbed') log.debug('level = %s', audioLevel) for i, (name, ypos) in enumerate(sorted(lightYPos.items())): @@ -158,6 +162,17 @@ log.error(self.lastError) self.lastErrorTime = time.time() + + +class OneShot(cyclone.web.RequestHandler): + def post(self): + g = Graph() + g.parse(StringInputSource(self.request.body), format={ + 'text/n3': 'n3', + }[self.request.headers['content-type']]) + + for anim in g.subjects(ROOM['playback'], ROOM['start']): + startAnim(anim) class IndexHandler(cyclone.web.RequestHandler): def get(self): @@ -176,5 +191,6 @@ log.info("listening http on 9051") reactor.listenTCP(9051, cyclone.web.Application([ (r'/', IndexHandler), + (r'/oneShot', OneShot), ], lightState=lightState)) reactor.run()