Be more efficient about getting info

This commit is contained in:
Nick Mowen 2023-12-07 18:29:35 -07:00
parent 7b649a5a19
commit 318fd70cff
3 changed files with 20 additions and 7 deletions

View File

@ -647,9 +647,19 @@ def hourly_timeline():
.iterator() .iterator()
) )
count = 0
start = 0
end = 0
hours: dict[str, list[dict[str, any]]] = {} hours: dict[str, list[dict[str, any]]] = {}
for t in timeline: for t in timeline:
if count == 0:
start = t["timestamp"]
else:
end = t["timestamp"]
count += 1
hour = ( hour = (
datetime.fromtimestamp(t["timestamp"]).replace( datetime.fromtimestamp(t["timestamp"]).replace(
minute=0, second=0, microsecond=0 minute=0, second=0, microsecond=0
@ -665,9 +675,9 @@ def hourly_timeline():
return jsonify( return jsonify(
{ {
"start": timeline[0].timestamp, "start": start,
"end": timeline[-1].timestamp, "end": end,
"count": timeline.count(), "count": count,
"hours": hours, "hours": hours,
} }
) )

View File

@ -23,14 +23,14 @@ export function Review() {
} }
const cards: CardsData = {}; const cards: CardsData = {};
Object.keys(hourlyTimeline) Object.keys(hourlyTimeline["hours"])
.reverse() .reverse()
.forEach((hour) => { .forEach((hour) => {
const day = new Date(parseInt(hour) * 1000); const day = new Date(parseInt(hour) * 1000);
day.setHours(0, 0, 0, 0); day.setHours(0, 0, 0, 0);
const dayKey = (day.getTime() / 1000).toString(); const dayKey = (day.getTime() / 1000).toString();
const source_to_types: {[key: string]: string[]} = {}; const source_to_types: {[key: string]: string[]} = {};
Object.values(hourlyTimeline[hour]).forEach((i) => { Object.values(hourlyTimeline["hours"][hour]).forEach((i) => {
const time = new Date(i.timestamp * 1000); const time = new Date(i.timestamp * 1000);
time.setSeconds(0); time.setSeconds(0);
time.setMilliseconds(0); time.setMilliseconds(0);
@ -46,7 +46,7 @@ export function Review() {
cards[dayKey] = {}; cards[dayKey] = {};
} }
cards[dayKey][hour] = {}; cards[dayKey][hour] = {};
Object.values(hourlyTimeline[hour]).forEach((i) => { Object.values(hourlyTimeline["hours"][hour]).forEach((i) => {
const time = new Date(i.timestamp * 1000); const time = new Date(i.timestamp * 1000);
time.setSeconds(0); time.setSeconds(0);
time.setMilliseconds(0); time.setMilliseconds(0);

View File

@ -32,5 +32,8 @@ type Timeline = {
} }
type HourlyTimeline = { type HourlyTimeline = {
[key: string]: Timeline[]; start: number,
end: number,
count: number,
hours: { [key: string]: Timeline[] };
} }