-
-
Notifications
You must be signed in to change notification settings - Fork 68
fix(query): expose pulsetime parameter in flood() query function #139
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,8 +280,16 @@ def q2_union_no_overlap(events1: list, events2: list) -> List[Event]: | |
|
|
||
| @q2_function(flood) | ||
| @q2_typecheck | ||
| def q2_flood(events: list) -> List[Event]: | ||
| return flood(events) | ||
| def q2_flood(events: list, pulsetime: float = 5.0) -> List[Event]: | ||
| """Fill gaps between events up to pulsetime seconds. | ||
|
|
||
| The default pulsetime of 5s works well for the default 1s poll interval. | ||
| If you have set a higher polling interval (e.g. 30s), set pulsetime to | ||
| at least poll_time + 1 to avoid gaps in the activity timeline. | ||
|
|
||
| See ActivityWatch/activitywatch#1177. | ||
| """ | ||
| return flood(events, pulsetime) | ||
|
Comment on lines
+283
to
+292
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The |
||
|
|
||
|
|
||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,3 +78,33 @@ def test_flood_negative_small_gap_differing_data(): | |
| flooded = flood(events) | ||
| duration = sum((e.duration for e in flooded), timedelta(0)) | ||
| assert duration == timedelta(seconds=100 + 99.99) | ||
|
|
||
|
|
||
| def test_flood_large_gap_not_filled_with_default_pulsetime(): | ||
| """A gap larger than the default pulsetime (5s) should not be filled.""" | ||
| events = [ | ||
| Event(timestamp=now, duration=10, data={"a": 0}), | ||
| Event(timestamp=now + 25 * td1s, duration=10, data={"b": 1}), | ||
| ] | ||
| flooded = flood(events) | ||
| # Gap is 25s - 10s = 15s, larger than default pulsetime=5; stays as a gap | ||
| assert len(flooded) == 2 | ||
| gap = flooded[1].timestamp - (flooded[0].timestamp + flooded[0].duration) | ||
| assert gap > timedelta(0) | ||
|
|
||
|
|
||
| def test_flood_large_gap_filled_with_custom_pulsetime(): | ||
| """A gap larger than default pulsetime should be filled when pulsetime is increased. | ||
|
|
||
| This is the fix for ActivityWatch/activitywatch#1177: users with a high | ||
| poll interval (e.g. 30s) need to call flood with pulsetime=poll_time+1. | ||
| """ | ||
| events = [ | ||
| Event(timestamp=now, duration=10, data={"a": 0}), | ||
| Event(timestamp=now + 25 * td1s, duration=10, data={"b": 1}), | ||
| ] | ||
| flooded = flood(events, pulsetime=20) | ||
| # Gap is 15s, within pulsetime=20; should be filled | ||
| assert len(flooded) == 2 | ||
| gap = flooded[1].timestamp - (flooded[0].timestamp + flooded[0].duration) | ||
| assert gap == timedelta(0) | ||
|
Comment on lines
+83
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Both new tests import and call Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q2_flood inherits its docstring from
floodvia theq2_functiondecorator, so shouldn't have docstrings here.