comparison bin/inputdemo @ 1067:c33158b367a5

inputdemo reports latency of posting each point. takes curve uri on cmdline Ignore-this: 640cf036dfb5f5ae956be1cde5190846
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 02 Jun 2014 06:04:19 +0000
parents 0f51a1a5785e
children c756638275d6
comparison
equal deleted inserted replaced
1066:e71abaa857ed 1067:c33158b367a5
3 sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk 3 sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk
4 from twisted.internet import gtk3reactor 4 from twisted.internet import gtk3reactor
5 gtk3reactor.install() 5 gtk3reactor.install()
6 from twisted.internet import reactor 6 from twisted.internet import reactor
7 from rdflib import URIRef 7 from rdflib import URIRef
8 import optparse, logging, urllib 8 import optparse, logging, urllib, time
9 from gi.repository import Gtk 9 from gi.repository import Gtk
10 from run_local import log 10 from run_local import log
11 from light9 import showconfig, networking 11 from light9 import showconfig, networking
12 from light9.rdfdb import clientsession 12 from light9.rdfdb import clientsession
13 from light9.rdfdb.syncedgraph import SyncedGraph 13 from light9.rdfdb.syncedgraph import SyncedGraph
14 import cyclone.httpclient 14 import cyclone.httpclient
15 15
16 class App(object): 16 class App(object):
17 def __init__(self): 17 def __init__(self):
18 parser = optparse.OptionParser() 18 parser = optparse.OptionParser()
19 parser.set_usage("%prog [opts]") 19 parser.set_usage("%prog [opts] [curve uri]")
20 parser.add_option("--debug", action="store_true", 20 parser.add_option("--debug", action="store_true",
21 help="log at DEBUG") 21 help="log at DEBUG")
22 clientsession.add_option(parser) 22 clientsession.add_option(parser)
23 opts, args = parser.parse_args() 23 opts, args = parser.parse_args()
24 24
27 self.session = clientsession.getUri('inputdemo', opts) 27 self.session = clientsession.getUri('inputdemo', opts)
28 self.graph = SyncedGraph("inputdemo") 28 self.graph = SyncedGraph("inputdemo")
29 29
30 self.graph.initiallySynced.addCallback(lambda _: self.launch()) 30 self.graph.initiallySynced.addCallback(lambda _: self.launch())
31 31
32 self.curve = URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-1401259747.675542') 32 self.curve = args[0] if args else URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-1401259747.675542')
33 print "sending points on curve %s" % self.curve 33 print "sending points on curve %s" % self.curve
34 34
35 reactor.run() 35 reactor.run()
36 36
37 def launch(self): 37 def launch(self):
50 50
51 def onChanged(self, scale): 51 def onChanged(self, scale):
52 f = cyclone.httpclient.fetch( 52 f = cyclone.httpclient.fetch(
53 networking.curveCalc.path('liveInputPoint'), 53 networking.curveCalc.path('liveInputPoint'),
54 method='POST', timeout=1, 54 method='POST', timeout=1,
55 postdata=urllib.urlencode({'curve': self.curve, 55 postdata=urllib.urlencode({
56 'value': str(scale.get_value())})) 56 'curve': self.curve,
57 'value': str(scale.get_value()),
58 }))
57 @f.addCallback 59 @f.addCallback
58 def cb(result): 60 def cb(result):
59 if result.code // 100 != 2: 61 if result.code // 100 != 2:
60 log.error("curveCalc said %s: %s", result.code, result.body) 62 log.error("curveCalc said %s: %s", result.code, result.body)
63 print "posted in %.1f ms" % (1000 * (time.time() - t1))
61 @f.addErrback 64 @f.addErrback
62 def eb(err): 65 def eb(err):
63 print "err", err 66 print "err", err
64 67
65 App() 68 App()