Skip to content

Commit 430e2f4

Browse files
committed
Adding plot
1 parent 2acf8b4 commit 430e2f4

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

Analytics/graphics.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import matplotlib.pyplot as plt
2+
import pandas as pd
3+
import numpy as np
4+
5+
6+
def create_plot(name:str, guild_id:str):
7+
df = pd.read_csv(f"./src/csv/{guild_id}_{name}.csv")
8+
df["timestamp"] = pd.to_datetime(df["timestamp"])
9+
df["hours"] = df["timestamp"].dt.hour
10+
name_count = pd.value_counts(df["hours"])
11+
get_x = dict(name_count).keys()
12+
get_y = dict(name_count).values()
13+
x = [*get_x]
14+
y = [*get_y]
15+
plt.bar(np.array(x), np.array(y))
16+
plt.yticks(np.arange(min(y), max(y)+1, 2.0))
17+
plt.xticks(np.arange(min(x), max(x)+1, 1.0))
18+
plt.xlabel("Hours")
19+
plt.ylabel(f"{name}-Count")
20+
plt.title(f"{name} ~ Plot")
21+
22+
plt.savefig(f"./src/img/{guild_id}_{name}.png")
23+
plt.close()

cogs/plot.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from Analytics.graphics import create_plot
2+
from discord.ext import commands
3+
import discord
4+
from dataminer import bot_requests
5+
6+
class Plot(commands.Cog):
7+
def __init__(self, bot):
8+
self.bot = bot
9+
10+
@commands.is_owner()
11+
@commands.cooldown(1, 10.0, commands.BucketType.user)
12+
@commands.group(name="plot")
13+
async def _plot(self, ctx):
14+
return
15+
16+
@commands.is_owner()
17+
@commands.cooldown(1, 10.0, commands.BucketType.user)
18+
@_plot.command(name="message")
19+
async def _plot_message(self, ctx):
20+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
21+
create_plot("message", str(ctx.guild.id))
22+
img = discord.File(f"./src/img/{str(ctx.guild.id)}_message.png")
23+
return await ctx.send(file=img)
24+
25+
@commands.is_owner()
26+
@commands.cooldown(1, 10.0, commands.BucketType.user)
27+
@_plot.command(name="reaction")
28+
async def _plot_reaction(self, ctx):
29+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
30+
create_plot("reaction", str(ctx.guild.id))
31+
img = discord.File(f"./src/img/{str(ctx.guild.id)}_reaction.png")
32+
return await ctx.send(file=img)
33+
34+
@commands.is_owner()
35+
@commands.cooldown(1, 10.0, commands.BucketType.user)
36+
@_plot.command(name="botrequest", aliases=["bot_request", "bot-requests"])
37+
async def _plot_botrequests(self, ctx):
38+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
39+
create_plot("bot_requests",str(ctx.guild.id))
40+
img = discord.File(f"./src/img/{str(ctx.guild.id)}_bot_requests.png")
41+
return await ctx.send(file=img)
42+
43+
@commands.is_owner()
44+
@commands.cooldown(1, 10.0, commands.BucketType.user)
45+
@_plot.command(name="userjoins", aliases=["userjoin"])
46+
async def _plot_userjoins(self, ctx):
47+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
48+
create_plot("userjoin", str(ctx.guild.id))
49+
img = discord.File(f"./src/img/{str(ctx.guild.id)}_userjoins.png")
50+
return await ctx.send(file=img)
51+
52+
@commands.is_owner()
53+
@commands.cooldown(1, 10.0, commands.BucketType.user)
54+
@_plot.command(name="userleaves", aliases=["userleave"])
55+
async def _plot_userleaves(self, ctx):
56+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
57+
create_plot("userleave", str(ctx.guild.id))
58+
img = discord.File(f"./src/img/{str(ctx.guild.id)}_userleave.png")
59+
return await ctx.send(file=img)
60+
61+
@commands.is_owner()
62+
@commands.cooldown(1, 10.0, commands.BucketType.user)
63+
@_plot.command(name="mentions", aliases=["mention"])
64+
async def _plot_mentions(self, ctx):
65+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
66+
create_plot("mentions", str(ctx.guild.id))
67+
img = discord.File(f"./src/img/{str(ctx.guild.id)}_mentions.png")
68+
return await ctx.send(file=img)
69+
70+
@commands.is_owner()
71+
@commands.cooldown(1, 10.0, commands.BucketType.user)
72+
@_plot.command(name="botmsg", aliases=["bot_msg", "bot-msg"])
73+
async def _plot_botmsg(self, ctx):
74+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
75+
create_plot("bot_msg", str(ctx.guild.id))
76+
img = discord.File(f"./src/img/{str(ctx.guild.id)}_bot_msg.png")
77+
return await ctx.send(file=img)
78+
79+
def setup(bot):
80+
bot.add_cog(Plot(bot))

src/csv/example.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
msgid,timestamp,roles,channelid

src/img/example.png

19.1 KB
Loading

0 commit comments

Comments
 (0)