[mod-perdu] Voilà tout ce que j'ai
This commit is contained in:
parent
59f58df037
commit
c6868d7977
11
Pipfile
11
Pipfile
@ -1,26 +1,19 @@
|
|||||||
[[source]]
|
[[source]]
|
||||||
|
|
||||||
url = "https://pypi.org/simple"
|
url = "https://pypi.org/simple"
|
||||||
verify_ssl = true
|
verify_ssl = true
|
||||||
name = "pypi"
|
name = "pypi"
|
||||||
|
|
||||||
|
|
||||||
[packages]
|
[packages]
|
||||||
|
|
||||||
packaging = "*"
|
packaging = "*"
|
||||||
aiohttp = "*"
|
aiohttp = "*"
|
||||||
aiofiles = "*"
|
aiofiles = "*"
|
||||||
lupa = "*"
|
lupa = "*"
|
||||||
aiofile = "*"
|
aiofile = "*"
|
||||||
toml = "*"
|
toml = "*"
|
||||||
"discord.py" = {version = "*", extras = ["voice",]}
|
"discord.py" = {version = "*",extras = ["voice",]}
|
||||||
|
matplotlib = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
|
|
||||||
python_version = "3.7"
|
python_version = "3.7"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
import matplotlib.pyplot as np
|
||||||
|
|
||||||
import utils.emojis
|
import utils.emojis
|
||||||
from modules.base import BaseClassPython
|
from modules.base import BaseClassPython
|
||||||
@ -14,7 +16,8 @@ class MainClass(BaseClassPython):
|
|||||||
"`{prefix}{command}`": "Donne le classement des perdants de la semaine",
|
"`{prefix}{command}`": "Donne le classement des perdants de la semaine",
|
||||||
"`{prefix}{command} all`": "Donne le classement des perdants depuis toujours",
|
"`{prefix}{command} all`": "Donne le classement des perdants depuis toujours",
|
||||||
"`{prefix}{command} <nombre de jours>`": "Donne le classement des perdants sur la durée spécifiée",
|
"`{prefix}{command} <nombre de jours>`": "Donne le classement des perdants sur la durée spécifiée",
|
||||||
"`{prefix}{command} stats [@mention]`": "Donne les statistiques d'un perdant",
|
"`{prefix}{command} stats [@mention]`": "Donne les statistiques d'un perdant.",
|
||||||
|
"`{prefix}{command} stats history": "Affiche un graphique avec le nombre de pertes."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
help_active = True
|
help_active = True
|
||||||
@ -55,17 +58,33 @@ class MainClass(BaseClassPython):
|
|||||||
if delta.total_seconds() >= self.config.min_delta:
|
if delta.total_seconds() >= self.config.min_delta:
|
||||||
self.history[message.author.id].append((message.created_at, delta))
|
self.history[message.author.id].append((message.created_at, delta))
|
||||||
|
|
||||||
def get_top(self, top=10, since=datetime.datetime(year=1, month=1, day=1)):
|
def get_top(self, top=10, since=datetime.datetime(year=1, month=1, day=1), with_user=None, only_users=None):
|
||||||
"""Return [(userid, [(date, delta), (date,delta), ...]), ... ]"""
|
"""Return [(userid, [(date, delta), (date,delta), ...]), ... ]"""
|
||||||
# Extract only messages after until
|
# Extract only messages after until
|
||||||
|
if only_users is not None:
|
||||||
|
# Extract data for only_users
|
||||||
|
messages = []
|
||||||
|
for user in only_users:
|
||||||
|
try:
|
||||||
|
if self.history[user][-1][0] > since:
|
||||||
|
messages.append((user, [message for message in self.history[user] if message[0] > since]))
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
messages.sort(key=lambda x: len(x[1]), reverse=True)
|
||||||
|
return messages
|
||||||
|
if with_user is None:
|
||||||
|
with_user = []
|
||||||
|
# Extract TOP top users, and with_users data
|
||||||
messages = []
|
messages = []
|
||||||
for user in self.history.keys():
|
for user in self.history.keys():
|
||||||
if self.history[user][-1][0] > since:
|
if self.history[user][-1][0] > since:
|
||||||
messages.append((user, [message for message in self.history[user] if message[0] > since]))
|
messages.append((user, [message for message in self.history[user] if message[0] > since]))
|
||||||
messages.sort(key=lambda x: len(x[1]), reverse=True)
|
messages.sort(key=lambda x: len(x[1]), reverse=True)
|
||||||
# Extract top-ten
|
# Extract top-ten
|
||||||
messages = messages[:min(top, len(messages))]
|
saved_messages = messages[:min(top, len(messages))]
|
||||||
return messages
|
# Add with_user
|
||||||
|
saved_messages.extend([message for message in messages if message[0] in with_user])
|
||||||
|
return saved_messages
|
||||||
|
|
||||||
async def com_fill(self, message: discord.Message, args, kwargs):
|
async def com_fill(self, message: discord.Message, args, kwargs):
|
||||||
if await self.auth(message.author):
|
if await self.auth(message.author):
|
||||||
@ -86,7 +105,66 @@ class MainClass(BaseClassPython):
|
|||||||
color=self.color))
|
color=self.color))
|
||||||
|
|
||||||
async def com_stats(self, message: discord.Message, args, kwargs):
|
async def com_stats(self, message: discord.Message, args, kwargs):
|
||||||
pass
|
if "sum" in args:
|
||||||
|
if message.mentions:
|
||||||
|
top = self.get_top(only_users=[mention.id for mention in message.mentions] + [message.author.id])
|
||||||
|
else:
|
||||||
|
# TOP 5 + auteur
|
||||||
|
top = self.get_top(top=5, with_user=[message.author.id])
|
||||||
|
dates = []
|
||||||
|
new_top = {}
|
||||||
|
for t in top:
|
||||||
|
for date, _ in t[1]:
|
||||||
|
dates.append(date)
|
||||||
|
dates.sort()
|
||||||
|
dates.append(datetime.datetime.today() + datetime.timedelta(days=1))
|
||||||
|
for t in top:
|
||||||
|
user = t[0]
|
||||||
|
new_top.update({user: ([dates[0]], [0])})
|
||||||
|
i = 0
|
||||||
|
for date, _ in t[1]:
|
||||||
|
while date < dates[i]:
|
||||||
|
new_top[user][0].append(dates[i])
|
||||||
|
new_top[user][1].append(new_top[user][1][-1])
|
||||||
|
i += 1
|
||||||
|
new_top[user][0].append(date)
|
||||||
|
new_top[user][1].append(new_top[user][1][-1] + 1)
|
||||||
|
|
||||||
|
to_plot = [t[1][1:] for t in new_top.values()]
|
||||||
|
np.stackplot(dates, *to_plot)
|
||||||
|
np.xlabel("Temps", fontsize=30)
|
||||||
|
np.ylabel("Score", fontsize=30)
|
||||||
|
np.title("Évolution du nombre de perdu au cours du temps.", fontsize=40)
|
||||||
|
file_name = f"/tmp/{time.time()}.png"
|
||||||
|
np.savefig(file_name, bbox_inches='tight')
|
||||||
|
await message.channel.send(file=discord.File(file_name))
|
||||||
|
|
||||||
|
if "history" in args:
|
||||||
|
# Si mention, alors uniquement les mentions
|
||||||
|
if message.mentions:
|
||||||
|
top = self.get_top(only_users=[mention.id for mention in message.mentions] + [message.author.id])
|
||||||
|
else:
|
||||||
|
# TOP 5 + auteur
|
||||||
|
top = self.get_top(top=5, with_user=[message.author.id])
|
||||||
|
new_top = {}
|
||||||
|
for t in top:
|
||||||
|
c = 0
|
||||||
|
counts = []
|
||||||
|
dates = []
|
||||||
|
for date, _ in t[1][::-1]:
|
||||||
|
c += 1
|
||||||
|
counts.append(c)
|
||||||
|
dates.append(date)
|
||||||
|
new_top.update({t[0]: (dates, counts)})
|
||||||
|
np.figure(num=None, figsize=(25, 15), dpi=120, facecolor='w', edgecolor='k')
|
||||||
|
for user, (dates, counts) in new_top.items():
|
||||||
|
np.plot_date(dates, counts, linestyle='-')
|
||||||
|
np.xlabel("Temps", fontsize=30)
|
||||||
|
np.ylabel("Score", fontsize=30)
|
||||||
|
np.title("Évolution du nombre de perdu au cours du temps.", fontsize=40)
|
||||||
|
file_name = f"/tmp/{time.time()}.png"
|
||||||
|
np.savefig(file_name, bbox_inches='tight')
|
||||||
|
await message.channel.send(file=discord.File(file_name))
|
||||||
|
|
||||||
async def command(self, message, args, kwargs):
|
async def command(self, message, args, kwargs):
|
||||||
if message.mentions:
|
if message.mentions:
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
NUMBERS = ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣", "🔟"]
|
NUMBERS = ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣", "🔟"]
|
||||||
|
|
||||||
|
THUMBS_UP = "👍"
|
||||||
|
THUMBS_DOWN = "👎"
|
||||||
|
|
||||||
|
|
||||||
def write_with_number(i):
|
def write_with_number(i):
|
||||||
raw = str(i)
|
raw = str(i)
|
||||||
|
Loading…
Reference in New Issue
Block a user