Skip to content

Commit

Permalink
Merge pull request #219 from NavAbility/23Q1/twig/fastlistfactors
Browse files Browse the repository at this point in the history
query side listFactors
  • Loading branch information
dehann authored Mar 27, 2023
2 parents f47c8a0 + c5910a1 commit e6f0008
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]."
authors = ["NavAbility <[email protected]>"]
version = "0.5.1"
version = "0.5.2"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
17 changes: 17 additions & 0 deletions src/navability/graphql/Factor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ fragment factor_full_fields on Factor {
}
"""

GQL_LISTFACTORS = """
query sdk_list_factors (
\$userId: ID!,
\$robotId: ID!,
\$sessionId: ID!) {
users(where:{id: \$userId}) {
robots(where:{id: \$robotId}) {
sessions(where:{id: \$sessionId}) {
factors {
label
}
}
}
}
}
"""

GQL_GETFACTOR = """
query sdk_get_factor(
\$userId: ID!,
Expand Down
48 changes: 43 additions & 5 deletions src/navability/services/Factor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,55 @@ end

getFactors( navAbilityClient::NavAbilityClient, client::Client; detail::QueryDetail = SKELETON) = @async getFactorsEvent(navAbilityClient, client; detail )


"""
$(SIGNATURES)
Get a list of the Factors as labels in the graph.
Get a list of all factors labels in the graph.
"""
function listFactors(navAbilityClient::NavAbilityClient, client::Client)
@async begin
factors = getFactors(navAbilityClient,client) |> fetch
map(v -> v["label"], factors)
function listFactorsEvent(
client::NavAbilityClient,
context::Client
)
response = client.query(QueryOptions(
"sdk_list_factors",
GQL_LISTFACTORS,
Dict(
"userId" => context.userId,
"robotId" => context.robotId,
"sessionId" => context.sessionId,
)
)) |> fetch
payload = JSON.parse(response.Data)
try
# FIXME, this list can be empty, using try catch as lazy check
(s->s["label"]).(payload["data"]["users"][1]["robots"][1]["sessions"][1]["factors"])
catch err
if err isa BoundsError
String[]
else
throw(err)
end
end
end

"""
$(SIGNATURES)
Get a list of Variable labels in the graph.
Returns: A Task with response `::Vector{String}`.
"""
function listFactors(client::NavAbilityClient, context::Client)
@async listFactorsEvent(client, context)
end


# function listFactors(navAbilityClient::NavAbilityClient, client::Client)
# @async begin
# factors = getFactors(navAbilityClient,client) |> fetch
# map(v -> v["label"], factors)
# end
# end

function lsf(navAbilityClient::NavAbilityClient, client::Client)
return listFactors(navAbilityClient,client)
end
Expand Down

0 comments on commit e6f0008

Please sign in to comment.