diff --git a/src/part.jl b/src/part.jl index f60aaf7..cbc46fd 100644 --- a/src/part.jl +++ b/src/part.jl @@ -49,15 +49,15 @@ function Base.merge!(a::Centroid, b::Centroid, astat, bstat) a end -#-----------------------------------------------------------------------------# TimeBucket -mutable struct TimeBucket{T <: Dates.TimeType} +#-----------------------------------------------------------------------------# ClosedInterval +mutable struct ClosedInterval{T} first::T last::T end -Base.show(io::IO, b::TimeBucket) = print(io, "TimeBucket: [$(b.first), $(b.last)]") -Base.in(x, bucket::TimeBucket) = bucket.first ≤ x ≤ bucket.last -Base.isless(a::TimeBucket, b::TimeBucket) = isless(a.first, b.first) -function Base.merge!(a::TimeBucket, b::TimeBucket) +Base.show(io::IO, b::ClosedInterval) = print(io, "ClosedInterval: [$(b.first), $(b.last)]") +Base.in(x, bucket::ClosedInterval) = bucket.first ≤ x ≤ bucket.last +Base.isless(a::ClosedInterval, b::ClosedInterval) = isless(a.first, b.first) +function Base.merge!(a::ClosedInterval, b::ClosedInterval) a.first = min(a.first, b.first) a.last = max(a.last, b.last) a diff --git a/test/test_stats.jl b/test/test_stats.jl index e22127f..79555a7 100644 --- a/test/test_stats.jl +++ b/test/test_stats.jl @@ -181,7 +181,7 @@ println(" > Part") a, b = mergevals(Part(Counter(), OnlineStatsBase.Centroid(0.0)), zip(y,y), zip(y2,y2)) @test a.stat == b.stat - o = Part(Mean(), OnlineStatsBase.TimeBucket(today() - Day(10), today())) + o = Part(Mean(), OnlineStatsBase.ClosedInterval(today() - Day(10), today())) fit!(o, today() => 10) fit!(o, today() - Day(5) => 20) @test value(value(o).stat) == 15.0