openreplay/api/chalicelib/utils/metrics_helper.py
Kraiem Taha Yassine 8d0c9d5a1f
Dev (#3037)
* refactor(chalice): refactored code

* fix(frontend): changed LAST_7_DAYS/LAST_30_DAYS/PREV_7_DAYS/PREV_30_DAYS to return rounded boundaries
2025-02-17 17:55:32 +01:00

27 lines
899 B
Python

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