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

Use last element as end time #58

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/pyaro/timeseries/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def envelope(self) -> tuple[datetime, datetime]:
end = datetime.min
for s, e in self._start_include + self._startend_include + self._end_include:
start = min(start, s)
end = max(end, s)
end = max(end, e)
Comment on lines 613 to +616
Copy link
Collaborator

@avaldebe avaldebe Nov 1, 2024

Choose a reason for hiding this comment

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

Is this the cleanest way to set the start/end
Also, why is does start depends on self._end_include and end depends on self._start_include?

maybe itertools.chain can improve the readability

from itertools import chain
[...]
        if self._start_include or self._startend_include:
            start = min(s for s, e in chain(self._start_include, self._startend_include))
        else:
            start = datetime.max

        if self._end_include or self._startend_include:
            end = max(e for s, e in chain(self._end_include, self._startend_include))
        else:
            end = datetime.min

Copy link
Member

Choose a reason for hiding this comment

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

I don't think the chain-version is very readable here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the chain-version is very readable here.

Yes, at the cost of creating new lists this could be written on a simpler way

        if self._start_include or self._startend_include:
            start = min(s for s, e in self._start_include + self._startend_include)
        else:
            start = datetime.max

        if self._end_include or self._startend_include:
            end = max(e for s, e in self._end_include + self._startend_include)
        else:
            end = datetime.min

In any case, my question still stands

Also, why is does start depends on self._end_include and end depends on self._start_include?

Copy link
Member

Choose a reason for hiding this comment

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

The tuple values of (start, end) are the time-ranges of the filter, while start_include/end_include refer to measurements starttime/endtime.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, very well that you also included a test.

if end < start:
raise TimeBoundsException(
f"TimeBoundsEnvelope end < start: {end} < {start}"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_timefilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from datetime import datetime

from pyaro.timeseries.Filter import TimeBoundsFilter


def test_timemax():
bounds = TimeBoundsFilter(start_include=[("2023-01-01 00:00:00", "2024-01-01 00:00:00")])

envelope = bounds.envelope()
assert envelope[0] == datetime.fromisoformat("2023-01-01 00:00:00")
assert envelope[1] == datetime.fromisoformat("2024-01-01 00:00:00")