From e6d3892c84f834c202b2871fcd3ba3cf9e2e0dc2 Mon Sep 17 00:00:00 2001 From: GabrielKS <23368820+GabrielKS@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:54:42 -0700 Subject: [PATCH] Add conversion logic for subsystems and attributes --- src/base.jl | 4 ++++ src/data_format_conversions.jl | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/base.jl b/src/base.jl index a8404bd17b..234c79a399 100644 --- a/src/base.jl +++ b/src/base.jl @@ -1549,6 +1549,10 @@ function IS.deserialize( JSON3.read(io, Dict) end + if raw["data_format_version"] != DATA_FORMAT_VERSION + pre_read_conversion!(raw) + end + # These file paths are relative to the system file. directory = dirname(filename) for file_key in ("time_series_storage_file", "validation_descriptor_file") diff --git a/src/data_format_conversions.jl b/src/data_format_conversions.jl index 63622726f6..e265eead44 100644 --- a/src/data_format_conversions.jl +++ b/src/data_format_conversions.jl @@ -121,6 +121,15 @@ function _convert_data!( return end +# Conversions to occur immediately after the data is loaded from disk +function pre_read_conversion!(raw) + if VersionNumber(raw["data_format_version"]) < v"4.0.0" + haskey(raw["data"], "subsystems") || (raw["data"]["subsystems"] = Dict{String, Any}()) + haskey(raw["data"], "attributes") || (raw["data"]["attributes"] = Any[]) + end +end + +# Conversions to occur before deserialize_components! function pre_deserialize_conversion!(raw, sys::System) old = raw["data_format_version"] if old == DATA_FORMAT_VERSION @@ -133,6 +142,7 @@ function pre_deserialize_conversion!(raw, sys::System) end end +# Conversions to occur at the end of deserialization function post_deserialize_conversion!(sys::System, raw) old = raw["data_format_version"] if old == "1.0.0"