@@ -91,16 +91,7 @@ function addVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::Bool
91
91
if exists (dfg, variable)
92
92
error (" Variable '$(variable. label) ' already exists in the factor graph" )
93
93
end
94
- props = Dict {String, Any} ()
95
- props[" label" ] = string (variable. label)
96
- props[" timestamp" ] = string (variable. timestamp)
97
- props[" tags" ] = JSON2. write (variable. tags)
98
- props[" estimateDict" ] = JSON2. write (variable. estimateDict)
99
- props[" solverDataDict" ] = JSON2. write (Dict (keys (variable. solverDataDict) .=> map (vnd -> pack (dfg, vnd), values (variable. solverDataDict))))
100
- props[" smallData" ] = JSON2. write (variable. smallData)
101
- props[" ready" ] = variable. solvable
102
- props[" backendset" ] = variable. solveInProgress
103
- # Don't handle big data at the moment.
94
+ props = packVariable (dfg, variable)
104
95
105
96
neo4jNode = Neo4j. createnode (dfg. neo4jInstance. graph, props);
106
97
variable. _internalId = neo4jNode. id
@@ -132,20 +123,7 @@ function addFactor!(dfg::CloudGraphsDFG, variables::Vector{DFGVariable}, factor:
132
123
factor. _variableOrderSymbols = map (v-> v. label, variables)
133
124
134
125
# Construct the properties to save
135
- props = Dict {String, Any} ()
136
- props[" label" ] = string (factor. label)
137
- props[" tags" ] = JSON2. write (factor. tags)
138
- # Pack the node data
139
- fnctype = factor. data. fnc. usrfnc!
140
- packtype = getfield (_getmodule (fnctype), Symbol (" Packed$(_getname (fnctype)) " ))
141
- packed = convert (PackedFunctionNodeData{packtype}, factor. data)
142
- props[" data" ] = JSON2. write (packed)
143
- # Include the type
144
- props[" fnctype" ] = String (_getname (fnctype))
145
- props[" _variableOrderSymbols" ] = JSON2. write (factor. _variableOrderSymbols)
146
- props[" backendset" ] = factor. solveInProgress
147
- props[" ready" ] = factor. solvable
148
- # Don't handle big data at the moment.
126
+ props = packFactor (dfg, factor)
149
127
150
128
neo4jNode = Neo4j. createnode (dfg. neo4jInstance. graph, props);
151
129
factor. _internalId = neo4jNode. id
@@ -182,27 +160,8 @@ Get a DFGVariable from a DFG using its underlying integer ID.
182
160
"""
183
161
function getVariable (dfg:: CloudGraphsDFG , variableId:: Int64 ):: DFGVariable
184
162
props = getnodeproperties (dfg. neo4jInstance. graph, variableId)
185
- # Time to do deserialization
186
- # props["label"] = Symbol(variable.label)
187
- timestamp = DateTime (props[" timestamp" ])
188
- tags = JSON2. read (props[" tags" ], Vector{Symbol})
189
- # TODO this will work for some time, but unpacking in an <: AbstractPointParametricEst would be lekker.
190
- estimateDict = JSON2. read (props[" estimateDict" ], Dict{Symbol, MeanMaxPPE})
191
- smallData = nothing
192
- smallData = JSON2. read (props[" smallData" ], Dict{String, String})
193
-
194
- packed = JSON2. read (props[" solverDataDict" ], Dict{String, PackedVariableNodeData})
195
- solverData = Dict (Symbol .(keys (packed)) .=> map (p -> unpack (dfg, p), values (packed)))
196
-
197
- # Rebuild DFGVariable
198
- variable = DFGVariable (Symbol (props[" label" ]), variableId)
199
- variable. timestamp = timestamp
200
- variable. tags = tags
201
- variable. estimateDict = estimateDict
202
- variable. solverDataDict = solverData
203
- variable. smallData = smallData
204
- variable. solvable = props[" ready" ]
205
- variable. solveInProgress = props[" backendset" ]
163
+ variable = unpackVariable (dfg, props)
164
+ variable. _internalId = variableId
206
165
207
166
# Add to cache
208
167
push! (dfg. variableCache, variable. label=> variable)
@@ -235,35 +194,14 @@ Get a DFGFactor from a DFG using its underlying integer ID.
235
194
"""
236
195
function getFactor (dfg:: CloudGraphsDFG , factorId:: Int64 ):: DFGFactor
237
196
props = getnodeproperties (dfg. neo4jInstance. graph, factorId)
238
-
239
- label = props[" label" ]
240
- tags = JSON2. read (props[" tags" ], Vector{Symbol})
241
-
242
- data = props[" data" ]
243
- datatype = props[" fnctype" ]
244
- # fulltype = getfield(Main, Symbol(datatype))
245
- packtype = getfield (Main, Symbol (" Packed" * datatype))
246
- packed = JSON2. read (data, GenericFunctionNodeData{packtype,String})
247
- fullFactor = dfg. decodePackedTypeFunc (dfg, packed)
248
-
249
- # Include the type
250
- _variableOrderSymbols = JSON2. read (props[" _variableOrderSymbols" ], Vector{Symbol})
251
- backendset = props[" backendset" ]
252
- ready = props[" ready" ]
253
-
254
- # Rebuild DFGVariable
255
- factor = DFGFactor {typeof(fullFactor.fnc), Symbol} (Symbol (label), factorId)
256
- factor. tags = tags
257
- factor. data = fullFactor
258
- factor. _variableOrderSymbols = _variableOrderSymbols
259
- factor. solvable = ready
260
- factor. solveInProgress = backendset
197
+ factor = unpackFactor (dfg, props, getSerializationModule (dfg))
198
+ factor. _internalId = factorId
261
199
262
200
# Lastly, rebuild the metadata
263
201
factor = dfg. rebuildFactorMetadata! (dfg, factor)
264
202
# GUARANTEED never to bite us in the future...
265
203
# ... TODO : refactor if changed: https://github.com/JuliaRobotics/IncrementalInference.jl/issues/350
266
- solverData (factor). fncargvID = _variableOrderSymbols
204
+ solverData (factor). fncargvID = factor . _variableOrderSymbols
267
205
268
206
# Add to cache
269
207
push! (dfg. factorCache, factor. label=> factor)
@@ -302,17 +240,7 @@ function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariabl
302
240
variable. _internalId = nodeId
303
241
304
242
neo4jNode = Neo4j. getnode (dfg. neo4jInstance. graph, nodeId)
305
- props = getnodeproperties (dfg. neo4jInstance. graph, nodeId)
306
-
307
- props[" label" ] = string (variable. label)
308
- props[" timestamp" ] = string (variable. timestamp)
309
- props[" tags" ] = JSON2. write (variable. tags)
310
- props[" estimateDict" ] = JSON2. write (variable. estimateDict)
311
- props[" solverDataDict" ] = JSON2. write (Dict (keys (variable. solverDataDict) .=> map (vnd -> pack (dfg, vnd), values (variable. solverDataDict))))
312
- props[" smallData" ] = JSON2. write (variable. smallData)
313
- props[" ready" ] = variable. solvable
314
- props[" backendset" ] = variable. solveInProgress
315
- # Don't handle big data at the moment.
243
+ props = packVariable (dfg, variable)
316
244
317
245
Neo4j. updatenodeproperties (neo4jNode, props)
318
246
Neo4j. updatenodelabels (neo4jNode, union ([string (variable. label), " VARIABLE" , dfg. userId, dfg. robotId, dfg. sessionId], variable. tags))
@@ -349,21 +277,7 @@ function updateFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor
349
277
# Update the _internalId
350
278
factor. _internalId = nodeId
351
279
neo4jNode = Neo4j. getnode (dfg. neo4jInstance. graph, nodeId)
352
- props = getnodeproperties (dfg. neo4jInstance. graph, nodeId)
353
-
354
- props[" label" ] = string (factor. label)
355
- props[" tags" ] = JSON2. write (factor. tags)
356
- # Pack the node data
357
- fnctype = factor. data. fnc. usrfnc!
358
- packtype = getfield (_getmodule (fnctype), Symbol (" Packed$(_getname (fnctype)) " ))
359
- packed = convert (PackedFunctionNodeData{packtype}, factor. data)
360
- props[" data" ] = JSON2. write (packed)
361
- # Include the type
362
- props[" fnctype" ] = String (_getname (fnctype))
363
- props[" _variableOrderSymbols" ] = JSON2. write (factor. _variableOrderSymbols)
364
- props[" backendset" ] = factor. solveInProgress
365
- props[" ready" ] = factor. solvable
366
- # Don't handle big data at the moment.
280
+ props = packFactor (dfg, factor)
367
281
368
282
Neo4j. updatenodeproperties (neo4jNode, props)
369
283
Neo4j. updatenodelabels (neo4jNode, union ([string (factor. label), " FACTOR" , dfg. userId, dfg. robotId, dfg. sessionId], factor. tags))
@@ -597,10 +511,10 @@ function getNeighbors(dfg::CloudGraphsDFG, node::T; ready::Union{Nothing, Int}=n
597
511
query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(node. label) )--(node) where (node:VARIABLE or node:FACTOR) "
598
512
if ready != nothing || backendset != nothing
599
513
if ready != nothing
600
- query = query * " and node.ready >= $(ready) "
514
+ query = query * " and node.solvable >= $(ready) "
601
515
end
602
516
if backendset != nothing
603
- query = query * " and node.backendset = $(backendset) "
517
+ query = query * " and node.solveInProgress = $(backendset) "
604
518
end
605
519
end
606
520
@debug " [Query] $query "
@@ -620,10 +534,10 @@ function getNeighbors(dfg::CloudGraphsDFG, label::Symbol; ready::Union{Nothing,
620
534
query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(label) )--(node) where (node:VARIABLE or node:FACTOR) "
621
535
if ready != nothing || backendset != nothing
622
536
if ready != nothing
623
- query = query * " and node.ready >= $(ready) "
537
+ query = query * " and node.solvable >= $(ready) "
624
538
end
625
539
if backendset != nothing
626
- query = query * " and node.backendset = $(backendset) "
540
+ query = query * " and node.solveInProgress = $(backendset) "
627
541
end
628
542
end
629
543
@debug " [Query] $query "
@@ -756,32 +670,3 @@ function getAdjacencyMatrixSparse(dfg::CloudGraphsDFG)::Tuple{SparseMatrixCSC, V
756
670
757
671
return adjMat, varLabels, factLabels
758
672
end
759
-
760
- # """
761
- # $(SIGNATURES)
762
- # Produces a dot-format of the graph for visualization.
763
- # """
764
- # function toDot(dfg::CloudGraphsDFG)::String
765
- # m = PipeBuffer()
766
- # write(m,Graphs.to_dot(dfg.g))
767
- # data = take!(m)
768
- # close(m)
769
- # return String(data)
770
- # end
771
- #
772
- # """
773
- # $(SIGNATURES)
774
- # Produces a dot file of the graph for visualization.
775
- # Download XDot to see the data
776
- #
777
- # Note
778
- # - Default location "/tmp/dfg.dot" -- MIGHT BE REMOVED
779
- # - Can be viewed with the `xdot` system application.
780
- # - Based on graphviz.org
781
- # """
782
- # function toDotFile(dfg::CloudGraphsDFG, fileName::String="/tmp/dfg.dot")::Nothing
783
- # open(fileName, "w") do fid
784
- # write(fid,Graphs.to_dot(dfg.g))
785
- # end
786
- # return nothing
787
- # end
0 commit comments