You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Import required libraries
import re
from collections import defaultdict
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use("TkAgg")
import pandas as pd
# Read the file with UTF-16 encoding
with open('D:\GreenSoft\KMCounter.ini', 'r', encoding='utf-16') as file:
file_content = file.readlines()
# Initialize a dictionary to store the data
data_dict = defaultdict(lambda: {'lbcount': 0, 'rbcount': 0, 'wheel': 0, 'move': 0, 'keystrokes': 0})
# Regular expression pattern to extract date in the format YYYYMMDD and the relevant data
pattern = re.compile(r'\[(\d{8})\]')
key_patterns = ['lbcount', 'rbcount', 'wheel', 'move', 'keystrokes']
# Extract data
current_date = None
for line in file_content:
# if ==[total]==, then skip
if line.strip() == '[total]':
current_date = None
continue
date_match = pattern.match(line.strip())
if date_match:
current_date = date_match.group(1)
current_date = f"{current_date[:4]}-{current_date[4:6]}-{current_date[6:]}"
continue
if current_date:
for key in key_patterns:
if line.startswith(key):
value = float(line.split('=')[1].strip())
data_dict[current_date][key] = value
# Convert the defaultdict to a normal dict
data_dict = dict(data_dict)
# Convert the data dictionary to a DataFrame
df = pd.DataFrame.from_dict(data_dict, orient='index')
df.index = pd.to_datetime(df.index)
# Filter out rows with 'total' in the index
df_filtered = df[~df.index.astype(str).str.contains('total', case=False)]
# Normalize the data for plotting
df_filtered_normalized = (df_filtered - df_filtered.min()) / (df_filtered.max() - df_filtered.min())
# Plotting
fig, ax = plt.subplots(figsize=(15, 10))
for column in df_filtered_normalized.columns:
df_filtered_normalized[column].plot(ax=ax, marker='o', label=column)
ax.set_xlabel('Date')
ax.set_ylabel('Normalized Value')
ax.set_title('Comparison of lbcount, rbcount, wheel, move, and keystrokes Over Time')
ax.legend()
plt.tight_layout()
plt.show()
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: