Skip to content

Commit 7a81f52

Browse files
authored
Merge pull request #942 from JuliaRobotics/23Q1/dfg_v0_19_1_updates
Standardizing DFG objects against new patterns
2 parents 09e83a7 + 218b6ff commit 7a81f52

17 files changed

+133
-161
lines changed

src/DFGPlots/DFGPlots.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ function plotDFG(io::IO, ::MIME"application/prs.juno.plotpane+html", dfg::Abstra
104104
">
105105
$(typeof(dfg))
106106
<ul>
107-
<li>$(dfg.userId)</li>
108-
<li>$(dfg.robotId)</li>
109-
<li>$(dfg.sessionId)</li>
110-
<li>$(dfg.description)</li>
107+
<li>$(getUserLabel(dfg))</li>
108+
<li>$(getRobotLabel(dfg))</li>
109+
<li>$(getSessionLabel(dfg))</li>
110+
<li>$(getDescription(dfg))</li>
111111
</ul>
112112
<script charset="utf-8">
113113
$(read(GraphPlot.Compose.snapsvgjs, String))

src/DataBlobs/DataBlobs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ export getData, addData!, updateData!, deleteData!, listStoreEntries
2020
export getDataBlob, addDataBlob!, updateDataBlob!, deleteDataBlob!, listDataBlobs
2121
export copyStore
2222

23-
export getId, getHash, getCreatedTimestamp
23+
export getId, getHash, getTimestamp

src/DataBlobs/entities/AbstractDataEntries.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
getLabel(entry::AbstractDataEntry) = entry.label
99
getId(entry::AbstractDataEntry) = entry.id
1010
getHash(entry::AbstractDataEntry) = hex2bytes(entry.hash)
11-
getCreatedTimestamp(entry::AbstractDataEntry) = entry.createdTimestamp
11+
getTimestamp(entry::AbstractDataEntry) = entry.timestamp
1212

1313

1414
##==============================================================================
@@ -18,43 +18,46 @@ export BlobStoreEntry
1818

1919
"""
2020
$(TYPEDEF)
21-
Genaral Data Store Entry.
21+
General Data Store Entry.
2222
"""
23-
struct BlobStoreEntry <: AbstractDataEntry
23+
@Base.kwdef struct BlobStoreEntry <: AbstractDataEntry
24+
id::Union{UUID, Nothing}=nothing
2425
label::Symbol
25-
id::UUID
2626
blobstore::Symbol
2727
hash::String # Probably https://docs.julialang.org/en/v1/stdlib/SHA
2828
origin::String # E.g. user|robot|session|varlabel
2929
description::String
3030
mimeType::String
31-
createdTimestamp::ZonedDateTime # of when the entry was created
31+
metadata::String
32+
timestamp::ZonedDateTime = now(localzone())
33+
_type::String = "BlobStoreEntry"
34+
_version::String = _getDFGVersion()
3235
end
3336

3437
_fixtimezone(cts::NamedTuple) = ZonedDateTime(cts.utc_datetime*"+00")
3538

3639
# needed for deserialization from JSON during DFG v0.19 transition, see #867
3740
function BlobStoreEntry(;
38-
label,
3941
id,
42+
label,
4043
blobstore,
4144
hash,
4245
origin,
4346
description,
4447
mimeType,
45-
createdTimestamp,
48+
timestamp,
4649
kwargs... # drop excessive fields
4750
)
4851
#
4952
BlobStoreEntry(
50-
Symbol(label),
5153
UUID(id),
54+
Symbol(label),
5255
Symbol(blobstore),
5356
hash,
5457
origin,
5558
description,
5659
mimeType,
57-
_fixtimezone(createdTimestamp),
60+
_fixtimezone(timestamp),
5861
)
5962
end
6063

src/DataBlobs/services/AbstractDataEntries.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ end
1414

1515
"""
1616
$(SIGNATURES)
17-
Function to generate source string - userId|robotId|sessionId|varLabel
17+
Function to generate source string - userLabel|robotLabel|sessionLabel|varLabel
1818
"""
1919
buildSourceString(dfg::AbstractDFG, label::Symbol) =
20-
"$(dfg.userId)|$(dfg.robotId)|$(dfg.sessionId)|$label"
20+
"$(getUserLabel(dfg))|$(getRobotLabel(dfg))|$(getSessionLabel(dfg))|$label"
2121

2222

2323
##==============================================================================

src/DataBlobs/services/BlobStores.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ end
103103

104104
function updateData!(dfg::AbstractDFG, blobstore::AbstractBlobStore, label::Symbol, entry::AbstractDataEntry, blob::Vector{UInt8}; hashfunction = sha256)
105105
# Recalculate the hash - NOTE Assuming that this is going to be a BlobStoreEntry. TBD.
106-
newEntry = BlobStoreEntry(entry.label, entry.id, blobstore.key, bytes2hex(hashfunction(blob)),
107-
"$(dfg.userId)|$(dfg.robotId)|$(dfg.sessionId)|$(label)",
108-
entry.description, entry.mimeType, entry.createdTimestamp)
106+
newEntry = BlobStoreEntry(entry.id, entry.label, blobstore.key, bytes2hex(hashfunction(blob)),
107+
buildSourceString(dfg, label),
108+
entry.description, entry.mimeType, entry.metadata, entry.timestamp, entry._type, _getDFGVersion())
109109

110110
de = updateDataEntry!(dfg, label, newEntry)
111111
db = updateDataBlob!(blobstore, de, blob)
@@ -136,9 +136,16 @@ function addData!(dfg::AbstractDFG, blobstore::AbstractBlobStore, label::Symbol,
136136
blob::Vector{UInt8}, timestamp=now(localzone()); description="", mimeType = "application/octet-stream", id::UUID = uuid4(), hashfunction = sha256)
137137

138138

139-
entry = BlobStoreEntry(key, id, blobstore.key, bytes2hex(hashfunction(blob)),
140-
"$(dfg.userId)|$(dfg.robotId)|$(dfg.sessionId)|$(label)",
141-
description, mimeType, timestamp)
139+
entry = BlobStoreEntry(
140+
id = id,
141+
label = key,
142+
blobstore = blobstore.key,
143+
hash = bytes2hex(hashfunction(blob)),
144+
origin = buildSourceString(dfg, label),
145+
description = description,
146+
mimeType = mimeType,
147+
metadata = "",
148+
timestamp = timestamp)
142149

143150
addData!(dfg, blobstore, label, entry, blob; hashfunction)
144151
end

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export AbstractParams, NoSolverParams
5757
export AbstractBlobStore
5858

5959
# accessors & crud
60-
export getUserId, getRobotId, getSessionId
60+
export getUserLabel, getRobotLabel, getSessionLabel
6161
export getDFGInfo
6262
export getDescription, setDescription!,
6363
getSolverParams, setSolverParams!,

src/GraphsDFG/GraphsDFG.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ using ...DistributedFactorGraphs
1111
# import DFG functions to extend
1212
import ...DistributedFactorGraphs: setSolverParams!,
1313
getFactor,
14-
setDescription!,
1514
# getLabelDict,
1615
getUserData,
1716
setUserData!,
@@ -27,7 +26,6 @@ import ...DistributedFactorGraphs: setSolverParams!,
2726
exists,
2827
isVariable,
2928
isFactor,
30-
getDescription,
3129
updateVariable!,
3230
updateFactor!,
3331
deleteVariable!,

src/GraphsDFG/entities/GraphsDFG.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ An in-memory DistributedFactorGraph based on Graphs.jl with parameters:
1010
mutable struct GraphsDFG{T <: AbstractParams, V <: AbstractDFGVariable, F <:AbstractDFGFactor} <: AbstractDFG{T}
1111
g::FactorGraph{Int, V, F}
1212
description::String
13-
userId::String
14-
robotId::String
15-
sessionId::String
13+
userLabel::String
14+
robotLabel::String
15+
sessionLabel::String
1616
userData::Dict{Symbol, String}
1717
robotData::Dict{Symbol, String}
1818
sessionData::Dict{Symbol, String}
@@ -31,19 +31,19 @@ Create an in-memory GraphsDFG with the following parameters:
3131
"""
3232
function GraphsDFG{T,V,F}(g::FactorGraph{Int,V,F}=FactorGraph{Int,V,F}();
3333
description::String="Graphs.jl implementation",
34-
userId::String="DefaultUser",
35-
robotId::String="DefaultRobot",
36-
sessionId::String="Session_$(string(uuid4())[1:6])",
34+
userLabel::String="DefaultUser",
35+
robotLabel::String="DefaultRobot",
36+
sessionLabel::String="Session_$(string(uuid4())[1:6])",
3737
userData::Dict{Symbol, String} = Dict{Symbol, String}(),
3838
robotData::Dict{Symbol, String} = Dict{Symbol, String}(),
3939
sessionData::Dict{Symbol, String} = Dict{Symbol, String}(),
4040
solverParams::T=T(),
4141
blobstores=Dict{Symbol, AbstractBlobStore}()) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor}
42-
# Validate the userId, robotId, and sessionId
43-
!isValidLabel(userId) && error("'$userId' is not a valid User ID")
44-
!isValidLabel(robotId) && error("'$robotId' is not a valid Robot ID")
45-
!isValidLabel(sessionId) && error("'$sessionId' is not a valid Session ID")
46-
return GraphsDFG{T,V,F}(g, description, userId, robotId, sessionId, userData, robotData, sessionData, Symbol[], solverParams, blobstores)
42+
# Validate the userLabel, robotLabel, and sessionLabel
43+
!isValidLabel(userLabel) && error("'$userLabel' is not a valid User label")
44+
!isValidLabel(robotLabel) && error("'$robotLabel' is not a valid Robot label")
45+
!isValidLabel(sessionLabel) && error("'$sessionLabel' is not a valid Session label")
46+
return GraphsDFG{T,V,F}(g, description, userLabel, robotLabel, sessionLabel, userData, robotData, sessionData, Symbol[], solverParams, blobstores)
4747
end
4848

4949
# GraphsDFG{T}(; kwargs...) where T <: AbstractParams = GraphsDFG{T,DFGVariable,DFGFactor}(;kwargs...)
@@ -68,24 +68,24 @@ end
6868

6969

7070
GraphsDFG(description::String,
71-
userId::String,
72-
robotId::String,
73-
sessionId::String,
71+
userLabel::String,
72+
robotLabel::String,
73+
sessionLabel::String,
7474
userData::Dict{Symbol, String},
7575
robotData::Dict{Symbol, String},
7676
sessionData::Dict{Symbol, String},
7777
solverParams::AbstractParams,
7878
blobstores=Dict{Symbol, AbstractBlobStore}()) =
79-
GraphsDFG(FactorGraph{Int,DFGVariable,DFGFactor}(), description, userId, robotId, sessionId, userData, robotData, sessionData, Symbol[], solverParams, blobstores)
79+
GraphsDFG(FactorGraph{Int,DFGVariable,DFGFactor}(), description, userLabel, robotLabel, sessionLabel, userData, robotData, sessionData, Symbol[], solverParams, blobstores)
8080

8181

8282
GraphsDFG{T,V,F}(description::String,
83-
userId::String,
84-
robotId::String,
85-
sessionId::String,
83+
userLabel::String,
84+
robotLabel::String,
85+
sessionLabel::String,
8686
userData::Dict{Symbol, String},
8787
robotData::Dict{Symbol, String},
8888
sessionData::Dict{Symbol, String},
8989
solverParams::T,
9090
blobstores=Dict{Symbol, AbstractBlobStore}()) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor} =
91-
GraphsDFG(FactorGraph{Int,V,F}(), description, userId, robotId, sessionId, userData, robotData, sessionData, Symbol[], solverParams, blobstores)
91+
GraphsDFG(FactorGraph{Int,V,F}(), description, userLabel, robotLabel, sessionLabel, userData, robotData, sessionData, Symbol[], solverParams, blobstores)

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ Gets an empty and unique GraphsDFG derived from an existing DFG.
317317
"""
318318
function _getDuplicatedEmptyDFG(dfg::GraphsDFG{P,V,F}) where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
319319
newDfg = GraphsDFG{P,V,F}(;
320-
userId=dfg.userId, robotId=dfg.robotId, sessionId=dfg.sessionId,
320+
userLabel=getUserLabel(dfg), robotLabel=getRobotLabel(dfg), sessionLabel=getSessionLabel(dfg),
321321
solverParams=deepcopy(dfg.solverParams))
322322
newDfg.description ="(Copy of) $(dfg.description)"
323323
return newDfg

src/entities/AbstractDFGSummary.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Structure for a graph summary.
66
struct DFGSummary
77
variables::Dict{Symbol, DFGVariableSummary}
88
factors::Dict{Symbol, DFGFactorSummary}
9-
userId::String
10-
robotId::String
11-
sessionId::String
9+
userLabel::String
10+
robotLabel::String
11+
sessionLabel::String
1212
end

0 commit comments

Comments
 (0)