Files
@ ce32d00263a6
Branch filter:
Location: light9/bin/paintserver - annotation
ce32d00263a6
4.6 KiB
text/plain
set 2019 show to all-localhost
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 1a7e5b07bf17 6fa4288da8a6 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 f140153c087c 15f296550447 40cc863d2b63 3c523c71da29 f066d6e874db 15f296550447 69088fe2865e 7772cc48e016 5d2dcae1a7c6 15f296550447 15f296550447 15f296550447 0d2247ec8f49 7772cc48e016 7772cc48e016 0480fc790527 0d2247ec8f49 0480fc790527 0480fc790527 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 15f296550447 0d2247ec8f49 f066d6e874db 0d2247ec8f49 0d2247ec8f49 0d2247ec8f49 7772cc48e016 5d2dcae1a7c6 7772cc48e016 5d2dcae1a7c6 5d2dcae1a7c6 5d2dcae1a7c6 5d2dcae1a7c6 5d2dcae1a7c6 5d2dcae1a7c6 5d2dcae1a7c6 7772cc48e016 7772cc48e016 7772cc48e016 15f296550447 7772cc48e016 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 f29e26811206 7772cc48e016 7772cc48e016 0d2247ec8f49 15f296550447 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 0d2247ec8f49 7772cc48e016 15f296550447 1a7e5b07bf17 1a7e5b07bf17 1a7e5b07bf17 15f296550447 5d2dcae1a7c6 15f296550447 15f296550447 15f296550447 0d2247ec8f49 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 7772cc48e016 7772cc48e016 15f296550447 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 15f296550447 7772cc48e016 7772cc48e016 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 7772cc48e016 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 15f296550447 | #!bin/python
from run_local import log
import json
from twisted.internet import reactor
from greplin.scales.cyclonehandler import StatsHandler
from rdfdb.syncedgraph import SyncedGraph
from light9 import networking, showconfig
from greplin import scales
import optparse, sys, logging
import cyclone.web
from rdflib import URIRef
from light9 import clientsession
import light9.paint.solve
from cycloneerr import PrettyErrorHandler
from light9.namespaces import L9, DEV
import imp
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, device=DEV['aura2'])
with self.settings.graph.currentState() as g:
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,
'dist': sampleDist
},
# 'layers': layers,
# 'out': out,
}))
def reloadSolver(self):
imp.reload(light9.paint.solve)
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):
self.show = show
self.session = session
self.graph = SyncedGraph(networking.rdfdb.url, "paintServer")
self.graph.initiallySynced.addCallback(self.launch).addErrback(
log.error)
self.stats = scales.collection(
'/',
scales.PmfStat('solve', recalcPeriod=1),
)
def launch(self, *args):
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/(.*)', StatsHandler, {
'serverName': 'paintserver'
}),
(r'/solve', Solve),
(r'/bestMatches', BestMatches),
],
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)
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option(
'--show',
help='show URI, like http://light9.bigasterisk.com/show/dance2008',
default=showconfig.showUri())
parser.add_option("-v",
"--verbose",
action="store_true",
help="logging.DEBUG")
parser.add_option("--twistedlog",
action="store_true",
help="twisted logging")
clientsession.add_option(parser)
(options, args) = parser.parse_args()
log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
if not options.show:
raise ValueError("missing --show http://...")
session = clientsession.getUri('paint', options)
app = App(URIRef(options.show), session)
if options.twistedlog:
from twisted.python import log as twlog
twlog.startLogging(sys.stderr)
reactor.run()
|