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>
28 lines
914 B
Python
28 lines
914 B
Python
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
|