Mercurial > code > home > repos > light9
diff bin/paintserver @ 1575:0d2247ec8f49
bestMatch works in paintserver
Ignore-this: c237f9f9a3dafe3ccfa3087423a5259a
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Mon, 29 May 2017 07:59:59 +0000 |
parents | 0480fc790527 |
children | 17da56a3c8df |
line wrap: on
line diff
--- a/bin/paintserver Mon May 29 06:09:50 2017 +0000 +++ b/bin/paintserver Mon May 29 07:59:59 2017 +0000 @@ -20,23 +20,26 @@ class Solve(PrettyErrorHandler, cyclone.web.RequestHandler): def post(self): painting = json.loads(self.request.body) - reload(light9.paint.solve) - solver = light9.paint.solve.Solver(self.settings.graph) - solver.loadSamples() with self.settings.stats.solve.time(): - img = solver.draw(painting) - sample = solver.bestMatch(img) + img = self.settings.solver.draw(painting) + sample, sampleDist = self.settings.solver.bestMatch(img) with self.settings.graph.currentState() as g: - bestPath = 'show/dance2017/cam/test/%s' % g.value(sample, L9['path']) + bestPath = g.value(sample, L9['imagePath']).replace(L9[''], '') #out = solver.solve(painting) #layers = solver.simulationLayers(out) self.write(json.dumps({ - 'bestMatch': {'uri': sample, 'path': bestPath}, + 'bestMatch': {'uri': sample, 'path': bestPath, 'dist': sampleDist}, # 'layers': layers, # 'out': out, })) + def reloadSolver(self): + reload(light9.paint.solve) + self.settings.solver = light9.paint.solve.Solver(self.settings.graph) + self.settings.solver.loadSamples() + + class App(object): def __init__(self, show, session): self.show = show @@ -44,17 +47,22 @@ self.graph = SyncedGraph(networking.rdfdb.url, "paintServer") self.graph.initiallySynced.addCallback(self.launch) + + self.stats = scales.collection('/', scales.PmfStat('solve'), + ) + + def launch(self, *args): - self.stats = scales.collection('/', - scales.PmfStat('solve'), - ) - def launch(self, *args): + self.solver = light9.paint.solve.Solver(self.graph) + self.solver.loadSamples() + self.cycloneApp = cyclone.web.Application(handlers=[ (r'/stats', StatsForCyclone), (r'/solve', Solve), ], debug=True, graph=self.graph, + solver=self.solver, stats=self.stats) reactor.listenTCP(networking.paintServer.port, self.cycloneApp) log.info("listening on %s" % networking.paintServer.port)