Skip to content

Commit 1d20f9d

Browse files
committed
Merge branch 'master' into nstime_as_epoch
2 parents 253af4d + 1858564 commit 1d20f9d

24 files changed

+732
-385
lines changed

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.20.1"
3+
version = "0.20.2"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
7+
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
78
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
89
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
910
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
@@ -20,12 +21,14 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2021
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
2122
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
2223
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
24+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2325
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
2426
TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b"
2527
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
2628
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
2729

2830
[compat]
31+
CSV = "0.10"
2932
Colors = "0.10, 0.11, 0.12"
3033
Distributions = "0.23, 0.24, 0.25"
3134
DocStringExtensions = "0.8, 0.9"

docs/extra/CoreAPI.fods

Lines changed: 201 additions & 105 deletions
Large diffs are not rendered by default.

docs/src/variable_factor_serialization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ prior = addFactor!(dfg, [:x0], PriorPose2( MvNormal([10; 10; 1.0/8.0], Matrix(Di
2626

2727
# Now serialize them:
2828
pVariable = packVariable(dfg, x0)
29-
pFactor = packFactor(dfg, prior)
29+
pFactor = packFactor(prior)
3030

3131
# And we can deserialize them
3232
upVariable = unpackVariable(dfg, pVariable)
@@ -60,7 +60,7 @@ for v in getVariables(dfg)
6060
end
6161
# Factors
6262
for f in getFactors(dfg)
63-
fPacked = packFactor(dfg, f)
63+
fPacked = packFactor(f)
6464
io = open("$folder/factors/$(f.label).json", "w")
6565
JSON3.write(io, fPacked)
6666
close(io)

src/DataBlobs/DataBlobs.jl

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ StructTypes.StructType(::Type{BlobEntry}) = StructTypes.UnorderedStruct()
3030
StructTypes.idproperty(::Type{BlobEntry}) = :id
3131
StructTypes.omitempties(::Type{BlobEntry}) = (:id,)
3232

33-
34-
3533
_fixtimezone(cts::NamedTuple) = ZonedDateTime(cts.utc_datetime*"+00")

src/DataBlobs/services/BlobEntry.jl

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function assertHash(de::BlobEntry, db; hashfunction::Function = sha256)
4646
end
4747

4848

49-
function Base.show(io::IO, entry::BlobEntry)
49+
function Base.show(io::IO, ::MIME"text/plain", entry::BlobEntry)
5050
println(io, "_type=BlobEntry {")
5151
println(io, " id: ", entry.id)
5252
println(io, " blobId: ", entry.blobId)
@@ -62,10 +62,6 @@ function Base.show(io::IO, entry::BlobEntry)
6262
println(io, "}")
6363
end
6464

65-
Base.show(io::IO, ::MIME"text/plain", entry::BlobEntry) = show(io, entry)
66-
67-
68-
6965
##==============================================================================
7066
## BlobEntry - CRUD
7167
##==============================================================================
@@ -85,8 +81,7 @@ end
8581

8682
function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
8783
for (k,v) in var.dataDict
88-
# FIXME stop using v.id since that has been repurposed for unique BlobEntry indexing
89-
if v.originId == blobId || v.blobId == blobId || v.id == blobId
84+
if blobId in [v.originId, v.blobId]
9085
return v
9186
end
9287
end
@@ -95,9 +90,15 @@ function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
9590
)
9691
end
9792

98-
#TODO consider changing this to use `first` as in julia's findfirst - as in findfirstBlobEntry->label::Symbol
99-
# or getBlobEntryFirst, btw this returns a vector in some other places
100-
function getBlobEntry(var::AbstractDFGVariable, key::Regex)
93+
@deprecate getBlobEntry(var::AbstractDFGVariable, key::Regex) getBlobEntryFirst(var, key)
94+
95+
"""
96+
$(SIGNATURES)
97+
Finds and returns the first blob entry that matches the regex.
98+
99+
Also see: [`getBlobEntry`](@ref)
100+
"""
101+
function getBlobEntryFirst(var::AbstractDFGVariable, key::Regex)
101102
for (k,v) in var.dataDict
102103
if occursin(key, string(v.label))
103104
return v
@@ -110,7 +111,7 @@ end
110111

111112
getBlobEntry(var::AbstractDFGVariable, key::AbstractString) = getBlobEntry(var,Regex(key))
112113

113-
114+
#TODO split betweeen getfirstBlobEntry and getBlobEntry
114115
getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol, UUID, <:AbstractString, Regex}) = getBlobEntry(getVariable(dfg, label), key)
115116
# getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getBlobEntry(getVariable(dfg, label), key)
116117

@@ -125,22 +126,30 @@ Also see: [`getBlobEntry`](@ref), [`addBlob!`](@ref), [`mergeBlobEntries!`](@ref
125126
function addBlobEntry!(
126127
var::AbstractDFGVariable,
127128
entry::BlobEntry;
128-
blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
129-
blobSize::Int = (hasfield(BlobEntry, :size) ? entry.size : -1)
130129
)
131130
# see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
131+
# blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
132+
# blobSize::Int = (hasfield(BlobEntry, :size) ? entry.size : -1)
132133
haskey(var.dataDict, entry.label) && error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
133134
var.dataDict[entry.label] = entry
134135
return entry
135136
end
136137

138+
function addBlobEntry!(
139+
var::PackedVariable,
140+
entry::BlobEntry,
141+
)
142+
entry.label in getproperty.(var.blobEntries,:label) && error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
143+
push!(var.blobEntries, entry)
144+
return entry
145+
end
146+
137147
function addBlobEntry!(
138148
dfg::AbstractDFG,
139149
vLbl::Symbol,
140150
entry::BlobEntry;
141-
kw...
142151
)
143-
return addBlobEntry!(getVariable(dfg, vLbl), entry; kw...)
152+
return addBlobEntry!(getVariable(dfg, vLbl), entry)
144153
end
145154

146155

@@ -200,18 +209,62 @@ hasBlobEntry(var::AbstractDFGVariable, blobLabel::Symbol) = haskey(var.dataDict,
200209

201210
"""
202211
$(SIGNATURES)
203-
Get data entries, Vector{BlobEntry}
212+
213+
Get blob entries, Vector{BlobEntry}
204214
"""
205215
function getBlobEntries(var::AbstractDFGVariable)
206216
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
207217
collect(values(var.dataDict))
208218
end
219+
220+
function getBlobEntries(var::PackedVariable)
221+
var.blobEntries
222+
end
223+
209224
function getBlobEntries(dfg::AbstractDFG, label::Symbol)
210225
# !isVariable(dfg, label) && return nothing
211226
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
212227
getBlobEntries(getVariable(dfg, label))
213228
end
214229

230+
function getBlobEntries(dfg::AbstractDFG, label::Symbol, regex::Regex)
231+
entries = getBlobEntries(dfg, label)
232+
return filter(entries) do e
233+
occursin(regex, string(e.label))
234+
end
235+
end
236+
237+
238+
"""
239+
$(SIGNATURES)
240+
241+
Get all blob entries matching a Regex pattern over variables
242+
243+
Notes
244+
- Use `dropEmpties=true` to not include empty lists in result.
245+
- Use keyword `varList` for which variables to search through.
246+
"""
247+
function getBlobEntriesVariables(
248+
dfg::AbstractDFG,
249+
bLblPattern::Regex;
250+
varList::AbstractVector{Symbol} = sort(listVariables(dfg); lt=natural_lt),
251+
dropEmpties::Bool = false
252+
)
253+
RETLIST = Vector{Vector{BlobEntry}}()
254+
@showprogress "Get entries matching $bLblPattern" for vl in varList
255+
bes = filter(
256+
s->occursin(bLblPattern,string(s.label)),
257+
listBlobEntries(dfg,vl)
258+
)
259+
# only push to list if there are entries on this variable
260+
(!dropEmpties || 0 < length(bes)) ? nothing : continue
261+
push!(RETLIST, bes)
262+
end
263+
264+
return RETLIST
265+
end
266+
267+
215268
"""
216269
$(SIGNATURES)
217270
List the blob entries associated with a particular variable.

0 commit comments

Comments
 (0)