Keystorke Dynamics¶
Typing Speed¶
- typing_speed(df=None, traces=None, per_traces=True)¶
Calculate the average typing speed in characters per minute (CPM).
- Parameters:
df (pd.DataFrame) – DataFrame containing interaction data with ‘event_type’, ‘timestamp’, and ‘key’ columns.
traces (dict[str, list[pd.DataFrame]]) – optional Pre-extracted keystroke traces by session.
per_traces (bool) – optional Whether to calculate speed per trace. Default is True. if False, mind that the df must only contain typing data in order to obtain the correct CPM calculation.
- Returns:
A dictionary with session IDs as keys and lists of typing speeds (CPM) per trace as values, or a float representing the typing speed if per_traces is False.
- Return type:
dict (dict[list[float]] | float)
Practical Example¶
from pywib import typing_speed
speed = typing_speed(data_frame)
for session_id, speed_value in speed.items():
print(f"Session ID: {session_id}")
print(f"Typing Speed (CPM): {speed_value}")
Notes¶
CPM stands for Characters Per Minute, and it is calculated by taking the total number of keystrokes (characters typed) and dividing it by the total time taken (in minutes) to type those characters.
The method can be either run with either per_traces=True or per_traces=False, the first one segments the data by groups of keystroke events, while the second one computes the speed for the entire DataFrame without pauses into consideration.
This is important to consider for the specific given dataset, if the data contains anything else than keystroke data, then per_traces=True should be used to avoid incorrect CPM calculations. Whereas a dataset of consecutive keystroke events can be processed with per_traces=False to obtain a single CPM.
Backspace Usage¶
- backspace_usage(df=None, traces=None, per_trace=True)¶
Calculate the backspace usage rate (backspaces per 100 characters typed) for each session.
- Parameters:
df (pd.DataFrame) – DataFrame containing interaction data with ‘event_type’, ‘timestamp’, and ‘key’ columns.
traces (dict[str, list[pd.DataFrame]]) – optional Pre-extracted keystroke traces by session.
per_trace (bool) – optional Whether to calculate usage per trace. Default is True.
- Returns:
A dictionary with session IDs as keys and their corresponding backspace counts as values.
- Return type:
dict
Practical Example¶
from pywib import backspace_usage
backspace_counts = backspace_usage(data_frame)
for session_id, count in backspace_counts.items():
print(f"Session ID: {session_id}")
print(f"Backspace Usage: {count}")