Distance¶
- path(df=None, traces=None, per_traces=True)¶
Calculate the path length between the points of the sessions trajectories for the given DataFrame. Returns them in a DataFrame or in a dictionary (if per traces) with a “distance” column..
The trajectory is only based on movement events. This function computes the path length based on the Euclidean distance between consecutive points.
- Parameters:
df (pd.DataFrame) – DataFrame containing ‘x’ and ‘y’ columns.
traces (dict) – A dictionary with keys as (sessionId) and values as lists of DataFrames. If None, traces will be computed from df.
- Returns:
If not per traces, returns the DataFrame with the “distance” column dict[str, list[pd.DataFrame]]: If per traces, returns a dictionary with keys as (sessionId) and values as lists of DataFrames with the “distance” column
- Return type:
pd.DataFrame
- total_distance(df=None, traces=None, per_user=False, per_traces=True)¶
Calculate the total distance of the sessions trajectory and return it as a float or as a dictonary of float values per session.
This method can compute the total distance in three different ways: - per_traces:True by default. Computes the path length of each trace and then adds all their values up. This renders a different result than a computation without traces. TODO - per_user: If true, needs per_traces to be false. If set, the DataFrame is first segmented by session and then all movement points are taken into account for the path length. - without traces: The entire DataFrame is filtered only by movement metrics to compute the length of all points.
- Return type:
float|dict[str,float]