* refactor(chalice): refactored code

* fix(frontend): changed LAST_7_DAYS/LAST_30_DAYS/PREV_7_DAYS/PREV_30_DAYS to return rounded boundaries
This commit is contained in:
Kraiem Taha Yassine 2025-02-17 17:55:32 +01:00 committed by GitHub
parent f8a1c9447b
commit 8d0c9d5a1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 26 deletions

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -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);