Include which cameras detected motion during aggregated data (#10663)

This commit is contained in:
Nicolas Mowen 2024-03-25 10:00:28 -06:00 committed by GitHub
parent 7b64091128
commit 258cd5b6d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -358,6 +358,7 @@ def motion_activity():
)
clauses = [(Recordings.start_time > after) & (Recordings.end_time < before)]
clauses.append((Recordings.motion > 0))
if cameras != "all":
camera_list = cameras.split(",")
@ -365,6 +366,7 @@ def motion_activity():
data: list[Recordings] = (
Recordings.select(
Recordings.camera,
Recordings.start_time,
Recordings.motion,
)
@ -378,18 +380,22 @@ def motion_activity():
scale = request.args.get("scale", type=int, default=30)
# resample data using pandas to get activity on scaled basis
df = pd.DataFrame(data, columns=["start_time", "motion"])
df = pd.DataFrame(data, columns=["start_time", "motion", "camera"])
# set date as datetime index
df["start_time"] = pd.to_datetime(df["start_time"], unit="s")
df.set_index(["start_time"], inplace=True)
# normalize data
df = (
df.resample(f"{scale}S")
motion = (
df["motion"]
.resample(f"{scale}S")
.apply(lambda x: max(x, key=abs, default=0.0))
.fillna(0.0)
.to_frame()
)
cameras = df["camera"].resample(f"{scale}S").agg(lambda x: ",".join(set(x)))
df = motion.join(cameras)
length = df.shape[0]
chunk = int(60 * (60 / scale))