Skip to content

Commit

Permalink
fix outages tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Mar 6, 2024
1 parent 808af13 commit 00b5103
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/PowerSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ export GeometricDistributionForcedOutage
export PlannedOutage
export TimeSeriesForcedOutage

export get_mean_time_to_recovery
export get_outage_transition_probability
export get_outage_schedule

export Service
export AbstractReserve
export Reserve
Expand Down
10 changes: 5 additions & 5 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1367,13 +1367,13 @@ Call collect on the result if an array is desired.
# Examples
```julia
iter = get_supplemental_attributes(ForcedOutage, sys)
iter = get_supplemental_attributes(GeometricDistributionForcedOutage, sys)
iter = get_supplemental_attributes(Outage, sys)
iter = get_supplemental_attributes(x -> x.forced_outage_rate >= 0.5, ForcedOutage, sys)
outages = get_supplemental_attributes(ForcedOutage, sys) do outage
x.forced_outage_rate >= 0.5
iter = get_supplemental_attributes(x -> get_mean_time_to_recovery(x) == >= 0.5, GeometricDistributionForcedOutage, sys)
outages = get_supplemental_attributes(GeometricDistributionForcedOutage, sys) do outage
get_mean_time_to_recovery(x) == >= 0.5
end
outages = collect(get_supplemental_attributes(ForcedOutage, sys))
outages = collect(get_supplemental_attributes(GeometricDistributionForcedOutage, sys))
```
See also: [`iterate_supplemental_attributes`](@ref)
Expand Down
12 changes: 9 additions & 3 deletions test/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,16 @@ function create_system_with_outages()
initial_time = Dates.DateTime("2020-01-01T00:00:00")
end_time = Dates.DateTime("2020-01-01T23:00:00")
dates = collect(initial_time:Dates.Hour(1):end_time)
fo1 = GeometricDistributionForcedOutage(; outage_transition_probability = 0.5)
fo2 = GeometricDistributionForcedOutage(; outage_transition_probability = 0.5)
fo1 = GeometricDistributionForcedOutage(;
mean_time_to_recovery = 1.0,
outage_transition_probability = 0.5,
)
fo2 = GeometricDistributionForcedOutage(;
mean_time_to_recovery = 2.0,
outage_transition_probability = 0.5,
)
po1 = PlannedOutage(; outage_schedule = "1")
po2 = PlannedOutage(; outage_schedule = "1")
po2 = PlannedOutage(; outage_schedule = "2")
add_supplemental_attribute!(sys, gen1, fo1)
add_supplemental_attribute!(sys, gen1, po1)
add_supplemental_attribute!(sys, gen2, fo2)
Expand Down
41 changes: 31 additions & 10 deletions test/test_outages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
gen1 = gens[1]
gen2 = gens[2]
@test length(get_supplemental_attributes(Outage, sys)) == 4
forced_outages = collect(get_supplemental_attributes(ForcedOutage, sys))
forced_outages =
collect(get_supplemental_attributes(GeometricDistributionForcedOutage, sys))
@test length(forced_outages) == 2
@test get_supplemental_attribute(sys, IS.get_uuid(forced_outages[1])) ==
forced_outages[1]
Expand All @@ -19,7 +20,7 @@
end

for gen in (gen1, gen2)
for type in (ForcedOutage, PlannedOutage, GeographicInfo)
for type in (GeometricDistributionForcedOutage, PlannedOutage, GeographicInfo)
attributes = collect(get_supplemental_attributes(type, gen))
@test length(attributes) == 1
uuid = IS.get_uuid(attributes[1])
Expand All @@ -31,21 +32,41 @@
end

@test length(
get_supplemental_attributes(x -> x.forced_outage_rate == 2.0, ForcedOutage, sys),
get_supplemental_attributes(
x -> get_mean_time_to_recovery(x) == 2.0,
GeometricDistributionForcedOutage,
sys,
),
) == 1
@test length(
get_supplemental_attributes(x -> x.forced_outage_rate == 2.0, ForcedOutage, gen1),
get_supplemental_attributes(
x -> get_mean_time_to_recovery(x) == 2.0,
GeometricDistributionForcedOutage,
gen1,
),
) == 0
@test length(
get_supplemental_attributes(x -> x.forced_outage_rate == 2.0, ForcedOutage, gen2),
get_supplemental_attributes(
x -> get_mean_time_to_recovery(x) == 2.0,
GeometricDistributionForcedOutage,
gen2,
),
) == 1
@test length(
get_supplemental_attributes(x -> x.outage_schedule == 4.0, PlannedOutage, sys),
get_supplemental_attributes(x -> get_outage_schedule(x) == "1", PlannedOutage, sys),
) == 1
@test length(
get_supplemental_attributes(x -> x.outage_schedule == 4.0, PlannedOutage, gen1),
) == 0
@test length(
get_supplemental_attributes(x -> x.outage_schedule == 4.0, PlannedOutage, gen2),
get_supplemental_attributes(
x -> get_outage_schedule(x) == "1",
PlannedOutage,
gen1,
),
) == 1
@test length(
get_supplemental_attributes(
x -> get_outage_schedule(x) == "1",
PlannedOutage,
gen2,
),
) == 0
end

0 comments on commit 00b5103

Please sign in to comment.