Skip to content

Commit

Permalink
fix: reinstate nested try/catch statements
Browse files Browse the repository at this point in the history
  • Loading branch information
lanesmith committed May 2, 2021
1 parent 5891174 commit 661821e
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,47 +127,48 @@ function read_demand_flexibility(filepath)::DemandFlexibility
demand_flexibility["rolling_balance"] = true

# Try loading the demand flexibility parameters
demand_flexibility_parameters = DataFrames.DataFrame()
try
demand_flexibility_parameters = CSV.File(
joinpath(filepath, "demand_flexibility_parameters.csv")
) |> DataFrames.DataFrame
println("...loading demand flexibility parameters")

# Create a dictionary to hold the error messages relevant to loading the
# demand flexibility parameters
demand_flexibility_params_errs = Dict()
demand_flexibility_params_errs["duration"] = (
"The demand flexibility duration parameter is not defined. Will "
* "default to nothing."
)
demand_flexibility_params_errs["enabled"] = (
"The parameter that indicates if demand flexibility is enabled is not "
* "defined. Will default to being enabled."
)
demand_flexibility_params_errs["interval_balance"] = (
"The parameter that indicates if the interval load balance constraint "
* "is enabled is not defined. Will default to being enabled."
)
demand_flexibility_params_errs["rolling_balance"] = (
"The parameter that indicates if the rolling load balance constraint "
* "is enabled is not defined. Will default to being enabled."
)

# Try assigning the different demand flexibility parameters from the file
for k in keys(demand_flexibility_params_errs)
try
demand_flexibility[k] = demand_flexibility_parameters[1, k]
catch e
println(demand_flexibility_params_errs[k])
end
end
catch e
println("Demand flexibility parameters not found in " * filepath)
println(
"Demand flexibility parameters will default to allowing demand "
* "flexibility to occur."
)
end

# Create a dictionary to hold the error messages relevant to loading demand
# flexibility parameters
demand_flexibility_params_errs = Dict()
demand_flexibility_params_errs["duration"] = (
"The demand flexibility duration parameter is not defined. Will default to "
* "nothing."
)
demand_flexibility_params_errs["enabled"] = (
"The parameter that indicates if demand flexibility is enabled is not "
* "defined. Will default to being enabled."
)
demand_flexibility_params_errs["interval_balance"] = (
"The parameter that indicates if the interval load balance constraint is "
* "enabled is not defined. Will default to being enabled."
)
demand_flexibility_params_errs["rolling_balance"] = (
"The parameter that indicates if the rolling load balance constraint is "
* "enabled is not defined. Will default to being enabled."
)

# Try assigning the different demand flexibility parameters from the input file
for k in keys(demand_flexibility_params_errs)
try
demand_flexibility[k] = demand_flexibility_parameters[1, k]
catch e
println(demand_flexibility_params_errs[k])
end
end
end

# Convert Dict to NamedTuple
Expand Down

0 comments on commit 661821e

Please sign in to comment.