Skip to content

Commit b8f4f2e

Browse files
committed
Reintroducing factor tests, optimizations
1 parent f6c124d commit b8f4f2e

File tree

5 files changed

+74
-12
lines changed

5 files changed

+74
-12
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,31 @@ copySession!(sourceDFG::CloudGraphsDFG)::CloudGraphsDFG = copySession!(sourceDFG
146146
Return whether `sym::Symbol` represents a variable vertex in the graph.
147147
"""
148148
isVariable(dfg::CloudGraphsDFG, sym::Symbol)::Bool =
149-
"VARIABLE" in _getNodeTags(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, sym)
149+
"VARIABLE" in _getNodeTags(dfg.neo4jInstance, [dfg.userId, dfg.robotId, dfg.sessionId, String(sym)])
150150

151151
"""
152152
$SIGNATURES
153153
154154
Return whether `sym::Symbol` represents a factor vertex in the graph.
155155
"""
156156
isFactor(dfg::CloudGraphsDFG, sym::Symbol)::Bool =
157-
"FACTOR" in _getNodeTags(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, sym)
157+
"FACTOR" in _getNodeTags(dfg.neo4jInstance, [dfg.userId, dfg.robotId, dfg.sessionId, String(sym)])
158+
159+
getUserData(dfg::CloudGraphsDFG)::Dict{Symbol, String} = _getNodeProperty(dfg.neo4jInstance, [dfg.userId, "USER"])
160+
function setUserData(dfg::CloudGraphsDFG, data::Dict{Symbol, String})::Bool
161+
error("Not implemented yet")
162+
return true
163+
end
164+
getRobotData(dfg::CloudGraphsDFG)::Dict{Symbol, String} = _getNodeProperty(dfg.neo4jInstance, [dfg.userId, dfg.robotId, "ROBOT"])
165+
function setRobotData(dfg::CloudGraphsDFG, data::Dict{Symbol, String})::Bool
166+
error("Not implemented yet")
167+
return true
168+
end
169+
getSessionData(dfg::CloudGraphsDFG)::Dict{Symbol, String} = _getNodeProperty(dfg.neo4jInstance, [dfg.userId, dfg.robotId, dfg.sessionId, "SESSION"])
170+
function setSessionData(dfg::CloudGraphsDFG, data::Dict{Symbol, String})::Bool
171+
error("Not implemented yet")
172+
return true
173+
end
158174

159175
"""
160176
$(SIGNATURES)
@@ -695,7 +711,7 @@ function getNeighbors(dfg::CloudGraphsDFG, label::Symbol; ready::Union{Nothing,
695711
# If factor, need to do variable ordering
696712
if isFactor(dfg, label)
697713
# Server is authority
698-
serverOrder = Symbol.(JSON2.read(_getNodeProperty(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, label, "_variableOrderSymbols")))
714+
serverOrder = Symbol.(JSON2.read(_getNodeProperty(dfg.neo4jInstance, [dfg.userId, dfg.robotId, dfg.sessionId, String(label)], "_variableOrderSymbols")))
699715
neighbors = intersect(serverOrder, neighbors)
700716
end
701717
return neighbors

src/CloudGraphsDFG/services/CommonFunctions.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ end
3737
$(SIGNATURES)
3838
Get a node property - returns nothing if not found
3939
"""
40-
function _getNodeProperty(neo4jInstance::Neo4jInstance, userId::String, robotId::String, sessionId::String, nodeId::Symbol, property::String)
41-
query = "match (n:$userId:$robotId:$sessionId:$nodeId) return n.$property"
40+
function _getNodeProperty(neo4jInstance::Neo4jInstance, nodeLabels::Vector{String}, property::String)
41+
query = "match (n:$(join(nodeLabels, ":"))) return n.$property"
4242
result = DistributedFactorGraphs._queryNeo4j(neo4jInstance, query)
43-
43+
4444
return result.results[1]["data"][1]["row"][1]
4545
end
4646

4747
"""
4848
$(SIGNATURES)
4949
Get a node's tags
5050
"""
51-
function _getNodeTags(neo4jInstance::Neo4jInstance, userId::String, robotId::String, sessionId::String, nodeId::Symbol)::Union{Nothing, Vector{String}}
52-
query = "match (n:$userId:$robotId:$sessionId:$nodeId) return labels(n)"
51+
function _getNodeTags(neo4jInstance::Neo4jInstance, nodeLabels::Vector{String})::Union{Nothing, Vector{String}}
52+
query = "match (n:$(join(nodeLabels, ":"))) return labels(n)"
5353
result = DistributedFactorGraphs._queryNeo4j(neo4jInstance, query)
5454
length(result.results[1]["data"]) != 1 && return nothing
5555
return result.results[1]["data"][1]["row"][1]

src/services/DFGFactor.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,32 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any}, iifModule)::DFGFac
7272
# Note, once inserted, you still need to call IIF.rebuildFactorMetadata!
7373
return factor
7474
end
75+
76+
# function ==(a::GenericFunctionNodeData{T1, S1}, b::GenericFunctionNodeData{T2, S2})
77+
# T1 != T2 && @debug("T-Types are not the same")==nothing && return false
78+
# S1 != S2 && @debug("S-Types are not the same")==nothing && return false
79+
# a.fncargvID != a.fncargvID && @debug("fncargvID are not the same")==nothing && return false
80+
# a.eliminated != b.eliminated && @debug("eliminated are not the same")==nothing && return false
81+
# a.potentialused != b.potentialused && @debug("potentialused are not the same")==nothing && return false
82+
# a.edgeIDs != b.edgeIDs && @debug("edgeIDs are not the same")==nothing && return false
83+
# a.frommodule != b.frommodule && @debug("frommodule are not the same")==nothing && return false
84+
# a.fnc != b.fnc && @debug("fnc are not the same")==nothing && return false
85+
# a.multihypo != b.multihypo && @debug("multihypo are not the same")==nothing && return false
86+
# a.certainhypo != b.certainhypo && @debug("certainhypo are not the same")==nothing && return false
87+
# return true
88+
# end
89+
#
90+
# """
91+
# $(SIGNATURES)
92+
# Equality check for DFGFactor.
93+
# """
94+
# function ==(a::DFGFactor, b::DFGFactor)::Bool
95+
# a.label != b.label && @debug("label is not equal")==nothing && return false
96+
# a.tags != b.tags && @debug("tags is not equal")==nothing && return false
97+
# a.data != b.data && @debug("data is not equal")==nothing && return false
98+
# a.ready != b.ready && @debug("ready is not equal")==nothing && return false
99+
# a.backendset != b.backendset && @debug("backendset is not equal")==nothing && return false
100+
# a._internalId != b._internalId && @debug("_internalId is not equal")==nothing && return false
101+
# a._variableOrderSymbols != b._variableOrderSymbols && @debug("_variableOrderSymbols is not equal")==nothing && return false
102+
# return true
103+
# end

test/Project.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[deps]
2+
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
3+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
4+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
5+
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
6+
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
7+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
8+
IncrementalInference = "904591bb-b899-562f-9e6f-b8df64c7d480"
9+
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
10+
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
11+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
12+
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
13+
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
14+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
15+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
16+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
17+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
18+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/iifInterfaceTests.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ end
125125
@testset "Gets, Sets, and Accessors" begin
126126
global dfg,v1,v2,f1
127127
@test getVariable(dfg, v1.label) == v1
128-
#TODO compare factor
129-
@test_skip getFactor(dfg, f1.label) == f1
128+
@test getFactor(dfg, f1.label) == f1
130129
@test_throws Exception getVariable(dfg, :nope)
131130
@test_throws Exception getVariable(dfg, "nope")
132131
@test_throws Exception getFactor(dfg, :nope)
@@ -137,8 +136,8 @@ end
137136
@test updateVariable!(dfg, v1Prime) == v1 #Maybe move to crud
138137
@test updateVariable!(dfg, v1Prime) == getVariable(dfg, v1.label)
139138
f1Prime = deepcopy(f1)
140-
@test_skip updateFactor!(dfg, f1Prime) == f1 #Maybe move to crud
141-
@test_skip updateFactor!(dfg, f1Prime) == getFactor(dfg, f1.label)
139+
@test updateFactor!(dfg, f1Prime) == f1 #Maybe move to crud
140+
@test updateFactor!(dfg, f1Prime) == getFactor(dfg, f1.label)
142141

143142
# Accessors
144143
@test label(v1) == v1.label

0 commit comments

Comments
 (0)