Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,15 @@ function solveGraph! end
Standard parametric graph solution (Experimental).
"""
function solveGraphParametric! end

# delta timestamps
calcDeltatime(from::Nanosecond, to::Nanosecond) = Dates.value(to - from) / 10^9
function calcDeltatime(from::TimeDateZone, to::TimeDateZone)
return Dates.value(convert(Nanosecond, to - from)) / 10^9
end
calcDeltatime(from_node, to_node) = calcDeltatime(from_node.timestamp, to_node.timestamp)

function tdz_now(zone = tz"UTC") #TODO or default to slower localzone()?
t = time()
return TimeDateZone(TimeDate(1970) + Nanosecond(t * 10^9), zone)
end
2 changes: 1 addition & 1 deletion src/DataBlobs/entities/BlobEntry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ StructUtils.@kwarg struct Blobentry
""" Storage for a couple of bytes directly in the graph. Use with caution and keep it small and simple."""
metadata::JSONText = JSONText("{}")
""" When the Blob itself was first created. Serialized as an ISO 8601 string."""
timestamp::TimeDateZone = TimeDateZone(now(localzone()))
timestamp::TimeDateZone = tdz_now()
""" Type version of this Blobentry."""
version::VersionNumber = DFG.version(Blobentry)
end
Expand Down
10 changes: 4 additions & 6 deletions src/entities/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ StructUtils.@kwarg struct FactorDFG{T <: AbstractObservation, N} <: AbstractGrap
variableorder::NTuple{N, Symbol} & (choosetype = x->NTuple{length(x), Symbol},) # NOTE v0.29 renamed from _variableOrderSymbols
"""Variable timestamp.
Accessors: [`getTimestamp`](@ref)"""
timestamp::TimeDateZone = TimeDateZone(now(localzone())) # NOTE v0.29 changed from ZonedDateTime
timestamp::TimeDateZone = tdz_now() # NOTE v0.29 changed from ZonedDateTime
# TODO
# """(Optional) Steady (monotonic) time in nanoseconds `Nanosecond` (`Int64``)"""
# nstime::Nanosecond #NOTE v0.29 REMOVED as not used, add when needed, or now as steadytime.
Expand Down Expand Up @@ -103,7 +103,7 @@ function FactorDFG(
variableorder::Union{<:Tuple, Vector{Symbol}},
observation::AbstractObservation;
label::Symbol = assembleFactorName(variableorder),
timestamp::Union{TimeDateZone, ZonedDateTime} = TimeDateZone(now(localzone())),
timestamp::Union{TimeDateZone, ZonedDateTime} = tdz_now(),
tags::Union{Set{Symbol}, Vector{Symbol}} = Set{Symbol}([:FACTOR]),
bloblets::Bloblets = Bloblets(),
multihypo::Vector{Float64} = Float64[],
Expand Down Expand Up @@ -160,9 +160,7 @@ function FactorDFG(
state::Recipestate = Recipestate(),
cache = nothing;
tags::Set{Symbol} = Set{Symbol}([:FACTOR]),
timestamp::Union{DateTime, ZonedDateTime, TimeDateZone} = TimeDateZone(
now(localzone()),
),
timestamp::Union{DateTime, ZonedDateTime, TimeDateZone} = tdz_now(),
solvable::Int = 1,
bloblets::Bloblets = Bloblets(),
blobentries::Blobentries = Blobentries(),
Expand Down Expand Up @@ -237,7 +235,7 @@ end
function FactorSummary(
label::Symbol,
variableorder::Union{Vector{Symbol}, Tuple};
timestamp::TimeDateZone = TimeDateZone(now(localzone())),
timestamp::TimeDateZone = tdz_now(),
tags::Set{Symbol} = Set{Symbol}(),
)
return FactorSummary(label, tags, Tuple(variableorder), timestamp)
Expand Down
24 changes: 8 additions & 16 deletions src/entities/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ end
##------------------------------------------------------------------------------
# The Variable information packed in a way that accomdates multi-lang using json.

# Notes:
# - timestamp is a `ZonedDateTime` in UTC.
# - nstime can be used as mission time, with the convention that the timestamp millis coincide with the mission start nstime
# - e.g. timestamp is `2020-01-01 06:30:01.250 UTC` and first nstime is `250_000_000`.

"""
$(TYPEDEF)
Complete variable structure for a DistributedFactorGraph variable.
Expand All @@ -147,9 +142,9 @@ $(TYPEDFIELDS)
label::Symbol
"""Variable timestamp.
Accessors: [`getTimestamp`](@ref)"""
timestamp::TimeDateZone = TimeDateZone(now(localzone())) #NOTE changed to TimeDateZone in v0.29
"""Nanoseconds since a user-understood epoch (i.e unix epoch, robot boot time, etc.)"""
steadytime::Union{Nothing, Nanosecond} = nothing #NOTE changed to TimeDateZone in v0.29
timestamp::TimeDateZone = tdz_now() #NOTE changed to TimeDateZone in v0.29
# """Nanoseconds since a user-understood epoch (i.e unix epoch, robot boot time, etc.)"""
# steadytime::Union{Nothing, Nanosecond} = nothing #NOTE changed to TimeDateZone in v0.29
#nstime::String = "0" #NOTE different uses, as 0-999_999 nanosecond part of timestamp now in timestamp, as steady timestamp now in steadytime
"""Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK].
Accessors: [`getTags`](@ref), [`mergeTags!`](@ref), and [`deleteTags!`](@ref)"""
Expand Down Expand Up @@ -179,7 +174,7 @@ function StructUtils.fielddefaults(
::Type{VariableDFG{T, P, N}},
) where {T, P, N}
return (
timestamp = TimeDateZone(now(localzone())),
timestamp = tdz_now(),
tags = Set{Symbol}(),
# states = OrderedDict{Symbol, State{T, P, N}}(),
bloblets = Bloblets(),
Expand Down Expand Up @@ -218,9 +213,9 @@ function VariableDFG(
label::Symbol,
statetype::Union{T, Type{T}};
tags::Union{Set{Symbol}, Vector{Symbol}} = Set{Symbol}(),
timestamp::Union{TimeDateZone, ZonedDateTime} = TimeDateZone(now(localzone())),
timestamp::Union{TimeDateZone, ZonedDateTime} = tdz_now(),
solvable::Union{Int, Base.RefValue{Int}} = Ref{Int}(1),
steadytime::Union{Nothing, Nanosecond} = nothing,
# steadytime::Union{Nothing, Nanosecond} = nothing,
nanosecondtime = nothing,
smalldata = nothing,
kwargs...,
Expand All @@ -230,13 +225,10 @@ function VariableDFG(
timestamp = TimeDateZone(timestamp)
end
if !isnothing(nanosecondtime)
@assert isnothing(steadytime),
"nanosecondtime is replaced by steadytime. Cannot specify both steadytime and nanosecondtime"
Base.depwarn(
"nanosecondtime kwarg is deprecated, use steadytime instead",
"nanosecondtime kwarg is deprecated, use `timestamp` or `bloblets` instead",
:VariableDFG,
)
steadytime = Nanosecond(nanosecondtime)
end
if !isnothing(smalldata)
Base.depwarn("smalldata kwarg is deprecated, use bloblets instead", :VariableDFG)
Expand All @@ -249,7 +241,7 @@ function VariableDFG(

N = getDimension(T)
P = getPointType(T)
return VariableDFG{T, P, N}(; label, steadytime, solvable, tags, timestamp, kwargs...)
return VariableDFG{T, P, N}(; label, solvable, tags, timestamp, kwargs...)
end

function VariableDFG(label::Symbol, state::State; kwargs...)
Expand Down
1 change: 0 additions & 1 deletion src/services/CustomPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function printVariable(
nothing
end
println(ioc, " timestamp: ", vert.timestamp)
isnothing(vert.steadytime) || println(ioc, " steadytime: ", vert.steadytime)
print(ioc, " label: ")
printstyled(ioc, vert.label; bold = true)
println(ioc)
Expand Down
8 changes: 4 additions & 4 deletions src/services/find.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"""
$SIGNATURES

Find and return the closest timestamp from two sets of Tuples. Also return the minimum delta-time (`::Millisecond`) and how many elements match from the two sets are separated by the minimum delta-time.
Find and return the closest timestamp from two sets of Tuples. Also return the minimum delta-time (`::Nanosecond`) and how many elements match from the two sets are separated by the minimum delta-time.
"""
function findClosestTimestamp(
setA::Vector{Tuple{TimeDateZone, T}},
setB::Vector{Tuple{TimeDateZone, S}},
) where {S, T}
#
# build matrix of delta times, ranges on rows x vars on columns
DT = Array{Millisecond, 2}(undef, length(setA), length(setB))
DT = Array{Nanosecond, 2}(undef, length(setA), length(setB))
for i = 1:length(setA), j = 1:length(setB)
DT[i, j] = setB[j][1] - setA[i][1]
end
Expand All @@ -38,7 +38,7 @@ end
Find and return nearest variable labels per delta time. Function will filter on `regexFilter`, `tags`, and `solvable`.

Notes
- Returns `Vector{Tuple{Vector{Symbol}, Millisecond}}`
- Returns `Vector{Tuple{Vector{Symbol}, Nanosecond}}`

DevNotes:
- TODO `number` should allow returning more than one for k-nearest matches.
Expand Down Expand Up @@ -68,7 +68,7 @@ function findVariableNearTimestamp(
mask = BitArray{1}(undef, length(syms))
fill!(mask, true)

RET = Vector{Tuple{Vector{Symbol}, Millisecond}}()
RET = Vector{Tuple{Vector{Symbol}, Nanosecond}}()
SYMS = Symbol[]
CORRS = 1
NUMBER = number
Expand Down
3 changes: 0 additions & 3 deletions test/GraphsDFGSummaryTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ if false
tags = [:FACTOR],
variableorder = [:a],
timestamp = DFG.Dates.now(DFG.tz"Z"),
nstime = 0,
fnctype = "PriorPose2",
solvable = 1,
data = "",
Expand All @@ -68,7 +67,6 @@ if false
tags = [:FACTOR],
variableorder = [:a, :b],
timestamp = DFG.Dates.now(DFG.tz"Z"),
nstime = 0,
fnctype = "Pose2Pose2",
solvable = 1,
data = "",
Expand All @@ -79,7 +77,6 @@ if false
tags = [:FACTOR],
variableorder = [:b, :c],
timestamp = DFG.Dates.now(DFG.tz"Z"),
nstime = 0,
fnctype = "Pose2Pose2",
solvable = 1,
data = "",
Expand Down
5 changes: 2 additions & 3 deletions test/interfaceTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ end
@test printVariable(var1) === nothing
@test printFactor(fac1) === nothing

@test printVariable(iobuf, var1; skipfields = [:timestamp, :solver, :ppe, :nstime]) ===
nothing
@test printVariable(iobuf, var1; skipfields = [:timestamp]) === nothing

varstr = String(take!(iobuf))
@test occursin(r"VariableDFG", varstr)
Expand All @@ -79,7 +78,7 @@ end
@test occursin(r"bandwidths", varstr)
# == "VariableCompute{TestVariableType1}\nlabel: a\ntags: Set([:VARIABLE, :POSE])\nsize marginal samples: (1, 1)\nkde bandwidths: [0.0]\nNo PPEs\n"

@test printFactor(iobuf, fac1; skipfields = [:timestamp, :solver, :nstime]) === nothing
@test printFactor(iobuf, fac1; skipfields = [:timestamp]) === nothing
@test occursin(r"FactorDFG.*\nlabel:\n:abf1", String(take!(iobuf)))

@test printFactor(iobuf, fac1; short = true) === nothing
Expand Down
3 changes: 3 additions & 0 deletions test/testBlocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ function DFGVariableSCA()
@test getDimension(testvar) == 1
@test getManifold(testvar) == TranslationGroup(1)

@test DFG.calcDeltatime(v1, v2) isa Real

# #TODO sort out
# getState
# getSolvedCount
Expand Down Expand Up @@ -389,6 +391,7 @@ function DFGFactorSCA()
# create f0 here for a later timestamp
f0 = FactorCompute(:af1, [:a], obs_prior; tags = Set([:PRIOR]))

@test DFG.calcDeltatime(f1, f2) isa Real
#fill in undefined fields
# f2.solverData.certainhypo = Int[]
# f2.solverData.multihypo = Float64[]
Expand Down
Loading