mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-07 11:45:24 +03:00
Organize data more effictively and ensure data is not overwritten
This commit is contained in:
parent
8d143dc655
commit
a35dfd0e69
@ -10,7 +10,7 @@ import axios from "axios";
|
|||||||
import TimelinePlayerCard from "@/components/card/TimelinePlayerCard";
|
import TimelinePlayerCard from "@/components/card/TimelinePlayerCard";
|
||||||
import { getHourlyTimelineData } from "@/utils/historyUtil";
|
import { getHourlyTimelineData } from "@/utils/historyUtil";
|
||||||
|
|
||||||
const API_LIMIT = 120;
|
const API_LIMIT = 200;
|
||||||
|
|
||||||
function History() {
|
function History() {
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
// group history cards by 60 seconds of activity
|
||||||
|
const GROUP_SECONDS = 60;
|
||||||
|
|
||||||
export function getHourlyTimelineData(
|
export function getHourlyTimelineData(
|
||||||
timelinePages: HourlyTimeline[],
|
timelinePages: HourlyTimeline[],
|
||||||
detailLevel: string
|
detailLevel: string
|
||||||
@ -10,26 +13,42 @@ export function getHourlyTimelineData(
|
|||||||
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();
|
||||||
|
|
||||||
|
// build a map of course to the types that are included in this hour
|
||||||
|
// which allows us to know what items to keep depending on detail level
|
||||||
const source_to_types: { [key: string]: string[] } = {};
|
const source_to_types: { [key: string]: string[] } = {};
|
||||||
|
let cardTypeStart: { [camera: string]: number } = {};
|
||||||
Object.values(hourlyTimeline["hours"][hour]).forEach((i) => {
|
Object.values(hourlyTimeline["hours"][hour]).forEach((i) => {
|
||||||
const time = new Date(i.timestamp * 1000);
|
if (i.timestamp > (cardTypeStart[i.camera] ?? 0) + GROUP_SECONDS) {
|
||||||
time.setSeconds(0);
|
cardTypeStart[i.camera] = i.timestamp;
|
||||||
time.setMilliseconds(0);
|
}
|
||||||
const key = `${i.source_id}-${time.getMinutes()}`;
|
|
||||||
if (key in source_to_types) {
|
const groupKey = `${i.source_id}-${cardTypeStart[i.camera]}`;
|
||||||
source_to_types[key].push(i.class_type);
|
|
||||||
|
if (groupKey in source_to_types) {
|
||||||
|
source_to_types[groupKey].push(i.class_type);
|
||||||
} else {
|
} else {
|
||||||
source_to_types[key] = [i.class_type];
|
source_to_types[groupKey] = [i.class_type];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!Object.keys(cards).includes(dayKey)) {
|
if (!(dayKey in cards)) {
|
||||||
cards[dayKey] = {};
|
cards[dayKey] = {};
|
||||||
}
|
}
|
||||||
cards[dayKey][hour] = {};
|
|
||||||
|
if (!(hour in cards[dayKey])) {
|
||||||
|
cards[dayKey][hour] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
let cardStart: { [camera: string]: number } = {};
|
||||||
Object.values(hourlyTimeline["hours"][hour]).forEach((i) => {
|
Object.values(hourlyTimeline["hours"][hour]).forEach((i) => {
|
||||||
|
if (i.timestamp > (cardStart[i.camera] ?? 0) + GROUP_SECONDS) {
|
||||||
|
cardStart[i.camera] = i.timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
const time = new Date(i.timestamp * 1000);
|
const time = new Date(i.timestamp * 1000);
|
||||||
const minuteKey = `${i.camera}-${time.getMinutes()}`;
|
const groupKey = `${i.camera}-${cardStart[i.camera]}`;
|
||||||
|
const sourceKey = `${i.source_id}-${cardStart[i.camera]}`;
|
||||||
const uniqueKey = `${i.source_id}-${i.class_type}`;
|
const uniqueKey = `${i.source_id}-${i.class_type}`;
|
||||||
|
|
||||||
// detail level for saving items
|
// detail level for saving items
|
||||||
@ -42,8 +61,7 @@ export function getHourlyTimelineData(
|
|||||||
let add = true;
|
let add = true;
|
||||||
if (detailLevel == "normal") {
|
if (detailLevel == "normal") {
|
||||||
if (
|
if (
|
||||||
source_to_types[`${i.source_id}-${time.getMinutes()}`].length >
|
source_to_types[sourceKey].length > 1 &&
|
||||||
1 &&
|
|
||||||
["active", "attribute", "gone", "stationary", "visible"].includes(
|
["active", "attribute", "gone", "stationary", "visible"].includes(
|
||||||
i.class_type
|
i.class_type
|
||||||
)
|
)
|
||||||
@ -52,8 +70,7 @@ export function getHourlyTimelineData(
|
|||||||
}
|
}
|
||||||
} else if (detailLevel == "extra") {
|
} else if (detailLevel == "extra") {
|
||||||
if (
|
if (
|
||||||
source_to_types[`${i.source_id}-${time.getMinutes()}`].length >
|
source_to_types[sourceKey].length > 1 &&
|
||||||
1 &&
|
|
||||||
i.class_type in ["attribute", "gone", "visible"]
|
i.class_type in ["attribute", "gone", "visible"]
|
||||||
) {
|
) {
|
||||||
add = false;
|
add = false;
|
||||||
@ -61,18 +78,16 @@ export function getHourlyTimelineData(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (add) {
|
if (add) {
|
||||||
if (minuteKey in cards[dayKey][hour]) {
|
if (groupKey in cards[dayKey][hour]) {
|
||||||
if (
|
if (
|
||||||
!cards[dayKey][hour][minuteKey].uniqueKeys.includes(
|
!cards[dayKey][hour][groupKey].uniqueKeys.includes(uniqueKey) ||
|
||||||
uniqueKey
|
|
||||||
) ||
|
|
||||||
detailLevel == "full"
|
detailLevel == "full"
|
||||||
) {
|
) {
|
||||||
cards[dayKey][hour][minuteKey].entries.push(i);
|
cards[dayKey][hour][groupKey].entries.push(i);
|
||||||
cards[dayKey][hour][minuteKey].uniqueKeys.push(uniqueKey);
|
cards[dayKey][hour][groupKey].uniqueKeys.push(uniqueKey);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cards[dayKey][hour][minuteKey] = {
|
cards[dayKey][hour][groupKey] = {
|
||||||
camera: i.camera,
|
camera: i.camera,
|
||||||
time: time.getTime() / 1000,
|
time: time.getTime() / 1000,
|
||||||
entries: [i],
|
entries: [i],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user