Skip to content

Commit 9dc3d51

Browse files
committed
VariableEstimate -> MeanMaxPPE
1 parent 9014fb4 commit 9dc3d51

File tree

7 files changed

+23
-55
lines changed

7 files changed

+23
-55
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ function getVariable(dfg::CloudGraphsDFG, variableId::Int64)::DFGVariable
182182
# props["label"] = Symbol(variable.label)
183183
timestamp = DateTime(props["timestamp"])
184184
tags = JSON2.read(props["tags"], Vector{Symbol})
185-
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
185+
#TODO this will work for some time, but unpacking in an <: AbstractPointParametricEst would be lekker.
186+
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, MeanMaxPPE})
186187
smallData = nothing
187188
smallData = JSON2.read(props["smallData"], Dict{String, String})
188189

src/DistributedFactorGraphs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isF
3333
export mergeUpdateVariableSolverData!, mergeUpdateGraphSolverData!
3434

3535
# Solver (IIF) Exports
36-
export VariableNodeData, PackedVariableNodeData, VariableEstimate
36+
export VariableNodeData, PackedVariableNodeData
3737
export GenericFunctionNodeData#, FunctionNodeData
3838
export getSerializationModule, setSerializationModule!
3939
export pack, unpack
4040
# Resolve with above
4141
export packVariable, unpackVariable, packFactor, unpackFactor
4242

43+
#PPE exports
44+
export MeanMaxPPE
45+
4346
#Interfaces
4447
export getAdjacencyMatrixSparse
4548

src/entities/DFGVariable.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ struct MeanMaxPPE <: AbstractPointParametricEst
7878
end
7979
MeanMaxPPE(solverKey::Symbol,max::Vector{Float64},mean::Vector{Float64}) = MeanMaxPPE(solverKey, max, mean, now())
8080

81-
getMaxEstimate(est::AbstractPointParametricEst) = est.max
82-
getMeanEstimate(est::AbstractPointParametricEst) = est.mean
81+
getMaxPPE(est::AbstractPointParametricEst) = est.max
82+
getMeanPPE(est::AbstractPointParametricEst) = est.mean
8383
getLastUpdatedTimestamp(est::AbstractPointParametricEst) = est.lastUpdatedTimestamp
8484

8585

@@ -109,10 +109,10 @@ end
109109
DFGVariable constructors.
110110
"""
111111
DFGVariable(label::Symbol, _internalId::Int64) =
112-
DFGVariable(label, now(), Symbol[], Dict{Symbol, Dict{Symbol, VariableEstimate}}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
112+
DFGVariable(label, now(), Symbol[], Dict{Symbol, MeanMaxPPE}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
113113

114114
DFGVariable(label::Symbol) =
115-
DFGVariable(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, 0)
115+
DFGVariable(label, now(), Symbol[], Dict{Symbol, MeanMaxPPE}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, 0)
116116

117117
# Accessors
118118
label(v::DFGVariable) = v.label

src/services/DFGVariable.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function unpackVariable(dfg::G, packedProps::Dict{String, Any})::DFGVariable whe
1717
label = Symbol(packedProps["label"])
1818
timestamp = DateTime(packedProps["timestamp"])
1919
tags = JSON2.read(packedProps["tags"], Vector{Symbol})
20-
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
20+
#TODO this will work for some time, but unpacking in an <: AbstractPointParametricEst would be lekker.
21+
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, MeanMaxPPE})
2122
smallData = nothing
2223
smallData = JSON2.read(packedProps["smallData"], Dict{String, String})
2324

@@ -113,14 +114,10 @@ end
113114

114115
"""
115116
$(SIGNATURES)
116-
Equality check for VariableEstimate.
117+
Equality check for AbstractPointParametricEst.
117118
"""
118-
function ==(a::VariableEstimate, b::VariableEstimate)::Bool
119-
a.solverKey != b.solverKey && @debug("solverKey are not equal")==nothing && return false
120-
a.ppeType != b.ppeType && @debug("ppeType is not equal")==nothing && return false
121-
a.estimate != b.estimate && @debug("estimate are not equal")==nothing && return false
122-
a.lastUpdatedTimestamp != b.lastUpdatedTimestamp && @debug("lastUpdatedTimestamp is not equal")==nothing && return false
123-
return true
119+
@generated function ==(x::T, y::T) where T <: AbstractPointParametricEst
120+
mapreduce(n -> :(x.$n == y.$n), (a,b)->:($a && $b), fieldnames(x))
124121
end
125122

126123
"""

test/LightDFGSummaryTypes.jl

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dfg = LightDFG{NoSolverParams, DFGVariableSummary, DFGFactorSummary}()
22

3-
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(label, DistributedFactorGraphs.now(), Symbol[], Dict{Symbol, VariableEstimate}(), :NA, 0)
3+
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(label, DistributedFactorGraphs.now(), Symbol[], Dict{Symbol, MeanMaxPPE}(), :NA, 0)
44

55
DistributedFactorGraphs.DFGFactorSummary(label::Symbol) = DFGFactorSummary(label, Symbol[], 0, Symbol[])
66

@@ -124,30 +124,16 @@ end
124124
var = getVariable(dfg, :a)
125125
#make a copy and simulate external changes
126126
newvar = deepcopy(var)
127-
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
128-
:max => VariableEstimate(:default, :max, [100.0]),
129-
:mean => VariableEstimate(:default, :mean, [50.0]),
130-
:modefit => VariableEstimate(:default, :modefit, [75.0]))
127+
estimates(newvar)[:default] = MeanMaxPPE(:default, [100.0], [50.0])
131128
#update
132129
mergeUpdateVariableSolverData!(dfg, newvar)
133-
#TODO maybe implement ==; @test newvar==var
134-
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
135-
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
136-
varest1.ppeType == varest2.ppeType || return false
137-
varest1.solverKey == varest2.solverKey || return false
138-
varest1.estimate == varest2.estimate || return false
139-
return true
140-
end
141130
#For now spot check
142131
# @test solverDataDict(newvar) == solverDataDict(var)
143132
@test estimates(newvar) == estimates(var)
144133

145134
# Delete :default and replace to see if new ones can be added
146135
delete!(estimates(newvar), :default)
147-
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
148-
:max => VariableEstimate(:default, :max, [10.0]),
149-
:mean => VariableEstimate(:default, :mean, [5.0]),
150-
:ppe => VariableEstimate(:default, :ppe, [7.0]))
136+
estimates(newvar)[:second] = MeanMaxPPE(:second, [10.0], [5.0])
151137

152138
# Persist to the original variable.
153139
mergeUpdateVariableSolverData!(dfg, newvar)

test/iifInterfaceTests.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ end
234234
var = getVariable(dfg, :a)
235235
#make a copy and simulate external changes
236236
newvar = deepcopy(var)
237-
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
238-
:max => VariableEstimate(:default, :max, [100.0]),
239-
:mean => VariableEstimate(:default, :mean, [50.0]),
240-
:modefit => VariableEstimate(:default, :modefit, [75.0]))
237+
estimates(newvar)[:default] = MeanMaxPPE(:default, [100.0], [50.0])
241238
#update
242239
mergeUpdateVariableSolverData!(dfg, newvar)
243240

@@ -246,10 +243,7 @@ end
246243
@test estimates(newvar) == estimates(var)
247244

248245
# Add a new estimate.
249-
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
250-
:max => VariableEstimate(:default, :max, [10.0]),
251-
:mean => VariableEstimate(:default, :mean, [5.0]),
252-
:modefit => VariableEstimate(:default, :modefit, [7.0]))
246+
estimates(newvar)[:second] = MeanMaxPPE(:second, [10.0], [5.0])
253247

254248
# Confirm they're different
255249
@test estimates(newvar) != estimates(var)

test/interfaceTests.jl

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,30 +208,17 @@ end
208208
var = getVariable(dfg, :a)
209209
#make a copy and simulate external changes
210210
newvar = deepcopy(var)
211-
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
212-
:max => VariableEstimate(:default, :max, [100.0]),
213-
:mean => VariableEstimate(:default, :mean, [50.0]),
214-
:modefit => VariableEstimate(:default, :modefit, [75.0]))
211+
estimates(newvar)[:default] = MeanMaxPPE(:default, [100.0], [50.0])
215212
#update
216213
mergeUpdateVariableSolverData!(dfg, newvar)
217-
#TODO maybe implement ==; @test newvar==var
218-
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
219-
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
220-
varest1.ppeType == varest2.ppeType || return false
221-
varest1.solverKey == varest2.solverKey || return false
222-
varest1.estimate == varest2.estimate || return false
223-
return true
224-
end
214+
225215
#For now spot check
226216
@test solverDataDict(newvar) == solverDataDict(var)
227217
@test estimates(newvar) == estimates(var)
228218

229219
# Delete :default and replace to see if new ones can be added
230220
delete!(estimates(newvar), :default)
231-
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
232-
:max => VariableEstimate(:default, :max, [10.0]),
233-
:mean => VariableEstimate(:default, :mean, [5.0]),
234-
:modefit => VariableEstimate(:default, :modefit, [7.0]))
221+
estimates(newvar)[:second] = MeanMaxPPE(:second, [10.0], [5.0])
235222

236223
# Persist to the original variable.
237224
mergeUpdateVariableSolverData!(dfg, newvar)

0 commit comments

Comments
 (0)