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' %} + + + + + {% elif accmmodation_option == 'yes-longtraffic' %} + + + + + {% endif %} + {% endfor %} + +
住宿選項人數
需要住宿{{ count }}
需要住宿,且通勤時間大於一小時{{ count }}
+
diff --git a/view/project.py b/view/project.py index a394d3c..8c5578c 100644 --- a/view/project.py +++ b/view/project.py @@ -514,11 +514,13 @@ def project_statictics(pid: str) -> str | ResponseBase: habit_statistics = User.get_dietary_habit_statistics(uids=list(all_users)) clothes_statistics = Form.get_clothes_statistics(pid=pid) + accommodation_statictics = FormAccommodation.get_statistics(pid=pid) return render_template('./project_statistics.html', project=project.dict(by_alias=True), habit_statistics=habit_statistics, clothes_statistics=clothes_statistics, + accommodation_statictics=accommodation_statictics, editable=editable)