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
This commit is contained in:
parent
f8a1c9447b
commit
8d0c9d5a1f
4 changed files with 31 additions and 26 deletions
|
|
@ -121,8 +121,10 @@ def search2_series(data: schemas.SessionsSearchPayloadSchema, project_id: int, d
|
||||||
s.pop("main_count")
|
s.pop("main_count")
|
||||||
sessions = {"count": count, "values": helper.list_to_camel_case(sessions)}
|
sessions = {"count": count, "values": helper.list_to_camel_case(sessions)}
|
||||||
|
|
||||||
return helper.complete_missing_steps(rows=sessions, start_timestamp=data.startTimestamp,
|
return metrics_helper.complete_missing_steps(rows=sessions,
|
||||||
end_timestamp=data.endTimestamp, step=step_size, neutral={"count": 0})
|
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,
|
def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, density: int,
|
||||||
|
|
|
||||||
|
|
@ -336,19 +336,3 @@ def cast_session_id_to_string(data):
|
||||||
return 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
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,27 @@
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
def get_step_size(startTimestamp, endTimestamp, density, decimal=False, factor=1000):
|
def get_step_size(startTimestamp, endTimestamp, density, decimal=False, factor=1000):
|
||||||
|
print("-------density:")
|
||||||
|
print(density)
|
||||||
step_size = (endTimestamp // factor - startTimestamp // factor)
|
step_size = (endTimestamp // factor - startTimestamp // factor)
|
||||||
if density <= 1:
|
if density <= 1:
|
||||||
return step_size
|
return step_size
|
||||||
if decimal:
|
if decimal:
|
||||||
return step_size / density
|
return step_size / density
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,11 @@ function getRange(rangeName, offset) {
|
||||||
const now = DateTime.now().setZone(offset);
|
const now = DateTime.now().setZone(offset);
|
||||||
switch (rangeName) {
|
switch (rangeName) {
|
||||||
case TODAY:
|
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:
|
case YESTERDAY:
|
||||||
const yesterday = now.minus({ days: 1 });
|
|
||||||
return Interval.fromDateTimes(
|
return Interval.fromDateTimes(
|
||||||
yesterday.startOf("day"),
|
now.minus({ days: 1 }).startOf("day"),
|
||||||
yesterday.endOf("day")
|
now.startOf("day")
|
||||||
);
|
);
|
||||||
case LAST_24_HOURS:
|
case LAST_24_HOURS:
|
||||||
return Interval.fromDateTimes(now.minus({ hours: 24 }), now);
|
return Interval.fromDateTimes(now.minus({ hours: 24 }), now);
|
||||||
|
|
@ -37,12 +36,12 @@ function getRange(rangeName, offset) {
|
||||||
case LAST_7_DAYS:
|
case LAST_7_DAYS:
|
||||||
return Interval.fromDateTimes(
|
return Interval.fromDateTimes(
|
||||||
now.minus({ days: 6 }).startOf("day"),
|
now.minus({ days: 6 }).startOf("day"),
|
||||||
now.endOf("day")
|
now.plus({ days: 1 }).startOf("day")
|
||||||
);
|
);
|
||||||
case LAST_30_DAYS:
|
case LAST_30_DAYS:
|
||||||
return Interval.fromDateTimes(
|
return Interval.fromDateTimes(
|
||||||
now.minus({ days: 29 }).startOf("day"),
|
now.minus({ days: 29 }).startOf("day"),
|
||||||
now.endOf("day")
|
now.plus({ days: 1 }).startOf("day")
|
||||||
);
|
);
|
||||||
case THIS_MONTH:
|
case THIS_MONTH:
|
||||||
return Interval.fromDateTimes(now.startOf("month"), now.endOf("month"));
|
return Interval.fromDateTimes(now.startOf("month"), now.endOf("month"));
|
||||||
|
|
@ -56,12 +55,12 @@ function getRange(rangeName, offset) {
|
||||||
case PREV_7_DAYS:
|
case PREV_7_DAYS:
|
||||||
return Interval.fromDateTimes(
|
return Interval.fromDateTimes(
|
||||||
now.minus({ days: 13 }).startOf("day"),
|
now.minus({ days: 13 }).startOf("day"),
|
||||||
now.minus({ days: 7 }).endOf("day")
|
now.minus({ days: 6 }).startOf("day")
|
||||||
);
|
);
|
||||||
case PREV_30_DAYS:
|
case PREV_30_DAYS:
|
||||||
return Interval.fromDateTimes(
|
return Interval.fromDateTimes(
|
||||||
now.minus({ days: 59 }).startOf("day"),
|
now.minus({ days: 59 }).startOf("day"),
|
||||||
now.minus({ days: 30 }).endOf("day")
|
now.minus({ days: 29 }).startOf("day")
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return Interval.fromDateTimes(now, now);
|
return Interval.fromDateTimes(now, now);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue