From 4ebc1b4131919a5624defe14328a3ede7965ac00 Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 5 Aug 2022 21:16:09 -0700 Subject: [PATCH 01/63] starting work on initVariable --- src/navability/services/Variable.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index a56dfe7..c04e5c7 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -12,6 +12,7 @@ function addPackedVariable(navAbilityClient::NavAbilityClient, client::Client, v )) |> fetch rootData = JSON.parse(response.Data) if haskey(rootData, "errors") + @error response throw("Error: $(rootData["errors"])") end data = get(rootData,"data",nothing) From dd125a0d6bae00ecf2881a6385eadfe8f8d115e5 Mon Sep 17 00:00:00 2001 From: dehann Date: Sat, 6 Aug 2022 23:49:26 -0700 Subject: [PATCH 02/63] wip initVariable --- src/navability/graphql/Variable.jl | 33 +++++++++++++++++++ src/navability/services/Variable.jl | 51 +++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/src/navability/graphql/Variable.jl b/src/navability/graphql/Variable.jl index ce01bc4..d61d7a7 100644 --- a/src/navability/graphql/Variable.jl +++ b/src/navability/graphql/Variable.jl @@ -119,3 +119,36 @@ GQL_GETVARIABLESFILTERED = """ } } }""" + +GQL_INITVARIABLE = """ + mutation sdk_init_variable( + \$userId: ID!, + \$robotId: ID!, + \$sessionId: ID!, + \$label: String!, + \$variableType: VariableType!, + \$points: [CartesianPointInput]!) { + initVariable( + variable: where: { + sessionKey: { + userId: \$userId, + robotId: \$robotId, + sessionId: \$sessionId, + }, + label: \$label, + variableType: \$variableType + }, + distribution: { + particle: { + points: \$points + } + } + ) { + status { + state + } + context { + eventId + } + } + }""" \ No newline at end of file diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index c04e5c7..fb7e11d 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -99,4 +99,55 @@ end function ls(navAbilityClient::NavAbilityClient, client::Client) return listVariables(navAbilityClient,client) +end + + +function CartesianPointInput(; + x::Float64 = 0.0, + y::Float64 = 0.0, + z::Float64 = 0.0, + rotx::Float64 = 0.0, + roty::Float64 = 0.0, + rotz::Float64 = 0.0 + ) + # + Dict{String,Float64}( + "x" => x, + "y" => y, + "z" => z, + "rotx" => rotx, + "roty" => roty, + "rotz" => rotz, + ) +end + +function initVariableEvent( + client::NavAbilityClient, + context::Client, + label::String, + varType, + points::AbstractVector{Dict{<:AbstractString,<:Real}} + ) + # + response = client.query(QueryOptions( + "sdk_init_variable", + """ + $GQL_INITVARIABLE + """, + Dict( + "userId" => context.userId, + "robotId" => context.robotId, + "sessionId" => context.sessionId, + "label" => label, + "variableType" => varType, + "points" => points + ) + )) |> fetch + + rootData = JSON.parse(response.Data) + if haskey(rootData, "errors") + throw("Error: $(rootData["errors"])") + end + + return "FIXME" end \ No newline at end of file From f34e4f14b03c141e1aaf98a3bce937e5309cd408 Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 7 Aug 2022 11:35:30 -0700 Subject: [PATCH 03/63] wip --- src/navability/entities/Variable.jl | 8 ++++++++ src/navability/services/Variable.jl | 21 +++++++++++---------- test/integration/runtests.jl | 1 + test/integration/testInitVariable.jl | 27 +++++++++++++++++++++++++++ test/unit/runtests.jl | 1 + 5 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 test/integration/testInitVariable.jl diff --git a/src/navability/entities/Variable.jl b/src/navability/entities/Variable.jl index 09af1b9..84846b2 100644 --- a/src/navability/entities/Variable.jl +++ b/src/navability/entities/Variable.jl @@ -3,6 +3,14 @@ using JSON DFG_VERSION = "0.18.1"; +@enum VariableType begin + POINT2 + POINT3 + POSE2 + POSE2Z + POSE3 +end + # FIXME, use dispatch for proper Julian implementation _variableTypeConvert = Dict{Symbol, String}( :Point2 => "RoME.Point2", diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index fb7e11d..7f4555e 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -125,15 +125,13 @@ function initVariableEvent( client::NavAbilityClient, context::Client, label::String, - varType, - points::AbstractVector{Dict{<:AbstractString,<:Real}} - ) + varType::VariableType, + points::AbstractVector{Dict{K,F}} + ) where {K<:AbstractString, F<:Real} # - response = client.query(QueryOptions( + @show mo = MutationOptions( "sdk_init_variable", - """ - $GQL_INITVARIABLE - """, + GQL_INITVARIABLE, Dict( "userId" => context.userId, "robotId" => context.robotId, @@ -142,12 +140,15 @@ function initVariableEvent( "variableType" => varType, "points" => points ) - )) |> fetch + ) + response = client.mutate(mo) |> fetch rootData = JSON.parse(response.Data) if haskey(rootData, "errors") throw("Error: $(rootData["errors"])") end - return "FIXME" -end \ No newline at end of file + return response +end + +# \ No newline at end of file diff --git a/test/integration/runtests.jl b/test/integration/runtests.jl index 53f5605..b8fb963 100644 --- a/test/integration/runtests.jl +++ b/test/integration/runtests.jl @@ -3,6 +3,7 @@ using Random include("./fixtures.jl") include("./testVariable.jl") +include("./testInitVariable.jl") include("./testFactor.jl") include("./testSolve.jl") diff --git a/test/integration/testInitVariable.jl b/test/integration/testInitVariable.jl new file mode 100644 index 0000000..2fc6221 --- /dev/null +++ b/test/integration/testInitVariable.jl @@ -0,0 +1,27 @@ +# test initVariable + + + + +function runInitVariableTests() + @testset "run initVariable tests" begin + + ## + userId = "guest@navability.io" + robotId = "TESTING" + sessionId = "INIT_"*(string(NVA.uuid4())[1:4]) + # connections + @show context = NVA.Client(userId,robotId,sessionId) + client = NVA.NavAbilityHttpsClient(;authorize=false) + resultId = NVA.addVariable(client, context, NVA.Variable("x0", :Pose2)) + # Wait for them to be done before proceeding. + NVA.waitForCompletion(client, [resultId], expectedStatuses=["Complete"], maxSeconds=180) + + # init some value to variable x0 + points = [ NVA.CartesianPointInput(;x=-rand(),y=rand(),rotz=-0.1) for _ in 1:5 ] + + NVA.initVariableEvent(client, context, "x0", NVA.POSE2, points) + end +end + +# \ No newline at end of file diff --git a/test/unit/runtests.jl b/test/unit/runtests.jl index 15b5b6f..f4c9f18 100644 --- a/test/unit/runtests.jl +++ b/test/unit/runtests.jl @@ -1,4 +1,5 @@ using NavAbilitySDK +NVA = NavAbilitySDK using Test using JSON using LinearAlgebra From 98a79d52b913fbb1b1af62bc4e9c1bb47e08959c Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 7 Aug 2022 11:50:39 -0700 Subject: [PATCH 04/63] stuck --- src/navability/entities/Variable.jl | 7 +++ src/navability/graphql/Variable.jl | 69 +++++++++++++++++------------ 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/navability/entities/Variable.jl b/src/navability/entities/Variable.jl index 84846b2..d2bde0a 100644 --- a/src/navability/entities/Variable.jl +++ b/src/navability/entities/Variable.jl @@ -98,4 +98,11 @@ function Variable(label::AbstractString, type::Union{<:AbstractString, Symbol}, timestamp ) return result +end + + +struct InitVariableInput + where + distribution + bandwidth end \ No newline at end of file diff --git a/src/navability/graphql/Variable.jl b/src/navability/graphql/Variable.jl index d61d7a7..695c4e9 100644 --- a/src/navability/graphql/Variable.jl +++ b/src/navability/graphql/Variable.jl @@ -120,35 +120,48 @@ GQL_GETVARIABLESFILTERED = """ } }""" -GQL_INITVARIABLE = """ - mutation sdk_init_variable( - \$userId: ID!, - \$robotId: ID!, - \$sessionId: ID!, - \$label: String!, - \$variableType: VariableType!, - \$points: [CartesianPointInput]!) { - initVariable( - variable: where: { - sessionKey: { - userId: \$userId, - robotId: \$robotId, - sessionId: \$sessionId, - }, - label: \$label, - variableType: \$variableType - }, - distribution: { - particle: { - points: \$points - } - } - ) { - status { - state - } +GQL_INIT_VARIABLE = """ + mutation test_init_variable(\$variable: InitVariableInput!, \$options: EmptyInputOptions) { + test: initVariable(variable: \$variable, options:\$options) { context { eventId } + status { + state + progress + } } - }""" \ No newline at end of file + }""" + +# GQL_INITVARIABLE = """ +# mutation sdk_init_variable( +# \$userId: ID!, +# \$robotId: ID!, +# \$sessionId: ID!, +# \$label: String!, +# \$variableType: VariableType!, +# \$points: [CartesianPointInput]!) { +# initVariable( +# variable: where: { +# sessionKey: { +# userId: \$userId, +# robotId: \$robotId, +# sessionId: \$sessionId, +# }, +# label: \$label, +# variableType: \$variableType +# }, +# distribution: { +# particle: { +# points: \$points +# } +# } +# ) { +# status { +# state +# } +# context { +# eventId +# } +# } +# }""" \ No newline at end of file From 9a64e457815c2e65c56a0d10f88dc39f50330c02 Mon Sep 17 00:00:00 2001 From: dehann Date: Mon, 8 Aug 2022 03:25:03 -0700 Subject: [PATCH 05/63] first initVariable mutation ran --- src/navability/entities/Variable.jl | 6 -- src/navability/graphql/Variable.jl | 7 +- src/navability/services/Variable.jl | 101 ++++++++++++++++++++------- test/integration/testInitVariable.jl | 15 +++- 4 files changed, 93 insertions(+), 36 deletions(-) diff --git a/src/navability/entities/Variable.jl b/src/navability/entities/Variable.jl index d2bde0a..f4b6e9e 100644 --- a/src/navability/entities/Variable.jl +++ b/src/navability/entities/Variable.jl @@ -100,9 +100,3 @@ function Variable(label::AbstractString, type::Union{<:AbstractString, Symbol}, return result end - -struct InitVariableInput - where - distribution - bandwidth -end \ No newline at end of file diff --git a/src/navability/graphql/Variable.jl b/src/navability/graphql/Variable.jl index 695c4e9..a4a30e3 100644 --- a/src/navability/graphql/Variable.jl +++ b/src/navability/graphql/Variable.jl @@ -121,8 +121,11 @@ GQL_GETVARIABLESFILTERED = """ }""" GQL_INIT_VARIABLE = """ - mutation test_init_variable(\$variable: InitVariableInput!, \$options: EmptyInputOptions) { - test: initVariable(variable: \$variable, options:\$options) { + mutation sdk_init_variable( + \$variable: InitVariableInput!, + \$options: EmptyInputOptions + ) { + initVariable(variable: \$variable, options:\$options) { context { eventId } diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index 7f4555e..ccc55db 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -102,43 +102,86 @@ function ls(navAbilityClient::NavAbilityClient, client::Client) end -function CartesianPointInput(; - x::Float64 = 0.0, - y::Float64 = 0.0, - z::Float64 = 0.0, - rotx::Float64 = 0.0, - roty::Float64 = 0.0, - rotz::Float64 = 0.0 +function SessionKey( + userId::AbstractString, + robotId::AbstractString, + sessionId::AbstractString ) # - Dict{String,Float64}( - "x" => x, - "y" => y, - "z" => z, - "rotx" => rotx, - "roty" => roty, - "rotz" => rotz, + Dict{String,String}( + "userId" => userId, + "robotId" => robotId, + "sessionId" => sessionId, ) end +function VariableWhere( + sessionKey, + label::AbstractString, + variableType::VariableType + ) + # + Dict{String,Any}( + "sessionKey" => sessionKey, + "label" => label, + "variableType" => variableType + ) +end + +function CartesianPointInput(; + x::Float64 = 0.0, + y::Float64 = 0.0, + z::Float64 = 0.0, + rotx::Float64 = 0.0, + roty::Float64 = 0.0, + rotz::Float64 = 0.0 + ) + # + Dict{String,Float64}( + "x" => x, + "y" => y, + "z" => z, + "rotx" => rotx, + "roty" => roty, + "rotz" => rotz, + ) +end + +function DistributionInput(; + particle=nothing, + rayleigh=nothing + ) + # + Dict{String,Any}( + (particle isa Nothing ? () : ("particle"=>particle,))..., + (rayleigh isa Nothing ? () : ("rayleigh"=>rayleigh,))... + ) +end + +# struct InitVariableInput +# where +# distribution +# bandwidth +# end +function InitVariableInput(wh,dstr,bw::AbstractVector=[]) + Dict{String,Any}( + "where"=>wh, + "distribution"=>dstr, + (0bw,) : ())... + ) +end + function initVariableEvent( client::NavAbilityClient, context::Client, - label::String, - varType::VariableType, - points::AbstractVector{Dict{K,F}} - ) where {K<:AbstractString, F<:Real} + initVariableInput::Dict, + ) # @show mo = MutationOptions( "sdk_init_variable", - GQL_INITVARIABLE, + GQL_INIT_VARIABLE, Dict( - "userId" => context.userId, - "robotId" => context.robotId, - "sessionId" => context.sessionId, - "label" => label, - "variableType" => varType, - "points" => points + "variable" => initVariableInput ) ) response = client.mutate(mo) |> fetch @@ -150,5 +193,13 @@ function initVariableEvent( return response end +# Dict( +# "userId" => context.userId, +# "robotId" => context.robotId, +# "sessionId" => context.sessionId, +# "label" => label, +# "variableType" => varType, +# "points" => points +# ) # \ No newline at end of file diff --git a/test/integration/testInitVariable.jl b/test/integration/testInitVariable.jl index 2fc6221..faeb22c 100644 --- a/test/integration/testInitVariable.jl +++ b/test/integration/testInitVariable.jl @@ -9,7 +9,7 @@ function runInitVariableTests() ## userId = "guest@navability.io" robotId = "TESTING" - sessionId = "INIT_"*(string(NVA.uuid4())[1:4]) + sessionId = "INITVARIABLE_"*(string(NVA.uuid4())[1:4]) # connections @show context = NVA.Client(userId,robotId,sessionId) client = NVA.NavAbilityHttpsClient(;authorize=false) @@ -18,9 +18,18 @@ function runInitVariableTests() NVA.waitForCompletion(client, [resultId], expectedStatuses=["Complete"], maxSeconds=180) # init some value to variable x0 - points = [ NVA.CartesianPointInput(;x=-rand(),y=rand(),rotz=-0.1) for _ in 1:5 ] + points = Dict{String,Float64}[ NVA.CartesianPointInput(;x=-rand(),y=rand(),rotz=-0.1) for _ in 1:5 ] - NVA.initVariableEvent(client, context, "x0", NVA.POSE2, points) + sessionKey = NVA.SessionKey(userId,robotId,sessionId) + variableWhere = NVA.VariableWhere(sessionKey, "x0", NVA.POSE2) + particleInput = Dict{String,Any}("points"=>points) + distributionInput = Dict{String,Any}("particle"=>particleInput) + # distr = Dict{String,Any}("distribution"=>distributionInput) + initVarInp = NVA.InitVariableInput(variableWhere, distributionInput) + + NVA.initVariableEvent(client, context, initVarInp) + + @warn "TODO, get values back from API to make sure numerics were properly set." end end From b6d6173859606781a7c11b5f27bec5029a780013 Mon Sep 17 00:00:00 2001 From: dehann Date: Mon, 8 Aug 2022 03:46:10 -0700 Subject: [PATCH 06/63] incl new initVariable loop-back test --- Project.toml | 4 +++- src/navability/services/Variable.jl | 2 +- test/integration/runtests.jl | 1 + test/integration/testInitVariable.jl | 17 +++++++++++++---- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 11cbea8..93f224b 100644 --- a/Project.toml +++ b/Project.toml @@ -22,10 +22,12 @@ DocStringExtensions = "0.8, 0.9" Downloads = "1" HTTP = "0.9, 1" JSON = "0.21" +TensorCast = "0.4" julia = "1.6" [extras] +TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["TensorCast","Test"] diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index ccc55db..25f68b3 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -177,7 +177,7 @@ function initVariableEvent( initVariableInput::Dict, ) # - @show mo = MutationOptions( + mo = MutationOptions( "sdk_init_variable", GQL_INIT_VARIABLE, Dict( diff --git a/test/integration/runtests.jl b/test/integration/runtests.jl index b8fb963..6c289b3 100644 --- a/test/integration/runtests.jl +++ b/test/integration/runtests.jl @@ -24,6 +24,7 @@ sessionId2d = get(ENV,"SESSION_ID","TestSession2D"*randstring(7)) # Note - Tests incrementally build on each other because this is an # integration test. runVariableTests( client, navabilityClient2D ) + runInitVariableTests(; client ) runFactorTests( client, navabilityClient2D ) runSolveTests( client, navabilityClient2D ) diff --git a/test/integration/testInitVariable.jl b/test/integration/testInitVariable.jl index faeb22c..ac40339 100644 --- a/test/integration/testInitVariable.jl +++ b/test/integration/testInitVariable.jl @@ -1,9 +1,9 @@ # test initVariable +using TensorCast - -function runInitVariableTests() +function runInitVariableTests(;client = NVA.NavAbilityHttpsClient(;authorize=false)) @testset "run initVariable tests" begin ## @@ -12,13 +12,14 @@ function runInitVariableTests() sessionId = "INITVARIABLE_"*(string(NVA.uuid4())[1:4]) # connections @show context = NVA.Client(userId,robotId,sessionId) - client = NVA.NavAbilityHttpsClient(;authorize=false) + resultId = NVA.addVariable(client, context, NVA.Variable("x0", :Pose2)) # Wait for them to be done before proceeding. NVA.waitForCompletion(client, [resultId], expectedStatuses=["Complete"], maxSeconds=180) # init some value to variable x0 - points = Dict{String,Float64}[ NVA.CartesianPointInput(;x=-rand(),y=rand(),rotz=-0.1) for _ in 1:5 ] + pts = [[-rand();rand();-0.1] for _ in 1:5] + points = Dict{String,Float64}[ NVA.CartesianPointInput(;x=pt[1],y=pt[2],rotz=pt[3]) for pt in pts ] sessionKey = NVA.SessionKey(userId,robotId,sessionId) variableWhere = NVA.VariableWhere(sessionKey, "x0", NVA.POSE2) @@ -30,6 +31,14 @@ function runInitVariableTests() NVA.initVariableEvent(client, context, initVarInp) @warn "TODO, get values back from API to make sure numerics were properly set." + res = NVA.getVariable(client, context, "x0") + x0 = fetch(res) + + # FIXME cannot remember which way round the reshape should work + x0_vv = reshape(x0["solverData"][1]["vecval"],3,:) + @cast refvv[i][d] := x0_vv[d,i] + + @test isapprox(pts, refvv; atol=1e-8) end end From 117629aeba5bf01dc7488e66105d05954561c1e9 Mon Sep 17 00:00:00 2001 From: dehann Date: Mon, 8 Aug 2022 04:01:25 -0700 Subject: [PATCH 07/63] export, wait for complete, eventId --- src/NavAbilitySDK.jl | 1 + src/navability/services/Variable.jl | 5 +++-- test/integration/testInitVariable.jl | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/NavAbilitySDK.jl b/src/NavAbilitySDK.jl index 476b421..855ee38 100644 --- a/src/NavAbilitySDK.jl +++ b/src/NavAbilitySDK.jl @@ -69,6 +69,7 @@ export getVariable, getVariables, listVariables, ls export addVariable, addPackedVariable export getFactor, getFactors, listFactors, lsf export addFactor, addPackedFactor +export initVariable export solveSession, solveFederated export getStatusMessages, getStatusLatest, getStatusesLatest export waitForCompletion diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index 25f68b3..0e2a935 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -190,8 +190,7 @@ function initVariableEvent( if haskey(rootData, "errors") throw("Error: $(rootData["errors"])") end - - return response + return rootData["data"]["initVariable"]["context"]["eventId"] end # Dict( # "userId" => context.userId, @@ -202,4 +201,6 @@ end # "points" => points # ) +initVariable(w...;kw...) = @async initVariableEvent(w...;kw...) + # \ No newline at end of file diff --git a/test/integration/testInitVariable.jl b/test/integration/testInitVariable.jl index ac40339..2e61a45 100644 --- a/test/integration/testInitVariable.jl +++ b/test/integration/testInitVariable.jl @@ -28,7 +28,9 @@ function runInitVariableTests(;client = NVA.NavAbilityHttpsClient(;authorize=fal # distr = Dict{String,Any}("distribution"=>distributionInput) initVarInp = NVA.InitVariableInput(variableWhere, distributionInput) - NVA.initVariableEvent(client, context, initVarInp) + eventId = NVA.initVariable(client, context, initVarInp) |> fetch + @info "waitForCompletion on initVariable" eventId + NVA.waitForCompletion(client, [eventId], expectedStatuses=["Complete"], maxSeconds=180) @warn "TODO, get values back from API to make sure numerics were properly set." res = NVA.getVariable(client, context, "x0") From 4f9f83f3a14f2ae0a7d7d75014398aaab1d2c7a3 Mon Sep 17 00:00:00 2001 From: Dehann Fourie <6412556+dehann@users.noreply.github.com> Date: Mon, 8 Aug 2022 04:33:39 -0700 Subject: [PATCH 08/63] Update test/integration/testInitVariable.jl --- test/integration/testInitVariable.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/testInitVariable.jl b/test/integration/testInitVariable.jl index 2e61a45..cdfbeb2 100644 --- a/test/integration/testInitVariable.jl +++ b/test/integration/testInitVariable.jl @@ -32,7 +32,6 @@ function runInitVariableTests(;client = NVA.NavAbilityHttpsClient(;authorize=fal @info "waitForCompletion on initVariable" eventId NVA.waitForCompletion(client, [eventId], expectedStatuses=["Complete"], maxSeconds=180) - @warn "TODO, get values back from API to make sure numerics were properly set." res = NVA.getVariable(client, context, "x0") x0 = fetch(res) From d1a4ec12e59b4da30ed66b09c9f638809ee634f4 Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 12 Aug 2022 12:35:18 -0700 Subject: [PATCH 09/63] improve testing Pose3 and initVariable --- Project.toml | 2 +- test/integration/testInitVariable.jl | 15 +++++++++------ test/integration/testStandardAPI.jl | 6 ++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 93f224b..03e630c 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] -Diana = "0.2" +Diana = "0.2, 0.3" DocStringExtensions = "0.8, 0.9" Downloads = "1" HTTP = "0.9, 1" diff --git a/test/integration/testInitVariable.jl b/test/integration/testInitVariable.jl index 2e61a45..3943b6d 100644 --- a/test/integration/testInitVariable.jl +++ b/test/integration/testInitVariable.jl @@ -3,18 +3,22 @@ using TensorCast -function runInitVariableTests(;client = NVA.NavAbilityHttpsClient(;authorize=false)) +function runInitVariableTests(; + client = NVA.NavAbilityHttpsClient(;authorize=false), + userId = "guest@navability.io", + robotId = "TESTING", + sessionId = "INITVARIABLE_"*(string(NVA.uuid4())[1:4]) + ) + # @testset "run initVariable tests" begin ## - userId = "guest@navability.io" - robotId = "TESTING" - sessionId = "INITVARIABLE_"*(string(NVA.uuid4())[1:4]) # connections @show context = NVA.Client(userId,robotId,sessionId) - resultId = NVA.addVariable(client, context, NVA.Variable("x0", :Pose2)) + resultId = NVA.addVariable(client, context, NVA.Variable("x0", :Pose2)) |> fetch # Wait for them to be done before proceeding. + @info "Wait on addVariable eventId" resultId NVA.waitForCompletion(client, [resultId], expectedStatuses=["Complete"], maxSeconds=180) # init some value to variable x0 @@ -25,7 +29,6 @@ function runInitVariableTests(;client = NVA.NavAbilityHttpsClient(;authorize=fal variableWhere = NVA.VariableWhere(sessionKey, "x0", NVA.POSE2) particleInput = Dict{String,Any}("points"=>points) distributionInput = Dict{String,Any}("particle"=>particleInput) - # distr = Dict{String,Any}("distribution"=>distributionInput) initVarInp = NVA.InitVariableInput(variableWhere, distributionInput) eventId = NVA.initVariable(client, context, initVarInp) |> fetch diff --git a/test/integration/testStandardAPI.jl b/test/integration/testStandardAPI.jl index d1de61b..eba2393 100644 --- a/test/integration/testStandardAPI.jl +++ b/test/integration/testStandardAPI.jl @@ -32,4 +32,10 @@ sessionId = get(ENV,"SESSION_ID","TestSession_"*string(uuid4())[1:8]) addVariable(client, context, "z1", :Point2) addFactor(client, context, ["z0", "z1"], NVA.Point2Point2(Z=FullNormal([1.,0.], diagm([1.,1])))) + addVariable(client, context, "p3_0", :Pose3) + addFactor(client, context, ["p3_0"], NVA.PriorPose3(Z=FullNormal([0.;1.;0;zeros(3)], diagm([1.;1;1;ones(3)])))) + + addVariable(client, context, :p3_1, :Pose3) + addFactor(client, context, [:p3_0,:p3_1], NVA.Pose3Pose3(Z=FullNormal([1.;0.;0;zeros(3)], diagm([1.;1;1;ones(3)])))) + end \ No newline at end of file From 7ce8756b54b5b41ded9180427943fe18bca7f038 Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 12 Aug 2022 12:53:46 -0700 Subject: [PATCH 10/63] new waitForCompletion2 --- src/navability/graphql/Status.jl | 13 +++++++++++++ src/navability/services/Utils.jl | 26 ++++++++++++++++++++++++++ test/integration/testInitVariable.jl | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/navability/graphql/Status.jl b/src/navability/graphql/Status.jl index 687ed67..94c45a3 100644 --- a/src/navability/graphql/Status.jl +++ b/src/navability/graphql/Status.jl @@ -29,3 +29,16 @@ query sdk_get_statuslatest(\$id: ID!) { } } """ + +GQL_GET_EVENTS_BY_ID = """ + query events_by_id(\$eventId:String) { + test: events(where: {context:{eventId:\$eventId}}) { + context { + eventId + } + status { + state + } + } + } +""" \ No newline at end of file diff --git a/src/navability/services/Utils.jl b/src/navability/services/Utils.jl index 1c308e0..ba6395d 100644 --- a/src/navability/services/Utils.jl +++ b/src/navability/services/Utils.jl @@ -43,6 +43,32 @@ function waitForCompletion( waitForCompletion(navAbilityClient, rids; kw...) end +function WaitForCompletion2(client, eventId; maxSeconds=60, totalRequired=1, completeRequired=1) + elapsedInSeconds = 0 + incrementInSeconds = 5 + while elapsedInSeconds < maxSeconds + get_event_response = client.query(QueryOptions( + GQL_GET_EVENTS_BY_ID, + Dict( + "eventId" => eventId + ) + )) + payload = JSON.parse(get_event_response.Data) + events = payload["data"]["test"] + completeEvents = filter(event -> event["status"]["state"] == "Complete", events) + if size(events)[1] >= totalRequired && size(completeEvents)[1] >= completeRequired + return true + end + failedEvents = filter(event -> event["status"]["state"] == "Failed", payload["data"]["test"]) + if size(failedEvents)[1] > 0 + return false + end + elapsedInSeconds += incrementInSeconds + sleep(incrementInSeconds) + end + return false + end + # helper functions to construct for most likely user object function GraphVizApp(ct::Client; variableStartsWith=nothing) suffix = "" diff --git a/test/integration/testInitVariable.jl b/test/integration/testInitVariable.jl index 6307e84..316e3fe 100644 --- a/test/integration/testInitVariable.jl +++ b/test/integration/testInitVariable.jl @@ -33,7 +33,7 @@ function runInitVariableTests(; eventId = NVA.initVariable(client, context, initVarInp) |> fetch @info "waitForCompletion on initVariable" eventId - NVA.waitForCompletion(client, [eventId], expectedStatuses=["Complete"], maxSeconds=180) + NVA.waitForCompletion2(client, eventId) #, expectedStatuses=["Complete"], maxSeconds=180) res = NVA.getVariable(client, context, "x0") x0 = fetch(res) From 8e96a87699e7a7da20eb8a31e7be91b601cfee67 Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 12 Aug 2022 12:54:47 -0700 Subject: [PATCH 11/63] fixing --- src/navability/services/Utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/navability/services/Utils.jl b/src/navability/services/Utils.jl index ba6395d..7da818f 100644 --- a/src/navability/services/Utils.jl +++ b/src/navability/services/Utils.jl @@ -43,7 +43,7 @@ function waitForCompletion( waitForCompletion(navAbilityClient, rids; kw...) end -function WaitForCompletion2(client, eventId; maxSeconds=60, totalRequired=1, completeRequired=1) +function waitForCompletion2(client, eventId; maxSeconds=60, totalRequired=1, completeRequired=1) elapsedInSeconds = 0 incrementInSeconds = 5 while elapsedInSeconds < maxSeconds From 1a8bd853c9d55c64e18d58096ea58c853f81f47b Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 12 Aug 2022 13:01:35 -0700 Subject: [PATCH 12/63] more fixes --- src/navability/graphql/Status.jl | 2 +- src/navability/services/Utils.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/navability/graphql/Status.jl b/src/navability/graphql/Status.jl index 94c45a3..4f24163 100644 --- a/src/navability/graphql/Status.jl +++ b/src/navability/graphql/Status.jl @@ -31,7 +31,7 @@ query sdk_get_statuslatest(\$id: ID!) { """ GQL_GET_EVENTS_BY_ID = """ - query events_by_id(\$eventId:String) { + query sdk_events_by_id(\$eventId:String) { test: events(where: {context:{eventId:\$eventId}}) { context { eventId diff --git a/src/navability/services/Utils.jl b/src/navability/services/Utils.jl index 7da818f..056b7d5 100644 --- a/src/navability/services/Utils.jl +++ b/src/navability/services/Utils.jl @@ -48,11 +48,12 @@ function waitForCompletion2(client, eventId; maxSeconds=60, totalRequired=1, com incrementInSeconds = 5 while elapsedInSeconds < maxSeconds get_event_response = client.query(QueryOptions( + "sdk_events_by_id", GQL_GET_EVENTS_BY_ID, Dict( "eventId" => eventId ) - )) + )) |> fetch payload = JSON.parse(get_event_response.Data) events = payload["data"]["test"] completeEvents = filter(event -> event["status"]["state"] == "Complete", events) From d63f97e3110af62d899e785ec5d9a46df195a9fb Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 12 Aug 2022 13:44:34 -0700 Subject: [PATCH 13/63] further test fixes --- test/integration/testSolve.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/integration/testSolve.jl b/test/integration/testSolve.jl index 25aed4d..d13adcc 100644 --- a/test/integration/testSolve.jl +++ b/test/integration/testSolve.jl @@ -11,9 +11,11 @@ function testSolveSession(client, context, variableLabels; maxSeconds=180) # allVariableLabels = ls(client, context, variableLabels) # do the solve - resultId = solveSession(client,context) + resultId = solveSession(client,context) |> fetch + @info "solveSession" resultId # Wait for them to be done before proceeding. - waitForCompletion(client, Task[resultId;]; expectedStatuses=["Complete"], maxSeconds) + NVA.waitForCompletion2(client, resultId; maxSeconds) #, expectedStatuses=["Complete"]) + # NVA.waitForCompletion(client, resultId; maxSeconds, expectedStatuses=["Complete"]) # Get PPE's are there for the connected variables. # TODO - complete the factor graph. From 0baed45c9a5ab992aae1d32a081eb28cb6d639a2 Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 12 Aug 2022 13:55:24 -0700 Subject: [PATCH 14/63] add a printout --- test/integration/testInitVariable.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/integration/testInitVariable.jl b/test/integration/testInitVariable.jl index 316e3fe..35560b6 100644 --- a/test/integration/testInitVariable.jl +++ b/test/integration/testInitVariable.jl @@ -42,6 +42,8 @@ function runInitVariableTests(; x0_vv = reshape(x0["solverData"][1]["vecval"],3,:) @cast refvv[i][d] := x0_vv[d,i] + @show refvv + @test isapprox(pts, refvv; atol=1e-8) end end From 0450191b4cd265de210f1d366017254eb9d5477e Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 14 Aug 2022 07:32:49 -0700 Subject: [PATCH 15/63] add exportSession --- src/NavAbilitySDK.jl | 7 ++++++ src/navability/entities/Session.jl | 35 ++++++++++++++++++++++++++++++ src/navability/graphql/Session.jl | 13 +++++++++++ src/navability/services/Session.jl | 29 +++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/navability/entities/Session.jl create mode 100644 src/navability/graphql/Session.jl create mode 100644 src/navability/services/Session.jl diff --git a/src/NavAbilitySDK.jl b/src/NavAbilitySDK.jl index 855ee38..f858913 100644 --- a/src/NavAbilitySDK.jl +++ b/src/NavAbilitySDK.jl @@ -25,8 +25,11 @@ include("./navability/graphql/Factor.jl") include("./navability/graphql/Status.jl") include("./navability/graphql/Variable.jl") include("./navability/graphql/DataBlobs.jl") +include("./navability/graphql/Session.jl") + include("./navability/graphql/QueriesDeprecated.jl") +# TODO remove GQL exports, since users can easily just use NVA.QUERY___ export QUERY_VARIABLE_LABELS export QUERY_FILES, QUERY_CALIBRATION export MUTATION_ADDVARIABLE, MUTATION_ADDFACTOR, MUTATION_ADDSESSIONDATA @@ -45,6 +48,7 @@ include("./navability/entities/Variable.jl") include("./navability/entities/InferenceTypes.jl") include("./navability/entities/Factor.jl") include("./navability/entities/Solve.jl") +include("./navability/entities/Session.jl") export NavAbilityClient, NavAbilityWebsocketClient, NavAbilityHttpsClient, QueryOptions, MutationOptions export Client, Scope export QueryDetail, LABEL, SKELETON, SUMMARY, FULL @@ -56,6 +60,7 @@ export PriorPose3, Pose3Pose3 export ScatterAlignPose2Data export FactorType, Factor export SolveOptions +export BagFormat, SessionKey, SessionId, ExportSessionInput, ExportSessionOptions # Services include("./navability/services/Variable.jl") @@ -65,6 +70,7 @@ include("./navability/services/Status.jl") include("./navability/services/Utils.jl") include("./navability/services/StandardAPI.jl") include("./navability/services/DataBlobs.jl") +include("./navability/services/Session.jl") export getVariable, getVariables, listVariables, ls export addVariable, addPackedVariable export getFactor, getFactors, listFactors, lsf @@ -73,6 +79,7 @@ export initVariable export solveSession, solveFederated export getStatusMessages, getStatusLatest, getStatusesLatest export waitForCompletion +export exportSession export GraphVizApp, MapVizApp diff --git a/src/navability/entities/Session.jl b/src/navability/entities/Session.jl new file mode 100644 index 0000000..2f7a2ca --- /dev/null +++ b/src/navability/entities/Session.jl @@ -0,0 +1,35 @@ + +# @enum BagFormat begin +# NVA # FIXME TARGZ +# ROS1BAG +# MCAP +# end + + +Base.@kwdef struct SessionKey + userId::String + robotId::String + sessionId::String +end + +# dictionary since either fields can be used +function SessionId(; + id::Union{<:AbstractString,Nothing}=nothing, + key::Union{SessionKey,Nothing}=nothing + ) + # + _idorkeys = id isa Nothing + Dict( + (_idorkeys ? () : ("id"=>id,))..., + (!_idorkeys ? () : ("key"=>key,))... + ) +end + +Base.@kwdef struct ExportSessionInput + id::Dict + filename::String +end + +Base.@kwdef struct ExportSessionOptions + format::String +end \ No newline at end of file diff --git a/src/navability/graphql/Session.jl b/src/navability/graphql/Session.jl new file mode 100644 index 0000000..559a773 --- /dev/null +++ b/src/navability/graphql/Session.jl @@ -0,0 +1,13 @@ + +MUTATION_EXPORT_SESSION = """ +mutation sdk_export_session( + $session: ExportSessionInput!, + $options: ExportSessionOptions + ){ + exportSession(session:$session, options:$options) { + context { + eventId + } + } +} +""" \ No newline at end of file diff --git a/src/navability/services/Session.jl b/src/navability/services/Session.jl new file mode 100644 index 0000000..ec8b7c4 --- /dev/null +++ b/src/navability/services/Session.jl @@ -0,0 +1,29 @@ + +function exportSessionEvent( + session::ExportSessionInput; + options = nothing + ) + # + payload = Dict{String, Any}( + "session" => session, + ) + if (!isnothing(solveOptions)) + payload["options"] = options + end + response = navAbilityClient.mutate(MutationOptions( + "solveSession", + MUTATION_EXPORT_SESSION, + payload + )) |> fetch + rootData = JSON.parse(response.Data) + if haskey(rootData, "errors") + throw("Error: $(rootData["errors"])") + end + data = get(rootData,"data",nothing) + if data === nothing return "Error" end + + # return the eventId + return data["exportSession"]["context"]["eventId"] +end + +exportSession( session::ExportSessionInput; options = nothing) = @async exportSessionEvent(session; options) From 9bcfbbb664044230a1bf0ff8dba2f43b881d355b Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 14 Aug 2022 08:54:16 -0700 Subject: [PATCH 16/63] no BagFormat type yet --- src/NavAbilitySDK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NavAbilitySDK.jl b/src/NavAbilitySDK.jl index f858913..5c036ee 100644 --- a/src/NavAbilitySDK.jl +++ b/src/NavAbilitySDK.jl @@ -60,7 +60,7 @@ export PriorPose3, Pose3Pose3 export ScatterAlignPose2Data export FactorType, Factor export SolveOptions -export BagFormat, SessionKey, SessionId, ExportSessionInput, ExportSessionOptions +export SessionKey, SessionId, ExportSessionInput, ExportSessionOptions # Services include("./navability/services/Variable.jl") From 914a38cb5a7bba90749daf000ca4345fc9acec5c Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 14 Aug 2022 09:03:01 -0700 Subject: [PATCH 17/63] bug fix --- src/navability/graphql/Session.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/navability/graphql/Session.jl b/src/navability/graphql/Session.jl index 559a773..e221c89 100644 --- a/src/navability/graphql/Session.jl +++ b/src/navability/graphql/Session.jl @@ -1,10 +1,10 @@ MUTATION_EXPORT_SESSION = """ mutation sdk_export_session( - $session: ExportSessionInput!, - $options: ExportSessionOptions + \$session: ExportSessionInput!, + \$options: ExportSessionOptions ){ - exportSession(session:$session, options:$options) { + exportSession(session:\$session, options:\$options) { context { eventId } From 8b0ead921324b738258daa5e02a88249bb5df664 Mon Sep 17 00:00:00 2001 From: dehann Date: Tue, 16 Aug 2022 13:23:48 -0700 Subject: [PATCH 18/63] update gql for export session --- src/navability/graphql/Session.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/navability/graphql/Session.jl b/src/navability/graphql/Session.jl index e221c89..b0d7fc3 100644 --- a/src/navability/graphql/Session.jl +++ b/src/navability/graphql/Session.jl @@ -8,6 +8,10 @@ mutation sdk_export_session( context { eventId } + status { + state + progress + } } } -""" \ No newline at end of file +""" From f3e79e0af32aadf9f53d20f9326dd02ce02c2f37 Mon Sep 17 00:00:00 2001 From: dehann Date: Tue, 16 Aug 2022 13:24:16 -0700 Subject: [PATCH 19/63] switch to variables to waitForCompletion1 --- src/navability/services/Utils.jl | 55 +++++++++++++++++++++----------- test/integration/testVariable.jl | 2 +- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/navability/services/Utils.jl b/src/navability/services/Utils.jl index 056b7d5..be1546b 100644 --- a/src/navability/services/Utils.jl +++ b/src/navability/services/Utils.jl @@ -35,11 +35,15 @@ end # Dispatch for vector of Tasks function waitForCompletion( - navAbilityClient::NavAbilityClient, - requestIds::AbstractVector{<:Task}; - kw...) + navAbilityClient::NavAbilityClient, + requestIds::AbstractVector{<:Task}; + kw... + ) # - rids = fetch.(requestIds) .|> string + rids = String[] + for reqId in requestIds + push!(rids, fetch(reqId) |> string) + end waitForCompletion(navAbilityClient, rids; kw...) end @@ -53,22 +57,37 @@ function waitForCompletion2(client, eventId; maxSeconds=60, totalRequired=1, com Dict( "eventId" => eventId ) - )) |> fetch - payload = JSON.parse(get_event_response.Data) - events = payload["data"]["test"] - completeEvents = filter(event -> event["status"]["state"] == "Complete", events) - if size(events)[1] >= totalRequired && size(completeEvents)[1] >= completeRequired - return true - end - failedEvents = filter(event -> event["status"]["state"] == "Failed", payload["data"]["test"]) - if size(failedEvents)[1] > 0 - return false - end - elapsedInSeconds += incrementInSeconds - sleep(incrementInSeconds) + )) |> fetch + payload = JSON.parse(get_event_response.Data) + events = payload["data"]["test"] + completeEvents = filter(event -> event["status"]["state"] == "Complete", events) + if size(events)[1] >= totalRequired && size(completeEvents)[1] >= completeRequired + return true + end + failedEvents = filter(event -> event["status"]["state"] == "Failed", payload["data"]["test"]) + if size(failedEvents)[1] > 0 + return false + end + elapsedInSeconds += incrementInSeconds + sleep(incrementInSeconds) end return false - end +end + +# Dispatch for vector of Tasks +function waitForCompletion2( + navAbilityClient::NavAbilityClient, + requestIds::AbstractVector{<:Task}; + kw... + ) + # + # rids = String[] + for reqId in requestIds + # push!(rids, fetch(reqId) |> string) + waitForCompletion2(navAbilityClient, fetch(reqId) |> string; kw...) + end +end + # helper functions to construct for most likely user object function GraphVizApp(ct::Client; variableStartsWith=nothing) diff --git a/test/integration/testVariable.jl b/test/integration/testVariable.jl index f94664e..c9739f3 100644 --- a/test/integration/testVariable.jl +++ b/test/integration/testVariable.jl @@ -8,7 +8,7 @@ function testAddVariable(client, context, variableLabels, variableTypes, variabl end # Wait for them to be done before proceeding. - waitForCompletion(client, resultIds, expectedStatuses=["Complete"], maxSeconds=180) + NVA.waitForCompletion2(client, resultIds; maxSeconds=180) # expectedStatuses=["Complete"] return resultIds end From 875914a47118b7528fcbe7e320cf6c363d2d91cb Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 17 Aug 2022 14:03:14 -0700 Subject: [PATCH 20/63] wip --- src/navability/graphql/Session.jl | 41 +++++++++++++++++++++++++++++++ test/integration/testSolve.jl | 4 +-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/navability/graphql/Session.jl b/src/navability/graphql/Session.jl index b0d7fc3..e1e6b22 100644 --- a/src/navability/graphql/Session.jl +++ b/src/navability/graphql/Session.jl @@ -1,4 +1,23 @@ +GQL_GET_SESSION = """ +query test_get_session(\$userId: ID!, \$robotId: ID!, \$sessionId: ID!) { + users(where: {id: \$userId}) { + id + robots(where:{id: \$robotId}) { + id + sessions(where:{id: \$sessionId}) { + variables { + label + } + factors { + label + } + } + } + } +} +""" + MUTATION_EXPORT_SESSION = """ mutation sdk_export_session( \$session: ExportSessionInput!, @@ -15,3 +34,25 @@ mutation sdk_export_session( } } """ + +GQL_GET_EXPORT_SESSION_COMPLETE_EVENT_BY_ID = """ + query events_by_id(\$eventId:String) { + events(where: {status:{state:Complete}, context:{eventId:\$eventId}}) { + status { + state + } + data { + ... on ExportSessionComplete { + blob { + id + } + } + ... on AddBlobMetadataComplete { + blob { + id + } + } + } + } + } +""" \ No newline at end of file diff --git a/test/integration/testSolve.jl b/test/integration/testSolve.jl index d13adcc..7e9b885 100644 --- a/test/integration/testSolve.jl +++ b/test/integration/testSolve.jl @@ -14,8 +14,8 @@ function testSolveSession(client, context, variableLabels; maxSeconds=180) resultId = solveSession(client,context) |> fetch @info "solveSession" resultId # Wait for them to be done before proceeding. - NVA.waitForCompletion2(client, resultId; maxSeconds) #, expectedStatuses=["Complete"]) - # NVA.waitForCompletion(client, resultId; maxSeconds, expectedStatuses=["Complete"]) + # NVA.waitForCompletion2(client, resultId; maxSeconds) + NVA.waitForCompletion(client, [resultId;]; maxSeconds, expectedStatuses=["Complete"]) # Get PPE's are there for the connected variables. # TODO - complete the factor graph. From f1f1ee8e8c88891a62c065fd5c01c73580ffee62 Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 17 Aug 2022 14:42:28 -0700 Subject: [PATCH 21/63] printout for parametric test --- test/integration/testSolve.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/integration/testSolve.jl b/test/integration/testSolve.jl index 7e9b885..67c56e0 100644 --- a/test/integration/testSolve.jl +++ b/test/integration/testSolve.jl @@ -13,6 +13,7 @@ function testSolveSession(client, context, variableLabels; maxSeconds=180) # do the solve resultId = solveSession(client,context) |> fetch @info "solveSession" resultId + GraphVizApp(context) # Wait for them to be done before proceeding. # NVA.waitForCompletion2(client, resultId; maxSeconds) NVA.waitForCompletion(client, [resultId;]; maxSeconds, expectedStatuses=["Complete"]) @@ -27,9 +28,10 @@ function testSolveSessionParametric(client, context, variableLabels; maxSeconds= # do the solve options = SolveOptions(key=nothing, useParametric=true) - resultId = solveSession(client, context, options) + eventId = solveSession(client, context, options) |> fetch # Wait for them to be done before proceeding. - waitForCompletion(client, Task[resultId;]; expectedStatuses=["Complete"], maxSeconds) + @info "test solveParametric eventId" eventId + waitForCompletion(client, Task[eventId;]; expectedStatuses=["Complete"], maxSeconds) # Get PPE's are there for the connected variables. # TODO - complete the factor graph. From 2112317b24e52a03a2367fdc124977c3002cd97c Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 17 Aug 2022 14:56:55 -0700 Subject: [PATCH 22/63] get event on parametric --- test/integration/testSolve.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/testSolve.jl b/test/integration/testSolve.jl index 67c56e0..bd06b90 100644 --- a/test/integration/testSolve.jl +++ b/test/integration/testSolve.jl @@ -27,11 +27,11 @@ function testSolveSessionParametric(client, context, variableLabels; maxSeconds= # allVariableLabels = ls(client, context, variableLabels) # do the solve - options = SolveOptions(key=nothing, useParametric=true) + options = SolveOptions(key="parametric", useParametric=true) eventId = solveSession(client, context, options) |> fetch # Wait for them to be done before proceeding. @info "test solveParametric eventId" eventId - waitForCompletion(client, Task[eventId;]; expectedStatuses=["Complete"], maxSeconds) + waitForCompletion(client, [eventId;]; expectedStatuses=["Complete"], maxSeconds) # Get PPE's are there for the connected variables. # TODO - complete the factor graph. From 97a770c32f04a0ee6397e5fb764004a906aff6ef Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 17 Aug 2022 15:19:55 -0700 Subject: [PATCH 23/63] remove failing parametric test, see #144 --- test/integration/testSolve.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/testSolve.jl b/test/integration/testSolve.jl index bd06b90..0c34fa5 100644 --- a/test/integration/testSolve.jl +++ b/test/integration/testSolve.jl @@ -54,7 +54,8 @@ function runSolveTests(client, context) variableLabels = ["x0", "x1"] testSolveSession(client, context, variableLabels) - testSolveSessionParametric(client, context, variableLabels) + @error "restore solve parametric test, see #144" + # testSolveSessionParametric(client, context, variableLabels) end @testset "appviz-testset" begin From 331126a0394f6fcc6a4429a6f8fb7d1d6adfd4c0 Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 17 Aug 2022 18:32:46 -0700 Subject: [PATCH 24/63] new test failing on exportSession --- src/NavAbilitySDK.jl | 1 + src/navability/entities/Client.jl | 3 ++ src/navability/entities/NavAbilityClient.jl | 1 - src/navability/graphql/Session.jl | 6 ++- src/navability/services/Session.jl | 33 ++++++++++++-- src/navability/services/Utils.jl | 8 ++++ test/integration/runtests.jl | 2 + test/integration/testExportSession.jl | 48 +++++++++++++++++++++ 8 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 test/integration/testExportSession.jl diff --git a/src/NavAbilitySDK.jl b/src/NavAbilitySDK.jl index 5c036ee..daf9089 100644 --- a/src/NavAbilitySDK.jl +++ b/src/NavAbilitySDK.jl @@ -4,6 +4,7 @@ const NVA = NavAbilitySDK export NVA # Global imports +using Diana using DocStringExtensions using LinearAlgebra using JSON diff --git a/src/navability/entities/Client.jl b/src/navability/entities/Client.jl index 3bebfcf..c3e392b 100644 --- a/src/navability/entities/Client.jl +++ b/src/navability/entities/Client.jl @@ -5,6 +5,9 @@ $(TYPEDEF) The context for a session, made from a user, robot, and session. Users can have multiple robots and robots can have multiple sessions. So this indicates a unique session. + +DevNotes +- Rename to [`SessionKey`](@ref) """ struct Client userId::String diff --git a/src/navability/entities/NavAbilityClient.jl b/src/navability/entities/NavAbilityClient.jl index 5d62baf..236b64d 100644 --- a/src/navability/entities/NavAbilityClient.jl +++ b/src/navability/entities/NavAbilityClient.jl @@ -1,4 +1,3 @@ -using Diana struct QueryOptions name::String diff --git a/src/navability/graphql/Session.jl b/src/navability/graphql/Session.jl index e1e6b22..2730762 100644 --- a/src/navability/graphql/Session.jl +++ b/src/navability/graphql/Session.jl @@ -1,6 +1,10 @@ GQL_GET_SESSION = """ -query test_get_session(\$userId: ID!, \$robotId: ID!, \$sessionId: ID!) { +query sdk_get_session( + \$userId: ID!, + \$robotId: ID!, + \$sessionId: ID! + ) { users(where: {id: \$userId}) { id robots(where:{id: \$robotId}) { diff --git a/src/navability/services/Session.jl b/src/navability/services/Session.jl index ec8b7c4..67e1684 100644 --- a/src/navability/services/Session.jl +++ b/src/navability/services/Session.jl @@ -1,5 +1,6 @@ function exportSessionEvent( + client::NavAbilityClient, session::ExportSessionInput; options = nothing ) @@ -7,11 +8,11 @@ function exportSessionEvent( payload = Dict{String, Any}( "session" => session, ) - if (!isnothing(solveOptions)) + if (!isnothing(options)) payload["options"] = options end - response = navAbilityClient.mutate(MutationOptions( - "solveSession", + response = client.mutate(MutationOptions( + "exportSession", MUTATION_EXPORT_SESSION, payload )) |> fetch @@ -26,4 +27,28 @@ function exportSessionEvent( return data["exportSession"]["context"]["eventId"] end -exportSession( session::ExportSessionInput; options = nothing) = @async exportSessionEvent(session; options) +exportSession( client::NavAbilityClient, session::ExportSessionInput; options = nothing) = @async exportSessionEvent(client,session; options) + +function exportSession( + client::NavAbilityClient, + context::Client, + filename::AbstractString; options=nothing + ) + # + expSessInp = ExportSessionInput(; + id = SessionId(; + key = SessionKey( + userId = context.userId, + robotId = context.robotId, + sessionId = context.sessionId + ) + ), + filename + ) + + exportSession(client, expSessInp; options) +end + + + +# \ No newline at end of file diff --git a/src/navability/services/Utils.jl b/src/navability/services/Utils.jl index be1546b..2d0f7e2 100644 --- a/src/navability/services/Utils.jl +++ b/src/navability/services/Utils.jl @@ -88,6 +88,14 @@ function waitForCompletion2( end end +function waitForCompletionExportSession(client::NavAbilityClient, eventId::AbstractString) + response = client.query(QueryOptions( + GQL_GET_EXPORT_SESSION_COMPLETE_EVENT_BY_ID, + Dict("eventId" => eventId) + )) |> fetch + payload = JSON.parse(response.Data) + blobId = payload["data"]["test"][1]["data"]["blob"]["id"] +end # helper functions to construct for most likely user object function GraphVizApp(ct::Client; variableStartsWith=nothing) diff --git a/test/integration/runtests.jl b/test/integration/runtests.jl index 6c289b3..41423a4 100644 --- a/test/integration/runtests.jl +++ b/test/integration/runtests.jl @@ -6,6 +6,7 @@ include("./testVariable.jl") include("./testInitVariable.jl") include("./testFactor.jl") include("./testSolve.jl") +include("./testExportSession.jl") apiUrl = get(ENV,"API_URL","https://api.navability.io") userId = get(ENV,"USER_ID","guest@navability.io") @@ -27,6 +28,7 @@ sessionId2d = get(ENV,"SESSION_ID","TestSession2D"*randstring(7)) runInitVariableTests(; client ) runFactorTests( client, navabilityClient2D ) runSolveTests( client, navabilityClient2D ) + runExportTests( client, navabilityClient2D ) # test fixtures exampleGraph1D( client, navabilityClient1D; doSolve=false ) diff --git a/test/integration/testExportSession.jl b/test/integration/testExportSession.jl new file mode 100644 index 0000000..1497419 --- /dev/null +++ b/test/integration/testExportSession.jl @@ -0,0 +1,48 @@ + + + +function testExportSession( + client = NVA.NavAbilityHttpsClient(;authorize=false), + context = NVA.Client( + "guest@navability.io", + "TESTING", + "EXPORTSESSION_"*(string(NVA.uuid4())[1:4]) + ); + buildNewGraph::Bool=false + ) + # + if buildNewGraph + # build a graph + resultId = NVA.addVariable(client, context, NVA.Variable("x0", :Pose2)) |> fetch + # Wait for them to be done before proceeding. + @info "Wait on addVariable eventId" resultId + NVA.waitForCompletion(client, [resultId], expectedStatuses=["Complete"], maxSeconds=180) + + eventId = NVA.addFactor(client, context, + NVA.Factor("x0f1", "PriorPose2", ["x0"], NVA.PriorPose2Data()) + ) |> fetch + @info "Wait on addFactor eventId" resultId + + # eventId = NVA.addFactor(client, context, NVA.Factor()) + NVA.waitForCompletion(client, [eventId], expectedStatuses=["Complete"], maxSeconds=180) + end + + # export the graph + eventId = NVA.exportSession(client, context, "testexport.tar.gz", + options=NVA.ExportSessionOptions( + format="NVA" # TODO TARGZ + )) |> fetch + + @info "waiting for export Session" eventId + NVA.waitForCompletionExportSession(client, eventId) +end + + +function runSolveTests(client, context) + @testset "test exportSession" begin + @info "Running test exportSession" + + @error "restore exportSession test" + # testExportSession(client, context; buildNewGraph=false) + end +end From 0778b2287e06990c3d799750608b67e4a48b83d3 Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 17 Aug 2022 18:49:50 -0700 Subject: [PATCH 25/63] oops, typo fix --- test/integration/testExportSession.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/testExportSession.jl b/test/integration/testExportSession.jl index 1497419..369f3c5 100644 --- a/test/integration/testExportSession.jl +++ b/test/integration/testExportSession.jl @@ -38,7 +38,7 @@ function testExportSession( end -function runSolveTests(client, context) +function runExportTests(client, context) @testset "test exportSession" begin @info "Running test exportSession" From 10bbf80716c1a16c386b45cc1149d8c029e549ad Mon Sep 17 00:00:00 2001 From: Dehann Fourie <6412556+dehann@users.noreply.github.com> Date: Wed, 17 Aug 2022 19:25:06 -0700 Subject: [PATCH 26/63] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5be8e74..db823fe 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ # NavAbilitySDK.jl -[![Unit tests](https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml/badge.svg)](https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml) -[![Documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://navability.github.io/NavAbilitySDK.jl/dev/) + +| Stable Release | Dev branch | Documentation | +|----------------|------------|---------------| +| [![Unit tests stb][sdkjl-ci-stb-img]](https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml) | [![Unit tests dev][sdkjl-ci-dev-img]](https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml) | [![Documentation]][sdkjl-docs-url] | + +[sdkjl-ci-dev-img]: https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml/badge.svg?branch=main +[sdkjl-ci-std-img]: https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml/badge.svg?branch=release%2Fv0.4 +[sdkjl-docs-url]: https://img.shields.io/badge/docs-dev-blue.svg)](https://navability.github.io/NavAbilitySDK.jl/dev/ Access NavAbility Cloud factor graph features from Julia. From 0f5f4ddeabfd039f46b83e357d3a55e197f64bc0 Mon Sep 17 00:00:00 2001 From: Dehann Fourie <6412556+dehann@users.noreply.github.com> Date: Wed, 17 Aug 2022 21:01:03 -0700 Subject: [PATCH 27/63] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index db823fe..1716fe6 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,13 @@ | Stable Release | Dev branch | Documentation | |----------------|------------|---------------| -| [![Unit tests stb][sdkjl-ci-stb-img]](https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml) | [![Unit tests dev][sdkjl-ci-dev-img]](https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml) | [![Documentation]][sdkjl-docs-url] | +| [![Unit tests stb][sdkjl-ci-std-img]][sdkjl-ci-url] | [![Unit tests dev][sdkjl-ci-dev-img]][sdkjl-ci-url] | [![Documentation][sdkjl-docs-img]][sdkjl-docs-url] | [sdkjl-ci-dev-img]: https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml/badge.svg?branch=main [sdkjl-ci-std-img]: https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml/badge.svg?branch=release%2Fv0.4 -[sdkjl-docs-url]: https://img.shields.io/badge/docs-dev-blue.svg)](https://navability.github.io/NavAbilitySDK.jl/dev/ +[sdkjl-ci-url]: https://github.com/NavAbility/NavAbilitySDK.jl/actions/workflows/tests.yml +[sdkjl-docs-img]: https://img.shields.io/badge/docs-dev-blue.svg +[sdkjl-docs-url]: https://navability.github.io/NavAbilitySDK.jl/dev/ Access NavAbility Cloud factor graph features from Julia. From a7ada52fb7391bc8098be120997c3f4f229592c8 Mon Sep 17 00:00:00 2001 From: Dehann Fourie <6412556+dehann@users.noreply.github.com> Date: Wed, 17 Aug 2022 21:03:34 -0700 Subject: [PATCH 28/63] Update tests.yml --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6e78e7c..37c1a44 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - release** tags: - v** pull_request: From 8522f997a1850ceaa1699fdc68de5eaf91e51b3f Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 17 Aug 2022 21:09:38 -0700 Subject: [PATCH 29/63] reenable broken test exportSession --- test/integration/testExportSession.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/integration/testExportSession.jl b/test/integration/testExportSession.jl index 369f3c5..c8a7f9c 100644 --- a/test/integration/testExportSession.jl +++ b/test/integration/testExportSession.jl @@ -42,7 +42,6 @@ function runExportTests(client, context) @testset "test exportSession" begin @info "Running test exportSession" - @error "restore exportSession test" - # testExportSession(client, context; buildNewGraph=false) + testExportSession(client, context; buildNewGraph=false) end end From b2bb0a04c1eef0d229c508366ddc5b2e8b021f37 Mon Sep 17 00:00:00 2001 From: Jim hill Date: Thu, 18 Aug 2022 10:05:36 -0700 Subject: [PATCH 30/63] Add retries to sdk --- src/navability/entities/NavAbilityClient.jl | 36 +++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/navability/entities/NavAbilityClient.jl b/src/navability/entities/NavAbilityClient.jl index 5d62baf..5a18f95 100644 --- a/src/navability/entities/NavAbilityClient.jl +++ b/src/navability/entities/NavAbilityClient.jl @@ -44,11 +44,43 @@ function NavAbilityHttpsClient( function query(options::QueryOptions) # NOTE, the query client library used is synchronous, locally converted to async for package consistency - @async dianaClient.Query(options.query, operationName=options.name, vars=options.variables) + @async begin + attempts = 0 + while true + try + return dianaClient.Query(options.query, operationName=options.name, vars=options.variables) + catch err + if attempts < 3 + @warn "[Test Client] WARN Client saw an exception. Retrying!" exception=(err, catch_backtrace()) + sleep(2) + attempts += 1 + else + rethrow() + end + end + end + end end + function mutate(options::MutationOptions) # NOTE, the query client library used is synchronous, locally converted to async for package consistency - @async dianaClient.Query(options.mutation, operationName=options.name, vars=options.variables) + @async begin + attempts = 0 + while true + try + return dianaClient.Query(options.mutation, operationName=options.name, vars=options.variables) + catch err + if attempts < 3 + @warn "[Test Client] WARN Client saw an exception. Retrying!" exception=(err, catch_backtrace()) + sleep(2) + attempts += 1 + else + rethrow() + end + end + end + end end + return NavAbilityClient(query, mutate) end From eb0774508206fe3bc63fee28efbe96d0b24f5b95 Mon Sep 17 00:00:00 2001 From: Jim hill Date: Thu, 18 Aug 2022 14:48:22 -0700 Subject: [PATCH 31/63] export session is passing --- src/NavAbilitySDK.jl | 2 +- src/navability/entities/NavAbilityClient.jl | 34 +++++++++++++++++++-- src/navability/services/Session.jl | 13 +++++++- src/navability/services/Utils.jl | 9 ------ test/integration/testExportSession.jl | 4 ++- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/NavAbilitySDK.jl b/src/NavAbilitySDK.jl index daf9089..0745a3f 100644 --- a/src/NavAbilitySDK.jl +++ b/src/NavAbilitySDK.jl @@ -80,7 +80,7 @@ export initVariable export solveSession, solveFederated export getStatusMessages, getStatusLatest, getStatusesLatest export waitForCompletion -export exportSession +export exportSession, getExportSessionBlobId export GraphVizApp, MapVizApp diff --git a/src/navability/entities/NavAbilityClient.jl b/src/navability/entities/NavAbilityClient.jl index 236b64d..87c227e 100644 --- a/src/navability/entities/NavAbilityClient.jl +++ b/src/navability/entities/NavAbilityClient.jl @@ -43,11 +43,41 @@ function NavAbilityHttpsClient( function query(options::QueryOptions) # NOTE, the query client library used is synchronous, locally converted to async for package consistency - @async dianaClient.Query(options.query, operationName=options.name, vars=options.variables) + @async begin + attempts = 0 + while true + try + return dianaClient.Query(options.query, operationName=options.name, vars=options.variables) + catch err + if attempts < 3 + @warn "[Test Client] WARN Client saw an exception. Retrying!" exception=(err, catch_backtrace()) + sleep(2) + attempts += 1 + else + rethrow() + end + end + end + end end function mutate(options::MutationOptions) # NOTE, the query client library used is synchronous, locally converted to async for package consistency - @async dianaClient.Query(options.mutation, operationName=options.name, vars=options.variables) + @async begin + attempts = 0 + while true + try + return dianaClient.Query(options.mutation, operationName=options.name, vars=options.variables) + catch err + if attempts < 3 + @warn "[Test Client] WARN Client saw an exception. Retrying!" exception=(err, catch_backtrace()) + sleep(2) + attempts += 1 + else + rethrow() + end + end + end + end end return NavAbilityClient(query, mutate) end diff --git a/src/navability/services/Session.jl b/src/navability/services/Session.jl index 67e1684..6d0c92f 100644 --- a/src/navability/services/Session.jl +++ b/src/navability/services/Session.jl @@ -1,4 +1,15 @@ +function getExportSessionBlobId(client::NavAbilityClient, eventId::AbstractString) + response = client.query(QueryOptions( + "events_by_id", + GQL_GET_EXPORT_SESSION_COMPLETE_EVENT_BY_ID, + Dict("eventId" => eventId) + )) |> fetch + payload = JSON.parse(response.Data) + blobId = payload["data"]["events"][1]["data"]["blob"]["id"] + return blobId +end + function exportSessionEvent( client::NavAbilityClient, session::ExportSessionInput; @@ -12,7 +23,7 @@ function exportSessionEvent( payload["options"] = options end response = client.mutate(MutationOptions( - "exportSession", + "sdk_export_session", MUTATION_EXPORT_SESSION, payload )) |> fetch diff --git a/src/navability/services/Utils.jl b/src/navability/services/Utils.jl index 2d0f7e2..5c09040 100644 --- a/src/navability/services/Utils.jl +++ b/src/navability/services/Utils.jl @@ -88,15 +88,6 @@ function waitForCompletion2( end end -function waitForCompletionExportSession(client::NavAbilityClient, eventId::AbstractString) - response = client.query(QueryOptions( - GQL_GET_EXPORT_SESSION_COMPLETE_EVENT_BY_ID, - Dict("eventId" => eventId) - )) |> fetch - payload = JSON.parse(response.Data) - blobId = payload["data"]["test"][1]["data"]["blob"]["id"] -end - # helper functions to construct for most likely user object function GraphVizApp(ct::Client; variableStartsWith=nothing) suffix = "" diff --git a/test/integration/testExportSession.jl b/test/integration/testExportSession.jl index c8a7f9c..17e596b 100644 --- a/test/integration/testExportSession.jl +++ b/test/integration/testExportSession.jl @@ -34,7 +34,9 @@ function testExportSession( )) |> fetch @info "waiting for export Session" eventId - NVA.waitForCompletionExportSession(client, eventId) + NVA.waitForCompletion2(client, eventId) + blobId = NVA.getExportSessionBlobId(client, eventId) + @info "Success: Here is the blobId you can use to download: $blobId" end From 4bf86f31faf4a15fc09cb57b3ed20b712e252f20 Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 19 Aug 2022 09:28:16 -0700 Subject: [PATCH 32/63] add a comment on gql --- src/navability/graphql/Session.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/navability/graphql/Session.jl b/src/navability/graphql/Session.jl index 2730762..61ca046 100644 --- a/src/navability/graphql/Session.jl +++ b/src/navability/graphql/Session.jl @@ -39,6 +39,7 @@ mutation sdk_export_session( } """ +# get the blobId given the blob upload eventId GQL_GET_EXPORT_SESSION_COMPLETE_EVENT_BY_ID = """ query events_by_id(\$eventId:String) { events(where: {status:{state:Complete}, context:{eventId:\$eventId}}) { From e78d8a0b74973b410b64126c48b108a52a0539a1 Mon Sep 17 00:00:00 2001 From: dehann Date: Sat, 20 Aug 2022 06:58:38 -0700 Subject: [PATCH 33/63] kw client constructor --- src/navability/entities/Client.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/navability/entities/Client.jl b/src/navability/entities/Client.jl index c3e392b..6803f71 100644 --- a/src/navability/entities/Client.jl +++ b/src/navability/entities/Client.jl @@ -9,7 +9,7 @@ So this indicates a unique session. DevNotes - Rename to [`SessionKey`](@ref) """ -struct Client +Base.@kwdef struct Client userId::String robotId::String sessionId::String From dfb733a0a45e4dc248d5d11c56bb7d5df9d62b4e Mon Sep 17 00:00:00 2001 From: Dehann Fourie <6412556+dehann@users.noreply.github.com> Date: Mon, 22 Aug 2022 21:59:10 -0700 Subject: [PATCH 34/63] Update testSolve.jl --- test/integration/testSolve.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/integration/testSolve.jl b/test/integration/testSolve.jl index 0c34fa5..bd06b90 100644 --- a/test/integration/testSolve.jl +++ b/test/integration/testSolve.jl @@ -54,8 +54,7 @@ function runSolveTests(client, context) variableLabels = ["x0", "x1"] testSolveSession(client, context, variableLabels) - @error "restore solve parametric test, see #144" - # testSolveSessionParametric(client, context, variableLabels) + testSolveSessionParametric(client, context, variableLabels) end @testset "appviz-testset" begin From b7a776e3321e5fe06369bd6b568d6478d3e1ef9f Mon Sep 17 00:00:00 2001 From: dehann Date: Thu, 25 Aug 2022 23:13:57 -0700 Subject: [PATCH 35/63] default nothing option --- src/navability/entities/Solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/navability/entities/Solve.jl b/src/navability/entities/Solve.jl index 756fc31..30062e2 100644 --- a/src/navability/entities/Solve.jl +++ b/src/navability/entities/Solve.jl @@ -5,7 +5,7 @@ Solver options including the solve key and whether the parametric solver should be used. """ Base.@kwdef struct SolveOptions - key::Union{String, Nothing} + key::Union{String, Nothing} = nothing useParametric::Bool = false end From afbd00ce61476cd80e33113ec2a3fb00d474dc90 Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 26 Aug 2022 15:59:08 -0700 Subject: [PATCH 36/63] add getDataByLabel and exports --- src/NavAbilitySDK.jl | 2 ++ src/navability/services/DataBlobs.jl | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/NavAbilitySDK.jl b/src/NavAbilitySDK.jl index 0745a3f..0e277a0 100644 --- a/src/NavAbilitySDK.jl +++ b/src/NavAbilitySDK.jl @@ -77,6 +77,8 @@ export addVariable, addPackedVariable export getFactor, getFactors, listFactors, lsf export addFactor, addPackedFactor export initVariable +export listDataEntries +export getData, getDataByLabel export solveSession, solveFederated export getStatusMessages, getStatusLatest, getStatusesLatest export waitForCompletion diff --git a/src/navability/services/DataBlobs.jl b/src/navability/services/DataBlobs.jl index 0c60b1c..e80f1fe 100644 --- a/src/navability/services/DataBlobs.jl +++ b/src/navability/services/DataBlobs.jl @@ -55,6 +55,19 @@ getDataEvent(client::NavAbilityClient, context::Client, w...) = getDataEvent(cli getData(w...) = @async getDataEvent(w...) +function getDataByLabel(client, context, varlbl, regex::Regex) + ble = listDataEntries(client, context, varlbl) |> fetch + # filter for the specific blob label + ble_s = filter(x->!(match(regex,x.label) isa Nothing) , ble) + if 0 < length(ble_s) + @assert 1 === length(ble_s) "multiple matches on regex found, please provide a more precise regex: $(regex.pattern), $((s->s.label).(ble_s))" + ble_ = ble_s[1] + # get blob + return NVA.getData(client, context, ble_.id) + end + return nothing +end + ## ========================================================================= ## Upload ## ========================================================================= From 2c3b06c39c775ad16af3247c00db2d4c3c7a3e8b Mon Sep 17 00:00:00 2001 From: dehann Date: Sat, 27 Aug 2022 03:31:24 -0700 Subject: [PATCH 37/63] pass auth_token if available --- src/navability/entities/NavAbilityClient.jl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/navability/entities/NavAbilityClient.jl b/src/navability/entities/NavAbilityClient.jl index d5e5c00..ccdbd20 100644 --- a/src/navability/entities/NavAbilityClient.jl +++ b/src/navability/entities/NavAbilityClient.jl @@ -21,8 +21,9 @@ function NavAbilityWebsocketClient( apiUrl::String="wss://api.navability.io/grap end function NavAbilityHttpsClient( - apiUrl::String="https://api.navability.io"; - authorize::Bool=false + apiUrl::String = "https://api.navability.io"; + auth_token::String = "", + authorize::Bool = 0!==length(auth_token) )::NavAbilityClient # dianaClient = GraphQLClient(apiUrl) @@ -34,10 +35,14 @@ function NavAbilityHttpsClient( # seekstart(st) # tok = read(st, String) # Base.shred!(st) - println(" > VSCode ONLY WORKAROUND, input issue, see https://github.com/julia-vscode/julia-vscode/issues/785") - println(" > Workaround: first press 0 then enter, and then paste the token and hit enter a second time.") - println("Copy-paste auth token: ") - tok = readline(stdin) + tok = if 0===length(auth_token) + println(" > VSCode ONLY WORKAROUND, input issue, see https://github.com/julia-vscode/julia-vscode/issues/785") + println(" > Workaround: first press 0 then enter, and then paste the token and hit enter a second time.") + println("Copy-paste auth token: ") + readline(stdin) + else + auth_token + end dianaClient.serverAuth("Bearer "*tok) end From 988d85f284b76a60bfa0fae222cfc0987e469215 Mon Sep 17 00:00:00 2001 From: dehann Date: Sat, 27 Aug 2022 03:34:06 -0700 Subject: [PATCH 38/63] mv comment --- src/navability/entities/NavAbilityClient.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/navability/entities/NavAbilityClient.jl b/src/navability/entities/NavAbilityClient.jl index ccdbd20..c686f40 100644 --- a/src/navability/entities/NavAbilityClient.jl +++ b/src/navability/entities/NavAbilityClient.jl @@ -30,12 +30,12 @@ function NavAbilityHttpsClient( # auth if authorize - # FIXME, use Base.getpass instead of readline once VSCode supports getpass. - # st = Base.getpass("Copy-paste auth token") - # seekstart(st) - # tok = read(st, String) - # Base.shred!(st) tok = if 0===length(auth_token) + # FIXME, use Base.getpass instead of readline once VSCode supports getpass. + # st = Base.getpass("Copy-paste auth token") + # seekstart(st) + # tok = read(st, String) + # Base.shred!(st) println(" > VSCode ONLY WORKAROUND, input issue, see https://github.com/julia-vscode/julia-vscode/issues/785") println(" > Workaround: first press 0 then enter, and then paste the token and hit enter a second time.") println("Copy-paste auth token: ") From efce79663439b463ccde3a72aa9dee803f602871 Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 28 Aug 2022 23:31:28 -0700 Subject: [PATCH 39/63] improved getDataByLabel --- src/navability/services/DataBlobs.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/navability/services/DataBlobs.jl b/src/navability/services/DataBlobs.jl index e80f1fe..b01099d 100644 --- a/src/navability/services/DataBlobs.jl +++ b/src/navability/services/DataBlobs.jl @@ -55,13 +55,15 @@ getDataEvent(client::NavAbilityClient, context::Client, w...) = getDataEvent(cli getData(w...) = @async getDataEvent(w...) -function getDataByLabel(client, context, varlbl, regex::Regex) +function getDataByLabel(client, context, varlbl, regex::Regex; lt=isless, verbose::Bool=true) ble = listDataEntries(client, context, varlbl) |> fetch # filter for the specific blob label ble_s = filter(x->!(match(regex,x.label) isa Nothing) , ble) if 0 < length(ble_s) - @assert 1 === length(ble_s) "multiple matches on regex found, please provide a more precise regex: $(regex.pattern), $((s->s.label).(ble_s))" - ble_ = ble_s[1] + lbls = (s->s.label).(ble_s) + idx = sortperm(lbls; lt) + ble_ = ble_s[idx[end]] + (verbose && 1 < length(ble_s)) ? @warn("multiple matches on regex, fetching $(ble_.label), w/ regex: $(regex.pattern), $(lbls)") : nothing # get blob return NVA.getData(client, context, ble_.id) end From c2180d64e7c7f1e44bfdd12e9cee2a3cbd544987 Mon Sep 17 00:00:00 2001 From: dehann Date: Tue, 30 Aug 2022 22:38:25 -0700 Subject: [PATCH 40/63] accessible values --- src/navability/services/DataBlobs.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/navability/services/DataBlobs.jl b/src/navability/services/DataBlobs.jl index b01099d..7019e78 100644 --- a/src/navability/services/DataBlobs.jl +++ b/src/navability/services/DataBlobs.jl @@ -55,14 +55,25 @@ getDataEvent(client::NavAbilityClient, context::Client, w...) = getDataEvent(cli getData(w...) = @async getDataEvent(w...) -function getDataByLabel(client, context, varlbl, regex::Regex; lt=isless, verbose::Bool=true) +function getDataByLabel( + client, + context, + varlbl, + regex::Regex; + lt=isless, + verbose::Bool=true, + count::Base.RefValue{Int}=Ref(0), # return count of how many matches were found + datalabel::Base.RefValue{String}=Ref("") +) ble = listDataEntries(client, context, varlbl) |> fetch # filter for the specific blob label ble_s = filter(x->!(match(regex,x.label) isa Nothing) , ble) + count[] = length(ble_s) if 0 < length(ble_s) lbls = (s->s.label).(ble_s) idx = sortperm(lbls; lt) ble_ = ble_s[idx[end]] + datalabel[] = ble_.label (verbose && 1 < length(ble_s)) ? @warn("multiple matches on regex, fetching $(ble_.label), w/ regex: $(regex.pattern), $(lbls)") : nothing # get blob return NVA.getData(client, context, ble_.id) From d35524d89c387e4b56acbe271276e321ff31d06d Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 7 Sep 2022 01:48:05 -0700 Subject: [PATCH 41/63] better standardize getData and Entry --- src/Deprecated.jl | 6 +++ src/NavAbilitySDK.jl | 2 +- src/navability/services/DataBlobs.jl | 62 ++++++++++++++++++++-------- 3 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 src/Deprecated.jl diff --git a/src/Deprecated.jl b/src/Deprecated.jl new file mode 100644 index 0000000..12b0a43 --- /dev/null +++ b/src/Deprecated.jl @@ -0,0 +1,6 @@ + +## ========================= +## Remove below before v0.6 +## ========================= + +@deprecate getDataByLabel( client::NavAbilityClient, context::Client, vlbl::AbstractString, w...; kw...) getData(client, context, vlbl, w...; kw...) diff --git a/src/NavAbilitySDK.jl b/src/NavAbilitySDK.jl index 0e277a0..f1f3bd1 100644 --- a/src/NavAbilitySDK.jl +++ b/src/NavAbilitySDK.jl @@ -78,7 +78,7 @@ export getFactor, getFactors, listFactors, lsf export addFactor, addPackedFactor export initVariable export listDataEntries -export getData, getDataByLabel +export getDataEntry, getData export solveSession, solveFederated export getStatusMessages, getStatusLatest, getStatusesLatest export waitForCompletion diff --git a/src/navability/services/DataBlobs.jl b/src/navability/services/DataBlobs.jl index 7019e78..f5eeeb0 100644 --- a/src/navability/services/DataBlobs.jl +++ b/src/navability/services/DataBlobs.jl @@ -54,32 +54,58 @@ end getDataEvent(client::NavAbilityClient, context::Client, w...) = getDataEvent(client, context.userId, w...) getData(w...) = @async getDataEvent(w...) - -function getDataByLabel( - client, - context, - varlbl, - regex::Regex; +function getDataEntry( + client::NavAbilityClient, + context::Client, + vlbl::AbstractString, + regex::Regex; lt=isless, - verbose::Bool=true, count::Base.RefValue{Int}=Ref(0), # return count of how many matches were found - datalabel::Base.RefValue{String}=Ref("") ) - ble = listDataEntries(client, context, varlbl) |> fetch + ble = listDataEntries(client, context, vlbl) |> fetch # filter for the specific blob label ble_s = filter(x->!(match(regex,x.label) isa Nothing) , ble) count[] = length(ble_s) - if 0 < length(ble_s) - lbls = (s->s.label).(ble_s) - idx = sortperm(lbls; lt) - ble_ = ble_s[idx[end]] - datalabel[] = ble_.label - (verbose && 1 < length(ble_s)) ? @warn("multiple matches on regex, fetching $(ble_.label), w/ regex: $(regex.pattern), $(lbls)") : nothing - # get blob - return NVA.getData(client, context, ble_.id) + if 0 === count[] + return nothing end - return nothing + lbls = (s->s.label).(ble_s) + idx = sortperm(lbls; lt) + ble_s[idx] end +getDataEntry( + client::NavAbilityClient, + context::Client, + vlbl::AbstractString, + key::AbstractString; + kw... +) = getDataEntry(client, context, vlbl, Regex(key); kw...) + +function getData( + client::NavAbilityClient, + context::Client, + vlbl::AbstractString, + regex::Regex; + verbose::Bool=true, + datalabel::Base.RefValue{String}=Ref(""), + kw... +) + bles = getDataEntry(client, context, vlbl, regex; kw...) + ble_ = bles[end] + (verbose && 1 < length(bles)) ? @warn("multiple matches on regex, fetching $(ble_.label), w/ regex: $(regex.pattern), $((s->s.label).(bles))") : nothing + datalabel[] = ble_.label + # get blob + return NVA.getData(client, context, ble_.id) +end +getData( + client::NavAbilityClient, + context::Client, + vlbl::AbstractString, + key::AbstractString; + kw... +) = getData(client, context, vlbl, Regex(key); kw...) + + ## ========================================================================= ## Upload From b744df363ac3f1f74a6b6ee708eeaa8d63472c04 Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 7 Sep 2022 01:49:48 -0700 Subject: [PATCH 42/63] update CI for JL 1.8 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 37c1a44..4940b06 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,7 @@ jobs: matrix: julia-version: - '1.6' - - '1.7' + - '1.8' julia-arch: [x64] os: [ubuntu-latest] From ac859f889301b12810fa6086ee4f6985351d7131 Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 7 Sep 2022 02:04:46 -0700 Subject: [PATCH 43/63] include new Deprecated.jl file --- src/NavAbilitySDK.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NavAbilitySDK.jl b/src/NavAbilitySDK.jl index f1f3bd1..dd5bd75 100644 --- a/src/NavAbilitySDK.jl +++ b/src/NavAbilitySDK.jl @@ -85,5 +85,6 @@ export waitForCompletion export exportSession, getExportSessionBlobId export GraphVizApp, MapVizApp +include("Deprecated.jl") end From 7211638afb919c98285d4bf3082e3b9440e411fd Mon Sep 17 00:00:00 2001 From: Dehann Fourie <6412556+dehann@users.noreply.github.com> Date: Wed, 7 Sep 2022 08:22:44 -0700 Subject: [PATCH 44/63] Update DataBlobs.jl --- src/navability/services/DataBlobs.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/navability/services/DataBlobs.jl b/src/navability/services/DataBlobs.jl index f5eeeb0..232465a 100644 --- a/src/navability/services/DataBlobs.jl +++ b/src/navability/services/DataBlobs.jl @@ -91,6 +91,8 @@ function getData( kw... ) bles = getDataEntry(client, context, vlbl, regex; kw...) + # skip out if nothing + bles isa Nothing ? (return nothing) : nothing ble_ = bles[end] (verbose && 1 < length(bles)) ? @warn("multiple matches on regex, fetching $(ble_.label), w/ regex: $(regex.pattern), $((s->s.label).(bles))") : nothing datalabel[] = ble_.label @@ -336,4 +338,4 @@ listDataEntriesEvent(client::NavAbilityClient, listDataEntries(w...) = @async listDataEntriesEvent(w...) -## \ No newline at end of file +## From afcd1e25ec05a8fdd39d8bcc4f6183a8d01d1dd1 Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Mon, 12 Sep 2022 09:11:02 +0200 Subject: [PATCH 45/63] add deleteFactor --- src/navability/graphql/Factor.jl | 16 ++++++++++++++ src/navability/services/Factor.jl | 35 ++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/navability/graphql/Factor.jl b/src/navability/graphql/Factor.jl index 979901c..c011af9 100644 --- a/src/navability/graphql/Factor.jl +++ b/src/navability/graphql/Factor.jl @@ -85,3 +85,19 @@ GQL_GETFACTORSFILTERED = """ } } }""" + +GQL_DELETEFACTOR = """ + mutation sdk_delete_factor( + \$factor: DeleteFactorInput!, + \$options: DeleteFactorOptions + ) { + deleteFactor(factor: \$factor, options: \$options) { + context { + eventId + } + status { + state + progress + } + } +}""" diff --git a/src/navability/services/Factor.jl b/src/navability/services/Factor.jl index 2baa743..be15329 100644 --- a/src/navability/services/Factor.jl +++ b/src/navability/services/Factor.jl @@ -98,4 +98,37 @@ end function lsf(navAbilityClient::NavAbilityClient, client::Client) return listFactors(navAbilityClient,client) -end \ No newline at end of file +end + +function FactorKey(context::Client, label::String) + Dict{String,String}( + "userLabel" => context.userId, + "robotLabel" => context.robotId, + "sessionLabel" => context.sessionId, + "factorLabel" => label, + ) +end + +function deleteFactor(client::NavAbilityClient, context::Client, label::String) + + deleteFactorInput = Dict( + "id"=>Dict("key"=>FactorKey(context, label)) + ) + mo = MutationOptions( + "sdk_delete_factor", + GQL_DELETEFACTOR, + Dict( + "factor" => deleteFactorInput + ) + ) + task = @async begin + response = fetch(client.mutate(mo)) + rootData = JSON.parse(response.Data) + if haskey(rootData, "errors") + throw("Error: $(rootData["errors"])") + end + rootData["data"]["deleteFactor"]["context"]["eventId"] + end + + return task +end From a4b44813c8003b58bbcdf14f3c152aa91a2dc9c4 Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Mon, 12 Sep 2022 15:39:39 +0200 Subject: [PATCH 46/63] test deteteFactor --- src/NavAbilitySDK.jl | 2 +- test/integration/runtests.jl | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/NavAbilitySDK.jl b/src/NavAbilitySDK.jl index dd5bd75..66eb976 100644 --- a/src/NavAbilitySDK.jl +++ b/src/NavAbilitySDK.jl @@ -75,7 +75,7 @@ include("./navability/services/Session.jl") export getVariable, getVariables, listVariables, ls export addVariable, addPackedVariable export getFactor, getFactors, listFactors, lsf -export addFactor, addPackedFactor +export addFactor, addPackedFactor, deleteFactor export initVariable export listDataEntries export getDataEntry, getData diff --git a/test/integration/runtests.jl b/test/integration/runtests.jl index 41423a4..5226d47 100644 --- a/test/integration/runtests.jl +++ b/test/integration/runtests.jl @@ -25,11 +25,10 @@ sessionId2d = get(ENV,"SESSION_ID","TestSession2D"*randstring(7)) # Note - Tests incrementally build on each other because this is an # integration test. runVariableTests( client, navabilityClient2D ) - runInitVariableTests(; client ) runFactorTests( client, navabilityClient2D ) runSolveTests( client, navabilityClient2D ) runExportTests( client, navabilityClient2D ) - + runInitVariableTests(; client ) # test fixtures exampleGraph1D( client, navabilityClient1D; doSolve=false ) From 206173830e9217bba40fbaaa0bc1a2776a13d223 Mon Sep 17 00:00:00 2001 From: dehann Date: Mon, 12 Sep 2022 09:54:34 -0700 Subject: [PATCH 47/63] bug fix --- src/Deprecated.jl | 1 + src/navability/services/DataBlobs.jl | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Deprecated.jl b/src/Deprecated.jl index 12b0a43..2462989 100644 --- a/src/Deprecated.jl +++ b/src/Deprecated.jl @@ -3,4 +3,5 @@ ## Remove below before v0.6 ## ========================= +@deprecate getData(client::NavAbilityClient, context::Client, fileId::AbstactString) getData(client, context, UUID(fileId)) @deprecate getDataByLabel( client::NavAbilityClient, context::Client, vlbl::AbstractString, w...; kw...) getData(client, context, vlbl, w...; kw...) diff --git a/src/navability/services/DataBlobs.jl b/src/navability/services/DataBlobs.jl index 232465a..cfccbd9 100644 --- a/src/navability/services/DataBlobs.jl +++ b/src/navability/services/DataBlobs.jl @@ -12,7 +12,7 @@ Args: function createDownloadEvent( navAbilityClient::NavAbilityClient, userId::AbstractString, - fileId::AbstractString + fileId::UUID ) # response = navAbilityClient.mutate(MutationOptions( @@ -20,7 +20,7 @@ function createDownloadEvent( GQL_CREATEDOWNLOAD, Dict( "userId" => userId, - "fileId" => fileId + "fileId" => string(fileId) ) )) |> fetch rootData = JSON.parse(response.Data) @@ -42,7 +42,7 @@ createDownload(w...) = @async createDownloadEvent(w...) function getDataEvent( client::NavAbilityClient, userId::AbstractString, - fileId::AbstractString + fileId::UUID ) # url = createDownload(client, userId, fileId) |> fetch @@ -51,8 +51,9 @@ function getDataEvent( io end -getDataEvent(client::NavAbilityClient, context::Client, w...) = getDataEvent(client, context.userId, w...) -getData(w...) = @async getDataEvent(w...) +getDataEvent(client::NavAbilityClient, context::Client, fileId::UUID) = getDataEvent(client, context.userId, fileId) +getData(client::NavAbilityClient, context::Client, fileId::UUID) = @async getDataEvent(client, context, fileId) + function getDataEntry( client::NavAbilityClient, From 4add965a8a6a4c0c60bdf95894c0fb0abf81a84b Mon Sep 17 00:00:00 2001 From: dehann Date: Mon, 12 Sep 2022 09:58:12 -0700 Subject: [PATCH 48/63] typo --- src/Deprecated.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Deprecated.jl b/src/Deprecated.jl index 2462989..83d68e2 100644 --- a/src/Deprecated.jl +++ b/src/Deprecated.jl @@ -3,5 +3,5 @@ ## Remove below before v0.6 ## ========================= -@deprecate getData(client::NavAbilityClient, context::Client, fileId::AbstactString) getData(client, context, UUID(fileId)) +@deprecate getData(client::NavAbilityClient, context::Client, fileId::AbstractString) getData(client, context, UUID(fileId)) @deprecate getDataByLabel( client::NavAbilityClient, context::Client, vlbl::AbstractString, w...; kw...) getData(client, context, vlbl, w...; kw...) From 2c851ec7e5d785647f9e38ac00e526c3722613fb Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Mon, 12 Sep 2022 19:04:33 +0200 Subject: [PATCH 49/63] Oops the actual tests function --- test/integration/testFactor.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/integration/testFactor.jl b/test/integration/testFactor.jl index 9658f24..575602d 100644 --- a/test/integration/testFactor.jl +++ b/test/integration/testFactor.jl @@ -33,6 +33,22 @@ function testGetFactors(client, context, factorLabels, factorTypes) end end +function testDeleteFactor(client, context, factorLabels) + + resultId = fetch(addFactor(client,context,Factor("x0x1f_oops", "Pose2Pose2", ["x0", "x1"], Pose2Pose2Data()))) + @test resultId != "Error" + + waitForCompletion(client, [resultId], expectedStatuses=["Complete"]) + + resultId = fetch(deleteFactor(client, context, "x0x1f_oops")) + + @test NVA.waitForCompletion2(client, resultId) + + @test setdiff(factorLabels, fetch( lsf(client, context) )) == [] + + return nothing +end + function runFactorTests(client, context) @testset "factor-testset" begin @info "Running factor-testset" @@ -47,5 +63,7 @@ function runFactorTests(client, context) @testset "Listing" begin testLsf(client, context, factorLabels, factorTypes) end @testset "Getting" begin testGetFactor(client, context, factorLabels, factorTypes) end @testset "Getting Lists" begin testGetFactors(client, context, factorLabels, factorTypes) end + @testset "Delete" begin testDeleteFactor(client, context, factorLabels) end + end end \ No newline at end of file From 88d0710969ec8123d9051374b2a41e5064ab139b Mon Sep 17 00:00:00 2001 From: dehann Date: Mon, 12 Sep 2022 23:21:08 -0700 Subject: [PATCH 50/63] restore tests --- test/integration/runtests.jl | 10 +++++----- test/integration/testFactor.jl | 6 +++--- test/integration/testVariable.jl | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/integration/runtests.jl b/test/integration/runtests.jl index 5226d47..ea9627b 100644 --- a/test/integration/runtests.jl +++ b/test/integration/runtests.jl @@ -18,16 +18,16 @@ sessionId2d = get(ENV,"SESSION_ID","TestSession2D"*randstring(7)) @testset "nva-sdk-integration-testset" begin # Creating one client and two contexts client, navabilityClient1D = createClients(apiUrl, userId, robotId, sessionId1d) - client, navabilityClient2D = createClients(apiUrl, userId, robotId, sessionId2d) + client, context2D = createClients(apiUrl, userId, robotId, sessionId2d) @info "Running nva-sdk-integration-testset..." # Note - Tests incrementally build on each other because this is an # integration test. - runVariableTests( client, navabilityClient2D ) - runFactorTests( client, navabilityClient2D ) - runSolveTests( client, navabilityClient2D ) - runExportTests( client, navabilityClient2D ) + runVariableTests( client, context2D ) + runFactorTests( client, context2D ) + runSolveTests( client, context2D ) + runExportTests( client, context2D ) runInitVariableTests(; client ) # test fixtures exampleGraph1D( client, navabilityClient1D; doSolve=false ) diff --git a/test/integration/testFactor.jl b/test/integration/testFactor.jl index 575602d..7439bb2 100644 --- a/test/integration/testFactor.jl +++ b/test/integration/testFactor.jl @@ -7,7 +7,7 @@ function testAddFactor(client, context, factorLabels, factorTypes, factorVariabl push!(resultIds, resultId) end - waitForCompletion(client, resultIds, expectedStatuses=["Complete"]) + waitForCompletion(client, resultIds; expectedStatuses=["Complete"]) return resultIds end @@ -41,7 +41,7 @@ function testDeleteFactor(client, context, factorLabels) waitForCompletion(client, [resultId], expectedStatuses=["Complete"]) resultId = fetch(deleteFactor(client, context, "x0x1f_oops")) - + @test NVA.waitForCompletion2(client, resultId) @test setdiff(factorLabels, fetch( lsf(client, context) )) == [] @@ -63,7 +63,7 @@ function runFactorTests(client, context) @testset "Listing" begin testLsf(client, context, factorLabels, factorTypes) end @testset "Getting" begin testGetFactor(client, context, factorLabels, factorTypes) end @testset "Getting Lists" begin testGetFactors(client, context, factorLabels, factorTypes) end - @testset "Delete" begin testDeleteFactor(client, context, factorLabels) end + # @testset "Delete" begin testDeleteFactor(client, context, factorLabels) end end end \ No newline at end of file diff --git a/test/integration/testVariable.jl b/test/integration/testVariable.jl index c9739f3..a2fa9eb 100644 --- a/test/integration/testVariable.jl +++ b/test/integration/testVariable.jl @@ -8,7 +8,8 @@ function testAddVariable(client, context, variableLabels, variableTypes, variabl end # Wait for them to be done before proceeding. - NVA.waitForCompletion2(client, resultIds; maxSeconds=180) # expectedStatuses=["Complete"] + # NVA.waitForCompletion2(client, resultIds; maxSeconds=180) # expectedStatuses=["Complete"] + NVA.waitForCompletion(client, resultIds; maxSeconds=180, expectedStatuses=["Complete"] ) return resultIds end From 588ad7444dbcc735a057362f7467f458428af73c Mon Sep 17 00:00:00 2001 From: dehann Date: Tue, 13 Sep 2022 00:14:44 -0700 Subject: [PATCH 51/63] comment failing tests --- src/navability/graphql/Variable.jl | 2 +- test/integration/runtests.jl | 6 +++--- test/integration/testExportSession.jl | 19 +++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/navability/graphql/Variable.jl b/src/navability/graphql/Variable.jl index a4a30e3..edc450e 100644 --- a/src/navability/graphql/Variable.jl +++ b/src/navability/graphql/Variable.jl @@ -123,7 +123,7 @@ GQL_GETVARIABLESFILTERED = """ GQL_INIT_VARIABLE = """ mutation sdk_init_variable( \$variable: InitVariableInput!, - \$options: EmptyInputOptions + \$options: EmptyOptionsInput ) { initVariable(variable: \$variable, options:\$options) { context { diff --git a/test/integration/runtests.jl b/test/integration/runtests.jl index ea9627b..017a6f9 100644 --- a/test/integration/runtests.jl +++ b/test/integration/runtests.jl @@ -17,7 +17,7 @@ sessionId2d = get(ENV,"SESSION_ID","TestSession2D"*randstring(7)) @testset "nva-sdk-integration-testset" begin # Creating one client and two contexts - client, navabilityClient1D = createClients(apiUrl, userId, robotId, sessionId1d) + client, context1D = createClients(apiUrl, userId, robotId, sessionId1d) client, context2D = createClients(apiUrl, userId, robotId, sessionId2d) @info "Running nva-sdk-integration-testset..." @@ -28,8 +28,8 @@ sessionId2d = get(ENV,"SESSION_ID","TestSession2D"*randstring(7)) runFactorTests( client, context2D ) runSolveTests( client, context2D ) runExportTests( client, context2D ) - runInitVariableTests(; client ) + # runInitVariableTests(; client ) # test fixtures - exampleGraph1D( client, navabilityClient1D; doSolve=false ) + exampleGraph1D( client, context1D; doSolve=false ) end diff --git a/test/integration/testExportSession.jl b/test/integration/testExportSession.jl index 17e596b..5e3b168 100644 --- a/test/integration/testExportSession.jl +++ b/test/integration/testExportSession.jl @@ -23,20 +23,19 @@ function testExportSession( ) |> fetch @info "Wait on addFactor eventId" resultId - # eventId = NVA.addFactor(client, context, NVA.Factor()) NVA.waitForCompletion(client, [eventId], expectedStatuses=["Complete"], maxSeconds=180) end # export the graph - eventId = NVA.exportSession(client, context, "testexport.tar.gz", - options=NVA.ExportSessionOptions( - format="NVA" # TODO TARGZ - )) |> fetch - - @info "waiting for export Session" eventId - NVA.waitForCompletion2(client, eventId) - blobId = NVA.getExportSessionBlobId(client, eventId) - @info "Success: Here is the blobId you can use to download: $blobId" + # eventId = NVA.exportSession(client, context, "testexport.tar.gz", + # options=NVA.ExportSessionOptions( + # format="NVA" # TODO TARGZ + # )) |> fetch + + # @info "waiting for export Session" eventId + # NVA.waitForCompletion2(client, eventId) + # blobId = NVA.getExportSessionBlobId(client, eventId) + # @info "Success: Here is the blobId you can use to download: $blobId" end From 471cafbef399b60b83a82103b7c909f2b2ff9d82 Mon Sep 17 00:00:00 2001 From: dehann Date: Tue, 13 Sep 2022 00:19:42 -0700 Subject: [PATCH 52/63] add partial deleteFactor --- test/integration/testFactor.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/testFactor.jl b/test/integration/testFactor.jl index 7439bb2..9a6729c 100644 --- a/test/integration/testFactor.jl +++ b/test/integration/testFactor.jl @@ -40,11 +40,11 @@ function testDeleteFactor(client, context, factorLabels) waitForCompletion(client, [resultId], expectedStatuses=["Complete"]) - resultId = fetch(deleteFactor(client, context, "x0x1f_oops")) + # @show resultId = fetch(deleteFactor(client, context, "x0x1f_oops")) - @test NVA.waitForCompletion2(client, resultId) + # @test NVA.waitForCompletion2(client, resultId) - @test setdiff(factorLabels, fetch( lsf(client, context) )) == [] + # @test setdiff(factorLabels, fetch( lsf(client, context) )) == [] return nothing end @@ -63,7 +63,7 @@ function runFactorTests(client, context) @testset "Listing" begin testLsf(client, context, factorLabels, factorTypes) end @testset "Getting" begin testGetFactor(client, context, factorLabels, factorTypes) end @testset "Getting Lists" begin testGetFactors(client, context, factorLabels, factorTypes) end - # @testset "Delete" begin testDeleteFactor(client, context, factorLabels) end + @testset "Delete" begin testDeleteFactor(client, context, factorLabels) end end end \ No newline at end of file From fdb9308306a1902198db652caa112d91c774a04e Mon Sep 17 00:00:00 2001 From: dehann Date: Tue, 13 Sep 2022 00:31:23 -0700 Subject: [PATCH 53/63] restore initVariable test --- src/navability/services/Variable.jl | 2 +- test/integration/runtests.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index 0e2a935..767039f 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -165,7 +165,7 @@ end # end function InitVariableInput(wh,dstr,bw::AbstractVector=[]) Dict{String,Any}( - "where"=>wh, + "where"=>wh, # upgrade to "id" "distribution"=>dstr, (0bw,) : ())... ) diff --git a/test/integration/runtests.jl b/test/integration/runtests.jl index 017a6f9..7b4ee4a 100644 --- a/test/integration/runtests.jl +++ b/test/integration/runtests.jl @@ -28,7 +28,7 @@ sessionId2d = get(ENV,"SESSION_ID","TestSession2D"*randstring(7)) runFactorTests( client, context2D ) runSolveTests( client, context2D ) runExportTests( client, context2D ) - # runInitVariableTests(; client ) + runInitVariableTests(; client ) # test fixtures exampleGraph1D( client, context1D; doSolve=false ) From 6c40486cf6aab0bb1835ca6b94dbcf2ade5f37db Mon Sep 17 00:00:00 2001 From: dehann Date: Tue, 13 Sep 2022 00:41:05 -0700 Subject: [PATCH 54/63] restore deleteFactor test --- test/integration/testFactor.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/testFactor.jl b/test/integration/testFactor.jl index 9a6729c..e99ca29 100644 --- a/test/integration/testFactor.jl +++ b/test/integration/testFactor.jl @@ -40,11 +40,11 @@ function testDeleteFactor(client, context, factorLabels) waitForCompletion(client, [resultId], expectedStatuses=["Complete"]) - # @show resultId = fetch(deleteFactor(client, context, "x0x1f_oops")) + @show resultId = fetch(deleteFactor(client, context, "x0x1f_oops")) - # @test NVA.waitForCompletion2(client, resultId) + @test NVA.waitForCompletion2(client, resultId) - # @test setdiff(factorLabels, fetch( lsf(client, context) )) == [] + @test setdiff(factorLabels, fetch( lsf(client, context) )) == [] return nothing end From fdd3c6b7501659ed6c1650042f1b8229b1f0f0ea Mon Sep 17 00:00:00 2001 From: Jim hill Date: Wed, 14 Sep 2022 19:04:13 -0700 Subject: [PATCH 55/63] InitVariable passing --- Makefile | 4 +++ src/navability/graphql/Status.jl | 2 +- src/navability/services/Variable.jl | 50 ++++++++++++++++++++-------- test/integration/testInitVariable.jl | 28 ++++++++-------- 4 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..58e0eec --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY: test + +test: + julia --project -e "using Pkg; Pkg.test()" \ No newline at end of file diff --git a/src/navability/graphql/Status.jl b/src/navability/graphql/Status.jl index 4f24163..f99ec6f 100644 --- a/src/navability/graphql/Status.jl +++ b/src/navability/graphql/Status.jl @@ -32,7 +32,7 @@ query sdk_get_statuslatest(\$id: ID!) { GQL_GET_EVENTS_BY_ID = """ query sdk_events_by_id(\$eventId:String) { - test: events(where: {context:{eventId:\$eventId}}) { + test: events(event: {context:{eventId:\$eventId}}) { context { eventId } diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index 767039f..31be0a7 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -115,17 +115,37 @@ function SessionKey( ) end -function VariableWhere( - sessionKey, - label::AbstractString, - variableType::VariableType - ) - # - Dict{String,Any}( - "sessionKey" => sessionKey, - "label" => label, - "variableType" => variableType - ) +function VariableKey( + userId::AbstractString, + robotId::AbstractString, + sessionId::AbstractString, + variableLabel::AbstractString + ) + # + Dict{String,String}( + "userId" => userId, + "robotId" => robotId, + "sessionId" => sessionId, + "variableLabel" => variableLabel + ) +end + +function VariableId( + key + ) + # + Dict{String,Any}( + "key" => key + ) +end + +function VariableId( + variableKey + ) + # + Dict{String,Any}( + "key" => variableKey + ) end function CartesianPointInput(; @@ -159,13 +179,15 @@ function DistributionInput(; end # struct InitVariableInput -# where +# id +# variableType # distribution # bandwidth # end -function InitVariableInput(wh,dstr,bw::AbstractVector=[]) +function InitVariableInput(id,variableType,dstr,bw::AbstractVector=[]) Dict{String,Any}( - "where"=>wh, # upgrade to "id" + "id"=>id, + "variableType"=>variableType, "distribution"=>dstr, (0bw,) : ())... ) diff --git a/test/integration/testInitVariable.jl b/test/integration/testInitVariable.jl index 35560b6..128d972 100644 --- a/test/integration/testInitVariable.jl +++ b/test/integration/testInitVariable.jl @@ -25,26 +25,24 @@ function runInitVariableTests(; pts = [[-rand();rand();-0.1] for _ in 1:5] points = Dict{String,Float64}[ NVA.CartesianPointInput(;x=pt[1],y=pt[2],rotz=pt[3]) for pt in pts ] - sessionKey = NVA.SessionKey(userId,robotId,sessionId) - variableWhere = NVA.VariableWhere(sessionKey, "x0", NVA.POSE2) + variableKey = NVA.VariableKey(userId,robotId,sessionId,"x0") + variableId = NVA.VariableId(variableKey) particleInput = Dict{String,Any}("points"=>points) distributionInput = Dict{String,Any}("particle"=>particleInput) - initVarInp = NVA.InitVariableInput(variableWhere, distributionInput) + initVarInp = NVA.InitVariableInput(variableId, NVA.POSE2, distributionInput) eventId = NVA.initVariable(client, context, initVarInp) |> fetch @info "waitForCompletion on initVariable" eventId - NVA.waitForCompletion2(client, eventId) #, expectedStatuses=["Complete"], maxSeconds=180) - - res = NVA.getVariable(client, context, "x0") - x0 = fetch(res) - - # FIXME cannot remember which way round the reshape should work - x0_vv = reshape(x0["solverData"][1]["vecval"],3,:) - @cast refvv[i][d] := x0_vv[d,i] - - @show refvv - - @test isapprox(pts, refvv; atol=1e-8) + completedSuccessfully = NVA.waitForCompletion2(client, eventId) #, expectedStatuses=["Complete"], maxSeconds=180) + @test completedSuccessfully + if completedSuccessfully + res = NVA.getVariable(client, context, "x0") + x0 = fetch(res) + x0_vv = reshape(x0["solverData"][1]["vecval"],3,:) + @cast refvv[i][d] := x0_vv[d,i] + @show pts, refvv + @test isapprox(pts, refvv; atol=1e-12) + end end end From 8a5737e2fe8591d8cc36e30e9e476a7ef3852da0 Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 14 Sep 2022 22:41:12 -0700 Subject: [PATCH 56/63] rm duplicate variableId --- src/navability/services/Variable.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index 31be0a7..1421346 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -130,14 +130,14 @@ function VariableKey( ) end -function VariableId( - key - ) - # - Dict{String,Any}( - "key" => key - ) -end +# function VariableId( +# key +# ) +# # +# Dict{String,Any}( +# "key" => key +# ) +# end function VariableId( variableKey From 9e7373cbf69368cbd3c3926f59c1576c4e187cab Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 14 Sep 2022 23:30:06 -0700 Subject: [PATCH 57/63] allow longer test wait to solve --- test/integration/testSolve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/testSolve.jl b/test/integration/testSolve.jl index bd06b90..23a0998 100644 --- a/test/integration/testSolve.jl +++ b/test/integration/testSolve.jl @@ -23,7 +23,7 @@ function testSolveSession(client, context, variableLabels; maxSeconds=180) checkForSolveKeys(client, context, "default", variableLabels) end -function testSolveSessionParametric(client, context, variableLabels; maxSeconds=180) +function testSolveSessionParametric(client, context, variableLabels; maxSeconds=240) # allVariableLabels = ls(client, context, variableLabels) # do the solve From 7a372942e4e43eabd449e298bb0dd6c9da45bf51 Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 14 Sep 2022 23:38:40 -0700 Subject: [PATCH 58/63] fix DeleteFactorOptionsInput type --- src/navability/graphql/Factor.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/navability/graphql/Factor.jl b/src/navability/graphql/Factor.jl index c011af9..b06a7d1 100644 --- a/src/navability/graphql/Factor.jl +++ b/src/navability/graphql/Factor.jl @@ -89,7 +89,7 @@ GQL_GETFACTORSFILTERED = """ GQL_DELETEFACTOR = """ mutation sdk_delete_factor( \$factor: DeleteFactorInput!, - \$options: DeleteFactorOptions + \$options: DeleteFactorOptionsInput ) { deleteFactor(factor: \$factor, options: \$options) { context { From 5786b1d7e492c76142f9921012b37e44de047c2e Mon Sep 17 00:00:00 2001 From: dehann Date: Thu, 15 Sep 2022 00:57:10 -0700 Subject: [PATCH 59/63] listFactors connected to variable --- src/navability/entities/Session.jl | 14 +++ src/navability/entities/Variable.jl | 76 +++++++++++++--- src/navability/graphql/Variable.jl | 51 ++++------- src/navability/services/Variable.jl | 132 ++++++++++------------------ 4 files changed, 143 insertions(+), 130 deletions(-) diff --git a/src/navability/entities/Session.jl b/src/navability/entities/Session.jl index 2f7a2ca..53774c4 100644 --- a/src/navability/entities/Session.jl +++ b/src/navability/entities/Session.jl @@ -25,6 +25,20 @@ function SessionId(; ) end + +# function SessionKey( +# userId::AbstractString, +# robotId::AbstractString, +# sessionId::AbstractString +# ) +# # +# Dict{String,String}( +# "userId" => userId, +# "robotId" => robotId, +# "sessionId" => sessionId, +# ) +# end + Base.@kwdef struct ExportSessionInput id::Dict filename::String diff --git a/src/navability/entities/Variable.jl b/src/navability/entities/Variable.jl index f4b6e9e..b36f176 100644 --- a/src/navability/entities/Variable.jl +++ b/src/navability/entities/Variable.jl @@ -84,19 +84,71 @@ function _getSolverDataDict(variableType::String, solveKey::String)::SolverDataD throw(error("Variable type '$(variableType)' not supported.")) end -function Variable(label::AbstractString, type::Union{<:AbstractString, Symbol}, tags::AbstractVector{<:AbstractString} = ["VARIABLE"], timestamp::String = string(now(Dates.UTC))*"Z")::Variable - variableType = type isa Symbol ? get(_variableTypeConvert, type, Nothing) : type - type == Nothing && error("Variable type '$(type) is not supported") +function VariableKey( + userId::AbstractString, + robotId::AbstractString, + sessionId::AbstractString, + variableLabel::AbstractString + ) + # + Dict{String,String}( + "userId" => userId, + "robotId" => robotId, + "sessionId" => sessionId, + "variableLabel" => variableLabel + ) +end - solverDataDict = Dict("default" => _getSolverDataDict(variableType, "default")) - result = Variable(; - label, - variableType, - # TODO, should not require jsoning, see DFG#867 - solverDataDict = json(solverDataDict), - tags = json(tags), - timestamp +function VariableId( + variableKey + ) + # + Dict{String,Any}( + "key" => variableKey + ) +end + +function CartesianPointInput(; + x::Float64 = 0.0, + y::Float64 = 0.0, + z::Float64 = 0.0, + rotx::Float64 = 0.0, + roty::Float64 = 0.0, + rotz::Float64 = 0.0 + ) + # + Dict{String,Float64}( + "x" => x, + "y" => y, + "z" => z, + "rotx" => rotx, + "roty" => roty, + "rotz" => rotz, ) - return result end +function DistributionInput(; + particle=nothing, + rayleigh=nothing + ) + # + Dict{String,Any}( + (particle isa Nothing ? () : ("particle"=>particle,))..., + (rayleigh isa Nothing ? () : ("rayleigh"=>rayleigh,))... + ) +end + +# struct InitVariableInput +# id +# variableType +# distribution +# bandwidth +# end +function InitVariableInput(id,variableType,dstr,bw::AbstractVector=[]) + Dict{String,Any}( + "id"=>id, + "variableType"=>variableType, + "distribution"=>dstr, + (0bw,) : ())... + ) +end \ No newline at end of file diff --git a/src/navability/graphql/Variable.jl b/src/navability/graphql/Variable.jl index edc450e..cf487e0 100644 --- a/src/navability/graphql/Variable.jl +++ b/src/navability/graphql/Variable.jl @@ -136,35 +136,22 @@ GQL_INIT_VARIABLE = """ } }""" -# GQL_INITVARIABLE = """ -# mutation sdk_init_variable( -# \$userId: ID!, -# \$robotId: ID!, -# \$sessionId: ID!, -# \$label: String!, -# \$variableType: VariableType!, -# \$points: [CartesianPointInput]!) { -# initVariable( -# variable: where: { -# sessionKey: { -# userId: \$userId, -# robotId: \$robotId, -# sessionId: \$sessionId, -# }, -# label: \$label, -# variableType: \$variableType -# }, -# distribution: { -# particle: { -# points: \$points -# } -# } -# ) { -# status { -# state -# } -# context { -# eventId -# } -# } -# }""" \ No newline at end of file +GQL_LIST_VARIABLE_NEIGHBORS = """ + query sdk_list_variable_neighbors ( + \$userId: ID!, + \$robotId: ID!, + \$sessionId: ID!, + \$variableLabel: ID! + ) { + users(where:{id: \$userId}) { + robots(where:{id: \$robotId}) { + sessions(where:{id: \$sessionId}) { + variables(where:{label: \$variableLabel}) { + factors { + label + } + } + } + } + } + }""" \ No newline at end of file diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index 1421346..8b1d0a2 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -1,4 +1,20 @@ +function Variable(label::AbstractString, type::Union{<:AbstractString, Symbol}, tags::AbstractVector{<:AbstractString} = ["VARIABLE"], timestamp::String = string(now(Dates.UTC))*"Z")::Variable + variableType = type isa Symbol ? get(_variableTypeConvert, type, Nothing) : type + type == Nothing && error("Variable type '$(type) is not supported") + + solverDataDict = Dict("default" => _getSolverDataDict(variableType, "default")) + result = Variable(; + label, + variableType, + # TODO, should not require jsoning, see DFG#867 + solverDataDict = json(solverDataDict), + tags = json(tags), + timestamp + ) + return result +end + function addPackedVariable(navAbilityClient::NavAbilityClient, client::Client, variable)::String response = navAbilityClient.mutate(MutationOptions( "addVariable", @@ -101,97 +117,41 @@ function ls(navAbilityClient::NavAbilityClient, client::Client) return listVariables(navAbilityClient,client) end - -function SessionKey( - userId::AbstractString, - robotId::AbstractString, - sessionId::AbstractString - ) - # - Dict{String,String}( - "userId" => userId, - "robotId" => robotId, - "sessionId" => sessionId, - ) -end - -function VariableKey( - userId::AbstractString, - robotId::AbstractString, - sessionId::AbstractString, - variableLabel::AbstractString - ) - # - Dict{String,String}( - "userId" => userId, - "robotId" => robotId, - "sessionId" => sessionId, - "variableLabel" => variableLabel - ) -end - -# function VariableId( -# key -# ) -# # -# Dict{String,Any}( -# "key" => key -# ) -# end - -function VariableId( - variableKey - ) - # - Dict{String,Any}( - "key" => variableKey - ) -end - -function CartesianPointInput(; - x::Float64 = 0.0, - y::Float64 = 0.0, - z::Float64 = 0.0, - rotx::Float64 = 0.0, - roty::Float64 = 0.0, - rotz::Float64 = 0.0 - ) - # - Dict{String,Float64}( - "x" => x, - "y" => y, - "z" => z, - "rotx" => rotx, - "roty" => roty, - "rotz" => rotz, - ) +function listFactorsEvent( + client::NavAbilityClient, + ::Client, + variableKey::Dict +) + response = client.query(QueryOptions( + "sdk_list_variable_neighbors", + GQL_LIST_VARIABLE_NEIGHBORS, + variableKey + )) |> fetch + rootData = JSON.parse(response.Data) + if haskey(rootData, "errors") + @error response + throw("Error: $(rootData["errors"])") + end + data = get(rootData,"data",nothing) + if data === nothing return "Error" end + # listVarNei = get(data,"users","Error") + return (s->s["label"]).(data["users"][1]["robots"][1]["sessions"][1]["variables"][1]["factors"]) end -function DistributionInput(; - particle=nothing, - rayleigh=nothing - ) - # - Dict{String,Any}( - (particle isa Nothing ? () : ("particle"=>particle,))..., - (rayleigh isa Nothing ? () : ("rayleigh"=>rayleigh,))... +function listFactorsEvent(client::NavAbilityClient, context::Client, varLbl::AbstractString) + listFactorsEvent( + client, + context, + VariableKey( + context.userId, + context.robotId, + context.sessionId, + varLbl + ) ) end -# struct InitVariableInput -# id -# variableType -# distribution -# bandwidth -# end -function InitVariableInput(id,variableType,dstr,bw::AbstractVector=[]) - Dict{String,Any}( - "id"=>id, - "variableType"=>variableType, - "distribution"=>dstr, - (0bw,) : ())... - ) -end +listFactors(client::NavAbilityClient, context::Client, w...; kw...) = @async listFactorsEvent(client, context, w...; kw...) function initVariableEvent( client::NavAbilityClient, From 766b05e9a8b9ddec8c83ce925850fd0759b9d532 Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Thu, 15 Sep 2022 17:41:10 +0200 Subject: [PATCH 60/63] Add Pose3Pose3Rotation --- src/navability/entities/Factor.jl | 14 +++++++++- src/navability/entities/InferenceTypes.jl | 1 + test/integration/runtests.jl | 33 +++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/navability/entities/Factor.jl b/src/navability/entities/Factor.jl index 8700676..0a8ffac 100644 --- a/src/navability/entities/Factor.jl +++ b/src/navability/entities/Factor.jl @@ -115,7 +115,19 @@ between the variables, e.g. `FullNormal([1;zeros(5)], diagm(0.01*ones(6)))`. Default value of Z = `FullNormal(zeros(6), diagm(0.01*ones(6)))`. """ function Pose3Pose3Data(;Z::Distribution = FullNormal(zeros(6), diagm(0.01*ones(6))), kwargs...)::FactorData - data = FactorData(;fnc = ZInferenceType(Z), certainhypo = [1], kwargs...) + data = FactorData(;fnc = ZInferenceType(Z), certainhypo = [1,2], kwargs...) + return data +end + +""" +$(SIGNATURES) +Create a partial factor on Rotation only on Pose3->Pose3 with a distribution Z representing the relationship +between the variables. + +Default value of Z = `FullNormal(zeros(3), diagm(0.01*ones(3)))`. +""" +function Pose3Pose3RotationData(;Z::Distribution = FullNormal(zeros(3), diagm(0.01*ones(3))), kwargs...) + data = FactorData(;fnc = ZInferenceType(Z), certainhypo = [1,2], kwargs...) return data end diff --git a/src/navability/entities/InferenceTypes.jl b/src/navability/entities/InferenceTypes.jl index 684dc15..c00da50 100644 --- a/src/navability/entities/InferenceTypes.jl +++ b/src/navability/entities/InferenceTypes.jl @@ -29,6 +29,7 @@ end @nvaZInferenceType PriorPose3 @nvaZInferenceType Pose3Pose3 +@nvaZInferenceType Pose3Pose3Rotation """ diff --git a/test/integration/runtests.jl b/test/integration/runtests.jl index 7b4ee4a..deb3517 100644 --- a/test/integration/runtests.jl +++ b/test/integration/runtests.jl @@ -14,6 +14,7 @@ robotId = get(ENV,"ROBOT_ID","IntegrationRobot") sessionId = get(ENV,"SESSION_ID","TestSession"*randstring(7)) sessionId1d = get(ENV,"SESSION_ID","TestSession1D"*randstring(7)) sessionId2d = get(ENV,"SESSION_ID","TestSession2D"*randstring(7)) +sessionId3d = get(ENV,"SESSION_ID","TestSession3D"*randstring(7)) @testset "nva-sdk-integration-testset" begin # Creating one client and two contexts @@ -33,3 +34,35 @@ sessionId2d = get(ENV,"SESSION_ID","TestSession2D"*randstring(7)) exampleGraph1D( client, context1D; doSolve=false ) end + +@testset "testing Pose3" begin + + client, context3D = createClients(apiUrl, userId, robotId, sessionId3d) + +resultIds = Task[] +append!( + resultIds, + [addVariable(client, context3D, "x0", :Pose3), + addVariable(client, context3D, "x1", :Pose3)] +) + +NVA.waitForCompletion(client, resultIds; maxSeconds=180, expectedStatuses=["Complete"] ) + +resultIds = Task[] +append!( + resultIds, + [addFactor(client, context3D, ["x0"], NVA.PriorPose3(Z=NVA.FullNormal([0.,1.,0,0,0,0], diagm([0.1,0.1,0.1,0.01,0.01,0.01].^2)))), + addFactor(client, context3D, [:x0,:x1], NVA.Pose3Pose3Rotation(Z=NVA.FullNormal([0.1,0.,0], diagm([0.01,0.01,0.01].^2))))] +) + + +NVA.waitForCompletion(client, resultIds; maxSeconds=180, expectedStatuses=["Complete"] ) + +flabels = fetch(NVA.listFactors(client, context3D)) +fac = fetch(NVA.getFactor(client, context3D, "x0x1f_4e37")) + +# r = fetch(NVA.solveSession(client, context3D)) +# s = fetch(NVA.getStatusesLatest(client, [r])) +# v = fetch(NVA.getVariable(client, context3D, "x1")) + +end \ No newline at end of file From 0320f065fab7bb1d8f26a0a93ae0a592851fe228 Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 14 Oct 2022 05:50:06 -0700 Subject: [PATCH 61/63] api sort lt and var kw --- src/navability/services/Utils.jl | 33 +++++++++++++++++++++++++++++ src/navability/services/Variable.jl | 13 +++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/navability/services/Utils.jl b/src/navability/services/Utils.jl index 5c09040..c0a1d0a 100644 --- a/src/navability/services/Utils.jl +++ b/src/navability/services/Utils.jl @@ -114,3 +114,36 @@ end Base.show(io::IO, ::MIME"text/plain", gv::Union{GraphVizApp,MapVizApp}) = println(gv.url) Base.show(io::IO, ::MIME"text/markdown", gv::GraphVizApp) = display("text/markdown", "[![Navigate to Factor Graph]($assetGraphVizImg)]($(gv.url))") Base.show(io::IO, ::MIME"text/markdown", gv::MapVizApp) = display("text/markdown", "[![Navigate to Factor Graph]($assetGeomVizImg)]($(gv.url))") + + +""" + $SIGNATURES +Natural less than for sorting, + +```julia +sort(["x10"; "x1", "x11"]; lt=NavAbilitySDK.natural_lt) +```` + +Notes +- duplicated from DFG, hence don't export +""" +function natural_lt(x::T, y::T) where T <: AbstractString + # Adapted from https://rosettacode.org/wiki/Natural_sorting + # split at digit to not digit change + splitbynum(x::AbstractString) = split(x, r"(?<=\D)(?=\d)|(?<=\d)(?=\D)") + #parse to Int + numstringtonum(arr::Vector{<:AbstractString}) = [(n = tryparse(Int, e)) !== nothing ? n : e for e in arr] + xarr = numstringtonum(splitbynum(x)) + yarr = numstringtonum(splitbynum(y)) + for i in 1:min(length(xarr), length(yarr)) + if typeof(xarr[i]) != typeof(yarr[i]) + return isa(xarr[i], Int) + elseif xarr[i] == yarr[i] + continue + else + return xarr[i] < yarr[i] + end + end + return length(xarr) < length(yarr) +end +natural_lt(x::Symbol, y::Symbol) = natural_lt(string(x),string(y)) diff --git a/src/navability/services/Variable.jl b/src/navability/services/Variable.jl index 8b1d0a2..df2ea04 100644 --- a/src/navability/services/Variable.jl +++ b/src/navability/services/Variable.jl @@ -41,7 +41,12 @@ function addVariable(navAbilityClient::NavAbilityClient, client::Client, variabl return @async addPackedVariable(navAbilityClient, client, variable) end -function getVariableEvent(navAbilityClient::NavAbilityClient, client::Client, label::String)::Dict{String,Any} +function getVariableEvent( + navAbilityClient::NavAbilityClient, + client::Client, + label::String; + detail::QueryDetail = SKELETON +)::Dict{String,Any} response = navAbilityClient.query(QueryOptions( "sdk_get_variable", """ @@ -52,7 +57,9 @@ function getVariableEvent(navAbilityClient::NavAbilityClient, client::Client, la "label" => label, "userId" => client.userId, "robotId" => client.robotId, - "sessionId" => client.sessionId + "sessionId" => client.sessionId, + # "fields_summary" => detail === SUMMARY || detail === FULL, + # "fields_full" => detail === FULL, ) )) |> fetch rootData = JSON.parse(response.Data) @@ -72,7 +79,7 @@ function getVariableEvent(navAbilityClient::NavAbilityClient, client::Client, la return variables[1] end -getVariable(navAbilityClient::NavAbilityClient, client::Client, label::String) = @async getVariableEvent(navAbilityClient, client, label) +getVariable(navAbilityClient::NavAbilityClient, client::Client, label::String; detail::QueryDetail = SKELETON) = @async getVariableEvent(navAbilityClient, client, label; detail) function getVariablesEvent(navAbilityClient::NavAbilityClient, client::Client; detail::QueryDetail = SKELETON)::Vector{Dict{String,Any}} response = navAbilityClient.query(QueryOptions( From b381697405fc0555ba13e852a75b7749032880a7 Mon Sep 17 00:00:00 2001 From: dehann Date: Tue, 1 Nov 2022 00:32:09 -0700 Subject: [PATCH 62/63] UUID fixes for getDataEntry --- src/navability/services/DataBlobs.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/navability/services/DataBlobs.jl b/src/navability/services/DataBlobs.jl index cfccbd9..4943b1f 100644 --- a/src/navability/services/DataBlobs.jl +++ b/src/navability/services/DataBlobs.jl @@ -59,13 +59,15 @@ function getDataEntry( client::NavAbilityClient, context::Client, vlbl::AbstractString, - regex::Regex; + pattern::Union{Regex, UUID}; lt=isless, count::Base.RefValue{Int}=Ref(0), # return count of how many matches were found ) ble = listDataEntries(client, context, vlbl) |> fetch # filter for the specific blob label - ble_s = filter(x->!(match(regex,x.label) isa Nothing) , ble) + _matchpatt(regex::Regex, de) = match(regex, de.label) isa Nothing + _matchpatt(uuid::UUID, de) = uuid != UUID(de.id) + ble_s = filter(x->!(_matchpatt(pattern, x)), ble) # match(regex,x.label) isa Nothing count[] = length(ble_s) if 0 === count[] return nothing @@ -247,7 +249,7 @@ function addDataEntryEvent( robotId::AbstractString, sessionId::AbstractString, variableLabel::AbstractString, - dataId::AbstractString, + dataId::AbstractString, # TODO must also support ::UUID dataLabel::AbstractString, mimeType::AbstractString="", ) From 26441bae4465bb5483a47ca8be7662afccb87443 Mon Sep 17 00:00:00 2001 From: Dehann Fourie <6412556+dehann@users.noreply.github.com> Date: Tue, 1 Nov 2022 22:30:21 -0700 Subject: [PATCH 63/63] bump v0.4.8 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 03e630c..9af0f36 100644 --- a/Project.toml +++ b/Project.toml @@ -3,7 +3,7 @@ uuid = "f3e6a059-199c-4ada-8143-fcefb97e6165" keywords = ["navability", "navigation", "slam", "sdk", "robotics", "robots"] desc = "NavAbility SDK: Access NavAbility Cloud factor graph features. Note that this SDK and the related API are still in development. Please let us know if you have any issues at info@navability.io." authors = ["NavAbility "] -version = "0.4.7" +version = "0.4.8" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"