diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d239493..6f414bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,6 @@ jobs: with: depwarn: error - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v4 with: file: lcov.info \ No newline at end of file diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 76aff3f..31c3146 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -9,7 +9,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@latest with: version: '1' diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index 50bc51a..3e0d84f 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -13,13 +13,13 @@ jobs: - uses: julia-actions/setup-julia@latest with: version: '1' - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Format check shell: julia --color=yes {0} run: | using Pkg # If you update the version, also update the style guide docs. - Pkg.add(PackageSpec(name="JuliaFormatter", version="1")) + Pkg.add(PackageSpec(name="JuliaFormatter", version="2")) using JuliaFormatter format("src", verbose=true) format("test", verbose=true) diff --git a/src/calendar.jl b/src/calendar.jl index c142148..14cf5c3 100644 --- a/src/calendar.jl +++ b/src/calendar.jl @@ -21,6 +21,16 @@ struct CalendarTimes{T<:Union{Dates.DateTime,TimeZones.ZonedDateTime}} <: start_date::T length::Int period::Dates.Period + total_duration::Float64 + function CalendarTimes( + start_date::T, + length::Integer, + period::Dates.Period, + ) where {T<:Union{Dates.DateTime,TimeZones.ZonedDateTime}} + end_date = start_date + length * period + total_duration = Dates.value(Dates.Hour(end_date - start_date)) + return new{T}(start_date, length, period, total_duration) + end end function CalendarTimes( @@ -61,7 +71,7 @@ function CalendarTimes( return CalendarTimes(first, length, period) end -_total_duration(ts::CalendarTimes) = sum(duration(t) for t in ts) +_total_duration(ts::CalendarTimes) = ts.total_duration # Add basic functions of iterators Base.length(ts::CalendarTimes) = ts.length diff --git a/src/op_scenarios/core_types.jl b/src/op_scenarios/core_types.jl index 64f7573..be81f37 100644 --- a/src/op_scenarios/core_types.jl +++ b/src/op_scenarios/core_types.jl @@ -36,6 +36,7 @@ struct OperationalScenarios{T,OP<:TimeStructure{T}} <: TimeStructure{T} len::Int scenarios::Vector{OP} probability::Vector{Float64} + total_duration::T function OperationalScenarios( len::Integer, scenarios::Vector{OP}, @@ -59,7 +60,12 @@ struct OperationalScenarios{T,OP<:TimeStructure{T}} <: TimeStructure{T} "This can lead to unexpected behavior." ) end - return new{T,OP}(len, scenarios, convert(Vector{Float64}, probability)) + return new{T,OP}( + len, + scenarios, + convert(Vector{Float64}, probability), + maximum(_total_duration(osc) for osc in scenarios), + ) end end function OperationalScenarios(len::Integer, oper::TimeStructure{T}) where {T} @@ -73,7 +79,7 @@ function OperationalScenarios(oper::Vector{<:TimeStructure{T}}) where {T} end function _total_duration(oscs::OperationalScenarios) - return maximum(_total_duration(osc) for osc in oscs.scenarios) + return oscs.total_duration end function _multiple_adj(oscs::OperationalScenarios, scen) diff --git a/src/simple.jl b/src/simple.jl index 9db9b98..90088c9 100644 --- a/src/simple.jl +++ b/src/simple.jl @@ -19,6 +19,7 @@ varying = SimpleTimes([2, 2, 2, 4, 10]) # 5 periods of varying length struct SimpleTimes{T} <: TimeStructure{T} len::Int duration::Vector{T} + total_duration::T function SimpleTimes(len::Integer, duration::Vector{T}) where {T<:Duration} if len > length(duration) throw( @@ -27,7 +28,7 @@ struct SimpleTimes{T} <: TimeStructure{T} ), ) else - new{T}(len, duration) + new{T}(len, duration, sum(duration)) end end end @@ -36,7 +37,7 @@ function SimpleTimes(len::Integer, duration::Duration) end SimpleTimes(dur::Vector{T}) where {T<:Duration} = SimpleTimes(length(dur), dur) -_total_duration(st::SimpleTimes) = sum(st.duration) +_total_duration(st::SimpleTimes) = st.total_duration # Add basic functions of iterators Base.length(st::SimpleTimes) = st.len diff --git a/src/strat_scenarios/strat_scenarios.jl b/src/strat_scenarios/strat_scenarios.jl index a298424..4d36b2f 100644 --- a/src/strat_scenarios/strat_scenarios.jl +++ b/src/strat_scenarios/strat_scenarios.jl @@ -115,9 +115,11 @@ When the `TimeStructure` is a [`StrategicScenario`](@ref), `strat_periods` retur These are equivalent to a [`StrategicPeriod`](@ref) of a [`TwoLevel`](@ref) time structure. """ -strat_periods(ts::StrategicScenario) = StratTreeNodes( - TwoLevelTree(length(ts), first(ts), [n for n in ts.nodes], ts.op_per_strat), -) +function strat_periods(ts::StrategicScenario) + return StratTreeNodes( + TwoLevelTree(length(ts), first(ts), [n for n in ts.nodes], ts.op_per_strat), + ) +end """ struct StratScens{S,T,OP<:AbstractTreeNode{S,T}} <: AbstractStratScens{T}