Skip to content

Commit 0cb9675

Browse files
authored
Merge pull request #484 from JuliaRobotics/maint/20Q2/cgdfgmodule
move cgdfg to a module in dfg
2 parents 0d59341 + 8ccb71b commit 0cb9675

File tree

8 files changed

+122
-29
lines changed

8 files changed

+122
-29
lines changed

src/CloudGraphsDFG/CloudGraphsDFG.jl

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,94 @@
1+
module CloudGraphsDFGs
2+
3+
using ...DistributedFactorGraphs
4+
5+
import ...DistributedFactorGraphs: setSolverParams!,
6+
getFactor,
7+
setDescription!,
8+
# getLabelDict,
9+
getUserData,
10+
setUserData!,
11+
getRobotData,
12+
setRobotData!,
13+
getSessionData,
14+
setSessionData!,
15+
addVariable!,
16+
getVariable,
17+
getAddHistory,
18+
addFactor!,
19+
getSolverParams,
20+
exists,
21+
isVariable,
22+
isFactor,
23+
getDescription,
24+
updateVariable!,
25+
updateFactor!,
26+
deleteVariable!,
27+
deleteFactor!,
28+
getVariables,
29+
listVariables,
30+
ls,
31+
getFactors,
32+
listFactors,
33+
lsf,
34+
isConnected,
35+
getNeighbors,
36+
buildSubgraph,
37+
copyGraph!,
38+
getBiadjacencyMatrix,
39+
_getDuplicatedEmptyDFG,
40+
toDot,
41+
toDotFile,
42+
AbstractBigDataEntry,
43+
isValidLabel,
44+
_invalidIds,#TODO Export from DFG
45+
_validLabelRegex, #TODO Export from DFG
46+
updateUserData!,
47+
getUserData,
48+
deleteUserData!,
49+
emptyUserData!,
50+
updateRobotData!,
51+
getRobotData,
52+
deleteRobotData!,
53+
emptyRobotData!,
54+
updateSessionData!,
55+
getSessionData,
56+
deleteSessionData!,
57+
emptySessionData!,
58+
listTags,
59+
mergeTags!,
60+
removeTags!,
61+
emptyTags!,
62+
addVariableSolverData!,
63+
updateVariableSolverData!,
64+
deleteVariableSolverData!,
65+
getVariableSolverData,
66+
mergeVariableData!,
67+
getPPE,
68+
addPPE!,
69+
listPPEs,
70+
deletePPE!,
71+
updatePPE!,
72+
packPPE,
73+
unpackPPE,
74+
getSolvable,
75+
setSolvable!
76+
177
using Neo4j
278
using Base64
379

80+
using DocStringExtensions
81+
using Requires
82+
using Dates
83+
using Distributions
84+
using Reexport
85+
using JSON
86+
using Unmarshal
87+
using JSON2 # JSON2 requires all properties to be in correct sequence, can't guarantee that from DB.
88+
using LinearAlgebra
89+
using SparseArrays
90+
using UUIDs
91+
492
# Entities
593
include("entities/CloudGraphsDFG.jl")
694
include("entities/CGStructure.jl")
@@ -23,3 +111,5 @@ export existsSession, existsRobot, existsUser
23111
export getSession, getRobot, getUser
24112
export updateSession, updateRobot, updateUser
25113
export lsSessions, lsRobots, lsUsers
114+
115+
end

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ function mergeVariableData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable)::D
267267
return sourceVariable
268268
end
269269

270-
function mergeUpdateVariableSolverData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable)::DFGVariable
271-
@warn "Deprecated CloudGraphsDFG.mergeUpdateVariableSolverData!, use mergeVariableData! instead."
272-
mergeVariableData!(dfg, sourceVariable)
273-
end
274270

275271
function updateFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor
276272
if !exists(dfg, factor)

src/CloudGraphsDFG/services/CommonFunctions.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Get a node property - returns nothing if not found
5656
function _getNodeProperty(neo4jInstance::Neo4jInstance, nodeLabels::Vector{String}, property::String)
5757
query = "match (n:$(join(nodeLabels, ":"))) return n.$property"
5858
@debug "[Query] $query"
59-
result = DistributedFactorGraphs._queryNeo4j(neo4jInstance, query)
59+
result = _queryNeo4j(neo4jInstance, query)
6060
length(result.results[1]["data"]) != 1 && error("No data returned from the query.")
6161
length(result.results[1]["data"][1]["row"]) != 1 && error("No data returned from the query.")
6262
return result.results[1]["data"][1]["row"][1]
@@ -75,7 +75,7 @@ function _setNodeProperty(neo4jInstance::Neo4jInstance, nodeLabels::Vector{Strin
7575
set n.$property = $value
7676
return count(n)"""
7777
@debug "[Query] $query"
78-
result = DistributedFactorGraphs._queryNeo4j(neo4jInstance, query)
78+
result = _queryNeo4j(neo4jInstance, query)
7979
length(result.results[1]["data"]) != 1 && return 0
8080
length(result.results[1]["data"][1]["row"]) != 1 && return 0
8181
return result.results[1]["data"][1]["row"][1]
@@ -87,14 +87,14 @@ Get a node's tags
8787
"""
8888
function _getNodeTags(neo4jInstance::Neo4jInstance, nodeLabels::Vector{String})::Union{Nothing, Vector{String}}
8989
query = "match (n:$(join(nodeLabels, ":"))) return labels(n)"
90-
result = DistributedFactorGraphs._queryNeo4j(neo4jInstance, query)
90+
result = _queryNeo4j(neo4jInstance, query)
9191
length(result.results[1]["data"]) != 1 && return nothing
9292
return result.results[1]["data"][1]["row"][1]
9393
end
9494

9595
function _getNodeCount(neo4jInstance::Neo4jInstance, nodeLabels::Vector{String})::Int
9696
query = "match (n:$(join(nodeLabels, ":"))) return count(n)"
97-
result = DistributedFactorGraphs._queryNeo4j(neo4jInstance, query)
97+
result = _queryNeo4j(neo4jInstance, query)
9898
length(result.results[1]["data"]) != 1 && return 0
9999
length(result.results[1]["data"][1]["row"]) != 1 && return 0
100100
return result.results[1]["data"][1]["row"][1]

src/Common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ sortDFG(vars::Vector{Symbol}; lt=natural_lt, kwargs...)::Vector{Symbol} = sort(v
6262
##==============================================================================
6363
## Validation of session, robot, and user IDs.
6464
##==============================================================================
65-
6665
global _invalidIds = ["USER", "ROBOT", "SESSION", "VARIABLE", "FACTOR", "ENVIRONMENT", "PPE", "BIGDATA", "FACTORGRAPH"]
66+
6767
global _validLabelRegex = r"^[a-zA-Z]\w*$"
6868

6969
"""

src/DistributedFactorGraphs.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export findClosestTimestamp, findVariableNearTimestamp
208208

209209
# Serialization
210210
export packVariable, unpackVariable, packFactor, unpackFactor
211+
export rebuildFactorMetadata!
211212

212213
# File import and export
213214
export saveDFG, loadDFG!
@@ -273,24 +274,28 @@ include("services/CompareUtils.jl")
273274
# Include the FilesDFG API.
274275
include("FileDFG/FileDFG.jl")
275276

276-
include("CloudGraphsDFG/CloudGraphsDFG.jl")
277-
278277
# Custom show and printing for variable factor etc.
279278
include("services/CustomPrinting.jl")
280279

280+
# To be moved as necessary.
281+
include("Common.jl")
282+
283+
# Big data extensions
284+
include("BigData/BigData.jl")
285+
281286
function __init__()
282287
@require GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231" begin
283288
@info "Including Plots"
284289
include("DFGPlots/DFGPlots.jl")
285290
@reexport using .DFGPlots
286291
end
287292

293+
if get(ENV, "DFG_USE_CGDFG", "") == "true"
294+
@info "Including CloudGraphsDFG"
295+
@eval Base.include(DistributedFactorGraphs, joinpath(@__DIR__, "CloudGraphsDFG/CloudGraphsDFG.jl"))
296+
@eval DistributedFactorGraphs @reexport using .CloudGraphsDFGs
297+
end
288298
end
289299

290-
# To be moved as necessary.
291-
include("Common.jl")
292-
293-
# Big data extensions
294-
include("BigData/BigData.jl")
295300

296301
end

test/interfaceTests.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ end
9898
end
9999

100100
@testset "BigData Entries" begin
101-
if fg1 isa CloudGraphsDFG
102-
@test_skip BigDataEntriesTestBlock!(fg1, var2)
103-
else
101+
if typeof(fg1) <: InMemoryDFGTypes
104102
BigDataEntriesTestBlock!(fg1, var2)
103+
else
104+
@test_skip BigDataEntriesTestBlock!(fg1, var2)
105105
end
106106
end
107107

108108
@testset "TODO Sorteer groep" begin
109-
if fg1 isa CloudGraphsDFG
110-
@test_skip testGroup!(fg1, var1, var2, fac0, fac1)
111-
else
109+
if typeof(fg1) <: InMemoryDFGTypes
112110
testGroup!(fg1, var1, var2, fac0, fac1)
111+
else
112+
@test_skip testGroup!(fg1, var1, var2, fac0, fac1)
113113
end
114114
end
115115

@@ -146,10 +146,10 @@ end
146146

147147
@testset "Producing Dot Files" begin
148148
rand(4)
149-
if testDFGAPI == CloudGraphsDFG
150-
ProducingDotFiles(testDFGAPI, var1, var2, fac1)
151-
else
149+
if testDFGAPI <: InMemoryDFGTypes
152150
ProducingDotFiles(testDFGAPI)
151+
else
152+
ProducingDotFiles(testDFGAPI, var1, var2, fac1)
153153
end
154154
end
155155

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Test
22
using GraphPlot # For plotting tests
33
using Neo4j
4+
push!(ENV,"DFG_USE_CGDFG"=>"true")
45
using DistributedFactorGraphs
56
using Pkg
67
using Dates

test/testBlocks.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using DistributedFactorGraphs
22
using Test
33
using Dates
4+
using UUIDs
45

56
import Base: convert
67

@@ -93,8 +94,9 @@ end
9394

9495

9596
##
96-
global testDFGAPI = CloudGraphsDFG
97-
global testDFGAPI = LightDFG
97+
# global testDFGAPI = CloudGraphsDFG
98+
# global testDFGAPI = LightDFG
99+
# T = testDFGAPI
98100

99101
#test Specific definitions
100102
# struct TestInferenceVariable1 <: InferenceVariable end
@@ -105,7 +107,6 @@ global testDFGAPI = LightDFG
105107
struct GeenSolverParams <: AbstractParams
106108
end
107109

108-
T = testDFGAPI
109110
solparams=NoSolverParams()
110111
# DFG Accessors
111112
function DFGStructureAndAccessors(::Type{T}, solparams::AbstractParams=NoSolverParams()) where T <: AbstractDFG
@@ -217,7 +218,7 @@ function UserRobotSessionData!(fg::AbstractDFG)
217218
@test getSessionData(fg, :a) == "44"
218219
#TODO
219220
@test_broken addSessionData!
220-
updateSessionData!(fg, :b=>"3") == getSessionData(fg)
221+
@test updateSessionData!(fg, :b=>"3") == getSessionData(fg)
221222
@test getSessionData(fg, :b) == deleteSessionData!(fg, :b)
222223
@test emptySessionData!(fg) == Dict{Symbol,String}()
223224

0 commit comments

Comments
 (0)