Mercurial > code > home > repos > light9
annotate bin/paintserver @ 1570:0480fc790527
paint now looks for best match
Ignore-this: 5604a2a2181624a0612dddf1afa32985
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sat, 27 May 2017 12:22:28 +0000 |
parents | a30a73c12554 |
children | 0d2247ec8f49 |
rev | line source |
---|---|
1521 | 1 #!bin/python |
2 | |
3 from __future__ import division | |
4 from run_local import log | |
5 import json | |
6 from twisted.internet import reactor | |
7 from light9.greplin_cyclone import StatsForCyclone | |
8 from light9.rdfdb.syncedgraph import SyncedGraph | |
9 from light9 import networking, showconfig | |
10 from greplin import scales | |
11 import optparse, sys, logging | |
12 import cyclone.web | |
13 from rdflib import URIRef | |
14 from light9.rdfdb import clientsession | |
15 import light9.paint.solve | |
16 from lib.cycloneerr import PrettyErrorHandler | |
1570
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
17 from light9.namespaces import RDF, L9, DEV |
1521 | 18 |
1522
69088fe2865e
more progress on paint
Drew Perttula <drewp@bigasterisk.com>
parents:
1521
diff
changeset
|
19 |
1521 | 20 class Solve(PrettyErrorHandler, cyclone.web.RequestHandler): |
21 def post(self): | |
22 painting = json.loads(self.request.body) | |
23 reload(light9.paint.solve) | |
1522
69088fe2865e
more progress on paint
Drew Perttula <drewp@bigasterisk.com>
parents:
1521
diff
changeset
|
24 solver = light9.paint.solve.Solver(self.settings.graph) |
69088fe2865e
more progress on paint
Drew Perttula <drewp@bigasterisk.com>
parents:
1521
diff
changeset
|
25 solver.loadSamples() |
1521 | 26 with self.settings.stats.solve.time(): |
1570
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
27 img = solver.draw(painting) |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
28 sample = solver.bestMatch(img) |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
29 with self.settings.graph.currentState() as g: |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
30 bestPath = 'show/dance2017/cam/test/%s' % g.value(sample, L9['path']) |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
31 #out = solver.solve(painting) |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
32 #layers = solver.simulationLayers(out) |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
33 |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
34 self.write(json.dumps({ |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
35 'bestMatch': {'uri': sample, 'path': bestPath}, |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
36 # 'layers': layers, |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
37 # 'out': out, |
0480fc790527
paint now looks for best match
Drew Perttula <drewp@bigasterisk.com>
parents:
1524
diff
changeset
|
38 })) |
1521 | 39 |
40 class App(object): | |
41 def __init__(self, show, session): | |
42 self.show = show | |
43 self.session = session | |
44 | |
45 self.graph = SyncedGraph(networking.rdfdb.url, "paintServer") | |
46 self.graph.initiallySynced.addCallback(self.launch) | |
47 | |
48 self.stats = scales.collection('/', | |
49 scales.PmfStat('solve'), | |
50 ) | |
51 def launch(self, *args): | |
52 self.cycloneApp = cyclone.web.Application(handlers=[ | |
53 (r'/stats', StatsForCyclone), | |
54 (r'/solve', Solve), | |
55 ], | |
56 debug=True, | |
57 graph=self.graph, | |
58 stats=self.stats) | |
59 reactor.listenTCP(networking.paintServer.port, self.cycloneApp) | |
60 log.info("listening on %s" % networking.paintServer.port) | |
61 | |
62 | |
63 if __name__ == "__main__": | |
64 parser = optparse.OptionParser() | |
65 parser.add_option('--show', | |
66 help='show URI, like http://light9.bigasterisk.com/show/dance2008', | |
67 default=showconfig.showUri()) | |
68 parser.add_option("-v", "--verbose", action="store_true", | |
69 help="logging.DEBUG") | |
70 parser.add_option("--twistedlog", action="store_true", | |
71 help="twisted logging") | |
72 clientsession.add_option(parser) | |
73 (options, args) = parser.parse_args() | |
74 log.setLevel(logging.DEBUG if options.verbose else logging.INFO) | |
75 | |
76 if not options.show: | |
77 raise ValueError("missing --show http://...") | |
78 | |
79 session = clientsession.getUri('paint', options) | |
80 | |
81 app = App(URIRef(options.show), session) | |
82 if options.twistedlog: | |
83 from twisted.python import log as twlog | |
84 twlog.startLogging(sys.stderr) | |
85 reactor.run() |