Updated stats

This commit is contained in:
Maximilian Giller 2022-04-27 22:39:59 +02:00
parent 47197f653d
commit 6f3ecdece9

View file

@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
import json import json
from typing import Dict from typing import Dict
from xmlrpc.client import Boolean
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
@ -15,7 +16,8 @@ with open(FILE_PATH, "r") as file:
def parse_log_entry(entry: Dict) -> Dict: def parse_log_entry(entry: Dict) -> Dict:
if entry["countChange"] == 0: # Only keep last record of a sequence
if not is_last_in_sequence(entry):
return False return False
entry["dateTime"] = datetime.strptime( entry["dateTime"] = datetime.strptime(
@ -26,13 +28,31 @@ def parse_log_entry(entry: Dict) -> Dict:
return entry return entry
def is_last_in_sequence(entry: Dict) -> Boolean:
indoor = entry["directionState"]["indoor"]
outdoor = entry["directionState"]["outdoor"]
if len(indoor) <= 0 or len(outdoor) <= 0:
return False
end_key = "end_distance"
# Check version
if end_key not in indoor[-1]:
end_key = "end"
if indoor[-1][end_key] is None or outdoor[-1][end_key] is None:
return False
return True
# Collect # Collect
log = [json.loads(line.strip("\x00")) for line in content] log = [json.loads(line.strip("\x00")) for line in content]
print("Number of 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)]
print("Number of counts:", 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.
@ -40,6 +60,17 @@ 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")
plt.show() plt.show()
print("-"*20)
# Print stats
walk_ins = [entry for entry in log if entry["countChange"] > 0]
walk_outs = [entry for entry in log if entry["countChange"] < 0]
walk_unders = [entry for entry in log if entry["countChange"] == 0]
print("Number of walk-ins:", len(walk_ins))
print("Number of walk-outs:", len(walk_outs))
print("Number of walk-unders:", len(walk_unders))
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:]):
@ -52,7 +83,7 @@ for c, n in zip(list(range(len(log))), list(range(len(log)))[1:]):
log = log[:-1] log = log[:-1]
fault_count = sum(1 for entry in log if entry["faulty"]) 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"]
@ -61,5 +92,5 @@ faulty_on = [entry for entry in log if entry["faulty"]
and entry["faultyCount"] != 0] 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, "%")
print("Percentage of false-1:", len(faulty_on) / fault_count * 100) print("Percentage of false-1:", len(faulty_on) / fault_count * 100, "%")