adds docstrings
This commit is contained in:
@@ -3,6 +3,20 @@ import os
|
||||
import pandas as pd
|
||||
|
||||
def prepare_data(df):
|
||||
"""
|
||||
Prepares the data for analysis by converting timestamps, calculating previous timestamps,
|
||||
determining active status, and extracting the hour from the timestamp.
|
||||
|
||||
Parameters:
|
||||
df (pd.DataFrame): The input DataFrame containing user activity data.
|
||||
|
||||
Returns:
|
||||
pd.DataFrame: The processed DataFrame with additional columns for analysis.
|
||||
|
||||
The returned DataFrame will have the following columns:
|
||||
user_id name last_action status timestamp prev_timestamp was_active hour
|
||||
0 12345678 UserName 2025-02-08 17:58:11 Okay 2025-02-08 18:09:41.867984056 NaT False 18
|
||||
"""
|
||||
df["timestamp"] = pd.to_datetime(df["timestamp"])
|
||||
df["last_action"] = pd.to_datetime(df["last_action"])
|
||||
df["prev_timestamp"] = df.groupby("user_id")["timestamp"].shift(1)
|
||||
@@ -12,6 +26,15 @@ def prepare_data(df):
|
||||
return df
|
||||
|
||||
def mk_plotdir(output_filename):
|
||||
"""
|
||||
Creates the directory for storing plots and generates the output path and URL for the plot.
|
||||
|
||||
Parameters:
|
||||
output_filename (str): The filename for the output plot.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the output path and plot URL.
|
||||
"""
|
||||
plots_dir = os.path.join(current_app.root_path, "static", "plots")
|
||||
os.makedirs(plots_dir, exist_ok=True)
|
||||
|
||||
@@ -19,4 +42,4 @@ def mk_plotdir(output_filename):
|
||||
|
||||
plot_url = url_for('static', filename=f'plots/{output_filename}', _external=True)
|
||||
|
||||
return {'output_path': output_path, 'plot_url': plot_url}
|
||||
return {'output_path': output_path, 'plot_url': plot_url}
|
||||
Reference in New Issue
Block a user