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