1
- # Additional exports
2
- export copySession!
3
- # Please be careful with these
4
- # With great power comes great "Oh crap, I deleted everything..."
5
- export clearSession!!, clearRobot!!, clearUser!!
6
-
7
- function _getNodeType (dfg:: CloudGraphsDFG , nodeLabel:: Symbol ):: Symbol
8
- dfg. useCache && haskey (dfg. variableDict, nodeLabel) && return :VARIABLE
9
- dfg. useCache && haskey (dfg. factorDict, nodeLabel) && return :FACTOR
10
- nodeId = nothing
11
- if dfg. useCache && haskey (dfg. labelDict)
12
- nodeId = dfg. labelDict[nodeLabel]
13
- else
14
- nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, nodeLabel)
15
- end
16
- # Erk, little expensive to do this...
17
- nodeId == nothing && error (" Cannot find node with label '$nodeLabel '!" )
18
- labels = getnodelabels (getnode (dfg. neo4jInstance. graph, nodeId))
19
- " VARIABLE" in labels && return :VARIABLE
20
- " FACTOR" in labels && return :FACTOR
21
- error (" Node with label '$nodeLabel ' has neither FACTOR nor VARIABLE labels" )
22
- end
23
-
24
- # # End
25
1
26
2
"""
27
3
$(SIGNATURES)
@@ -92,70 +68,20 @@ function exists(dfg::CloudGraphsDFG, node::N) where N <: DFGNode
92
68
end
93
69
94
70
"""
95
- $(SIGNATURES)
96
- DANGER: Clears the whole session from the database.
97
- """
98
- function clearSession!! (dfg:: CloudGraphsDFG ):: Nothing
99
- # Perform detach+deletion
100
- _getNeoNodesFromCyphonQuery (dfg. neo4jInstance, " (node:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) ) detach delete node " )
71
+ $SIGNATURES
101
72
102
- # Clearing history
103
- dfg. addHistory = Symbol[]
104
- empty! (dfg. variableCache)
105
- empty! (dfg. factorCache)
106
- empty! (dfg. labelDict)
107
- return nothing
108
- end
109
-
110
- """
111
- $(SIGNATURES)
112
- DANGER: Clears the whole robot + sessions from the database.
73
+ Return whether `sym::Symbol` represents a variable vertex in the graph.
113
74
"""
114
- function clearRobot!! (dfg:: CloudGraphsDFG ):: Nothing
115
- # Perform detach+deletion
116
- _getNeoNodesFromCyphonQuery (dfg. neo4jInstance, " (node:$(dfg. userId) :$(dfg. robotId) ) detach delete node " )
117
-
118
- # Clearing history
119
- dfg. addHistory = Symbol[]
120
- empty! (dfg. variableCache)
121
- empty! (dfg. factorCache)
122
- empty! (dfg. labelDict)
123
- return nothing
124
- end
75
+ isVariable (dfg:: CloudGraphsDFG , sym:: Symbol ):: Bool =
76
+ " VARIABLE" in _getNodeTags (dfg. neo4jInstance, [dfg. userId, dfg. robotId, dfg. sessionId, String (sym)])
125
77
126
78
"""
127
- $(SIGNATURES)
128
- DANGER: Clears the whole user + robot + sessions from the database.
129
- """
130
- function clearUser!! (dfg:: CloudGraphsDFG ):: Nothing
131
- # Perform detach+deletion
132
- _getNeoNodesFromCyphonQuery (dfg. neo4jInstance, " (node:$(dfg. userId) ) detach delete node " )
133
-
134
- # Clearing history
135
- dfg. addHistory = Symbol[]
136
- empty! (dfg. variableCache)
137
- empty! (dfg. factorCache)
138
- empty! (dfg. labelDict)
139
- return nothing
140
- end
79
+ $SIGNATURES
141
80
81
+ Return whether `sym::Symbol` represents a factor vertex in the graph.
142
82
"""
143
- $(SIGNATURES)
144
- DANGER: Copies and overwrites the destination session.
145
- If no destination specified then it creates a unique one.
146
- """
147
- function copySession! (sourceDFG:: CloudGraphsDFG , destDFG:: Union{Nothing, CloudGraphsDFG} ):: CloudGraphsDFG
148
- if destDFG == nothing
149
- destDFG = _getDuplicatedEmptyDFG (sourceDFG)
150
- end
151
- _copyIntoGraph! (sourceDFG, destDFG, union (getVariableIds (sourceDFG), getFactorIds (sourceDFG)), true )
152
- return destDFG
153
- end
154
- """
155
- $(SIGNATURES)
156
- DANGER: Copies the source to a new unique destination.
157
- """
158
- copySession! (sourceDFG:: CloudGraphsDFG ):: CloudGraphsDFG = copySession! (sourceDFG, nothing )
83
+ isFactor (dfg:: CloudGraphsDFG , sym:: Symbol ):: Bool =
84
+ " FACTOR" in _getNodeTags (dfg. neo4jInstance, [dfg. userId, dfg. robotId, dfg. sessionId, String (sym)])
159
85
160
86
"""
161
87
$(SIGNATURES)
@@ -392,13 +318,17 @@ end
392
318
$(SIGNATURES)
393
319
Update solver and estimate data for a variable (variable can be from another graph).
394
320
"""
395
- function updateVariableSolverData ! (dfg:: CloudGraphsDFG , sourceVariable:: DFGVariable ):: DFGVariable
321
+ function mergeUpdateVariableSolverData ! (dfg:: CloudGraphsDFG , sourceVariable:: DFGVariable ):: DFGVariable
396
322
if ! exists (dfg, sourceVariable)
397
323
error (" Source variable '$(sourceVariable. label) ' doesn't exist in the graph." )
398
324
end
399
- nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, sourceVariable. label)
400
- Neo4j. setnodeproperty (dfg. neo4jInstance. graph, nodeId, " estimateDict" , JSON2. write (sourceVariable. estimateDict))
401
- Neo4j. setnodeproperty (dfg. neo4jInstance. graph, nodeId, " solverDataDict" , JSON2. write (Dict (keys (sourceVariable. solverDataDict) .=> map (vnd -> pack (dfg, vnd), values (sourceVariable. solverDataDict)))))
325
+ var = getVariable (dfg, sourceVariable. label)
326
+ newEsts = merge! (var. estimateDict, deepcopy (sourceVariable. estimateDict))
327
+ newSolveData = merge! (var. solverDataDict, sourceVariable. solverDataDict)
328
+ Neo4j. setnodeproperty (dfg. neo4jInstance. graph, var. _internalId, " estimateDict" ,
329
+ JSON2. write (newEsts))
330
+ Neo4j. setnodeproperty (dfg. neo4jInstance. graph, var. _internalId, " solverDataDict" ,
331
+ JSON2. write (Dict (keys (newSolveData) .=> map (vnd -> pack (dfg, vnd), values (newSolveData)))))
402
332
return sourceVariable
403
333
end
404
334
@@ -659,19 +589,20 @@ hasOrphans(dfg::CloudGraphsDFG)::Bool = !isFullyConnected(dfg)
659
589
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
660
590
"""
661
591
function getNeighbors (dfg:: CloudGraphsDFG , node:: T ; ready:: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol} where T <: DFGNode
662
- query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(node. label) )--(node) where node:VARIABLE or node:FACTOR "
592
+ query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(node. label) )--(node) where ( node:VARIABLE or node:FACTOR) "
663
593
if ready != nothing || backendset != nothing
664
594
if ready != nothing
665
- query = query * " and node.ready = $(ready) "
595
+ query = query * " and node.ready = $(ready) "
666
596
end
667
597
if backendset != nothing
668
- query = query * " and node.backendset = $(backendset) "
598
+ query = query * " and node.backendset = $(backendset) "
669
599
end
670
600
end
601
+ @debug " [Query] $query "
671
602
neighbors = _getLabelsFromCyphonQuery (dfg. neo4jInstance, query)
672
603
# If factor, need to do variable ordering
673
- if T == DFGFactor
674
- order = intersect (node. _variableOrderSymbols, map (v -> v . dfgNode . label, neighbors) )
604
+ if T <: DFGFactor
605
+ neighbors = intersect (node. _variableOrderSymbols, neighbors)
675
606
end
676
607
return neighbors
677
608
end
@@ -681,20 +612,22 @@ end
681
612
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
682
613
"""
683
614
function getNeighbors (dfg:: CloudGraphsDFG , label:: Symbol ; ready:: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol}
684
- query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(label) )--(node) where node:VARIABLE or node:FACTOR "
615
+ query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(label) )--(node) where ( node:VARIABLE or node:FACTOR) "
685
616
if ready != nothing || backendset != nothing
686
617
if ready != nothing
687
- query = query * " and node.ready = $(ready) "
618
+ query = query * " and node.ready = $(ready) "
688
619
end
689
620
if backendset != nothing
690
- query = query * " and node.backendset = $(backendset) "
621
+ query = query * " and node.backendset = $(backendset) "
691
622
end
692
623
end
624
+ @debug " [Query] $query "
693
625
neighbors = _getLabelsFromCyphonQuery (dfg. neo4jInstance, query)
694
626
# If factor, need to do variable ordering
695
- if _getNodeType (dfg, label) == :FACTOR
696
- factor = getFactor (dfg, label)
697
- order = intersect (factor. _variableOrderSymbols, neighbors)
627
+ if isFactor (dfg, label)
628
+ # Server is authority
629
+ serverOrder = Symbol .(JSON2. read (_getNodeProperty (dfg. neo4jInstance, [dfg. userId, dfg. robotId, dfg. sessionId, String (label)], " _variableOrderSymbols" )))
630
+ neighbors = intersect (serverOrder, neighbors)
698
631
end
699
632
return neighbors
700
633
end
0 commit comments