annotate service/reasoning/inputgraph.py @ 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 f3f667769aef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
1 import logging
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
2 import time
755
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
3 import weakref
756
f3f667769aef python 3! and some types and cleanups
drewp@bigasterisk.com
parents: 755
diff changeset
4 from typing import Callable
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
5
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
6 from patchablegraph.patchsource import ReconnectingPatchSource
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
7 from prometheus_client import Summary
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
8 from rdfdb.patch import Patch
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
9 from rdfdb.rdflibpatch import patchQuads
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
10 from rdflib import RDFS, ConjunctiveGraph, Graph, Namespace, URIRef
755
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
11 from rdflib.parser import StringInputSource
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
12 from rx.subjects import BehaviorSubject
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
13 from twisted.internet import reactor
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
14 from twisted.python.filepath import FilePath
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
15
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
16 log = logging.getLogger('fetch')
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
17
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
18 ROOM = Namespace("http://projects.bigasterisk.com/room/")
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
19 DEV = Namespace("http://projects.bigasterisk.com/device/")
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
20
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
21 COMBINE_GRAPH_CALLS = Summary('combine_graph_calls', 'calls')
756
f3f667769aef python 3! and some types and cleanups
drewp@bigasterisk.com
parents: 755
diff changeset
22
f3f667769aef python 3! and some types and cleanups
drewp@bigasterisk.com
parents: 755
diff changeset
23
f3f667769aef python 3! and some types and cleanups
drewp@bigasterisk.com
parents: 755
diff changeset
24 def parseRdf(text: str, contentType: str):
281
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
25 g = Graph()
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
26 g.parse(StringInputSource(text), format={
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
27 'text/n3': 'n3',
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
28 }[contentType])
281
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
29 return g
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
30
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
31
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
32 class RemoteData(object):
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
33
756
f3f667769aef python 3! and some types and cleanups
drewp@bigasterisk.com
parents: 755
diff changeset
34 def __init__(self, onChange: Callable[[], None]):
755
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
35 """we won't fire onChange during init"""
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
36 self.onChange = onChange
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
37 self.graph = ConjunctiveGraph()
755
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
38 reactor.callLater(0, self._finishInit)
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
39
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
40 def _finishInit(self):
392
79d041273e26 mqtt has two devices now. various older cleanups.
drewp@bigasterisk.com
parents: 351
diff changeset
41 self.patchSource = ReconnectingPatchSource(
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
42 URIRef('http://collector.default.svc.cluster.local:9072/graph/home'),
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
43 # URIRef('http://frontdoor:10012/graph/events'),
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
44 self.onPatch,
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
45 reconnectSecs=10,
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
46 agent='reasoning')
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
47
756
f3f667769aef python 3! and some types and cleanups
drewp@bigasterisk.com
parents: 755
diff changeset
48 def onPatch(self, p: Patch, fullGraph: bool):
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
49 if fullGraph:
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
50 self.graph = ConjunctiveGraph()
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
51 patchQuads(self.graph, deleteQuads=p.delQuads, addQuads=p.addQuads, perfect=True)
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
52
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
53 ignorePredicates = [
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
54 ROOM['signalStrength'],
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
55 # perhaps anything with a number-datatype for its
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
56 # object should be filtered out, and you have to make
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
57 # an upstream quantization (e.g. 'temp high'/'temp
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
58 # low') if you want to do reasoning on the difference
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
59 URIRef("http://bigasterisk.com/map#lastSeenAgoSec"),
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
60 URIRef("http://bigasterisk.com/map#lastSeenAgo"),
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
61 ROOM['usingPower'],
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
62 ROOM['idleTimeMinutes'],
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
63 ROOM['idleTimeMs'],
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
64 ROOM['graphLoadMs'],
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
65 ROOM['localTimeToSecond'],
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
66 ROOM['history'],
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
67 ROOM['connectedAgo'],
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
68 RDFS['comment'],
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
69 ]
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
70 ignoreContexts = [
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
71 URIRef('http://bigasterisk.com/sse_collector/'),
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
72 ]
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
73 for affected in p.addQuads + p.delQuads:
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
74 if (affected[1] not in ignorePredicates and affected[3] not in ignoreContexts):
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
75 log.debug(" remote graph changed")
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
76 self.onChange()
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
77 break
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
78 else:
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
79 log.debug(" remote graph has no changes to trigger rules")
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
80
756
f3f667769aef python 3! and some types and cleanups
drewp@bigasterisk.com
parents: 755
diff changeset
81
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
82 class InputGraph(object):
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
83
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
84 def __init__(self, inputDirs, onChange):
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
85 """
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
86 this has one Graph that's made of:
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
87 - all .n3 files from inputDirs (read at startup)
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
88 - all the remote graphs, specified in the file graphs
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
89
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
90 call updateFileData or updateRemoteData to reread those
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
91 graphs. getGraph to access the combined graph.
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
92
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
93 onChange(self) is called if the contents of the full graph
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
94 change (in an interesting way) during updateFileData or
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
95 updateRemoteData. Interesting means statements other than the
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
96 ones with the predicates on the boring list. onChange(self,
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
97 oneShot=True) means: don't store the result of this change
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
98 anywhere; it needs to be processed only once
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
99 """
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
100 self.inputDirs = inputDirs
312
170dc9b1e789 fix input graph web display by dirtying combinedGraph better.
drewp@bigasterisk.com
parents: 303
diff changeset
101 self._onChange = onChange
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
102 self._fileGraph = Graph()
312
170dc9b1e789 fix input graph web display by dirtying combinedGraph better.
drewp@bigasterisk.com
parents: 303
diff changeset
103 self._remoteData = RemoteData(lambda: self.onChangeLocal())
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
104 self._combinedGraph = None
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
105 self._oneShotAdditionGraph = None
755
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
106 self._rxValues = weakref.WeakKeyDictionary()
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
107
312
170dc9b1e789 fix input graph web display by dirtying combinedGraph better.
drewp@bigasterisk.com
parents: 303
diff changeset
108 def onChangeLocal(self, oneShot=False, oneShotGraph=None):
170dc9b1e789 fix input graph web display by dirtying combinedGraph better.
drewp@bigasterisk.com
parents: 303
diff changeset
109 self._combinedGraph = None
170dc9b1e789 fix input graph web display by dirtying combinedGraph better.
drewp@bigasterisk.com
parents: 303
diff changeset
110 self._onChange(self, oneShot=oneShot, oneShotGraph=oneShotGraph)
755
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
111 for rxv, (subj, pred, default) in self._rxValues.items():
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
112 self._rxUpdate(subj, pred, default, rxv)
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
113
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
114 def _rxUpdate(self, subj, pred, default, rxv):
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
115 rxv.on_next(self.getGraph().value(subj, pred, default=default))
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
116
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
117 def rxValue(self, subj, pred, default): # -> BehaviorSubject:
755
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
118 value = BehaviorSubject(default)
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
119 self._rxValues[value] = (subj, pred, default)
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
120 self._rxUpdate(subj, pred, default, value)
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
121 return value
ffcad6bf9c57 something with rx on inputgraph, i forget. also cleanup imports and logging of oneshot
drewp@bigasterisk.com
parents: 723
diff changeset
122
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
123 def updateFileData(self):
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
124 """
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
125 make sure we contain the correct data from the files in inputDirs
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
126 """
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
127 # this sample one is actually only needed for the output, but I don't
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
128 # think I want to have a separate graph for the output
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
129 # handling
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
130 log.debug("read file graphs")
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
131 for fp in FilePath("input").walk():
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
132 if fp.isdir():
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
133 continue
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
134 if fp.splitext()[1] != '.n3':
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
135 continue
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
136 log.debug("read %s", fp)
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
137 # todo: if this fails, leave the report in the graph
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
138 self._fileGraph.parse(fp.open(), format="n3")
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
139 self._combinedGraph = None
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
140
312
170dc9b1e789 fix input graph web display by dirtying combinedGraph better.
drewp@bigasterisk.com
parents: 303
diff changeset
141 self.onChangeLocal()
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
142
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
143 def addOneShot(self, g):
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
144 """
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
145 add this graph to the total, call onChange, and then revert
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
146 the addition of this graph
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
147 """
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
148 self._oneShotAdditionGraph = g
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
149 self._combinedGraph = None
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
150 try:
314
c51075f267bc fix oneshot
drewp@bigasterisk.com
parents: 312
diff changeset
151 self.onChangeLocal(oneShot=True, oneShotGraph=g)
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
152 finally:
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
153 self._oneShotAdditionGraph = None
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
154 self._combinedGraph = None
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
155
281
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
156 def addOneShotFromString(self, body, contentType):
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
157 g = parseRdf(body, contentType)
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
158 if not len(g):
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
159 log.warn("incoming oneshot graph had no statements: %r", body)
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
160 return 0
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
161 t1 = time.time()
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
162 self.addOneShot(g)
9728288c7f2f refactor
drewp@bigasterisk.com
parents: 275
diff changeset
163 return time.time() - t1
392
79d041273e26 mqtt has two devices now. various older cleanups.
drewp@bigasterisk.com
parents: 351
diff changeset
164
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
165 @COMBINE_GRAPH_CALLS.time()
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
166 def getGraph(self) -> ConjunctiveGraph:
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
167 """rdflib Graph with the file+remote contents of the input graph"""
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
168 # this could be much faster with the combined readonly graph
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
169 # view from rdflib
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
170 if self._combinedGraph is None:
795
c8562ace4917 big updates for k8s, py3, drop FuXi, use prometheus for metrics.
drewp@bigasterisk.com
parents: 756
diff changeset
171 self._combinedGraph = ConjunctiveGraph()
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
172 if self._fileGraph:
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
173 for s in self._fileGraph:
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
174 self._combinedGraph.add(s)
303
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
175 for s in self._remoteData.graph:
66fe7a93753d reasoning uses sse_collector
drewp@bigasterisk.com
parents: 281
diff changeset
176 self._combinedGraph.add(s)
275
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
177 if self._oneShotAdditionGraph:
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
178 for s in self._oneShotAdditionGraph:
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
179 self._combinedGraph.add(s)
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
180
d3733587e749 refactor inputgraph
drewp@bigasterisk.com
parents:
diff changeset
181 return self._combinedGraph