Skip to content

Commit 5474f87

Browse files
committed
add packed variable deserlz for ppes
1 parent f5d333e commit 5474f87

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/entities/DFGVariable.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ abstract type AbstractPointParametricEst end
235235
236236
Data container to store Parameteric Point Estimate (PPE) for mean and max.
237237
"""
238-
struct MeanMaxPPE <: AbstractPointParametricEst
238+
Base.@kwdef struct MeanMaxPPE <: AbstractPointParametricEst
239239
# repeat key value internally (from a design request by Sam)
240240
solveKey::Symbol
241241
suggested::Vector{Float64}
242242
max::Vector{Float64}
243243
mean::Vector{Float64}
244-
lastUpdatedTimestamp::DateTime
244+
lastUpdatedTimestamp::DateTime = now(Dates.UTC)
245245
end
246246

247247
##------------------------------------------------------------------------------

src/services/Serialization.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ end
134134
# returns a DFGVariable
135135
function unpackVariable(dfg::G,
136136
packedProps::Dict{String, Any};
137-
unpackPPEs::Bool=true,
137+
unpackPPEs::Bool=haskey(packedProps,"ppeDict"),
138138
unpackSolverData::Bool=true,
139139
unpackBigData::Bool=true) where G <: AbstractDFG
140140
@debug "Unpacking variable:\r\n$packedProps"
@@ -152,7 +152,25 @@ function unpackVariable(dfg::G,
152152
else
153153
tags = Symbol.(packedProps["tags"])
154154
end
155-
ppeDict = unpackPPEs ? JSON2.read(packedProps["ppeDict"], Dict{Symbol, MeanMaxPPE}) : Dict{Symbol, MeanMaxPPE}()
155+
ppeDict = if unpackPPEs
156+
JSON2.read(packedProps["ppeDict"], Dict{Symbol, MeanMaxPPE})
157+
elseif haskey(packedProps,"ppes") && packedProps["ppes"] isa AbstractVector
158+
ppedict = Dict{Symbol, MeanMaxPPE}()
159+
for pd in packedProps["ppes"]
160+
pk = pd["solveKey"]
161+
_pk = Symbol(pk)
162+
ppedict[_pk] = MeanMaxPPE(;
163+
solveKey=_pk,
164+
suggested=float.(pd["suggested"]),
165+
max=float.(pd["max"]),
166+
mean=float.(pd["mean"]),
167+
lastUpdatedTimestamp=DateTime(string(pd["lastUpdatedTimestamp"]))
168+
)
169+
end
170+
ppedict
171+
else
172+
Dict{Symbol, MeanMaxPPE}()
173+
end
156174
smallData = JSON2.read(packedProps["smallData"], Dict{Symbol, SmallDataTypes})
157175

158176
variableTypeString = if haskey(packedProps, "softtype")

0 commit comments

Comments
 (0)