Skip to content

Commit

Permalink
standardize to dfg v0.25 Graph (#260)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Terblanche <[email protected]>
  • Loading branch information
Affie and Affie authored Oct 16, 2024
1 parent b61904c commit f53eb09
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 52 deletions.
16 changes: 8 additions & 8 deletions src/NavAbilityDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function NavAbilityDFG(
authorize = nothing,
storeLabel = :default,
addAgentIfAbsent = false,
addFgIfAbsent = false,
addGraphIfAbsent = false,
addRobotIfNotExists = nothing,
addSessionIfNotExists = nothing,
kwargs...
Expand All @@ -36,7 +36,7 @@ function NavAbilityDFG(
agentLabel;
storeLabel,
addAgentIfAbsent,
addFgIfAbsent,
addGraphIfAbsent,
addRobotIfNotExists,
addSessionIfNotExists
)
Expand All @@ -48,7 +48,7 @@ function NavAbilityDFG(
agentLabel::Symbol;
storeLabel = :default,
addAgentIfAbsent = false,
addFgIfAbsent = false,
addGraphIfAbsent = false,
addRobotIfNotExists = nothing,
addSessionIfNotExists = nothing,
)
Expand All @@ -62,19 +62,19 @@ function NavAbilityDFG(
addAgentIfAbsent = addRobotIfNotExists
end
if !isnothing(addSessionIfNotExists)
@warn "addSessionIfNotExists is deprecated, use addFgIfAbsent instead"
addFgIfAbsent = addSessionIfNotExists
@warn "addSessionIfNotExists is deprecated, use addGraphIfAbsent instead"
addGraphIfAbsent = addSessionIfNotExists
end

if addAgentIfAbsent && !in(agentLabel, listAgents(client))
agent = addAgent!(client, agentLabel)
else
agent = getAgent(client, agentLabel)
end
if addFgIfAbsent && !in(fgLabel, listFgs(client))
fg = addFg!(client, fgLabel)
if addGraphIfAbsent && !in(fgLabel, listGraphs(client))
fg = addGraph!(client, fgLabel)
else
fg = getFg(client, fgLabel)
fg = getGraph(client, fgLabel)
end

return NavAbilityDFG{DFG.Variable, DFG.PackedFactor}(
Expand Down
38 changes: 16 additions & 22 deletions src/NavAbilitySDK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,19 @@ import DistributedFactorGraphs:
addBlob!,
deleteBlob!,
hasBlob,
getSessionBlobEntry,
getSessionBlobEntries,
addSessionBlobEntry!,
addSessionBlobEntries!,
listSessionBlobEntries,
listRobotBlobEntries,
getGraphBlobEntry,
getGraphBlobEntries,
addGraphBlobEntry!,
addGraphBlobEntries!,
listGraphBlobEntries,
listAgentBlobEntries,
exists,
listNeighbors,
findVariableNearTimestamp
# To consider implementing
# setSolverParams!,
# getSolverParams,
# getAddHistory,
#getUserData, # TODO should propably rename to MetaData
#setUserData!, # TODO should propably rename to MetaData
#getRobotData, # TODO should propably rename to MetaData
#setRobotData!, # TODO should propably rename to MetaData
#getSessionData, # TODO should propably rename to MetaData
#setSessionData!, # TODO should propably rename to MetaData
# isVariable,
# isFactor,
# ls,
Expand Down Expand Up @@ -144,12 +138,12 @@ export NavAbilityClient,
PackedFactor

# Function exports
export addRobot!,
addSession!,
deleteSession!,
deleteRobot!,
listRobots,
listSessions,
export addAgent!,
addGraph!,
deleteGraph!,
deleteAgent!,
listAgents,
listGraphs,
getFactor,
getFactors,
getFactorsSkeleton,
Expand Down Expand Up @@ -186,10 +180,10 @@ export addRobot!,
addBlobEntry!,
updateBlobEntry!,
deleteBlobEntry!,
getSessionBlobEntry,
getSessionBlobEntries,
addSessionBlobEntries!,
listSessionBlobEntries,
getGraphBlobEntry,
getGraphBlobEntries,
addGraphBlobEntries!,
listGraphBlobEntries,
getBlob,
addBlob!,
deleteBlob!,
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/BlobEntry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ query listBlobEntries(\$id: ID!) {
"""

GQL_LIST_FACTORGRAPH_BLOBENTRIES = GQL.gql"""
query listFgBlobEntries($id: ID!) {
query listGraphBlobEntries($id: ID!) {
factorgraphs(where: { id: $id }) {
blobEntries {
label
Expand Down Expand Up @@ -106,7 +106,7 @@ query listModelBlobEntries($id: ID!) {

GQL_GET_FG_BLOBENTRIES = """
$(GQL_FRAGMENT_BLOBENTRY)
query getFgBlobEntries(\$id: ID!) {
query getGraphBlobEntries(\$id: ID!) {
factorgraphs(where: { id: \$id }) {
blobEntries {
...blobEntry_fields
Expand Down
11 changes: 5 additions & 6 deletions src/services/AsyncCalls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ methodstoasync = [
:addFactor!,
:addNodeBlobEntries!,
:addPPEs!,
:addRobot!,
:addRobotBlobEntries!,
:addSession!,
:addSessionBlobEntries!,
:addUserBlobEntries!,
:addAgent!,
:addAgentBlobEntries!,
:addGraph!,
:addGraphBlobEntries!,
:addVariable!,
:addVariableSolverData!,
#get
Expand All @@ -20,7 +19,7 @@ methodstoasync = [
:getFactors,
:getFncTypeName,
:getPPE,
:getRobotMeta,
:getAgentMetadata,
:getVariable,
:getVariableSkeleton,
:getVariableSolverData,
Expand Down
8 changes: 4 additions & 4 deletions src/services/BlobEntry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ end
# BlobEntry CRUD on other nodes
# =========================================================================================

function DFG.getFgBlobEntry(fgclient::NavAbilityDFG, label::Symbol)
function DFG.getGraphBlobEntry(fgclient::NavAbilityDFG, label::Symbol)
id = getId(fgclient.fg, label)

T = Vector{DFG.BlobEntry}
Expand All @@ -134,7 +134,7 @@ function DFG.getFgBlobEntry(fgclient::NavAbilityDFG, label::Symbol)
return handleQuery(response, "blobEntries", label)
end

function DFG.getFgBlobEntries(fgclient::NavAbilityDFG, startwith::Union{Nothing,String}=nothing)
function DFG.getGraphBlobEntries(fgclient::NavAbilityDFG, startwith::Union{Nothing,String}=nothing)

id = getId(fgclient.fg)
T = Vector{@NamedTuple{blobEntries::Vector{DFG.BlobEntry}}}
Expand Down Expand Up @@ -195,7 +195,7 @@ function addBlobEntries!(

end

function addFgBlobEntries!(fgclient::NavAbilityDFG, entries::Vector{DFG.BlobEntry})
function addGraphBlobEntries!(fgclient::NavAbilityDFG, entries::Vector{DFG.BlobEntry})
return addBlobEntries!(fgclient, fgclient.fg, entries)
end
function addAgentBlobEntries!(fgclient::NavAbilityDFG, entries::Vector{DFG.BlobEntry})
Expand All @@ -205,7 +205,7 @@ function addModelBlobEntries!(fgclient::NavAbilityDFG, entries::Vector{DFG.BlobE
error("Not implemented")
end

function DFG.listFgBlobEntries(fgclient::NavAbilityDFG)
function DFG.listGraphBlobEntries(fgclient::NavAbilityDFG)

variables = (id=getId(fgclient.fg),)

Expand Down
14 changes: 7 additions & 7 deletions src/services/FactorGraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ query QUERY_GET_FACTORGRAPH(\$fgId: ID!) {
}
"""

function getFg(client::NavAbilityClient, label::Symbol)
function getGraph(client::NavAbilityClient, label::Symbol)
fgId = getId(client.id, label)
variables = Dict("fgId" => fgId)

Expand Down Expand Up @@ -47,7 +47,7 @@ mutation addFactorGraph(
}
"""

function addFg!(client::NavAbilityClient, label::Symbol)
function addGraph!(client::NavAbilityClient, label::Symbol)
@assert isValidLabel(label) "Factor graph label ($Label) is not a valid label"

variables = Dict(
Expand Down Expand Up @@ -82,7 +82,7 @@ mutation deleteFG($id: ID!) {
}
"""

function deleteFg!(fgclient::NavAbilityDFG)
function deleteGraph!(fgclient::NavAbilityDFG)

id = getId(fgclient.fg)
variables = Dict("id" => id)
Expand Down Expand Up @@ -113,7 +113,7 @@ function deleteFg!(fgclient::NavAbilityDFG)
end

QUERY_LIST_FACTORGRAPHS = GQL.gql"""
query listFgs($id: ID!) {
query listGraphs($id: ID!) {
orgs(where: {id: $id}) {
fgs {
label
Expand All @@ -122,7 +122,7 @@ query listFgs($id: ID!) {
}
"""

function listFgs(client::NavAbilityClient)
function listGraphs(client::NavAbilityClient)

T = Vector{Dict{String, Vector{@NamedTuple{label::Symbol}}}}

Expand Down Expand Up @@ -176,7 +176,7 @@ function exists(fgclient::NavAbilityDFG, label::Symbol)
end

#TODO update to standard pattern
function DFG.getFgMetadata(fgclient::NavAbilityDFG)
function DFG.getGraphMetadata(fgclient::NavAbilityDFG)
gql = """
{
factorgraphs(where: {id: "$(getId(fgclient.fg))"}) {
Expand All @@ -197,7 +197,7 @@ function DFG.getFgMetadata(fgclient::NavAbilityDFG)
end
end

function DFG.setFgMetadata!(fgclient::NavAbilityDFG, smallData::Dict{Symbol, DFG.SmallDataTypes})
function DFG.setGraphMetadata!(fgclient::NavAbilityDFG, smallData::Dict{Symbol, DFG.SmallDataTypes})
meta = base64encode(JSON3.write(smallData))

gql = """
Expand Down
2 changes: 1 addition & 1 deletion src/services/Model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function addModel!(client::GQL.Client, modelLabel::String; status = "", descript
return response.data["addModels"]["models"][1]
end

function addFg!(client::GQL.Client, model::NvaNode{Model}, fg::NvaNode{Factorgraph})
function addGraph!(client::GQL.Client, model::NvaNode{Model}, fg::NvaNode{Factorgraph})
variables = Dict("modelId" => modelId, "sessionId" => sessionId)

response = GQL.execute(
Expand Down
4 changes: 2 additions & 2 deletions test/integration/testStandardAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fgLabel = Symbol("TestSession_" * randstring(7))
fgLabel,
agentLabel;
addAgentIfAbsent = true,
addFgIfAbsent = true,
addGraphIfAbsent = true,
)

a_var = NvaSDK.addVariable!(fgclient, :x0, "Pose2")
Expand Down Expand Up @@ -102,7 +102,7 @@ fgLabel = Symbol("TestSession_" * randstring(7))
@test length(listFactors(fgclient)) == 10

@test exists(fgclient, :x1)
x0_neigh = getNeighbors(fgclient, :x0)
x0_neigh = listNeighbors(fgclient, :x0)
@test length(x0_neigh) == 3
@test exists(fgclient, x0_neigh[1])

Expand Down

0 comments on commit f53eb09

Please sign in to comment.