Skip to content

Commit

Permalink
feat: add accmodation statistics information on project page
Browse files Browse the repository at this point in the history
Signed-off-by: orertrr <[email protected]>
  • Loading branch information
orertrr committed Jul 30, 2024
1 parent 8848c22 commit 0e8037d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions module/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions templates/project_statistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ <h4 class="title is-4">衣服尺寸人數分布</h4>
</tbody>
</table>
</div>
<div class="column">
<h4 class="title is-4">住宿人數</h4>
<table class="table">
<thead>
<th>住宿選項</th>
<th>人數</th>
</thead>
<tbody>
{% for accmmodation_option, count in accommodation_statictics.items() %}
{% if accmmodation_option == 'yes' %}
<tr>
<td>需要住宿</td>
<td>{{ count }}</td>
</tr>
{% elif accmmodation_option == 'yes-longtraffic' %}
<tr>
<td>需要住宿,且通勤時間大於一小時</td>
<td>{{ count }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</section>
Expand Down
2 changes: 2 additions & 0 deletions view/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 0e8037d

Please sign in to comment.