Files @ 4a385c26402f
Branch filter:

Location: light9/bin/paintserver - annotation

drewp@bigasterisk.com
rm some unused 3rdparty code
15f296550447
15f296550447
15f296550447
15f296550447
15f296550447
6fa4288da8a6
15f296550447
15f296550447
15f296550447
15f296550447
f140153c087c
15f296550447
40cc863d2b63
3c523c71da29
9aa046cc9b33
f066d6e874db
15f296550447
69088fe2865e
7772cc48e016
5d2dcae1a7c6
15f296550447
15f296550447
9aa046cc9b33
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
9aa046cc9b33
5d2dcae1a7c6
5d2dcae1a7c6
7772cc48e016
7772cc48e016
7772cc48e016
ccdfdc8183ad
7772cc48e016
15f296550447
15f296550447
15f296550447
15f296550447
15f296550447
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
0d2247ec8f49
15f296550447
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
7772cc48e016
0d2247ec8f49
7772cc48e016
15f296550447
15f296550447
5d2dcae1a7c6
9aa046cc9b33
15f296550447
15f296550447
15f296550447
9aa046cc9b33
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 rdfdb.syncedgraph import SyncedGraph
from light9 import networking, showconfig
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
from light9.metrics import metrics
import imp


class Solve(PrettyErrorHandler, cyclone.web.RequestHandler):

    def post(self):
        painting = json.loads(self.request.body)
        with metrics('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 metrics('solve').time():
            img = self.settings.solver.draw(painting)
            outSettings = self.settings.solver.bestMatches(img, devs)
            self.write(json.dumps({'settings': outSettings.asList()}))


class App:

    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)


    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'/solve', Solve),
            (r'/bestMatches', BestMatches),
            metricsRoute(),
        ],
                                                  debug=True,
                                                  graph=self.graph,
                                                  solver=self.solver)
        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()