Skip to content

Commit c5eafbd

Browse files
authored
Merge pull request #917 from JuliaRobotics/22Q4/enh/incrdesuff
incrDataLabelSuffix
2 parents 232f20d + d259d64 commit c5eafbd

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.18.8"
3+
version = "0.18.9"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/DataBlobs/services/AbstractDataEntries.jl

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,47 @@ function mergeDataEntries!(
217217
if 0 < length(des)
218218
union(((s->mergeDataEntries!(dst, dlbl, src, slbl, s.id)).(des))...)
219219
end
220-
end
220+
end
221+
222+
"""
223+
$SIGNATURES
224+
225+
If the blob label `datalabel` already exists, then this function will return the name `datalabel_1`.
226+
If the blob label `datalabel_1` already exists, then this function will return the name `datalabel_2`.
227+
"""
228+
function incrDataLabelSuffix(
229+
dfg::AbstractDFG,
230+
vla,
231+
bllb::S;
232+
datalabel=Ref("")
233+
) where {S <: Union{Symbol, <:AbstractString}}
234+
count = 1
235+
hasund = false
236+
len = 0
237+
try
238+
de,_ = getData(dfg, Symbol(vla), bllb)
239+
bllb = string(bllb)
240+
# bllb *= bllb[end] != '_' ? "_" : ""
241+
datalabel[] = string(de.label)
242+
dlb = match(r"\d*", reverse(datalabel[]))
243+
# slightly complicated search if blob name already has an underscore number suffix, e.g. `_4`
244+
count, hasund, len = if occursin(Regex(dlb.match*"_"), reverse(datalabel[]))
245+
parse(Int, dlb.match |> reverse)+1, true, length(dlb.match)
246+
else
247+
1, datalabel[][end] == '_', 0
248+
end
249+
catch err
250+
# append latest count
251+
if !(err isa KeyError)
252+
throw(err)
253+
end
254+
end
255+
# the piece from old label without the suffix count number
256+
bllb = datalabel[][1:(end-len)]
257+
if !hasund || bllb[end] != '_'
258+
bllb *= "_"
259+
end
260+
bllb *= string(count)
261+
262+
S(bllb)
263+
end

src/DistributedFactorGraphs.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,14 @@ export getSolvedCount, isSolved, setSolvedCount!, isInitialized, isMarginalized,
192192
export getNeighborhood, getNeighbors, _getDuplicatedEmptyDFG
193193
export findFactorsBetweenNaive
194194
export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph, mergeGraph!
195-
# Big Data
195+
196+
# Entry Blob Data
196197
##------------------------------------------------------------------------------
197198
export addDataEntry!, getDataEntry, updateDataEntry!, deleteDataEntry!, getDataEntries, listDataEntries, hasDataEntry, hasDataEntry
198199
export listDataEntrySequence
199200
# convenience wrappers
200201
export addDataEntry!, mergeDataEntries!
202+
export incrDataLabelSuffix
201203
# aliases
202204
export addData!
203205

test/consol_DataEntryBlobTests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,16 @@ ds = FolderStore{Vector{UInt8}}(:filestore, "/tmp/dfgFolderStore")
9292
addBlobStore!(dfg, ds)
9393

9494
ade,adb = addData!(dfg, :filestore, :x1, :random, dataset1)
95+
_,_ = addData!(dfg, :filestore, :x1, :another_1, dataset1)
9596
gde,gdb = getData(dfg, :x1, :random)
97+
98+
@test incrDataLabelSuffix(dfg,:x1,:random) == :random_1
99+
@test incrDataLabelSuffix(dfg,:x1,:another_1) == :another_2
100+
# @test incrDataLabelSuffix(dfg,:x1,:another) == :another_2 # TODO exand support for Regex likely search on labels
101+
# @test incrDataLabelSuffix(dfg,:x1,"random") == "random_1" # TODO expand support for label::String
102+
96103
dde,ddb = deleteData!(dfg, :x1, :random)
104+
_,_ = deleteData!(dfg, :x1, :another_1)
97105

98106
@test ade == gde == dde
99107
@test adb == gdb == ddb

test/testBlocks.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,10 @@ function ProducingDotFiles(testDFGAPI,
14371437

14381438
addVariable!(dotdfg, v1)
14391439
addVariable!(dotdfg, v2)
1440+
# FIXME, fix deprecation
1441+
# ┌ Warning: addFactor!(dfg, variables, factor) is deprecated, use addFactor!(dfg, factor)
1442+
# │ caller = ProducingDotFiles(testDFGAPI::Type{GraphsDFG}, v1::Nothing, v2::Nothing, f1::Nothing; VARTYPE::Type{DFGVariable}, FACTYPE::Type{DFGFactor}) at testBlocks.jl:1440
1443+
# └ @ Main ~/.julia/dev/DistributedFactorGraphs/test/testBlocks.jl:1440
14401444
addFactor!(dotdfg, [v1, v2], f1)
14411445
#NOTE hardcoded toDot will have different results so test LightGraphs seperately
14421446
if testDFGAPI <: LightDFG || testDFGAPI <: GraphsDFG || testDFGAPI <: Neo4jDFG
@@ -1490,7 +1494,8 @@ function CopyFunctionsTest(testDFGAPI; kwargs...)
14901494
@test issetequal(lsf(dcdfg_part), flbls)
14911495

14921496
# deepcopy subgraph ignoring orphans
1493-
@test_logs (:warn, r"orphan") dcdfg_part = deepcopyGraph(LightDFG, dfg, vlbls, union(flbls, [:x1x2f1]))
1497+
# @test_logs (:warn, r"orphan") # orphan warning has been suppressed given overwhelming printouts
1498+
dcdfg_part = deepcopyGraph(LightDFG, dfg, vlbls, union(flbls, [:x1x2f1]))
14941499
@test issetequal(ls(dcdfg_part), vlbls)
14951500
@test issetequal(lsf(dcdfg_part), flbls)
14961501

0 commit comments

Comments
 (0)