Separates old files
This commit is contained in:
parent
f83c6d0570
commit
6ee324095e
13 changed files with 16 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
from datetime import datetime, time, timedelta
|
from datetime import datetime, time, timedelta
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from services.philips_hue import PhilipsHue
|
from old.philips_hue import PhilipsHue
|
||||||
from sensors import PeopleCounter, Directions, VL53L1XSensor
|
from sensors import PeopleCounter, Directions, VL53L1XSensor
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
|
@ -15,13 +15,14 @@ with open(FILE_PATH, "r") as file:
|
||||||
content = file.readlines()
|
content = file.readlines()
|
||||||
|
|
||||||
|
|
||||||
def parse_log_entry(entry: Dict) -> Dict:
|
def parse_log_entry(entry: Dict) -> Dict | bool:
|
||||||
# Only keep last record of a sequence
|
# Only keep last record of a sequence
|
||||||
if not is_last_in_sequence(entry):
|
if not is_last_in_sequence(entry):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
entry["dateTime"] = datetime.strptime(
|
entry["dateTime"] = datetime.strptime(
|
||||||
str(entry["dateTime"])[:19], "%Y-%m-%d %H:%M:%S")
|
str(entry["dateTime"])[:19], "%Y-%m-%d %H:%M:%S"
|
||||||
|
)
|
||||||
if entry["dateTime"] < datetime(2022, 1, 1):
|
if entry["dateTime"] < datetime(2022, 1, 1):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -31,15 +32,15 @@ def parse_log_entry(entry: Dict) -> Dict:
|
||||||
def is_last_in_sequence(entry: Dict) -> Boolean:
|
def is_last_in_sequence(entry: Dict) -> Boolean:
|
||||||
indoor = entry["directionState"]["indoor"]
|
indoor = entry["directionState"]["indoor"]
|
||||||
outdoor = entry["directionState"]["outdoor"]
|
outdoor = entry["directionState"]["outdoor"]
|
||||||
|
|
||||||
if len(indoor) <= 0 or len(outdoor) <= 0:
|
if len(indoor) <= 0 or len(outdoor) <= 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
end_key = "end_distance"
|
end_key = "end_distance"
|
||||||
# Check version
|
# Check version
|
||||||
if end_key not in indoor[-1]:
|
if end_key not in indoor[-1]:
|
||||||
end_key = "end"
|
end_key = "end"
|
||||||
|
|
||||||
if indoor[-1][end_key] is None or outdoor[-1][end_key] is None:
|
if indoor[-1][end_key] is None or outdoor[-1][end_key] is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -47,20 +48,20 @@ def is_last_in_sequence(entry: Dict) -> Boolean:
|
||||||
|
|
||||||
|
|
||||||
# Collect
|
# Collect
|
||||||
log = [json.loads(line.strip("\x00")) for line in content]
|
log: list[Dict] = [json.loads(line.strip("\x00")) for line in content]
|
||||||
print("Number of total entries:", len(log))
|
print("Number of total entries:", len(log))
|
||||||
|
|
||||||
# Parse & Filter
|
# Parse & Filter
|
||||||
log = [parse_log_entry(entry) for entry in log if parse_log_entry(entry)]
|
log = [parse_log_entry(entry) for entry in log if parse_log_entry(entry)] # type: ignore
|
||||||
print("Number of filtered entries:", len(log))
|
print("Number of filtered entries:", len(log))
|
||||||
|
|
||||||
# Render
|
# Render
|
||||||
fig, ax = plt.subplots() # Create a figure containing a single axes.
|
fig, ax = plt.subplots() # Create a figure containing a single axes.
|
||||||
times: list[datetime] = [entry["dateTime"] for entry in log]
|
times: list[datetime] = [entry["dateTime"] for entry in log]
|
||||||
counts: list[int] = [entry["previousPeopleCount"] for entry in log]
|
counts: list[int] = [entry["previousPeopleCount"] for entry in log]
|
||||||
ax.step(times, counts, where="pre")
|
ax.step(times, counts, where="pre") # type: ignore
|
||||||
plt.show()
|
plt.show()
|
||||||
print("-"*20)
|
print("-" * 20)
|
||||||
|
|
||||||
|
|
||||||
# Print stats
|
# Print stats
|
||||||
|
@ -70,12 +71,11 @@ walk_unders = [entry for entry in log if entry["countChange"] == 0]
|
||||||
print("Number of walk-ins:", len(walk_ins))
|
print("Number of walk-ins:", len(walk_ins))
|
||||||
print("Number of walk-outs:", len(walk_outs))
|
print("Number of walk-outs:", len(walk_outs))
|
||||||
print("Number of walk-unders:", len(walk_unders))
|
print("Number of walk-unders:", len(walk_unders))
|
||||||
print("-"*20)
|
print("-" * 20)
|
||||||
|
|
||||||
# Calculate faults
|
# Calculate faults
|
||||||
for c, n in zip(list(range(len(log))), list(range(len(log)))[1:]):
|
for c, n in zip(list(range(len(log))), list(range(len(log)))[1:]):
|
||||||
estimated_count: int = log[c]["previousPeopleCount"] + \
|
estimated_count: int = log[c]["previousPeopleCount"] + log[c]["countChange"]
|
||||||
log[c]["countChange"]
|
|
||||||
faulty: bool = estimated_count != log[n]["previousPeopleCount"]
|
faulty: bool = estimated_count != log[n]["previousPeopleCount"]
|
||||||
log[c]["faulty"] = faulty
|
log[c]["faulty"] = faulty
|
||||||
log[c]["faultyCount"] = log[c]["previousPeopleCount"] if faulty else None
|
log[c]["faultyCount"] = log[c]["previousPeopleCount"] if faulty else None
|
||||||
|
@ -85,11 +85,9 @@ fault_count = sum(1 for entry in log if entry["faulty"])
|
||||||
print("Number of faults:", fault_count)
|
print("Number of faults:", fault_count)
|
||||||
print("Percentage of faults:", fault_count / len(log) * 100, "%")
|
print("Percentage of faults:", fault_count / len(log) * 100, "%")
|
||||||
|
|
||||||
print("-"*20)
|
print("-" * 20)
|
||||||
faulty_off = [entry for entry in log if entry["faulty"]
|
faulty_off = [entry for entry in log if entry["faulty"] and entry["faultyCount"] == 0]
|
||||||
and entry["faultyCount"] == 0]
|
faulty_on = [entry for entry in log if entry["faulty"] and entry["faultyCount"] != 0]
|
||||||
faulty_on = [entry for entry in log if entry["faulty"]
|
|
||||||
and entry["faultyCount"] != 0]
|
|
||||||
print("Number of false-0:", len(faulty_off))
|
print("Number of false-0:", len(faulty_off))
|
||||||
print("Number of false-1:", len(faulty_on))
|
print("Number of false-1:", len(faulty_on))
|
||||||
print("Percentage of false-0:", len(faulty_off) / fault_count * 100, "%")
|
print("Percentage of false-0:", len(faulty_off) / fault_count * 100, "%")
|
Loading…
Reference in a new issue