Dedup same cameras with different zones.

This commit is contained in:
Dermot Duffy
2022-10-02 19:30:16 -07:00
parent 33e0c0da40
commit 72dca1b712
6 changed files with 83 additions and 39 deletions
+30 -21
View File
@@ -183,27 +183,7 @@ export const mergeFrigateBrowseMediaSources = async (
}
}
const eventSort = (
a: FrigateBrowseMediaSource,
b: FrigateBrowseMediaSource,
): number => {
if (
!a.frigate?.event ||
(b.frigate?.event && b.frigate.event.start_time > a.frigate.event.start_time)
) {
return 1;
}
if (
!b.frigate?.event ||
(a.frigate?.event && b.frigate.event.start_time < a.frigate.event.start_time)
) {
return -1;
}
return 0;
};
return createEventParentForChildren('Merged events', children.sort(eventSort));
return createEventParentForChildren('Merged events', children.sort(sortYoungestToOldest));
};
/**
@@ -445,3 +425,32 @@ export const createChild = (
}
return result;
};
/**
* Sort the timeline items most recent to least recent.
* @param a The first item.
* @param b The second item.
* @returns -1, 0, 1 (standard array sort function configuration).
*/
export const sortYoungestToOldest = (
a: FrigateBrowseMediaSource,
b: FrigateBrowseMediaSource,
): number => {
const a_source = a.frigate?.event ?? a.frigate?.recording;
const b_source = b.frigate?.event ?? b.frigate?.recording;
if (
!a_source ||
(b_source && b_source.start_time > a_source.start_time)
) {
return 1;
}
if (
!b_source ||
(a_source && b_source.start_time < a_source.start_time)
) {
return -1;
}
return 0;
};