Skip to content

Commit

Permalink
Merge pull request #55 from NREL/jd/fix_name_getting
Browse files Browse the repository at this point in the history
use get_name methods
  • Loading branch information
jd-lara authored Feb 5, 2020
2 parents 331f01f + 6b8fb3a commit 3b38aa1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 69 deletions.
32 changes: 0 additions & 32 deletions .appveyor.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .codecov.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ language: julia
os:
- linux
- osx
- windows
julia:
- 1.2
- 1.3
- nightly

Expand All @@ -26,6 +26,7 @@ jobs:
allow_failures:
- julia: nightly
- os: osx
- os: windows
include:
- stage: "Cross Package Testing"
julia: 1.3
Expand Down
3 changes: 2 additions & 1 deletion src/component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ function add_forecast!(
component::T,
forecast::ForecastInternal,
) where {T <: InfrastructureSystemsType}
component_name = get_name(component)
container = _get_forecast_container(component)
if isnothing(container)
throw(ArgumentError("type $T does not support storing forecasts"))
end

add_forecast!(container, forecast)
@debug "Added $forecast to $(typeof(component)) $(component.name) " *
@debug "Added $forecast to $(typeof(component)) $(component_name) " *
"num_forecasts=$(length(component._forecasts.data))."
end

Expand Down
7 changes: 4 additions & 3 deletions src/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ function add_component!(
component::T;
skip_validation = false,
) where {T <: InfrastructureSystemsType}
component_name = get_name(component)
if !isconcretetype(T)
throw(ArgumentError("add_component! only accepts concrete types"))
end

if !haskey(components.data, T)
components.data[T] = Dict{String, T}()
elseif haskey(components.data[T], component.name)
throw(ArgumentError("$(component.name) is already stored for type $T"))
elseif haskey(components.data[T], component_name)
throw(ArgumentError("$(component_name) is already stored for type $T"))
end

if !isempty(components.validation_descriptors) && !skip_validation
Expand All @@ -63,7 +64,7 @@ function add_component!(
#end

set_time_series_storage!(component, components.time_series_storage)
components.data[T][component.name] = component
components.data[T][component_name] = component
return
end

Expand Down
11 changes: 5 additions & 6 deletions src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,24 @@ function validate_fields(
components::Components,
ist_struct::T,
) where {T <: InfrastructureSystemsType}
name = repr(T)
type_name = strip_parametric_type(strip_module_name(repr(T)))
struct_descriptor = get_config_descriptor(components.validation_descriptors, type_name)
isnothing(struct_descriptor) && return true
is_valid = true

for (name, fieldtype) in zip(fieldnames(T), fieldtypes(T))
field_value = getfield(ist_struct, name)
for (field_name, fieldtype) in zip(fieldnames(T), fieldtypes(T))
field_value = getfield(ist_struct, field_name)
if isnothing(field_value) # Many structs are of type Union{Nothing, xxx}.

elseif fieldtype <: Union{Nothing, InfrastructureSystemsType} &&
!(fieldtype <: InfrastructureSystemsType)
# Recurse. Components are validated separately and do not need to
# be validated twice.
if !validate_fields(components, getfield(ist_struct, name))
if !validate_fields(components, getfield(ist_struct, field_name))
is_valid = false
end
else
field_descriptor = get_field_descriptor(struct_descriptor, string(name))
field_descriptor = get_field_descriptor(struct_descriptor, string(field_name))
if !haskey(field_descriptor, "valid_range")
continue
end
Expand Down Expand Up @@ -179,7 +178,7 @@ function check_limits(
return result1 && result2
end

function check_limits_impl(valid_info::ValidationInfo, field_value)
function check_limits_impl(valid_info::ValidationInfo, field_value::Real)
is_valid = true
action_function = get_validation_action(valid_info.field_descriptor)
if (
Expand Down

0 comments on commit 3b38aa1

Please sign in to comment.