51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
![]() |
import pandas as pd
|
||
|
import matplotlib.pyplot as plt
|
||
|
import seaborn as sns
|
||
|
from .basePlotAnalysis import BasePlotAnalysis
|
||
|
from flask import current_app, url_for
|
||
|
|
||
|
import matplotlib
|
||
|
matplotlib.use('Agg')
|
||
|
|
||
|
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.
|
||
|
|
||
|
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.
|
||
|
|
||
|
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))
|
||
|
plt.xticks(rotation=90)
|
||
|
plt.title('Minutes Active')
|
||
|
plt.xlabel('Player')
|
||
|
plt.ylabel('Active Count')
|