updated to bar charts, as well as extending the scripts so that they can run fully automatically

This commit is contained in:
2023-03-25 17:46:54 +01:00
parent cd04402529
commit 16fc7cd4e1
2 changed files with 22 additions and 8 deletions
+19 -8
View File
@@ -1,4 +1,3 @@
import telegram_send
from sqlalchemy import create_engine, text from sqlalchemy import create_engine, text
import pandas as pd import pandas as pd
import datetime as dt import datetime as dt
@@ -15,26 +14,36 @@ grand_total = len(data)
data['datetime'] = pd.to_datetime(data['date']) data['datetime'] = pd.to_datetime(data['date'])
# Calculate weekdays and hours # Calculate weekdays and hours
data['weekday'] = data['datetime'].dt.dayofweek data['weekday'] = data['datetime'].dt.dayofweek + 1
data['hour'] = data['datetime'].dt.hour data['hour'] = data['datetime'].dt.hour
data['day'] = data['datetime'].dt.day data['day'] = data['datetime'].dt.day
lastmonth = (dt.datetime.now().month - 1) % 12 lastmonth = (dt.datetime.now().month - 1) % 12
monthly = data[data['datetime'].dt.month == lastmonth].copy() monthly = data[data['datetime'].dt.month == lastmonth].copy()
# Make plots # Make plots, first for monthly, then for all time
monthly['weekday'].plot.hist(bins=7) 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.savefig('files/monthly_weekdays.png')
plt.close() 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.savefig('files/monthly_hour.png')
plt.close() 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.savefig('files/all_weekdays.png')
plt.close() 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.savefig('files/all_hour.png')
plt.close() plt.close()
@@ -43,4 +52,6 @@ monthly['count'] = 1
aggregated = monthly.groupby(['day']).count()['count'] 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) 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()
+3
View File
@@ -2,4 +2,7 @@
cd ~/coffeestatistics cd ~/coffeestatistics
. env/bin/activate . env/bin/activate
cd code cd code
./sync.sh
python main.py python main.py
telegram-send --image files/*
cat message.txt | telegram-send --stdin