adds docstrings
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user