Skip to content

Commit

Permalink
Merge pull request #856 from NREL-SIIP/sd/hybrid_ts
Browse files Browse the repository at this point in the history
Updating copy subcomponent time series method
  • Loading branch information
jd-lara authored Feb 16, 2022
2 parents 33e5432 + c0f8fea commit cc318be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
CSV = "~0.9, 0.10"
DataFrames = "1"
DocStringExtensions = "~0.8.2"
InfrastructureSystems = "^1.16"
InfrastructureSystems = "^1.17"
JSON3 = "1"
NLsolve = "4"
PrettyTables = "1.2"
Expand Down
27 changes: 21 additions & 6 deletions src/models/static_injection_subsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,40 @@ function copy_subcomponent_time_series!(
subsystem::StaticInjectionSubsystem,
subcomponent::Component,
)
existing_ts = Set((typeof(x), get_name(x)) for x in get_time_series_multiple(subsystem))
name_mapping = Dict{String, String}()
# the existing_ts can remove entries from the set if the Subsystem has two device of
# the same type with the same time series type and label. Currently in the HybridSystem
# use case there can only be one devoe of each type.
existing_ts = Set(
(typeof(ts), get_name(ts_m)) for
(ts, ts_m) in IS.get_time_series_with_metadata_multiple(subsystem)
)
name_mapping = Dict{Tuple{String, String}, String}()
device_name = get_name(subcomponent)
for ts in get_time_series_multiple(subcomponent)
name = get_name(ts)
key = (typeof(ts), name)
if !(key in existing_ts)
new_name = make_subsystem_time_series_name(subcomponent, ts)
if name in keys(name_mapping)
IS.@assert_op new_name == name_mapping[name]
IS.@assert_op new_name == name_mapping[(device_name, name)]
continue
end
name_mapping[name] = new_name
name_mapping[(device_name, name)] = new_name
end
end

copy_time_series!(subsystem, subcomponent, name_mapping = name_mapping)
IS.copy_time_series!(subsystem, subcomponent, name_mapping = name_mapping)
@info "Copied time series from $(summary(subcomponent)) to $(summary(subsystem))"
end

function make_subsystem_time_series_name(subcomponent::Component, ts::TimeSeriesData)
return IS.strip_module_name(typeof(subcomponent)) * "__" * get_name(ts)
return make_subsystem_time_series_name(typeof(subcomponent), get_name(ts))
end

function make_subsystem_time_series_name(subcomponent::Component, label::String)
return make_subsystem_time_series_name(typeof(subcomponent), label)
end

function make_subsystem_time_series_name(subcomponent::Type{<:Component}, label::String)
return IS.strip_module_name(subcomponent) * "__" * label
end

0 comments on commit cc318be

Please sign in to comment.