Created
April 23, 2020 20:13
-
-
Save aryamanarora/1aba180326e4d05bfd7c40a046398b9f to your computer and use it in GitHub Desktop.
A chart for a Discord server's cumulative messages per user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import matplotlib.pyplot as plt | |
from matplotlib import colors | |
from matplotlib.ticker import PercentFormatter | |
import matplotlib.dates as mdates | |
import datetime | |
from collections import Counter, defaultdict | |
import glob, os | |
hist = defaultdict(Counter) | |
for file in glob.glob('SWW*'): | |
with open(file) as fin: | |
csv_reader = csv.reader(fin, delimiter=',') | |
for i, row in enumerate(csv_reader): | |
if i > 0: | |
d = datetime.datetime.strptime(row[2], '%d-%b-%y %I:%M %p') | |
d = d.replace(minute=0) | |
if True: | |
hist[row[1]][d] += 1 | |
summ = Counter() | |
for user in hist: | |
start_date = datetime.datetime(2019, 9, 1, 0, 0) | |
end_date = datetime.datetime.today() | |
while start_date <= end_date: | |
hist[user][start_date] += hist[user][start_date - datetime.timedelta(hours=1)] | |
summ[start_date] += hist[user][start_date] | |
start_date += datetime.timedelta(hours=1) | |
for user in hist: | |
for date in hist[user]: | |
if summ[date] != 0: | |
# hist[user][date] /= summ[date] | |
pass | |
data = sorted(hist[user].items()) | |
x, y = zip(*data) | |
plt.plot(x, y) | |
plt.text(end_date + datetime.timedelta(days=2), hist[user][start_date - datetime.timedelta(hours=1)], user) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment