-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: each Virtual now keeps a reference to its template; CoreTemplat…
…e now implements a proper summary extraction (and Base.show)
- Loading branch information
Stefan Strömer
committed
Oct 25, 2024
1 parent
7702563
commit e9378ad
Showing
7 changed files
with
107 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
CoreTemplate | ||
A struct to represent an IESopt.jl "Core Template". | ||
""" | ||
@kwdef struct CoreTemplate | ||
model::JuMP.Model | ||
name::String | ||
path::String | ||
raw::String | ||
yaml::Dict{String, Any} = Dict{String, Any}() | ||
|
||
"""A dictionary of functions that can be called by the template, options are `:validate`, `:prepare`, `:finalize`.""" | ||
functions::Dict{Symbol, Function} = Dict{Symbol, Function}() | ||
|
||
"""Type of this `CoreTemplate`: `:container` (if `"components"` exists), `:component` (if `"component"` exists).""" | ||
type::Ref{Symbol} = Ref(:none) | ||
|
||
_status::Ref{Symbol} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function _get_parameter_safe(p::String, parameters::Dict{String, Any}, default::Any = nothing) | ||
haskey(parameters, p) || @critical "Trying to access (`get`) undefined parameter in `CoreTemplate`" parameter = p | ||
return isnothing(default) ? parameters[p] : something(parameters[p], default) | ||
end | ||
|
||
function _set_parameter_safe(p::String, v::Any, parameters::Dict{String, Any}) | ||
haskey(parameters, p) || @critical "Trying to access (`set`) undefined parameter in `CoreTemplate`" parameter = p | ||
parameters[p] = v | ||
return nothing | ||
end | ||
|
||
function _get_timeseries_safe(p_or_cf::String, parameters::Dict{String, Any}, model::JuMP.Model) | ||
if !occursin("@", p_or_cf) | ||
p_or_cf = _get_parameter_safe(p_or_cf, parameters)::String | ||
end | ||
|
||
# Now we know, that `p_or_cf` is a "col@file" selector string. | ||
column, file = string.(split(p_or_cf, "@")) | ||
|
||
return _getfromcsv(model, file, column) | ||
end | ||
|
||
function _set_timeseries_safe(p_or_cf::String, v::Any, parameters::Dict{String, Any}, model::JuMP.Model) | ||
if !occursin("@", p_or_cf) | ||
p_or_cf = _get_parameter_safe(p_or_cf, parameters)::String | ||
end | ||
|
||
# Now we know, that `p_or_cf` is a "col@file" selector string. | ||
column, file = string.(split(p_or_cf, "@")) | ||
|
||
# Check if this file exists. | ||
if haskey(_iesopt(model).input.files, file) | ||
# This works for overwriting existing columns, as well as adding new ones. | ||
_iesopt(model).input.files[file][!, column] .= v | ||
else | ||
_iesopt(model).input.files[file] = DataFrames.DataFrame(column => v) | ||
end | ||
|
||
return nothing | ||
end | ||
|
||
_is_template(filename::String) = endswith(filename, ".iesopt.template.yaml") | ||
_get_template_name(filename::String) = string(rsplit(basename(filename), "."; limit=4)[1]) | ||
_is_component(template::CoreTemplate) = template.type[] == :component | ||
_is_container(template::CoreTemplate) = template.type[] == :container |