Acceleration¶
- acceleration(df=None, traces=None, per_traces=True)¶
Wrapper function to calculate acceleration for either a single DataFrame or a traces dictionary.
If traces is None, they will be computed from the DataFrame.
- Return type:
dict[str,list[DataFrame]]
Practical Example¶
from pywib import acceleration, velocity, compute_space_time_diff
df = compute_space_time_diff(df_data)
acceleration_traces = acceleration(None, velocity(df, per_traces=True), per_traces=True)
for _, traces in acceleration_traces.items():
for trace in traces:
print(trace['acceleration'])
Notes¶
The method can be either run with either per_traces=True or per_traces=False, the first one segments the data by movement traces, while the second one computes the acceleration for the entire DataFrame.
This is important to consider for the specific given dataset, if the data contains anything else than movement data, then per_traces=True should be used to avoid incorrect acceleration calculations. Whereas a dataset of consecutive movement events can be processed with per_traces=False to obtain a single acceleration DataFrame.
Acceleration Metrics¶
- acceleration_metrics(df, traces=None)¶
Calculate acceleration metrics for the given DataFrame or traces. This function computes the mean, max, and min acceleration for each session.
- Parameters:
df (pd.DataFrame) – DataFrame containing interaction data. Optionally already including ‘acceleration’ column.
traces (dict) – A dictionary with keys as (sessionId) and values as lists of DataFrames. If None, traces will be computed from df.
- Returns:
A dictionary with keys as (sessionId) and values as dictionaries with ‘mean’, ‘max’, and ‘min’ acceleration.
- Return type:
dict
Practical Example¶
from pywib import acceleration_metrics
acc_metrics = acceleration_metrics(data_df)
for _, session in acc_metrics.items():
print(f"Session Acceleration Metrics:")
print(f" Mean Acceleration: {session['mean']}")
print(f" Max Acceleration: {session['max']}")
print(f" Min Acceleration: {session['min']}")