-
-
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -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.
pulsetimetype is not validated byq2_typecheckThe
q2_typecheckdecorator only enforces type annotations on required parameters (param.default == param.empty). Becausepulsetimehas a default value of5.0, it is silently skipped. If a user callsflood(events, "30")in a query, Python will pass a string intoaw_transform.flood, which then callstimedelta(seconds="30"), producing a crypticTypeErrorinstead of aQueryFunctionException. A manual guard (if not isinstance(pulsetime, (int, float)): raise QueryFunctionException(...)) before thereturnwould give users a clear error message.