-
Notifications
You must be signed in to change notification settings - Fork 3
/
Analyse.py
33 lines (28 loc) · 1.09 KB
/
Analyse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from datetime import datetime
# Function to parse time from a line
def parse_time(line):
try:
time = datetime.strptime(line.strip(), '%Y-%m-%d %H:%M:%S').time()
return time
except ValueError:
return None
# Read data from the text file and count occurrences of each hour
hour_counts = {} # Dictionary to store counts for each hour
total_occurrences = 0
with open('drowsiness_log.txt', 'r') as file:
for line in file:
time = parse_time(line)
if time:
hour = time.hour
if hour not in hour_counts:
hour_counts[hour] = 0
hour_counts[hour] += 1
total_occurrences += 1
# Find the hour with the highest occurrence
max_hour = max(hour_counts, key=hour_counts.get)
max_occurrences = hour_counts[max_hour]
# Calculate percentage
percentage = (max_occurrences / total_occurrences) * 100
print("Hour with the most occurrences of drowsiness:", max_hour)
print("Number of occurrences:", max_occurrences)
print("Percentage of total occurrences: {:.2f}%".format(percentage))