Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions execution_engine/omop/criterion/combination/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
AFTERNOON_SHIFT = "afternoon_shift"
NIGHT_SHIFT = "night_shift"
DAY = "day"
ANY_TIME = "any_time"


class TemporalIndicatorCombination(CriterionCombination):
Expand Down Expand Up @@ -272,3 +273,15 @@
"""

return cls.Presence(criterion, category, TimeIntervalType.DAY)

@classmethod
def AnyTime(
cls,
criterion: Union[Criterion, "CriterionCombination"],
category: CohortCategory,
) -> "TemporalIndicatorCombination":
"""
Create a AnyTime combination of criteria.
"""

return cls.Presence(criterion, category, TimeIntervalType.ANY_TIME)

Check warning on line 287 in execution_engine/omop/criterion/combination/temporal.py

View check run for this annotation

Codecov / codecov/patch

execution_engine/omop/criterion/combination/temporal.py#L287

Added line #L287 was not covered by tests
11 changes: 0 additions & 11 deletions execution_engine/task/process/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,17 +639,6 @@ def create_time_intervals(
Raises:
ValueError: If start_datetime and end_datetime are not in the same timezone.
"""

# if start_datetime.tzinfo is not None or end_datetime.tzinfo is not None:
# if start_datetime.tzinfo != end_datetime.tzinfo:
# raise ValueError(
# "start_datetime and end_datetime must have the same timezone"
# )
# timezone = start_datetime.tzinfo
# else:
# # use local timezone if no timezone is provided
# timezone = datetime.datetime.now().astimezone().tzinfo

if isinstance(timezone, str):
timezone = cast(pytz.tzinfo.DstTzInfo, pytz.timezone(timezone))

Expand Down
43 changes: 26 additions & 17 deletions execution_engine/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from execution_engine.omop.db.celida.tables import ResultInterval
from execution_engine.omop.sqlclient import OMOPSQLClient
from execution_engine.settings import get_config
from execution_engine.task.process import get_processing_module
from execution_engine.task.process import Interval, get_processing_module
from execution_engine.util.interval import IntervalType
from execution_engine.util.types import PersonIntervals, TimeRange

Expand Down Expand Up @@ -467,23 +467,32 @@

assert isinstance(self.expr, logic.TemporalCount), "Invalid expression type"

if self.expr.interval_type is not None:
start_time, end_time = get_start_end_from_interval_type(
self.expr.interval_type
)
elif self.expr.start_time is not None and self.expr.end_time is not None:
start_time, end_time = self.expr.start_time, self.expr.end_time
if self.expr.interval_type == TimeIntervalType.ANY_TIME:
indicator_windows = [

Check warning on line 471 in execution_engine/task/task.py

View check run for this annotation

Codecov / codecov/patch

execution_engine/task/task.py#L471

Added line #L471 was not covered by tests
Interval(
lower=observation_window.start.timestamp(),
upper=observation_window.end.timestamp(),
type=IntervalType.POSITIVE,
)
]
else:
raise ValueError("Invalid time interval settings")

indicator_windows = process.create_time_intervals(
start_datetime=observation_window.start,
end_datetime=observation_window.end,
start_time=start_time,
end_time=end_time,
interval_type=IntervalType.POSITIVE,
timezone=get_config().timezone,
)
if self.expr.interval_type is not None:
start_time, end_time = get_start_end_from_interval_type(
self.expr.interval_type
)
elif self.expr.start_time is not None and self.expr.end_time is not None:
start_time, end_time = self.expr.start_time, self.expr.end_time
else:
raise ValueError("Invalid time interval settings")

Check warning on line 486 in execution_engine/task/task.py

View check run for this annotation

Codecov / codecov/patch

execution_engine/task/task.py#L486

Added line #L486 was not covered by tests

indicator_windows = process.create_time_intervals(
start_datetime=observation_window.start,
end_datetime=observation_window.end,
start_time=start_time,
end_time=end_time,
interval_type=IntervalType.POSITIVE,
timezone=get_config().timezone,
)

result = process.find_overlapping_windows(indicator_windows, data_p)

Expand Down
7 changes: 7 additions & 0 deletions scripts/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import os
import re
import sys
import time

import pendulum
from sqlalchemy import text
Expand Down Expand Up @@ -106,6 +107,7 @@
e = ExecutionEngine()
logging.getLogger().setLevel(logging.DEBUG)

start_time = time.time()

for recommendation_url in urls:
print(recommendation_url)
Expand All @@ -115,3 +117,8 @@
)

e.execute(cdd, start_datetime=start_datetime, end_datetime=end_datetime)

end_time = time.time()
runtime_seconds = end_time - start_time

logging.info(f"Total runtime: {runtime_seconds:.2f} seconds")
Loading