Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in custom indexing for realized results #995

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/simulation/realized_meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function get_realization(
columns = get_column_names(results_by_time)
num_cols = length(columns)
matrix = Matrix{Float64}(undef, num_rows, num_cols)
row_index = 1
for (step, (_, array)) in enumerate(results_by_time)
first_id = step > 1 ? 1 : meta.start_offset
last_id =
Expand All @@ -69,9 +70,9 @@ function get_realization(
Can't calculate the realized variables. Use `read_variables` instead and write your own concatenation",
)
end
row_start = (step - 1) * meta.interval_len + 1
row_end = row_start + last_id - first_id
matrix[row_start:row_end, :] = array[first_id:last_id, :]
row_end = row_index + last_id - first_id
matrix[row_index:row_end, :] = array[first_id:last_id, :]
row_index += last_id - first_id + 1
end
df = DataFrames.DataFrame(matrix, collect(columns); copycols = false)
DataFrames.insertcols!(
Expand Down
11 changes: 11 additions & 0 deletions test/test_simulation_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ function test_decision_problem_results_values(
@test size(var)[1] == 48
end

# Test custom indexing.
realized_variable_uc2 =
read_realized_variables(
results_uc,
[(ActivePowerVariable, ThermalStandard)];
start_time = Dates.DateTime("2024-01-01T01:00:00"),
len = 47,
)
@test realized_variable_uc["ActivePowerVariable__ThermalStandard"][2:end, :] ==
realized_variable_uc2["ActivePowerVariable__ThermalStandard"]

realized_param_uc = read_realized_parameters(results_uc)
@test length(keys(realized_param_uc)) == 3
for param in values(realized_param_uc)
Expand Down
Loading