1
- # #
2
-
3
- getHash (entry:: AbstractDataEntry ) = hex2bytes (entry. hash)
4
-
5
-
6
- # #
1
+ # #==============================================================================
2
+ # # AbstractDataEntry - compare
3
+ # #==============================================================================
7
4
8
5
import Base: ==
9
6
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
19
8
mapreduce (n -> :(x.$ n == y.$ n), (a,b)-> :($ a && $ b), fieldnames (x))
20
9
end
21
10
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
+ # #==============================================================================
32
14
33
15
"""
34
16
$(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
43
18
"""
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 "
49
21
50
- See docs for `getDataEntryElement`.
51
22
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
+ # #==============================================================================
79
26
80
27
"""
81
28
$(SIGNATURES)
@@ -91,61 +38,25 @@ function getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol)
91
38
end
92
39
93
40
"""
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
96
49
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)
144
58
end
145
- const fetchDataEntryElement = getDataEntryBlob
146
- const fetchData = getDataEntryBlob
147
59
148
- #
149
60
150
61
"""
151
62
$(SIGNATURES)
@@ -186,6 +97,18 @@ function deleteDataEntry!(var::AbstractDFGVariable, entry::AbstractDataEntry)
186
97
return deleteDataEntry! (var, entry. label)
187
98
end
188
99
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
+
189
112
"""
190
113
$(SIGNATURES)
191
114
Get big data entries, Vector{AbstractDataEntry}
@@ -200,7 +123,6 @@ function getDataEntries(dfg::AbstractDFG, label::Symbol)
200
123
getDataEntries (getVariable (dfg, label))
201
124
end
202
125
203
-
204
126
"""
205
127
$(SIGNATURES)
206
128
listDataEntries
0 commit comments