Mercurial > code > home > repos > homeauto
comparison service/reasoning/oneShot @ 795:c8562ace4917
big updates for k8s, py3, drop FuXi, use prometheus for metrics.
author | drewp@bigasterisk.com |
---|---|
date | Sun, 27 Dec 2020 03:29:18 -0800 |
parents | 0996e3a91c85 |
children |
comparison
equal
deleted
inserted
replaced
794:fafe86ae0b03 | 795:c8562ace4917 |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python3 |
2 """ | 2 """ |
3 send a statement to the reasoning server for one update cycle. Args | 3 send a statement to the reasoning server for one update cycle. Args |
4 are s/p/o in n3 notation, with many prefixes predefined here. | 4 are s/p/o in n3 notation, with many prefixes predefined here. |
5 """ | 5 """ |
6 import sys, requests, time, os | 6 import json |
7 import os | |
8 import subprocess | |
9 import sys | |
10 import time | |
11 | |
12 import requests | |
13 | |
7 s, p, o = sys.argv[1:] | 14 s, p, o = sys.argv[1:] |
8 | 15 |
9 prefixes = { | 16 prefixes = { |
10 '': 'http://projects.bigasterisk.com/room/', | 17 '': 'http://projects.bigasterisk.com/room/', |
11 'room' : 'http://projects.bigasterisk.com/room/', | 18 'room': 'http://projects.bigasterisk.com/room/', |
12 'shuttle': 'http://bigasterisk.com/room/livingRoom/shuttlepro/', | 19 'shuttle': 'http://bigasterisk.com/room/livingRoom/shuttlepro/', |
13 'sensor': 'http://bigasterisk.com/homeauto/sensor/', | 20 'sensor': 'http://bigasterisk.com/homeauto/sensor/', |
14 } | 21 } |
22 | |
15 | 23 |
16 def expand(term): | 24 def expand(term): |
17 if ':' not in term or term.startswith(('<', '"', "'")): | 25 if ':' not in term or term.startswith(('<', '"', "'")): |
18 return term | 26 return term |
19 left, right = term.split(':', 1) | 27 left, right = term.split(':', 1) |
20 if left in prefixes: | 28 if left in prefixes: |
21 return '<%s%s>' % (prefixes[left], right) | 29 return '<%s%s>' % (prefixes[left], right) |
22 return term | 30 return term |
23 | 31 |
32 | |
33 pod = json.loads(subprocess.check_output(["kubectl", "get", "pod", "--selector=app=reasoning", "-o", "json"])) | |
34 ip = pod['items'][0]['status']['podIP'] | |
35 | |
24 stmt = '%s %s %s .' % (expand(s), expand(p), expand(o)) | 36 stmt = '%s %s %s .' % (expand(s), expand(p), expand(o)) |
25 print "Sending: %s" % stmt | 37 print("Sending: %s" % stmt) |
26 | 38 |
27 t1 = time.time() | 39 t1 = time.time() |
28 ret = requests.post( | 40 ret = requests.post('http://%s/oneShot' % os.environ.get('REASONING', f'{ip}:9071'), |
29 'http://%s/oneShot' % os.environ.get('REASONING', 'bang:9071'), | 41 headers={"content-type": "text/n3"}, |
30 headers={"content-type": "text/n3"}, | 42 data=stmt.encode('ascii')) |
31 data=stmt.encode('ascii')) | |
32 g = float(ret.headers['x-graph-ms']) | 43 g = float(ret.headers['x-graph-ms']) |
33 print "%.1f ms for graph update; %.1f ms other overhead" % (g, 1000 * (time.time() - t1) - g) | 44 print("%.1f ms for graph update; %.1f ms other overhead" % (g, 1000 * (time.time() - t1) - g)) |