Mercurial > code > home > repos > homeauto
annotate lib/patchablegraph.py @ 350:a380561fd8a8
add setToGraph
Ignore-this: f1e1b6f7604ac19f73cb7622b6aa80fc
author | drewp@bigasterisk.com |
---|---|
date | Mon, 16 Apr 2018 22:18:49 -0700 |
parents | a94f2a522d41 |
children | fcd2c026f51e |
rev | line source |
---|---|
224
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
1 """ |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
2 Design: |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
3 |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
4 1. Services each have (named) graphs, which they patch as things |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
5 change. PatchableGraph is an object for holding this graph. |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
6 2. You can http GET that graph, or ... |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
7 3. You can http GET/SSE that graph and hear about modifications to it |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
8 4. The client that got the graph holds and maintains a copy. The |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
9 client may merge together multiple graphs. |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
10 5. Client queries its graph with low-level APIs or client-side sparql. |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
11 6. When the graph changes, the client knows and can update itself at |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
12 low or high granularity. |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
13 |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
14 |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
15 See also: |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
16 * http://iswc2007.semanticweb.org/papers/533.pdf RDFSync: efficient remote synchronization of RDF |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
17 models |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
18 * https://www.w3.org/2009/12/rdf-ws/papers/ws07 Supporting Change Propagation in RDF |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
19 * https://www.w3.org/DesignIssues/lncs04/Diff.pdf Delta: an ontology for the distribution of |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
20 differences between RDF graphs |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
21 |
224
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
22 """ |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
23 import sys, json, logging |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
24 import cyclone.sse |
331
a94f2a522d41
build and import updates for rdfdb, etc
drewp@bigasterisk.com
parents:
298
diff
changeset
|
25 sys.path.append("/my/proj/rdfdb") |
a94f2a522d41
build and import updates for rdfdb, etc
drewp@bigasterisk.com
parents:
298
diff
changeset
|
26 from rdfdb.grapheditapi import GraphEditApi |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
27 from rdflib import ConjunctiveGraph |
331
a94f2a522d41
build and import updates for rdfdb, etc
drewp@bigasterisk.com
parents:
298
diff
changeset
|
28 from rdfdb.rdflibpatch import patchQuads |
a94f2a522d41
build and import updates for rdfdb, etc
drewp@bigasterisk.com
parents:
298
diff
changeset
|
29 from rdfdb.patch import Patch |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
30 from rdflib_jsonld.serializer import from_rdf |
298
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
31 from rdflib.parser import StringInputSource |
224
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
32 from cycloneerr import PrettyErrorHandler |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
33 |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
34 log = logging.getLogger('patchablegraph') |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
35 |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
36 def writeGraphResponse(req, graph, acceptHeader): |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
37 if acceptHeader == 'application/nquads': |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
38 req.set_header('Content-type', 'application/nquads') |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
39 graph.serialize(req, format='nquads') |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
40 elif acceptHeader == 'application/ld+json': |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
41 req.set_header('Content-type', 'application/ld+json') |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
42 graph.serialize(req, format='json-ld', indent=2) |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
43 else: |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
44 req.set_header('Content-type', 'application/x-trig') |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
45 graph.serialize(req, format='trig') |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
46 |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
47 # forked from /my/proj/light9/light9/rdfdb/rdflibpatch.py |
224
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
48 def _graphFromQuads2(q): |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
49 g = ConjunctiveGraph() |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
50 #g.addN(q) # no effect on nquad output |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
51 for s,p,o,c in q: |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
52 g.get_context(c).add((s,p,o)) # kind of works with broken rdflib nquad serializer code |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
53 #g.store.add((s,p,o), c) # no effect on nquad output |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
54 return g |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
55 |
298
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
56 def jsonFromPatch(p): |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
57 return json.dumps({'patch': { |
224
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
58 'adds': from_rdf(_graphFromQuads2(p.addQuads)), |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
59 'deletes': from_rdf(_graphFromQuads2(p.delQuads)), |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
60 }}) |
298
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
61 patchAsJson = jsonFromPatch # deprecated name |
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
62 |
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
63 |
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
64 def patchFromJson(j): |
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
65 body = json.loads(j)['patch'] |
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
66 a = ConjunctiveGraph() |
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
67 a.parse(StringInputSource(json.dumps(body['adds'])), format='json-ld') |
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
68 d = ConjunctiveGraph() |
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
69 d.parse(StringInputSource(json.dumps(body['deletes'])), format='json-ld') |
8d89da1915df
sse_collector now kind of gets concurrent requests right
drewp@bigasterisk.com
parents:
233
diff
changeset
|
70 return Patch(addGraph=a, delGraph=d) |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
71 |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
72 def graphAsJson(g): |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
73 # This is not the same as g.serialize(format='json-ld')! That |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
74 # version omits literal datatypes. |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
75 return json.dumps(from_rdf(g)) |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
76 |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
77 class PatchableGraph(GraphEditApi): |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
78 """ |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
79 Master graph that you modify with self.patch, and we get the |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
80 updates to all current listeners. |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
81 """ |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
82 def __init__(self): |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
83 self._graph = ConjunctiveGraph() |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
84 self._observers = [] |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
85 |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
86 def serialize(self, to, **kw): |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
87 return self._graph.serialize(to, **kw) |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
88 |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
89 def patch(self, p): |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
90 if p.isNoop(): |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
91 return |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
92 patchQuads(self._graph, |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
93 deleteQuads=p.delQuads, |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
94 addQuads=p.addQuads, |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
95 perfect=False) # true? |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
96 for ob in self._observers: |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
97 ob(patchAsJson(p)) |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
98 |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
99 def asJsonLd(self): |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
100 return graphAsJson(self._graph) |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
101 |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
102 def addObserver(self, onPatch): |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
103 self._observers.append(onPatch) |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
104 |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
105 def removeObserver(self, onPatch): |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
106 try: |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
107 self._observers.remove(onPatch) |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
108 except ValueError: |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
109 pass |
350 | 110 |
111 def setToGraph(self, newGraph): | |
112 self.patch(Patch.fromDiff(self._graph, newGraph)) | |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
113 |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
114 |
224
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
115 class CycloneGraphHandler(PrettyErrorHandler, cyclone.web.RequestHandler): |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
116 def initialize(self, masterGraph): |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
117 self.masterGraph = masterGraph |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
118 |
224
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
119 def get(self): |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
120 writeGraphResponse(self, self.masterGraph, |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
121 self.request.headers.get('accept')) |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
122 |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
123 class CycloneGraphEventsHandler(cyclone.sse.SSEHandler): |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
124 """ |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
125 One session with one client. |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
126 |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
127 returns current graph plus future patches to keep remote version |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
128 in sync with ours. |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
129 |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
130 intsead of turning off buffering all over, it may work for this |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
131 response to send 'x-accel-buffering: no', per |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
132 http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
133 """ |
224
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
134 def __init__(self, application, request, masterGraph): |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
135 cyclone.sse.SSEHandler.__init__(self, application, request) |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
136 self.masterGraph = masterGraph |
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
137 |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
138 def bind(self): |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
139 graphJson = self.masterGraph.asJsonLd() |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
140 log.debug("send fullGraph event: %s", graphJson) |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
227
diff
changeset
|
141 self.sendEvent(message=graphJson, event='fullGraph') |
224
596c645a1fc5
refactor /graph and /graph/events handlers to lib/
drewp@bigasterisk.com
parents:
223
diff
changeset
|
142 self.masterGraph.addObserver(self.onPatch) |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
143 |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
144 def onPatch(self, patchJson): |
227 | 145 # throttle and combine patches here- ideally we could see how |
146 # long the latency to the client is to make a better rate choice | |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
147 self.sendEvent(message=patchJson, event='patch') |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
148 |
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
149 def unbind(self): |
227 | 150 self.masterGraph.removeObserver(self.onPatch) |
223
9236b736bc34
add new jsonld/SSE support to environment service as a test
drewp@bigasterisk.com
parents:
diff
changeset
|
151 |