33 lines
1.1 KiB
Python
33 lines
1.1 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
|
|
|
|
from app.logging_config import get_logger
|
|
|
|
import matplotlib
|
|
matplotlib.use('Agg')
|
|
|
|
logger = get_logger()
|
|
|
|
class PlotTopActiveUsers(BasePlotAnalysis):
|
|
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"""
|
|
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"""
|
|
# 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') |