commit 5ed6248886e9e72e57dee1e6a0634b60525d8d8a Author: Sven Geboers Date: Wed Mar 22 13:41:04 2023 +0100 extended readme diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b114dd --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Coffee statistics +This script calculates some statistics about the number of times coffee was being made in my student house. In essence, it is reading out a database that reads out a telegram chat where the word "Coffee" is being send by a bot when a button is pushed. + + diff --git a/main.py b/main.py new file mode 100644 index 0000000..10ab11c --- /dev/null +++ b/main.py @@ -0,0 +1,46 @@ +import telegram_send +from sqlalchemy import create_engine, text +import pandas as pd +import datetime as dt +import matplotlib.pyplot as plt + +# Get the relevant data +engine = create_engine('sqlite:///history/data.sqlite') +query = 'SELECT * FROM messages' +data = pd.read_sql_query(sql=text(query), con=engine.connect()) + +data = data[data['content']=='Coffee'] +grand_total = len(data) + +data['datetime'] = pd.to_datetime(data['date']) + +# Calculate weekdays and hours +data['weekday'] = data['datetime'].dt.dayofweek +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) +plt.savefig('files/monthly_weekdays.png') +plt.close() + +monthly['hour'].plot.hist(bins=24) +plt.savefig('files/monthly_hour.png') +plt.close() + +data['weekday'].plot.hist(bins=7) +plt.savefig('files/all_weekdays.png') +plt.close() + +data['hour'].plot.hist(bins=24) +plt.savefig('files/all_hour.png') +plt.close() + +# Calculate on which day the most coffee was made +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]) diff --git a/main.sh b/main.sh new file mode 100755 index 0000000..80a8089 --- /dev/null +++ b/main.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd ~/coffeestatistics +. env/bin/activate +cd code +python main.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8500bd7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,18 @@ +cffi==1.15.1 +cryptg==0.2.post2 +feedgen==0.9.0 +Jinja2==3.1.2 +lxml==4.9.2 +MarkupSafe==2.1.2 +Pillow==9.4.0 +pyaes==1.6.1 +pyasn1==0.4.8 +pycparser==2.21 +python-dateutil==2.8.2 +python-magic==0.4.27 +pytz==2022.7.1 +PyYAML==6.0 +rsa==4.9 +six==1.16.0 +Telethon==1.24.0 +tg-archive==1.1.2 diff --git a/sync.sh b/sync.sh new file mode 100755 index 0000000..2ed8115 --- /dev/null +++ b/sync.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd ~/coffeestatistics +. env/bin/activate +cd code/history +tg-archive --sync