updated to bar charts, as well as extending the scripts so that they can run fully automatically
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import telegram_send
|
||||
from sqlalchemy import create_engine, text
|
||||
import pandas as pd
|
||||
import datetime as dt
|
||||
@@ -15,26 +14,36 @@ grand_total = len(data)
|
||||
data['datetime'] = pd.to_datetime(data['date'])
|
||||
|
||||
# Calculate weekdays and hours
|
||||
data['weekday'] = data['datetime'].dt.dayofweek
|
||||
data['weekday'] = data['datetime'].dt.dayofweek + 1
|
||||
data['hour'] = data['datetime'].dt.hour
|
||||
data['day'] = data['datetime'].dt.day
|
||||
lastmonth = (dt.datetime.now().month - 1) % 12
|
||||
monthly = data[data['datetime'].dt.month == lastmonth].copy()
|
||||
|
||||
# Make plots
|
||||
monthly['weekday'].plot.hist(bins=7)
|
||||
# Make plots, first for monthly, then for all time
|
||||
monthly['count'] = 1
|
||||
|
||||
monthly.groupby(['weekday']).count()['count'].plot.bar(x='weekday', align='center')
|
||||
plt.xticks(rotation=0)
|
||||
plt.title('Weekday frequency of last month')
|
||||
plt.savefig('files/monthly_weekdays.png')
|
||||
plt.close()
|
||||
|
||||
monthly['hour'].plot.hist(bins=24)
|
||||
monthly.groupby(['hour']).count()['count'].plot.bar(x='hour', align='center')
|
||||
plt.xticks(rotation=0)
|
||||
plt.title('Hourly frequency of last month')
|
||||
plt.savefig('files/monthly_hour.png')
|
||||
plt.close()
|
||||
|
||||
data['weekday'].plot.hist(bins=7)
|
||||
data['count'] = 1
|
||||
data.groupby(['weekday']).count()['count'].plot.bar(x='weekday', align='center')
|
||||
plt.xticks(rotation=0)
|
||||
plt.title('Weekday frequency of all time')
|
||||
plt.savefig('files/all_weekdays.png')
|
||||
plt.close()
|
||||
|
||||
data['hour'].plot.hist(bins=24)
|
||||
data.groupby(['hour']).count()['count'].plot.bar(x='hour', align='center')
|
||||
plt.title('Hourly frquency of all time')
|
||||
plt.savefig('files/all_hour.png')
|
||||
plt.close()
|
||||
|
||||
@@ -43,4 +52,6 @@ monthly['count'] = 1
|
||||
aggregated = monthly.groupby(['day']).count()['count']
|
||||
message1 = 'Last month, coffee was made {amount} times.'.format(amount=len(monthly)) + ' Most coffee was made on day {day} of the month, with a total amount of {amount} times.'.format(day=aggregated.idxmax(),amount=aggregated.max()) + ' From the start of this chat, a grand total amount of {amount} times coffee was made.'.format(amount=grand_total)
|
||||
|
||||
telegram_send.send(messages=[message1])
|
||||
f = open('message.txt', 'w')
|
||||
f.write(message1)
|
||||
f.close()
|
||||
|
||||
Reference in New Issue
Block a user