Skip to content

Commit ced68a5

Browse files
committed
Reorder and deprecate
1 parent 559fd62 commit ced68a5

15 files changed

+253
-435
lines changed

src/DataBlobs/DataBlobs.jl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@
33
using JSON
44
using SHA
55

6-
include("entities/AbstractDataStore.jl")
76
include("entities/AbstractDataEntries.jl")
8-
include("entities/InMemoryDataStore.jl")
9-
include("entities/FileDataStore.jl")
7+
# include("entities/BlobStores.jl")
108

11-
include("services/AbstractDataStore.jl")
129
include("services/AbstractDataEntries.jl")
13-
include("services/InMemoryDataStore.jl")
14-
include("services/FileDataStore.jl")
10+
include("services/DataEntryBlob.jl")
11+
include("services/BlobStores.jl")
1512

16-
include("FileDataEntryBlob.jl")
17-
include("InMemoryDataEntryBlob.jl")
18-
include("DataBlobStores.jl")
19-
include("DataEntryBlob.jl")
13+
include("services/FileDataEntryBlob.jl")
14+
include("services/InMemoryDataEntryBlob.jl")
2015

21-
export AbstractDataStore
2216

2317
export AbstractDataEntry, GeneralDataEntry, MongodbDataEntry, FileDataEntry
2418
export InMemoryDataStore, FileDataStore

src/DataBlobs/entities/AbstractDataEntries.jl

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,37 @@
1-
"""
2-
$(TYPEDEF)
3-
GeneralDataEntry is a generic multipurpose data entry that creates a unique
4-
reproducible key using userId_robotId_sessionId_variableId_key.
5-
"""
6-
mutable struct GeneralDataEntry <: AbstractDataEntry
7-
label::Symbol
8-
id::UUID
9-
createdTimestamp::ZonedDateTime
10-
lastUpdatedTimestamp::ZonedDateTime
11-
mimeType::String
12-
end
1+
##==============================================================================
2+
## AbstractDataEntry - Defined in src/entities/AbstractDFG.jl
3+
##==============================================================================
4+
# Fields to be implemented
5+
# label
6+
# id
137

14-
#TODO Deprecation - Remove in v0.10
15-
Base.getproperty(x::GeneralDataEntry,f::Symbol) = begin
16-
if f == :key
17-
Base.depwarn("GeneralDataEntry field key is deprecated, use `label` instead", :getproperty)
18-
getfield(x,:label)
19-
elseif f == :storeKey
20-
Base.depwarn("GeneralDataEntry field storeKey is deprecated, use `id` instead", :getproperty)
21-
getfield(x,:id)
22-
else
23-
getfield(x,f)
24-
end
25-
end
8+
getLabel(entry::AbstractDataEntry) = entry.label
9+
getId(entry::AbstractDataEntry) = entry.id
10+
getHash(entry::AbstractDataEntry) = hex2bytes(entry.hash)
11+
getCreatedTimestamp(entry::AbstractDataEntry) = entry.createdTimestamp
2612

27-
#TODO Deprecation - Remove in v0.10
28-
Base.setproperty!(x::GeneralDataEntry, f::Symbol, val) = begin
29-
if f == :key
30-
Base.depwarn("GeneralDataEntry field `key` is deprecated, use `label` instead", :setproperty!)
31-
setfield(x, :label)
32-
elseif f == :storeKey
33-
Base.depwarn("GeneralDataEntry field `storeKey` is deprecated, use `id` instead", :setproperty!)
34-
setfield(x, :id)
35-
else
36-
setfield!(x,f,val)
37-
end
38-
end
3913

14+
##==============================================================================
15+
## BlobStoreEntry
16+
##==============================================================================
17+
export BlobStoreEntry
4018

4119
"""
42-
$(SIGNATURES)
43-
Function to generate source string - userId|robotId|sessionId|varLabel
20+
$(TYPEDEF)
21+
Genaral Data Store Entry.
4422
"""
45-
buildSourceString(dfg::AbstractDFG, label::Symbol) =
46-
"$(dfg.userId)|$(dfg.robotId)|$(dfg.sessionId)|$label"
47-
48-
49-
_uniqueKey(dfg::AbstractDFG, v::AbstractDFGVariable, key::Symbol)::Symbol =
50-
error("_uniqueKey is deprecated")
51-
52-
53-
GeneralDataEntry(key::Symbol, storeKey::Symbol; mimeType::String="") = error("storeKey Deprecated, use UUID")
54-
55-
GeneralDataEntry(label::Symbol, id::UUID=uuid4();
56-
mimeType::String="application/octet-stream") =
57-
GeneralDataEntry(label, id, now(localzone()), now(localzone()), mimeType)
58-
59-
function GeneralDataEntry(dfg::AbstractDFG, var::AbstractDFGVariable, key::Symbol;
60-
mimeType::String="application/octet-stream")
61-
return GeneralDataEntry(key, uuid4(), mimeType=mimeType)
23+
struct BlobStoreEntry <: AbstractDataEntry
24+
label::Symbol
25+
id::UUID
26+
blobstore::Symbol
27+
hash::String # Probably https://docs.julialang.org/en/v1/stdlib/SHA
28+
origin::String # E.g. user|robot|session|varlabel
29+
description::String
30+
mimeType::String
31+
createdTimestamp::ZonedDateTime # of when the entry was created
6232
end
6333

64-
34+
# TODO
6535
"""
6636
$(TYPEDEF)
6737
Data Entry in MongoDB.

src/DataBlobs/entities/AbstractDataStore.jl

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

src/DataBlobs/entities/FileDataStore.jl

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

src/DataBlobs/entities/InMemoryDataStore.jl

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

src/DataBlobs/services/AbstractDataEntries.jl

Lines changed: 41 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,28 @@
1-
##
2-
3-
getHash(entry::AbstractDataEntry) = hex2bytes(entry.hash)
4-
5-
6-
##
1+
##==============================================================================
2+
## AbstractDataEntry - compare
3+
##==============================================================================
74

85
import Base: ==
96

10-
function ==(a::GeneralDataEntry, b::GeneralDataEntry)
11-
return a.label == b.label &&
12-
a.storeKey == b.storeKey &&
13-
a.mimeType == b.mimeType &&
14-
Dates.value(a.createdTimestamp - b.createdTimestamp) < 1000 &&
15-
Dates.value(a.lastUpdatedTimestamp - b.lastUpdatedTimestamp) < 1000 #1 second
16-
end
17-
18-
@generated function ==(x::MongodbDataEntry, y::MongodbDataEntry)
7+
@generated function ==(x::T, y::T) where T <: AbstractDataEntry
198
mapreduce(n -> :(x.$n == y.$n), (a,b)->:($a && $b), fieldnames(x))
209
end
2110

22-
"""
23-
$(SIGNATURES)
24-
Add Big Data Entry to a DFG variable
25-
"""
26-
function addDataEntry!(var::AbstractDFGVariable, bde::AbstractDataEntry)
27-
haskey(var.dataDict, bde.label) && error("Data entry $(bde.label) already exists in variable")
28-
var.dataDict[bde.label] = bde
29-
return bde
30-
end
31-
11+
##==============================================================================
12+
## AbstractDataEntry - common
13+
##==============================================================================
3214

3315
"""
3416
$(SIGNATURES)
35-
Add Big Data Entry to distributed factor graph.
36-
Should be extended if DFG variable is not returned by reference.
37-
"""
38-
function addDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractDataEntry)
39-
return addDataEntry!(getVariable(dfg, label), bde)
40-
end
41-
42-
17+
Function to generate source string - userId|robotId|sessionId|varLabel
4318
"""
44-
$(SIGNATURES)
45-
Add Big Data Entry to distributed factor graph.
46-
Should be extended if DFG variable is not returned by reference.
47-
48-
Example
19+
buildSourceString(dfg::AbstractDFG, label::Symbol) =
20+
"$(dfg.userId)|$(dfg.robotId)|$(dfg.sessionId)|$label"
4921

50-
See docs for `getDataEntryElement`.
5122

52-
Related
53-
54-
addData!, getDataEntryElement, fetchData
55-
"""
56-
function addData!(dfg::AbstractDFG,
57-
lbl::Symbol,
58-
datastore::Union{FileDataStore, InMemoryDataStore},
59-
descr::Symbol,
60-
mimeType::AbstractString,
61-
data::Vector{UInt8} )
62-
#
63-
node = isVariable(dfg, lbl) ? getVariable(dfg, lbl) : getFactor(dfg, lbl)
64-
# Make a big data entry in the graph - use JSON2 to just write this
65-
entry = GeneralDataEntry(dfg, node, descr, mimeType=mimeType)
66-
# Set it in the store
67-
addDataBlob!(datastore, entry, data)
68-
# Add the entry to the graph
69-
addDataEntry!(node, entry)
70-
end
71-
# const addDataEntry! = addData!
72-
73-
"""
74-
$SIGNATURES
75-
76-
Does a data entry (element) exist at `key`.
77-
"""
78-
hasDataEntry(var::DFGVariable, key::Symbol) = haskey(var.dataDict, key)
23+
##==============================================================================
24+
## AbstractDataEntry - CRUD
25+
##==============================================================================
7926

8027
"""
8128
$(SIGNATURES)
@@ -91,61 +38,25 @@ function getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol)
9138
end
9239

9340
"""
94-
$SIGNATURES
95-
Get both the entry and raw data element from datastore returning as a tuple.
41+
$(SIGNATURES)
42+
Add Big Data Entry to a DFG variable
43+
"""
44+
function addDataEntry!(var::AbstractDFGVariable, bde::AbstractDataEntry)
45+
haskey(var.dataDict, bde.label) && error("Data entry $(bde.label) already exists in variable")
46+
var.dataDict[bde.label] = bde
47+
return bde
48+
end
9649

97-
Notes:
98-
- This is the counterpart to `addDataEntry!`.
99-
- Data is identified by the node in the DFG object `dfglabel::Symbol` as well as `datalabel::Symbol`.
100-
- The data should have been stored along with a `entry.mimeType::String` which describes the format of the data.
101-
- ImageMagick.jl is useful for storing images in png or jpg compressed format.
102-
103-
Example
104-
105-
```julia
106-
# some dfg object
107-
fg = initfg()
108-
addVariable!(fg, :x0, IIF.ContinuousScalar) # using IncrementalInference
109-
# FileDataStore (as example)
110-
datastore = FileDataStore(joinLogPath(fg,"datastore"))
111-
112-
# now some data comes in
113-
mydata = Dict(:soundBite => randn(Float32, 10000), :meta => "something about lazy foxes and fences.")
114-
115-
# store the data
116-
addDataEntry!( fg, :x0, datastore, :SOUND_DATA, "application/json", Vector{UInt8}(JSON2.write( mydata )) )
117-
118-
# get/fetch the data
119-
entry, rawData = fetchData(fg, :x0, datastore, :SOUND_DATA)
120-
121-
# unpack data to original format (this must be done by the user)
122-
@show entry.mimeType # "applicatio/json"
123-
userFormat = JSON2.read(IOBuffer(rawData))
124-
```
125-
126-
Related
127-
128-
addDataEntry!, addData!, fetchData, fetchDataEntryElement
129-
"""
130-
function getDataEntryBlob(dfg::AbstractDFG,
131-
dfglabel::Symbol,
132-
datastore::Union{FileDataStore, InMemoryDataStore},
133-
datalabel::Symbol)
134-
#
135-
vari = getVariable(dfg, dfglabel)
136-
if !hasDataEntry(vari, datalabel)
137-
# current standards is to fail hard
138-
error("missing data entry $datalabel in $dfglabel")
139-
# return nothing, nothing
140-
end
141-
entry = getDataEntry(vari, datalabel)
142-
element = getDataBlob(datastore, entry)
143-
return entry, element
50+
51+
"""
52+
$(SIGNATURES)
53+
Add Big Data Entry to distributed factor graph.
54+
Should be extended if DFG variable is not returned by reference.
55+
"""
56+
function addDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractDataEntry)
57+
return addDataEntry!(getVariable(dfg, label), bde)
14458
end
145-
const fetchDataEntryElement = getDataEntryBlob
146-
const fetchData = getDataEntryBlob
14759

148-
#
14960

15061
"""
15162
$(SIGNATURES)
@@ -186,6 +97,18 @@ function deleteDataEntry!(var::AbstractDFGVariable, entry::AbstractDataEntry)
18697
return deleteDataEntry!(var, entry.label)
18798
end
18899

100+
##==============================================================================
101+
## AbstractDataEntry - Helper functions, Lists, etc
102+
##==============================================================================
103+
104+
"""
105+
$SIGNATURES
106+
107+
Does a data entry (element) exist at `key`.
108+
"""
109+
hasDataEntry(var::DFGVariable, key::Symbol) = haskey(var.dataDict, key)
110+
111+
189112
"""
190113
$(SIGNATURES)
191114
Get big data entries, Vector{AbstractDataEntry}
@@ -200,7 +123,6 @@ function getDataEntries(dfg::AbstractDFG, label::Symbol)
200123
getDataEntries(getVariable(dfg, label))
201124
end
202125

203-
204126
"""
205127
$(SIGNATURES)
206128
listDataEntries

0 commit comments

Comments
 (0)