adds docstrings

This commit is contained in:
2025-02-10 02:28:50 +01:00
parent e57869374b
commit 595237c172
9 changed files with 225 additions and 22 deletions

View File

@@ -7,13 +7,30 @@ import matplotlib
matplotlib.use('Agg')
class PlotActivityHeatmap(BasePlotAnalysis):
"""
Class for analyzing user activity trends over multiple days and generating a heatmap.
Attributes:
name (str): The name of the analysis.
description (str): A brief description of the analysis.
plot_filename (str): The filename for the output plot.
note (str): Additional notes for the analysis.
"""
name = "Activity Heatmap"
description = "Displays user activity trends over multiple days using a heatmap. Generates a downloadable PNG image."
plot_filename = "activity_heatmap.png"
note = ""
def transform_data(self, df: pd.DataFrame) -> pd.DataFrame:
"""Transform data for the heatmap"""
"""
Transform data for the heatmap.
Parameters:
df (pd.DataFrame): The input DataFrame containing user activity data.
Returns:
pd.DataFrame: The transformed DataFrame with activity counts by hour.
"""
active_counts = df[df['was_active']].pivot_table(
index='name',
columns='hour',
@@ -25,7 +42,12 @@ class PlotActivityHeatmap(BasePlotAnalysis):
return active_counts.sort_values(by='total_active_minutes', ascending=False)
def plot_data(self, df: pd.DataFrame):
"""Generate heatmap plot"""
"""
Generate heatmap plot.
Parameters:
df (pd.DataFrame): The transformed DataFrame containing activity counts by hour.
"""
plt.figure(figsize=(12, 8))
sns.heatmap(df.loc[:, df.columns != 'total_active_minutes'], cmap='viridis', cbar_kws={'label': 'Count of was_active == True'})
plt.xlabel('Hour of Day')