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

Support TimeSpans interface to go back to continuous time #9

Merged
merged 11 commits into from
Mar 30, 2022

Conversation

ericphanson
Copy link
Member

@ericphanson ericphanson commented Mar 29, 2022

closes #7

Decided to use TimeSpans.duration instead of our own duration function here (in contrast to in #2), since now AlignedSpans are TimeSpans.jl-compatible timespans, so it's weird for them to have their own duration.

I think this is slightly breaking because TimeSpans.istimespan changed values, and now we use TimeSpans.duration instead of AlignedSpans.duration.

editorial note: I'm pretty excited about this bc I think it's the "right" choice (finally), but most likely only time/usage will be able to really tell if it's "good".


Some more background for reviewers:

TimeSpans.jl is a library for defining an interface for representing continous time spans. It also has some functionality for getting indicies out (index_from_time, time_from_index). It will probably help to see the TimeSpans docs, and TimeSpans#26 ,and maybe TimeSpans#2. It could also help to check out #2.

@ericphanson ericphanson requested a review from palday March 29, 2022 11:59
@codecov
Copy link

codecov bot commented Mar 29, 2022

Codecov Report

Merging #9 (cb2eab6) into main (6e701ac) will increase coverage by 1.61%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main       #9      +/-   ##
==========================================
+ Coverage   92.75%   94.36%   +1.61%     
==========================================
  Files           4        4              
  Lines          69       71       +2     
==========================================
+ Hits           64       67       +3     
+ Misses          5        4       -1     
Impacted Files Coverage Δ
src/AlignedSpans.jl 94.11% <100.00%> (+0.36%) ⬆️
src/interop.jl 89.65% <100.00%> (+3.94%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

docs/src/index.md Outdated Show resolved Hide resolved
@ericphanson ericphanson requested review from franzfurbass and kendal-s and removed request for palday March 29, 2022 17:24
@ericphanson
Copy link
Member Author

@palday rm'd the request for your review to comply with our <= 2 reviewers policy, but your feedback is always appreciated of course :)

Copy link
Contributor

@franzfurbass franzfurbass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! This is definetly an important issue. I tried my best to understand all aspects.
I made some suggestions to the documenation to be easier to understand for first-time-users.
One rounding mode seemed to have a missleading name to me, but I am not shure if it is possible to change that due already existing symbol names. One of the tests seems to have a glitch.

Project.toml Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved

* `EndpointRoundingMode`: consists of a `RoundingMode` for the `start` and `stop` of the span.
* The alias `RoundInward = EndpointRoundingMode(RoundUp, RoundDown)`, for example, constructs the largest span (whose endpoints are valid indices) that is entirely contained within `span`.
* The alias `RoundEndsDown = EndpointRoundingMode(RoundDown, RoundDown)` matches the rounding semantics of `TimeSpans.index_from_time(sample_rate, span)`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The alias `RoundEndsDown = EndpointRoundingMode(RoundDown, RoundDown)` matches the rounding semantics of `TimeSpans.index_from_time(sample_rate, span)`.
* The alias `RoundDown = EndpointRoundingMode(RoundDown, RoundDown)` matches the rounding semantics of `TimeSpans.index_from_time(sample_rate, span)`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When reading RoundEndsDown I expected that only the end time is rounded down. Maybe this alias is more intuitive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not shure if there is now a symbol clash as RoundDown was existing before?

docs/src/index.md Outdated Show resolved Hide resolved
docs/src/index.md Show resolved Hide resolved
@@ -40,6 +43,11 @@ end
const RoundInward = EndpointRoundingMode(RoundUp, RoundDown)
const RoundEndsDown = EndpointRoundingMode(RoundDown, RoundDown)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const RoundEndsDown = EndpointRoundingMode(RoundDown, RoundDown)
const RoundDown = EndpointRoundingMode(RoundDown, RoundDown)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am leaving the decision to rename to you. For me it seems more clear to use rounddown.
Other files will need that change too.

test/interop.jl Show resolved Hide resolved
test/interop.jl Outdated
for sample_rate in [1.0, 0.5, 100.0, 128.33]
# AlignedSpan -> TimeSpan -> AlignedSpan
for (i, j) in [1 => 10, 5 => 20, 3 => 6, 78 => 79]
for mode in (RoundEndsDown, RoundInward, ConstantSamplesRoundingMode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not shure if this is the correct test: should't mode used in constructing the reference object? Now RoundEndsDown is used always

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that's right! Hopefully the test still passes 😅

Copy link
Member Author

@ericphanson ericphanson Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not, so I had to weaken it a bit

test/interop.jl Outdated Show resolved Hide resolved
test/time_index_conversions.jl Outdated Show resolved Hide resolved
@ericphanson
Copy link
Member Author

Thanks for the review @franzfurbass! Regarding RoundEndsDown, I didn't go with RoundDown, since that's already exported by Base for things like

julia> round(Int, 1.8, RoundDown)
1

We could use the same object to represent rounding both endpoints down, but I thought that was kind of a bad pun to use RoundDown for both rounding a single endpoint down and for rounding both. For example, in EndpointRoundingMode(RoundDown, RoundUp), the meaning of RoundDown is the same as it is in round(Int, 1.8, RoundDown): it's rounding a single number down. But I thought it would be weird for EndpointRoundingMode(RoundDown, RoundDown) to be the same as just RoundDown.

To me, I hoped plural Ends would make it clear that it's both "ends" of the interval, not just the stop time. But if it's confusing then we should have a better name.

What about RoundEndpointsDown? Is that more clear?

@franzfurbass
Copy link
Contributor

What about RoundEndpointsDown? Is that more clear?

The thing that dropped my out was the "endpoint" in the name. The rounding mode of TimeSpans rounds down the startpoint and the endpoint of the timespan. This naming convention is also used for EndpointRoundingMode, on a second thought that has the same issue.

maybe
SampleRoundingMode for EndpointRoundingMode
RoundTimepointsDown fro RoundEndsDown

@ericphanson
Copy link
Member Author

What about SpanRoundingMode for EndpointRoundingMode, and RoundSpanDown for RoundEndsDown?

@franzfurbass
Copy link
Contributor

Sounds good!

@ericphanson
Copy link
Member Author

@franzfurbass if you're happy with the PR now, can you leave an "approval" review? That does 2 things:

  1. it clears the "changes requested",

Screen Shot 2022-03-30 at 16 15 40

2. and says it's OK for me to merge. Technically, I could merge anyway since I'm an admin on the repo, but we generally don't use that power and instead wait for an approving review:

Screen Shot 2022-03-30 at 16 16 28

Copy link
Contributor

@franzfurbass franzfurbass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, forgot to submit the review. Thanks!

@ericphanson ericphanson merged commit d8a9dcc into main Mar 30, 2022
@ericphanson ericphanson deleted the eph/discrete_to_cts branch March 30, 2022 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discrete back to continuous
2 participants