This commit is contained in:
NovaOSS Admins 2023-10-15 22:51:43 +00:00
parent b068225c72
commit a1543f9a4f
3 changed files with 32 additions and 5 deletions

7
requirements.txt Normal file
View file

@ -0,0 +1,7 @@
flask
pandas
cherrypy
requests
werkzeug
python-dotenv
requests-oauthlib

View file

@ -36,17 +36,37 @@ def register(app):
donations = data['donations'] donations = data['donations']
expenses = data['expenses'] expenses = data['expenses']
try:
avg = round(sum([i['amount_usd'] for i in donations]) / len(donations), 2)
except ZeroDivisionError:
avg = 0
try:
most_donation = max(donations, key=lambda x: x['amount_usd'])['currency']
except ValueError:
most_donation = '?'
try:
most_expense = max(expenses, key=lambda x: x['amount_usd'])['currency']
except ValueError:
most_expense = '?'
try:
donations_max = round(max([i['amount_usd'] for i in donations]))
except ValueError:
donations_max = 0
finances = { finances = {
'last_update': data['timestamp'], 'last_update': data['timestamp'],
'donations_total': round(sum([i['amount_usd'] for i in donations])), 'donations_total': round(sum([i['amount_usd'] for i in donations])),
'donations_num': len(donations), 'donations_num': len(donations),
'donations_avg': round(sum([i['amount_usd'] for i in donations]) / len(donations), 2), 'donations_avg': avg,
'donations_max': round(max([i['amount_usd'] for i in donations])), 'donations_max': donations_max,
'most_used_donation_currency': max(donations, key=lambda x: x['amount_usd'])['currency'], 'most_used_donation_currency': most_donation,
'expenses_total': round(sum([i['amount_usd'] for i in expenses])), 'expenses_total': round(sum([i['amount_usd'] for i in expenses])),
'expenses_wages': round(sum([i['amount_usd'] for i in expenses if i['type'] == 'wage'])), 'expenses_wages': round(sum([i['amount_usd'] for i in expenses if i['type'] == 'wage'])),
'most_used_expense_currency': max(expenses, key=lambda x: x['amount_usd'])['currency'], 'most_used_expense_currency': most_expense,
} }
transaction_table = [] transaction_table = []

View file

@ -19,8 +19,8 @@ def register(app):
emoji = random.choice(open('config/emojis.txt', encoding='utf8').read()) emoji = random.choice(open('config/emojis.txt', encoding='utf8').read())
if not os.path.exists('data/tos.json'): if not os.path.exists('data/tos.json'):
os.makedirs('data', exist_ok=True)
open('data/tos.json', 'w', encoding='utf8').write('{}') open('data/tos.json', 'w', encoding='utf8').write('{}')
try: try:
data = ujson.load(open('data/tos.json', encoding='utf8')) data = ujson.load(open('data/tos.json', encoding='utf8'))
except JSONDecodeError: except JSONDecodeError: