Skip to content

Commit

Permalink
fix(insights): hour truncation with "last days" (#20170)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra authored Feb 7, 2024
1 parent 1927797 commit e0af4f0
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _run_query(
):
query_series: List[EventsNode | ActionsNode] = [EventsNode(event="$pageview")] if series is None else series
query_date_from = date_from or self.default_date_from
query_date_to = date_to or self.default_date_to
query_date_to = None if date_to == "now" else date_to or self.default_date_to
query_interval = interval or IntervalType.day

query = StickinessQuery(
Expand Down Expand Up @@ -285,6 +285,23 @@ def test_interval_hour(self):
assert result["days"] == [hour + 1 for hour in range(25)]
assert result["data"] == hours_data

def test_interval_hour_last_days(self):
self._create_test_events()

with freeze_time("2020-01-20T12:00:00Z"):
response = self._run_query(interval=IntervalType.hour, date_from="-2d", date_to="now")
result = response.results[0]
# 61 = 48 + 12 + 1
hours_labels = [f"{hour + 1} hour{'' if hour == 0 else 's'}" for hour in range(61)]
hours_data = [0] * 61
hours_data[0] = 1
hours_data[1] = 1

assert result["label"] == "$pageview"
assert result["labels"] == hours_labels
assert result["days"] == [hour + 1 for hour in range(61)]
assert result["data"] == hours_data

def test_interval_day(self):
self._create_test_events()

Expand Down
Loading

0 comments on commit e0af4f0

Please sign in to comment.