Mercurial > code > home > repos > homeauto
changeset 250:c1287ab87add
fix oneshot. more time reportin
Ignore-this: c99ce7d8d31a8ed45bdcb8d0ad08a3aa
author | drewp@bigasterisk.com |
---|---|
date | Tue, 09 Feb 2016 22:10:38 -0800 |
parents | e5c27d2f11ab |
children | 254df9f881a6 |
files | service/reasoning/oneShot service/reasoning/reasoning.py |
diffstat | 2 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/service/reasoning/oneShot Tue Feb 09 22:01:19 2016 -0800 +++ b/service/reasoning/oneShot Tue Feb 09 22:10:38 2016 -0800 @@ -3,7 +3,7 @@ send a statement to the reasoning server for one update cycle. Args are s/p/o in n3 notation, with many prefixes predefined here. """ -import sys, restkit +import sys, restkit, time s, p, o = sys.argv[1:] prefixes = { @@ -22,8 +22,10 @@ stmt = '%s %s %s .' % (expand(s), expand(p), expand(o)) print "Sending: %s" % stmt +t1 = time.time() reasoning = restkit.Resource("http://bang:9071/") -reasoning.post("oneShot", - headers={"content-type": "text/n3"}, - payload=stmt) - +ret = reasoning.post("oneShot", + headers={"content-type": "text/n3"}, + payload=stmt) +g = float(ret.headers['x-graph-ms']) +print "%.1f ms for graph update; %.1f ms other overhead" % (g, 1000 * (time.time() - t1) - g)
--- a/service/reasoning/reasoning.py Tue Feb 09 22:01:19 2016 -0800 +++ b/service/reasoning/reasoning.py Tue Feb 09 22:10:38 2016 -0800 @@ -291,7 +291,7 @@ def parseRdf(text, contentType): g = Graph() g.parse(StringInputSource(text), format={ - 'text/n3': ['n3'], + 'text/n3': 'n3', }[contentType]) return g @@ -314,7 +314,9 @@ if not len(g): log.warn("incoming oneshot graph had no statements: %r", self.request.body) return + t1 = time.time() self.settings.reasoning.inputGraph.addOneShot(g) + self.set_header('x-graph-ms', str(1000 * (time.time() - t1))) except Exception as e: log.error(e) raise