Skip to content

Commit

Permalink
fix: incompatible criteria for most_recent_events_only
Browse files Browse the repository at this point in the history
Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Apr 8, 2024
1 parent 8868139 commit bcc85ee
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions timely_beliefs/beliefs/classes.py
Expand Up @@ -488,13 +488,10 @@ def apply_belief_timing_filters(q):
q = q.join(source_class).filter(cls.source_id.in_([s.id for s in sources]))

# Apply most recent beliefs filter as subquery
most_recent_beliefs_only_incompatible_criteria = (
most_recent_only_incompatible_criteria = (
beliefs_before is not None or beliefs_after is not None
) and sensor.knowledge_horizon_fnc not in (ex_ante.__name__, ex_post.__name__)
if (
most_recent_beliefs_only
and not most_recent_beliefs_only_incompatible_criteria
):
if most_recent_beliefs_only and not most_recent_only_incompatible_criteria:
subq = select(
cls.event_start,
cls.source_id,
Expand All @@ -519,7 +516,7 @@ def apply_belief_timing_filters(q):
)

# Apply most recent events filter as subquery
if most_recent_events_only:
if most_recent_events_only and not most_recent_only_incompatible_criteria:
subq_most_recent_events = select(
cls.source_id,
func.max(cls.event_start).label("most_recent_event_start"),
Expand Down Expand Up @@ -576,8 +573,10 @@ def apply_belief_timing_filters(q):
if beliefs_before is not None:
df = df[df.index.get_level_values("belief_time") <= beliefs_before]

# Select most recent beliefs using postprocessing in case of incompatible search criteria
if most_recent_beliefs_only and most_recent_beliefs_only_incompatible_criteria:
# Select most recent events/beliefs using postprocessing in case of incompatible search criteria
if most_recent_events_only and most_recent_only_incompatible_criteria:
df = df[df.index.get_level_values("event_start") == df.event_starts.max()]
if most_recent_beliefs_only and most_recent_only_incompatible_criteria:
df = belief_utils.select_most_recent_belief(df)

# Convert timezone of beliefs and events to sensor timezone
Expand Down

0 comments on commit bcc85ee

Please sign in to comment.