diff bin/paintserver @ 1626:5d2dcae1a7c6

paint can now do best matches on multiple lights at once Ignore-this: 3b8a333264edc9532f8c4ff48d92ac17
author drewp@bigasterisk.com
date Sat, 10 Jun 2017 02:02:33 +0000
parents 17da56a3c8df
children 6fa4288da8a6
line wrap: on
line diff
--- a/bin/paintserver	Sat Jun 10 02:00:29 2017 +0000
+++ b/bin/paintserver	Sat Jun 10 02:02:33 2017 +0000
@@ -17,12 +17,14 @@
 from light9.namespaces import RDF, L9, DEV
 
 
+
+
 class Solve(PrettyErrorHandler, cyclone.web.RequestHandler):
     def post(self):
         painting = json.loads(self.request.body)
         with self.settings.stats.solve.time():
             img = self.settings.solver.draw(painting)
-            sample, sampleDist = self.settings.solver.bestMatch(img)
+            sample, sampleDist = self.settings.solver.bestMatch(img, device=DEV['aura2'])
             with self.settings.graph.currentState() as g:
                 bestPath = g.value(sample, L9['imagePath']).replace(L9[''], '')
             #out = solver.solve(painting)
@@ -39,6 +41,17 @@
         self.settings.solver = light9.paint.solve.Solver(self.settings.graph)
         self.settings.solver.loadSamples()
 
+class BestMatches(PrettyErrorHandler, cyclone.web.RequestHandler):
+    def post(self):
+        body = json.loads(self.request.body)
+        painting = body['painting']
+        devs = [URIRef(d) for d in body['devices']]
+        with self.settings.stats.solve.time():
+            img = self.settings.solver.draw(painting)
+            outSettings = self.settings.solver.bestMatches(img, devs)
+            self.write(json.dumps({
+                'settings': outSettings.asList()
+                }))
         
 class App(object):
     def __init__(self, show, session):
@@ -46,19 +59,29 @@
         self.session = session
 
         self.graph = SyncedGraph(networking.rdfdb.url, "paintServer")
-        self.graph.initiallySynced.addCallback(self.launch)
+        self.graph.initiallySynced.addCallback(self.launch).addErrback(log.error)
         
         self.stats = scales.collection('/', scales.PmfStat('solve'),
                                        )
        
     def launch(self, *args):
 
-        self.solver = light9.paint.solve.Solver(self.graph, sessions=[L9['show/dance2017/capture/moving1/cap961804']])
+        self.solver = light9.paint.solve.Solver(self.graph, sessions=[
+            L9['show/dance2017/capture/aura1/cap1876596'],
+            L9['show/dance2017/capture/aura2/cap1876792'],
+            L9['show/dance2017/capture/aura3/cap1877057'],
+            L9['show/dance2017/capture/aura4/cap1877241'],
+            L9['show/dance2017/capture/aura5/cap1877406'],
+            L9['show/dance2017/capture/q1/cap1874255'],
+            L9['show/dance2017/capture/q2/cap1873665'],
+            L9['show/dance2017/capture/q3/cap1876223'],
+        ])
         self.solver.loadSamples()
         
         self.cycloneApp = cyclone.web.Application(handlers=[
             (r'/stats', StatsForCyclone),
             (r'/solve', Solve),
+            (r'/bestMatches', BestMatches),
         ],
                                                   debug=True,
                                                   graph=self.graph,