In [ ]:
%pip install seaborn
In [15]:
with open("keystroke.log", "r") as file:
lines = file.readlines()
In [ ]:
from datetime import datetime
keystrokes = []
i = 0
for line in lines:
i += 1
timeStr = line[:17]
keystroke = line[18:].strip()
try:
if keystroke and keystroke[0] != "[":
if "\n" not in keystroke:
datetime_str = timeStr
datetime_obj = datetime.strptime(datetime_str, "%Y%m%d %H:%M:%S")
print(timeStr, keystroke)
keystrokes.append({"time": datetime_obj, "keystroke": keystroke})
except Exception as e:
print(f"Error {keystroke}: {e}")
Returns something like:
20240222 18:46:26 d
20240222 18:46:26 e
20240222 18:46:26 t
20240222 18:46:26 a
20240222 18:46:26 i
20240222 18:46:26 l
In [65]:
import pandas as pd
df = pd.DataFrame(keystrokes)
In [70]:
import seaborn as sns
# Extract the day of the week from the 'endDate' column
df["hour_of_day"] = df["time"].dt.hour
df.keys()
# Plot the average heart rate by day of the week
sns.set(rc={"figure.figsize": (10, 11)})
sns.barplot(x="hour_of_day", y="keystroke", data=df)
Out[70]:
<Axes: xlabel='hour_of_day', ylabel='keystroke'>
In [72]:
df["formatted_date"] = df["time"].dt.strftime("%Y-%m-%d %H:%M:00")
df["rows_count"] = df.groupby("formatted_date")["formatted_date"].transform("count")
date_time = pd.to_datetime(df.pop("time"), format="%Y-%m-%d %H:%M:00")
In [77]:
plot_cols = ["formatted_date", "rows_count"]
plot_features = df[plot_cols][12000:]
plot_features.index = date_time[12000:]
_ = plot_features.plot(subplots=True, figsize=(30, 3))