Update Events (#10)

This update restructures the events page code and provides additional functionality.
- Overwrite old entries on re-submission of previously used emails
- Build data and stats caches on launch for use in submission checks and stats regeneration
- Update to form content
- Move stats function to separate utils file

Reviewed-on: ayo/website#10
Co-authored-by: Jimmy Vargo <james@ayo.tokyo>
Co-committed-by: Jimmy Vargo <james@ayo.tokyo>
This commit is contained in:
Jimmy Vargo 2024-05-07 18:59:57 +09:00 committed by james
commit dae67ce653
8 changed files with 128 additions and 53 deletions

28
events/utils.py Normal file
View file

@ -0,0 +1,28 @@
from form_content import FormContent
def get_data_stats(data: dict) -> dict:
summed = {
key: {
'sum': 0,
'total': 0,
'percent': 0
} for key in FormContent.all_keys
}
topic_other = set()
for entry in data.values():
for key, value in dict.items(entry):
if key == 'topic-other' and value is not None:
topic_other |= { value }
if isinstance(value, bool):
_sum = summed[key]['sum'] if key in summed else 0
_sum = _sum + 1 if value is True else _sum
total = summed[key]['total'] + 1 if key in summed else 1
summed[key] = {
'sum': _sum,
'total': total,
'percent': f'{((_sum / total) * 100):.1f}'
}
summed['topic-other'] = list(topic_other)
return summed