adds docstrings
This commit is contained in:
@@ -9,13 +9,30 @@ from app.logging_config import get_logger
|
||||
logger = get_logger()
|
||||
|
||||
class PlotlyLineActivityAllUsers(BasePlotlyAnalysis):
|
||||
"""
|
||||
Class for analyzing user activity trends over multiple days and generating an interactive line graph.
|
||||
|
||||
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 Line Graph (All Users, Interactive)"
|
||||
description = "This analysis shows the activity line graph for all users. The graph is interactive and can be used to explore the data."
|
||||
plot_filename = "line_activity-all_users.html"
|
||||
note = ""
|
||||
|
||||
def transform_data(self, df: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Transform data for the line plot"""
|
||||
"""
|
||||
Transform data for the line plot.
|
||||
|
||||
Parameters:
|
||||
df (pd.DataFrame): The input DataFrame containing user activity data.
|
||||
|
||||
Returns:
|
||||
pd.DataFrame: The transformed DataFrame with activity counts by hour.
|
||||
"""
|
||||
df['hour'] = df['timestamp'].dt.hour
|
||||
df = df[df['was_active'] == True].pivot_table(index='name', columns='hour', values='was_active', aggfunc='sum', fill_value=0)
|
||||
df['total_active_minutes'] = df.sum(axis=1)
|
||||
@@ -27,7 +44,12 @@ class PlotlyLineActivityAllUsers(BasePlotlyAnalysis):
|
||||
return df
|
||||
|
||||
def plot_data(self, df: pd.DataFrame):
|
||||
# Create a Plotly figure
|
||||
"""
|
||||
Generate interactive line graph for user activity throughout the day.
|
||||
|
||||
Parameters:
|
||||
df (pd.DataFrame): The transformed DataFrame containing activity counts by hour.
|
||||
"""
|
||||
self.fig = make_subplots()
|
||||
|
||||
# Plot each user's activity
|
||||
@@ -37,7 +59,6 @@ class PlotlyLineActivityAllUsers(BasePlotlyAnalysis):
|
||||
else:
|
||||
self.fig.add_trace(go.Scatter(x=row.index, y=row.values, mode='lines', name=index))
|
||||
|
||||
# Update layout
|
||||
self.fig.update_layout(
|
||||
title='User Activity Throughout the Day',
|
||||
xaxis_title='Hour of Day',
|
||||
|
||||
Reference in New Issue
Block a user