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

@@ -12,18 +12,40 @@ matplotlib.use('Agg')
logger = get_logger()
class PlotTopActiveUsers(BasePlotAnalysis):
"""
Class for analyzing the most active users and generating a bar chart.
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 = "Top Active Users"
description = "Displays the most active users based on their number of recorded actions."
plot_filename = "bar_activity-per-user.png"
note = ""
def transform_data(self, df: pd.DataFrame) -> pd.DataFrame:
"""Transform data for the bar plot"""
"""
Transform data for the bar plot.
Parameters:
df (pd.DataFrame): The input DataFrame containing user activity data.
Returns:
pd.DataFrame: The transformed DataFrame with active counts per user.
"""
df = df[df['was_active'] == True].groupby('name').size().reset_index(name='active_count')
return df
def plot_data(self, df: pd.DataFrame):
"""Generate bar plot"""
"""
Generate bar plot.
Parameters:
df (pd.DataFrame): The transformed DataFrame containing active counts per user.
"""
# create a barplot from active counts sorted by active count
plt.figure(figsize=(10, 6))
sns.barplot(x='active_count', y='name', data=df.sort_values('active_count', ascending=False))