From 5819ed55336b4616bfbb65fc0c086718e383e110 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Sun, 8 Oct 2023 01:56:10 +0200 Subject: [PATCH] Some filter stuff --- src/statistics/statistics.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/statistics/statistics.py b/src/statistics/statistics.py index eac2a96..41e7888 100644 --- a/src/statistics/statistics.py +++ b/src/statistics/statistics.py @@ -7,6 +7,7 @@ import matplotlib.pyplot as plt # Config FILE_PATH = "log.txt" +AFTER_DATE = datetime(2022, 1, 1) # Only keeps log entries after the specified date. Filter applied in parse_log_entry(..) # Read file @@ -15,14 +16,14 @@ with open(FILE_PATH, "r") as file: 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 if not is_last_in_sequence(entry): return False entry["dateTime"] = datetime.strptime( str(entry["dateTime"])[:19], "%Y-%m-%d %H:%M:%S") - if entry["dateTime"] < datetime(2022, 1, 1): + if entry["dateTime"] < AFTER_DATE: return False return entry @@ -59,6 +60,7 @@ fig, ax = plt.subplots() # Create a figure containing a single axes. times: list[datetime] = [entry["dateTime"] for entry in log] counts: list[int] = [entry["previousPeopleCount"] for entry in log] ax.step(times, counts, where="pre") +print("-"*20) plt.show() print("-"*20) @@ -73,6 +75,7 @@ print("Number of walk-unders:", len(walk_unders)) print("-"*20) # Calculate faults + for c, n in zip(list(range(len(log))), list(range(len(log)))[1:]): estimated_count: int = log[c]["previousPeopleCount"] + \ log[c]["countChange"] @@ -82,8 +85,9 @@ for c, n in zip(list(range(len(log))), list(range(len(log)))[1:]): log = log[:-1] fault_count = sum(1 for entry in log if entry["faulty"]) +fault_percentage = fault_count / len(log) print("Number of faults:", fault_count) -print("Percentage of faults:", fault_count / len(log) * 100, "%") +print("Percentage of faults:", fault_percentage * 100, "%") print("-"*20) faulty_off = [entry for entry in log if entry["faulty"] @@ -94,3 +98,17 @@ print("Number of false-0:", len(faulty_off)) print("Number of false-1:", len(faulty_on)) print("Percentage of false-0:", len(faulty_off) / fault_count * 100, "%") print("Percentage of false-1:", len(faulty_on) / fault_count * 100, "%") + +# Number of dates +unique_dates = set() +for entry in log: + date = entry["dateTime"].strftime("%Y-%m-%d") + unique_dates.add(date) +total_days = len(unique_dates) + +print("-"*20) +print("Number of days:", total_days) +print("Changes per day:", len(log) / total_days) + +corrections_per_day = len(log) / total_days * fault_percentage +print("Corrections per day:", corrections_per_day)