diff --git a/module/form.py b/module/form.py index 21a93bc..5a9d2dd 100644 --- a/module/form.py +++ b/module/form.py @@ -450,6 +450,19 @@ def get(pid: str) -> Generator[dict[str, Any], None, None]: ''' yield from FormDB().find({'case': 'accommodation', 'pid': pid, 'data.key': {'$ne': 'no'}}) + @staticmethod + def get_statistics(pid: str) -> dict[str, int]: + ''' Get accommodation statistics by given pid ''' + result = { + 'yes': 0, + 'yes-longtraffic': 0, + } + + for form in FormAccommodation.get(pid=pid): + result[form['data']['key']] += 1 + + return result + @staticmethod def update_room(pid: str, uid: str, room: str, change_key: bool = True) -> dict[str, Any]: ''' Update room no diff --git a/templates/project_statistics.html b/templates/project_statistics.html index d47122c..c1a9235 100644 --- a/templates/project_statistics.html +++ b/templates/project_statistics.html @@ -61,6 +61,30 @@
住宿選項 | +人數 | + + + {% for accmmodation_option, count in accommodation_statictics.items() %} + {% if accmmodation_option == 'yes' %} +
---|---|
需要住宿 | +{{ count }} | +
需要住宿,且通勤時間大於一小時 | +{{ count }} | +