From d19e6fb9c205ec8b0fea08a5ad2e206dc3dcc9c5 Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Wed, 30 Oct 2024 14:47:26 +0200 Subject: [PATCH 1/2] Update Model and some maintanaince --- src/NavAbilityClient.jl | 3 +- src/NavAbilityDFG.jl | 4 + src/entities/NvaNodes.jl | 2 + src/entities/Variable.jl | 2 +- src/graphql/Model.jl | 33 +++++--- src/services/BlobEntry.jl | 1 + src/services/Common.jl | 8 +- src/services/FactorGraph.jl | 71 ++++++++++++++++++ src/services/Model.jl | 146 ++++-------------------------------- src/services/Variable.jl | 10 ++- 10 files changed, 133 insertions(+), 147 deletions(-) diff --git a/src/NavAbilityClient.jl b/src/NavAbilityClient.jl index 0c0d505..c4803b0 100644 --- a/src/NavAbilityClient.jl +++ b/src/NavAbilityClient.jl @@ -19,10 +19,11 @@ function NavAbilityClient( auth_token::String, apiUrl::String = "https://api.navability.io"; orgLabel::Union{Symbol, Nothing} = nothing, + introspect::Bool = false, kwargs..., ) headers = Dict("Authorization" => "Bearer $auth_token") - client = GQL.Client(apiUrl; headers, kwargs...) + client = GQL.Client(apiUrl; headers, introspect, kwargs...) if isnothing(orgLabel) id = getOrgs(client)[1].id else diff --git a/src/NavAbilityDFG.jl b/src/NavAbilityDFG.jl index 2c7859e..954ca08 100644 --- a/src/NavAbilityDFG.jl +++ b/src/NavAbilityDFG.jl @@ -6,6 +6,8 @@ struct NavAbilityDFG{VT<:AbstractDFGVariable, FT<:AbstractDFGFactor} <: Abstract blobStores::Dict{Symbol, DFG.AbstractBlobStore} end +DFG.getLabel(dfg::NavAbilityDFG) = dfg.fg.label + DFG.getTypeDFGVariables(::NavAbilityDFG{T, <:AbstractDFGFactor}) where {T} = T DFG.getTypeDFGFactors(::NavAbilityDFG{<:AbstractDFGVariable, T}) where {T} = T @@ -77,6 +79,8 @@ function NavAbilityDFG( fg = getGraph(client, fgLabel) end + connect!(client, agent, fg) + return NavAbilityDFG{DFG.Variable, DFG.PackedFactor}( client, fg, diff --git a/src/entities/NvaNodes.jl b/src/entities/NvaNodes.jl index 7d2d42c..86d99a5 100644 --- a/src/entities/NvaNodes.jl +++ b/src/entities/NvaNodes.jl @@ -17,6 +17,8 @@ struct NvaNode{T} label::Symbol end +DFG.getLabel(node::NvaNode) = node.label + @kwdef struct AgentCreateInput # Interface id::UUID#! diff --git a/src/entities/Variable.jl b/src/entities/Variable.jl index 010027f..5c255b4 100644 --- a/src/entities/Variable.jl +++ b/src/entities/Variable.jl @@ -81,7 +81,7 @@ Base.@kwdef struct BlobEntryCreateInput metadata::String _version::String timestamp::ZonedDateTime - size::Int + size::Union{String, Nothing} #FIXME parent::Any end diff --git a/src/graphql/Model.jl b/src/graphql/Model.jl index 14ac4a0..8258d1a 100644 --- a/src/graphql/Model.jl +++ b/src/graphql/Model.jl @@ -5,11 +5,10 @@ #TODO replace sesssion # $GQL_FRAGMENT_SESSION # sessions { ...session_fields } +# $GQL_FRAGMENT_BLOBENTRY FRAGMENT_MODEL = """ -$GQL_FRAGMENT_BLOBENTRY fragment FRAGMENT_MODEL on Model { label - createdTimestamp namespace } """ @@ -23,27 +22,39 @@ QUERY_GET_MODEL = """ query QUERY_GET_MODEL(\$modelId: ID!) { models (where: {id: \$modelId}) { label - createdTimestamp namespace } } """ +# $FRAGMENT_MODEL +# ...FRAGMENT_MODEL QUERY_GET_MODELS_ALL = """ -$FRAGMENT_MODEL { + models { + label + namespace + } +} +""" + +GQL_ADD_MODELS = GQL.gql""" +mutation addModels($input: [ModelCreateInput!]!) { + addModels(input: $input) { models { - ...FRAGMENT_MODEL + label + namespace } + } } """ -GQL_ADD_MODEL = """ -$FRAGMENT_MODEL -mutation addModel(\$label: String!, \$status: String = "", \$description: String = "") { - addModels(input: {label: \$label, status: \$status, description: \$description}) { - models { - ...FRAGMENT_MODEL +QUERY_GET_MODEL_GRAPHS = GQL.gql""" +query getGraphs_Model($id: ID!) { + models(where: {id: $id}) { + fgs { + label + namespace } } } diff --git a/src/services/BlobEntry.jl b/src/services/BlobEntry.jl index 24ed0cd..201f77c 100644 --- a/src/services/BlobEntry.jl +++ b/src/services/BlobEntry.jl @@ -191,6 +191,7 @@ function addBlobEntries!( getCommonProperties(BlobEntryCreateInput, entry)..., id = getId(fgclient, parent, entry.label), parent = createConnect(fgclient, parent), + size = isnothing(entry.size) ? "" : entry.size, #FIXME remove once size is "required" ) end diff --git a/src/services/Common.jl b/src/services/Common.jl index 0668b07..f866038 100644 --- a/src/services/Common.jl +++ b/src/services/Common.jl @@ -11,9 +11,13 @@ function executeGql(cfg::NavAbilityDFG, query::AbstractString, variables, T::Ty executeGql(cfg.client, query, variables, T; kwargs...) end -function executeGql(client::NavAbilityClient, query::AbstractString, variables, T::Type = Any; throw_on_execution_error = true, kwargs...) +function executeGql(cfg::NavAbilityClient, query::AbstractString, variables, T::Type = Any; kwargs...) + executeGql(cfg.client, query, variables, T; kwargs...) +end + +function executeGql(client::GQL.Client, query::AbstractString, variables, T::Type = Any; throw_on_execution_error = true, kwargs...) return GQL.execute( - client.client, + client, query, T; variables, diff --git a/src/services/FactorGraph.jl b/src/services/FactorGraph.jl index 0a6289f..e8e9c7c 100644 --- a/src/services/FactorGraph.jl +++ b/src/services/FactorGraph.jl @@ -218,4 +218,75 @@ function DFG.setGraphMetadata!(fgclient::NavAbilityDFG, smallData::Dict{Symbol, base64decode(response.data["updateFactorgraphs"]["factorgraphs"][1]["metadata"]), Dict{Symbol, DFG.SmallDataTypes}, ) +end + + +## ======================================================================================= +## Connect Factorgraph to other nodes +## ======================================================================================= + + +GQL_CONNECT_GRAPH_TO_MODEL = GQL.gql""" +mutation connectGraphModel($modelId: ID!, $fgId: ID!) { + updateModels( + where: { id: $modelId } + update: { fgs: { connect: { where: { node: { id: $fgId } } } } } + ) { + info { + relationshipsCreated + } + } +} +""" + +function connect!(client, model::NvaNode{Model}, fg::NvaNode{Factorgraph}) + variables = Dict("modelId" => getId(model), "fgId" => getId(fg)) + + response = executeGql(client, GQL_CONNECT_GRAPH_TO_MODEL, variables) + + return response.data["updateModels"]["info"]["relationshipsCreated"] +end + + +GQL_CONNECT_GRAPH_TO_AGENT = GQL.gql""" +mutation connectGraphModel($agentId: ID!, $fgId: ID!) { + updateAgents( + where: { id: $agentId } + update: { fgs: { connect: { where: { node: { id: $fgId } } } } } + ) { + info { + relationshipsCreated + } + } +} +""" + +function connect!(client, agent::NvaNode{Agent}, fg::NvaNode{Factorgraph}) + variables = Dict("agentId" => getId(agent), "fgId" => getId(fg)) + + response = executeGql(client, GQL_CONNECT_GRAPH_TO_AGENT, variables) + + return response.data["updateAgents"]["info"]["relationshipsCreated"] +end + + +QUERY_GET_GRAPHS_AGENTS = GQL.gql""" +query getAgents_Graph($id: ID!) { + factorgraphs(where: {id: $id}) { + agents { + label + namespace + } + } +} +""" + +function getAgents(client::NavAbilityClient, fg::NvaNode{Factorgraph}) + response = executeGql( + client, + QUERY_GET_GRAPHS_AGENTS, + Dict("id" => getId(fg)), + Vector{Dict{Symbol, Vector{NvaNode{Agent}}}}, + ) + return handleQuery(response, "factorgraphs")[1][:agents] end \ No newline at end of file diff --git a/src/services/Model.jl b/src/services/Model.jl index 4b17ce7..2c8de81 100644 --- a/src/services/Model.jl +++ b/src/services/Model.jl @@ -1,35 +1,20 @@ function getModel(client::NavAbilityClient, label::Symbol) - id = getId(client.id, label) variables = Dict("modelId" => id) T = Vector{NvaNode{Model}} - response = GQL.execute( - client.client, - QUERY_GET_MODEL, - T; - variables, - throw_on_execution_error = true, - ) + response = executeGql(client, QUERY_GET_MODEL, variables, T) return handleQuery(response, "models", label) end +function getModels(client) + response = executeGql(client, QUERY_GET_MODELS_ALL, Dict(), Vector{NvaNode{Model}}) + return handleQuery(response, "models") +end -GQL_ADD_MODELS = GQL.gql""" -mutation addModels($input: [ModelCreateInput!]!) { - addModels(input: $input) { - models { - label - createdTimestamp - namespace - } - } -} -""" - -function addModel!(client::NavAbilityClient, label::Symbol, model=nothing; modelKwargs...) +function addModel!(client::NavAbilityClient, label::Symbol, model = nothing; modelKwargs...) input = [ ModelCreateInput(; id = getId(client.id, label), @@ -37,123 +22,24 @@ function addModel!(client::NavAbilityClient, label::Symbol, model=nothing; model org = createConnect(client.id), getCommonProperties(ModelCreateInput, model)..., getCommonProperties(ModelCreateInput, modelKwargs)..., - ) + ), ] - variables = (input=input,) + variables = (input = input,) - # AgentRemoteResponse T = @NamedTuple{models::Vector{NvaNode{Model}}} - response = - GQL.execute(client.client, GQL_ADD_MODELS, T; variables, throw_on_execution_error = true) + response = executeGql(client, GQL_ADD_MODELS, variables, T) return handleMutate(response, "addModels", :models)[1] end -## ======================================================================================= -function getModels(client::GQL.Client) - T = Vector{Model} - - response = GQL.execute(client, QUERY_GET_MODELS_ALL, T; throw_on_execution_error = true) - - return response.data["models"] -end - -function getModel(client::GQL.Client, modelId::UUID) - variables = Dict("modelId" => modelId) - - T = Vector{Model} - - response = - GQL.execute(client, QUERY_GET_MODEL, T; variables, throw_on_execution_error = true) - - return response.data["models"][1] -end - -GQL_LINK_SESSION_TO_MODEL = GQL.gql""" -mutation linkSessionModel($modelId: ID!, $sessionId: ID!) { - updateModels( - where: { id: $modelId } - connect: { sessions: { where: { node: { id: $sessionId } } } } - ) { - info { - nodesCreated - nodesDeleted - relationshipsCreated - relationshipsDeleted - } - } -} -""" - -function addModel!(client::GQL.Client, modelLabel::String; status = "", description = "") - variables = - Dict("label" => modelLabel, "status" => status, "description" => description) - response = GQL.execute( - client, - GQL_ADD_MODEL; - # T; - variables, - throw_on_execution_error = true, - ) - return response.data["addModels"]["models"][1] -end - -function addGraph!(client::GQL.Client, model::NvaNode{Model}, fg::NvaNode{Factorgraph}) - variables = Dict("modelId" => modelId, "sessionId" => sessionId) - - response = GQL.execute( +function getGraphs(client::NavAbilityClient, model::NvaNode{Model}) + response = executeGql( client, - GQL_LINK_SESSION_TO_MODEL; - variables, - throw_on_execution_error = true, + QUERY_GET_MODEL_GRAPHS, + Dict("id" => getId(model)), + Vector{Dict{Symbol, Vector{NvaNode{Factorgraph}}}}, ) - - return response.data["updateModels"]["info"] -end - - -## - -## model -# models: {connect: {where: {node: {id: $id2}}}}} -GQL_ADD_MODEL = GQL.gql""" -mutation addModel( - $id: ID = "", - $label: String = "", - $status: String = "", - $tags: [String!] = "", - $description: String = "", - $metadata: String = "", - $namespace: ID! = "" -) -{ - addModels( - input: {id: $id, - label: $label, - status: $status, - tags: $tags, - description: $description, - metadata: $metadata, - org: {connect: {where: {node: {id: $namespace}}}} - } - ) { - models { - createdTimestamp - description - id - label - lastUpdatedTimestamp - metadata - namespace - status - tags - } - info { - nodesCreated - relationshipsCreated - } - } -} -""" \ No newline at end of file + return handleQuery(response, "models")[1][:fgs] +end \ No newline at end of file diff --git a/src/services/Variable.jl b/src/services/Variable.jl index a52c68a..5de63a8 100644 --- a/src/services/Variable.jl +++ b/src/services/Variable.jl @@ -23,6 +23,7 @@ function VariableCreateInput(fgclient::NavAbilityDFG, v::Variable) else entry.blobId end, + size = isnothing(entry.size) ? "" : entry.size, ), ) end @@ -108,7 +109,12 @@ function addVariable!(fgclient::NavAbilityDFG, v::Variable) return handleMutate(response, "addVariables", :variables)[1] end -function DFG.addVariables!(fgclient::NavAbilityDFG, vars::Vector{Variable}; chunksize = 20) +function DFG.addVariables!( + fgclient::NavAbilityDFG, + vars::Vector{Variable}; + chunksize::Int = 20, + showprogress::Bool = length(vars) > 1000, +) # addvars = VariableCreateInput.(fgclient, vars) @@ -117,7 +123,7 @@ function DFG.addVariables!(fgclient::NavAbilityDFG, vars::Vector{Variable}; chun T = @NamedTuple{variables::Vector{Variable}} - newVarReturns = asyncmap(chunks) do c + newVarReturns = @showprogress enabled = showprogress asyncmap(chunks) do c response = executeGql(fgclient, GQL_ADD_VARIABLES, Dict("variablesToCreate" => c), T;) handleMutate(response, "addVariables", :variables) From 725b9a5d2c24f88209d89f5adc0643852966ea0d Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Wed, 30 Oct 2024 15:13:16 +0200 Subject: [PATCH 2/2] patch docs to be up to date for v0.8 --- docs/make.jl | 10 +++++----- docs/src/index.md | 6 +----- docs/src/summary.md | 4 ++-- docs/{src => todo}/buildgraph.md | 0 docs/{src => todo}/factors.md | 0 docs/todo/index_extra.md | 5 +++++ docs/{src => todo}/solvers.md | 0 docs/{src => todo}/start.md | 0 docs/{src => todo}/variables.md | 0 9 files changed, 13 insertions(+), 12 deletions(-) rename docs/{src => todo}/buildgraph.md (100%) rename docs/{src => todo}/factors.md (100%) create mode 100644 docs/todo/index_extra.md rename docs/{src => todo}/solvers.md (100%) rename docs/{src => todo}/start.md (100%) rename docs/{src => todo}/variables.md (100%) diff --git a/docs/make.jl b/docs/make.jl index 57b4f2b..e257e8a 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -17,11 +17,11 @@ makedocs(; ), pages = [ "Home" => "index.md", - "Getting Started" => "start.md", - "Variables" => "variables.md", - "Factors" => "factors.md", - "Build a Graph" => "buildgraph.md", - "Graph Solvers" => "solvers.md", + # "Getting Started" => "start.md", + # "Variables" => "variables.md", + # "Factors" => "factors.md", + # "Build a Graph" => "buildgraph.md", + # "Graph Solvers" => "solvers.md", "Index" => "summary.md", ], ) diff --git a/docs/src/index.md b/docs/src/index.md index 0892088..ab5cf37 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -2,8 +2,4 @@ Welcome to the NavAbilitySDK documentation. Various NavAbilitySDKs exist for different programming languages. This particular documentation set is for the Julia language package, however, there is strong consistency between the SDKs for various languages. All the SDKs make standard, authenticated requests to the NavAbility servers, thereby enforcing consistency of operations. -Convenient links to other language NavAbilitySDKs: -- [NavAbilitySDK.py](https://github.com/NavAbility/NavAbilitySDK.py) -- [NavAbilitySDK.js](https://github.com/NavAbility/NavAbilitySDK.js) - -Next, see the [Getting Started](@ref getting_started) page. \ No newline at end of file +NavAbilitySDK.jl extends functions of [DistributedFactorGraphs.jl](https://github.com/JuliaRobotics/DistributedFactorGraphs.jl) and more documentaion is avialable [here](https://juliarobotics.org/DistributedFactorGraphs.jl/latest/). \ No newline at end of file diff --git a/docs/src/summary.md b/docs/src/summary.md index 3777c09..0ed95b7 100644 --- a/docs/src/summary.md +++ b/docs/src/summary.md @@ -9,6 +9,6 @@ Documentation for [NavAbilitySDK](https://github.com/NavAbility/NavAbilitySDK.jl ```@index ``` - +``` diff --git a/docs/src/buildgraph.md b/docs/todo/buildgraph.md similarity index 100% rename from docs/src/buildgraph.md rename to docs/todo/buildgraph.md diff --git a/docs/src/factors.md b/docs/todo/factors.md similarity index 100% rename from docs/src/factors.md rename to docs/todo/factors.md diff --git a/docs/todo/index_extra.md b/docs/todo/index_extra.md new file mode 100644 index 0000000..3f96aa9 --- /dev/null +++ b/docs/todo/index_extra.md @@ -0,0 +1,5 @@ +Convenient links to other language NavAbilitySDKs: +- [NavAbilitySDK.py](https://github.com/NavAbility/NavAbilitySDK.py) +- [NavAbilitySDK.js](https://github.com/NavAbility/NavAbilitySDK.js) + +Next, see the [Getting Started](@ref getting_started) page. \ No newline at end of file diff --git a/docs/src/solvers.md b/docs/todo/solvers.md similarity index 100% rename from docs/src/solvers.md rename to docs/todo/solvers.md diff --git a/docs/src/start.md b/docs/todo/start.md similarity index 100% rename from docs/src/start.md rename to docs/todo/start.md diff --git a/docs/src/variables.md b/docs/todo/variables.md similarity index 100% rename from docs/src/variables.md rename to docs/todo/variables.md