Coverage for chalicelib/utils/metrics_helper.py: 39%
21 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:56 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:56 +0000
1from typing import List
4def get_step_size(startTimestamp, endTimestamp, density, decimal=False, factor=1000):
5 if endTimestamp == 0: 5 ↛ 6line 5 didn't jump to line 6 because the condition on line 5 was never true
6 raise Exception("endTimestamp cannot be 0 in order to get step size")
7 step_size = (endTimestamp // factor - startTimestamp // factor)
8 if density <= 1:
9 return step_size
10 if decimal: 10 ↛ 11line 10 didn't jump to line 11 because the condition on line 10 was never true
11 return step_size / density
12 return step_size // density
15def complete_missing_steps(rows: List[dict], start_timestamp: int, end_timestamp: int, step: int, neutral: dict,
16 time_key: str = "timestamp") -> List[dict]:
17 result = []
18 i = 0
19 for t in range(start_timestamp, end_timestamp, step):
20 if i >= len(rows) or rows[i][time_key] > t:
21 neutral[time_key] = t
22 result.append(neutral.copy())
23 elif i < len(rows) and rows[i][time_key] == t:
24 result.append(rows[i])
25 i += 1
26 return result