Prevent pandas overflow and runtime errors from division by zero/NaN

This commit is contained in:
Josh Hawkins 2024-07-24 09:21:51 -05:00
parent 524f03a650
commit fd937cb381
2 changed files with 9 additions and 6 deletions

1
docker/main/pysqlite3 Submodule

@ -0,0 +1 @@
Subproject commit 67014040e4eb5ab2abc0c7bdcf2dfefea13332ab

View File

@ -475,7 +475,7 @@ def motion_activity():
logger.warning("No motion data found for the requested time range") logger.warning("No motion data found for the requested time range")
return jsonify([]) return jsonify([])
df = df.astype(dtype={"motion": "float16"}) df = df.astype(dtype={"motion": "float32"})
# set date as datetime index # set date as datetime index
df["start_time"] = pd.to_datetime(df["start_time"], unit="s") df["start_time"] = pd.to_datetime(df["start_time"], unit="s")
@ -497,11 +497,13 @@ def motion_activity():
for i in range(0, length, chunk): for i in range(0, length, chunk):
part = df.iloc[i : i + chunk] part = df.iloc[i : i + chunk]
df.iloc[i : i + chunk, 0] = ( min_val, max_val = part["motion"].min(), part["motion"].max()
(part["motion"] - part["motion"].min()) if min_val != max_val:
/ (part["motion"].max() - part["motion"].min()) df.iloc[i : i + chunk, 0] = (
* 100 part["motion"].sub(min_val).div(max_val - min_val).mul(100).fillna(0)
).fillna(0.0) )
else:
df.iloc[i : i + chunk, 0] = 0.0
# change types for output # change types for output
df.index = df.index.astype(int) // (10**9) df.index = df.index.astype(int) // (10**9)