Some filter stuff
This commit is contained in:
parent
dffa83870d
commit
5819ed5533
1 changed files with 21 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue