Skip to content

Commit

Permalink
fix: apply event timing and belief timing filters to subquery to find…
Browse files Browse the repository at this point in the history
… the most recent event (#168)

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Mar 4, 2024
1 parent 9932242 commit 31f87c3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions timely_beliefs/beliefs/classes.py
Expand Up @@ -520,12 +520,18 @@ def apply_belief_timing_filters(q):

# Apply most recent events filter as subquery
if most_recent_events_only:
subq_most_recent_events = select(
cls.source_id,
func.max(cls.event_start).label("most_recent_event_start"),
)
subq_most_recent_events = apply_event_timing_filters(
subq_most_recent_events
)
subq_most_recent_events = apply_belief_timing_filters(
subq_most_recent_events
)
subq_most_recent_events = (
select(
cls.source_id,
func.max(cls.event_start).label("most_recent_event_start"),
)
.filter(cls.sensor_id == sensor.id)
subq_most_recent_events.filter(cls.sensor_id == sensor.id)
.group_by(cls.source_id)
.subquery()
)
Expand Down

0 comments on commit 31f87c3

Please sign in to comment.