diff --git a/api/chalicelib/core/sessions/sessions_ch.py b/api/chalicelib/core/sessions/sessions_ch.py index 6a987a2d3..63c1c9401 100644 --- a/api/chalicelib/core/sessions/sessions_ch.py +++ b/api/chalicelib/core/sessions/sessions_ch.py @@ -121,8 +121,10 @@ def search2_series(data: schemas.SessionsSearchPayloadSchema, project_id: int, d s.pop("main_count") sessions = {"count": count, "values": helper.list_to_camel_case(sessions)} - return helper.complete_missing_steps(rows=sessions, start_timestamp=data.startTimestamp, - end_timestamp=data.endTimestamp, step=step_size, neutral={"count": 0}) + return metrics_helper.complete_missing_steps(rows=sessions, + start_timestamp=data.startTimestamp, + end_timestamp=data.endTimestamp, step=step_size, + neutral={"count": 0}) def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, density: int, diff --git a/api/chalicelib/utils/helper.py b/api/chalicelib/utils/helper.py index 6710100ba..4d0d09427 100644 --- a/api/chalicelib/utils/helper.py +++ b/api/chalicelib/utils/helper.py @@ -336,19 +336,3 @@ def cast_session_id_to_string(data): return data -from typing import List - - -def complete_missing_steps(rows: List[dict], start_timestamp: int, end_timestamp: int, step: int, neutral: dict, - time_key: str = "timestamp") -> List[dict]: - result = [] - i = 0 - for t in range(start_timestamp, end_timestamp, step): - if i >= len(rows) or rows[i][time_key] > t: - neutral[time_key] = t - result.append(neutral.copy()) - elif i < len(rows) and rows[i][time_key] == t: - result.append(rows[i]) - i += 1 - - return result diff --git a/api/chalicelib/utils/metrics_helper.py b/api/chalicelib/utils/metrics_helper.py index fa9bca6a6..a6ee927bc 100644 --- a/api/chalicelib/utils/metrics_helper.py +++ b/api/chalicelib/utils/metrics_helper.py @@ -1,7 +1,27 @@ +from typing import List + + def get_step_size(startTimestamp, endTimestamp, density, decimal=False, factor=1000): + print("-------density:") + print(density) step_size = (endTimestamp // factor - startTimestamp // factor) if density <= 1: return step_size if decimal: return step_size / density return step_size // density + + +def complete_missing_steps(rows: List[dict], start_timestamp: int, end_timestamp: int, step: int, neutral: dict, + time_key: str = "timestamp") -> List[dict]: + result = [] + i = 0 + for t in range(start_timestamp, end_timestamp, step): + print(t) + if i >= len(rows) or rows[i][time_key] > t: + neutral[time_key] = t + result.append(neutral.copy()) + elif i < len(rows) and rows[i][time_key] == t: + result.append(rows[i]) + i += 1 + return result diff --git a/frontend/app/types/app/period.js b/frontend/app/types/app/period.js index 768bca7de..e614f2dd2 100644 --- a/frontend/app/types/app/period.js +++ b/frontend/app/types/app/period.js @@ -20,12 +20,11 @@ function getRange(rangeName, offset) { const now = DateTime.now().setZone(offset); switch (rangeName) { case TODAY: - return Interval.fromDateTimes(now.startOf("day"), now.endOf("day")); + return Interval.fromDateTimes(now.startOf("day"), now.plus({ days:1 }).startOf("day")); case YESTERDAY: - const yesterday = now.minus({ days: 1 }); return Interval.fromDateTimes( - yesterday.startOf("day"), - yesterday.endOf("day") + now.minus({ days: 1 }).startOf("day"), + now.startOf("day") ); case LAST_24_HOURS: return Interval.fromDateTimes(now.minus({ hours: 24 }), now); @@ -37,12 +36,12 @@ function getRange(rangeName, offset) { case LAST_7_DAYS: return Interval.fromDateTimes( now.minus({ days: 6 }).startOf("day"), - now.endOf("day") + now.plus({ days: 1 }).startOf("day") ); case LAST_30_DAYS: return Interval.fromDateTimes( now.minus({ days: 29 }).startOf("day"), - now.endOf("day") + now.plus({ days: 1 }).startOf("day") ); case THIS_MONTH: return Interval.fromDateTimes(now.startOf("month"), now.endOf("month")); @@ -56,12 +55,12 @@ function getRange(rangeName, offset) { case PREV_7_DAYS: return Interval.fromDateTimes( now.minus({ days: 13 }).startOf("day"), - now.minus({ days: 7 }).endOf("day") + now.minus({ days: 6 }).startOf("day") ); case PREV_30_DAYS: return Interval.fromDateTimes( now.minus({ days: 59 }).startOf("day"), - now.minus({ days: 30 }).endOf("day") + now.minus({ days: 29 }).startOf("day") ); default: return Interval.fromDateTimes(now, now);