import random
import numpy as np
import pandas as pd
import logging
import plotly.express as px
import matplotlib.pyplot as plt
import seaborn as sns
import session_info
logging.basicConfig(
format = '%(message)s',
level=logging.DEBUG,
encoding="utf-8"
)
Conteo de variables
kc_feb_23 = pd.read_json('https://kcreport-1-j9522234.deta.app/kcfeb23', orient='records')
logging.info(f'En total hubieron {kc_feb_23.shape[0]} duelistas con {kc_feb_23["deck"].nunique()} mazos distintos')
Registro de la comunidad
logging.info('Tabla de cuántos usuarios reportaron sus ndmax a los servers')
servers = kc_feb_23.iloc[:, 4:7].astype('int').sum()
comunidad_servers = pd.DataFrame(
{
'Servers': servers.to_dict().keys(),
'Total': servers.to_dict().values(),
}
)
fig = px.bar(comunidad_servers, y='Total', x="Servers", title="Registro de decks con su comunidad", text="Total")
fig.update_layout(showlegend=False)
fig.show()
kc_feb_23["ndmax"] = pd.to_datetime(kc_feb_23["ndmax"], format='%d-%m-%Y')
kc_feb_23['day'] = pd.DatetimeIndex(kc_feb_23['ndmax']).day
dias = (
kc_feb_23.groupby(['day'])['day'].count()
.reset_index(name='Decks'))
fig = px.line(dias, x="day", y="Decks", title="Decks subidos a NDmax por día", text="Decks", template='simple_white')
fig.update_traces(textposition="top center")
fig.show()
Top Decks Ndmax
logging.info('Viendo primero los top 5 mazos más usados')
decks = (
kc_feb_23.groupby(['deck'])['deck'].count()
.reset_index(name='total')
.sort_values('total', ascending=0)
)
decks[0:5]
logging.info('Descomponiendo en base a que skills usaron y armarlo en la gráfica')
decks_top_five = decks['deck'][0:5].tolist()
resume = (
kc_feb_23.groupby(['deck','skill'])['skill'].size()
.reset_index(name='total')
.sort_values('total', ascending=0)
)
topfive = resume[resume['deck'].isin(decks_top_five)].copy()
topfive['deck'] = pd.Categorical(
topfive['deck'], categories=decks_top_five, ordered=True)
topfive['deck'] = topfive['deck'].cat.reorder_categories(
decks_top_five,
ordered=True)
skills = topfive['skill'].unique()
colors = [f'#{random.randint(0, 0xFFFFFF):06x}' for _ in range(len(skills))]
color_map = {skill: color for skill, color in zip(skills, colors)}
fig = px.bar(
topfive, y='deck', x="total", color="skill",
title="Top Decks NdMAX KC CUP Febrero 2023",
color_discrete_map=color_map,
text="total", orientation='h'
)
fig.update_layout(
showlegend=False, title_x=0.5,
xaxis_title="Total de Usuarios", yaxis_title="Mazos",
yaxis={'categoryorder': 'array', 'categoryarray': decks_top_five[::-1]}
)
fig.show()
session_info.show()