Skip to content

Commit 59ae304

Browse files
committed
incrBlobLabelSuffix
1 parent 232f20d commit 59ae304

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

src/DataBlobs/services/AbstractDataEntries.jl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,41 @@ 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 incrBlobLabelSuffix(
229+
dfg::AbstractDFG,
230+
vla,
231+
bllb;
232+
datalabel=Ref("")
233+
)
234+
count = 1
235+
hasund = false
236+
try
237+
de,_ = getData(dfg, Symbol(vla), bllb)
238+
bllb = string(bllb)
239+
# bllb *= bllb[end] != '_' ? "_" : ""
240+
datalabel[] = string(de.label)
241+
dlb = match(r"\d*", reverse(datalabel[]))
242+
# slightly complicated search if blob name already has an underscore number suffix, e.g. `_4`
243+
count, hasund = if occursin(Regex(dlb.match*"_"), reverse(datalabel[]))
244+
parse(Int, dlb.match |> reverse)+1, true
245+
else
246+
1, datalabel[][end] == '_'
247+
end
248+
catch err
249+
# append latest count
250+
if !(err isa KeyError)
251+
throw(err)
252+
end
253+
end
254+
bllb *= !hasund || bllb[end] != '_' ? "_" : ""
255+
bllb *= string(count)
256+
bllb
257+
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 incrBlobLabelSuffix
201203
# aliases
202204
export addData!
203205

test/consol_DataEntryBlobTests.jl

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

9494
ade,adb = addData!(dfg, :filestore, :x1, :random, dataset1)
95+
ade,adb = addData!(dfg, :filestore, :x1, :another_1, dataset1)
9596
gde,gdb = getData(dfg, :x1, :random)
97+
98+
@test incrBlobLabelSuffix(dfg,:x2,:random) == :random_1
99+
@test incrBlobLabelSuffix(dfg,:x2,:another) == :another_2
100+
96101
dde,ddb = deleteData!(dfg, :x1, :random)
97102

98103
@test ade == gde == dde

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)