extended readme

main
Sven Geboers 2 years ago
commit 5ed6248886
  1. 4
      README.md
  2. 46
      main.py
  3. 5
      main.sh
  4. 18
      requirements.txt
  5. 5
      sync.sh

@ -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.

@ -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])

@ -0,0 +1,5 @@
#!/bin/bash
cd ~/coffeestatistics
. env/bin/activate
cd code
python main.py

@ -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

@ -0,0 +1,5 @@
#!/bin/bash
cd ~/coffeestatistics
. env/bin/activate
cd code/history
tg-archive --sync
Loading…
Cancel
Save