From 48e764025b614089d0465c5e1557247a6339b6d9 Mon Sep 17 00:00:00 2001 From: thomaswoehlke <thomas.woehlke@gmail.com> Date: Sun, 24 Jan 2021 23:09:10 +0100 Subject: [PATCH] work --- app.py | 84 +++++++++++++++++++ org/woehlke/covid19/who/who_model.py | 44 ++++++++++ ...t_who_global_data_table_date_reported.html | 66 +++++++++++++++ templates/who/who_date_reported_one.html | 2 +- ...ho_date_reported_one_cases_cumulative.html | 70 ++++++++++++++++ .../who/who_date_reported_one_cases_new.html | 70 ++++++++++++++++ ...o_date_reported_one_deaths_cumulative.html | 70 ++++++++++++++++ .../who/who_date_reported_one_deaths_new.html | 70 ++++++++++++++++ who_date_reported_one_cases_new.html | 0 9 files changed, 475 insertions(+), 1 deletion(-) create mode 100644 templates/who/fragment_who_global_data_table_date_reported.html create mode 100644 templates/who/who_date_reported_one_cases_cumulative.html create mode 100644 templates/who/who_date_reported_one_cases_new.html create mode 100644 templates/who/who_date_reported_one_deaths_cumulative.html create mode 100644 templates/who/who_date_reported_one_deaths_new.html create mode 100644 who_date_reported_one_cases_new.html diff --git a/app.py b/app.py index 0635693e..825b8b73 100644 --- a/app.py +++ b/app.py @@ -239,6 +239,90 @@ def url_who_date_reported(date_reported_id, page=1): page_info=page_info) +@app.route('/who/date_reported/<int:date_reported_id>/cases_new/page/<int:page>') +@app.route('/who/date_reported/<int:date_reported_id>/cases_new') +def url_who_date_reported_cases_new(date_reported_id, page=1): + date_reported = WhoDateReported.get_by_id(date_reported_id) + page_info = ApplicationPage( + "Date Reported: " + date_reported.date_reported, + 'WHO', + "data of all reported countries for WHO date reported " + date_reported.date_reported + " " + ) + try: + page_data = WhoGlobalData.get_data_for_day_order_by_cases_new(date_reported, page) + except OperationalError: + flash("No data in the database.") + page_data = None + return render_template( + 'who/who_date_reported_one_cases_new.html', + who_date_reported=date_reported, + page_data=page_data, + page_info=page_info) + + +@app.route('/who/date_reported/<int:date_reported_id>/cases_cumulative/page/<int:page>') +@app.route('/who/date_reported/<int:date_reported_id>/cases_cumulative') +def url_who_date_reported_cases_cumulative(date_reported_id, page=1): + date_reported = WhoDateReported.get_by_id(date_reported_id) + page_info = ApplicationPage( + "Date Reported: " + date_reported.date_reported, + 'WHO', + "data of all reported countries for WHO date reported " + date_reported.date_reported + " " + ) + try: + page_data = WhoGlobalData.get_data_for_day_order_by_cases_cumulative(date_reported, page) + except OperationalError: + flash("No data in the database.") + page_data = None + return render_template( + 'who/who_date_reported_one_cases_cumulative.html', + who_date_reported=date_reported, + page_data=page_data, + page_info=page_info) + + +@app.route('/who/date_reported/<int:date_reported_id>/deaths_new/page/<int:page>') +@app.route('/who/date_reported/<int:date_reported_id>/deaths_new') +def url_who_date_reported_deaths_new(date_reported_id, page=1): + date_reported = WhoDateReported.get_by_id(date_reported_id) + page_info = ApplicationPage( + "Date Reported: " + date_reported.date_reported, + 'WHO', + "data of all reported countries for WHO date reported " + date_reported.date_reported + " " + ) + try: + page_data = WhoGlobalData.get_data_for_day_order_by_deaths_new(date_reported, page) + except OperationalError: + flash("No data in the database.") + page_data = None + return render_template( + 'who/who_date_reported_one_deaths_new.html', + who_date_reported=date_reported, + page_data=page_data, + page_info=page_info) + + +@app.route('/who/date_reported/<int:date_reported_id>/deaths_cumulative/page/<int:page>') +@app.route('/who/date_reported/<int:date_reported_id>/deaths_cumulative') +def url_who_date_reported_deaths_cumulative(date_reported_id, page=1): + date_reported = WhoDateReported.get_by_id(date_reported_id) + page_info = ApplicationPage( + "Date Reported: " + date_reported.date_reported, + 'WHO', + "data of all reported countries for WHO date reported " + date_reported.date_reported + " " + ) + try: + page_data = WhoGlobalData.get_data_for_day_order_by_deaths_cumulative(date_reported, page) + except OperationalError: + flash("No data in the database.") + page_data = None + return render_template( + 'who/who_date_reported_one_deaths_cumulative.html', + who_date_reported=date_reported, + page_data=page_data, + page_info=page_info) + + @app.route('/who/region/all/page/<int:page>') @app.route('/who/region/all') def url_who_region_all(page=1): diff --git a/org/woehlke/covid19/who/who_model.py b/org/woehlke/covid19/who/who_model.py index a210b6d7..63cbc0f5 100644 --- a/org/woehlke/covid19/who/who_model.py +++ b/org/woehlke/covid19/who/who_model.py @@ -212,6 +212,50 @@ class WhoGlobalData(db.Model): cls.cases_cumulative.desc() ).paginate(page, per_page=ITEMS_PER_PAGE) + @classmethod + def get_data_for_day_order_by_cases_new(cls, date_reported, page): + return db.session.query(cls).filter( + cls.date_reported_id == date_reported.id + ).populate_existing().options( + joinedload(cls.country).subqueryload(WhoCountry.region), + joinedload(cls.date_reported) + ).order_by( + cls.cases_new.desc() + ).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_data_for_day_order_by_cases_cumulative(cls, date_reported, page): + return db.session.query(cls).filter( + cls.date_reported_id == date_reported.id + ).populate_existing().options( + joinedload(cls.country).subqueryload(WhoCountry.region), + joinedload(cls.date_reported) + ).order_by( + cls.cases_cumulative.desc() + ).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_data_for_day_order_by_deaths_new(cls, date_reported, page): + return db.session.query(cls).filter( + cls.date_reported_id == date_reported.id + ).populate_existing().options( + joinedload(cls.country).subqueryload(WhoCountry.region), + joinedload(cls.date_reported) + ).order_by( + cls.deaths_new.desc() + ).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_data_for_day_order_by_deaths_cumulative(cls, date_reported, page): + return db.session.query(cls).filter( + cls.date_reported_id == date_reported.id + ).populate_existing().options( + joinedload(cls.country).subqueryload(WhoCountry.region), + joinedload(cls.date_reported) + ).order_by( + cls.deaths_cumulative.desc() + ).paginate(page, per_page=ITEMS_PER_PAGE) + class WhoGlobalDataImportTable(db.Model): __tablename__ = 'who_global_data_import' diff --git a/templates/who/fragment_who_global_data_table_date_reported.html b/templates/who/fragment_who_global_data_table_date_reported.html new file mode 100644 index 00000000..5aaa9530 --- /dev/null +++ b/templates/who/fragment_who_global_data_table_date_reported.html @@ -0,0 +1,66 @@ + <table class="table table-hover table-striped table-dark"> + <thead> + <tr> + <th scope="col">date reported</th> + <th scope="col"> + <a href="/who/date_reported/{{ who_date_reported.id }}/deaths_new"> + deaths new + </a> + </th> + <th scope="col"> + <a href="/who/date_reported/{{ who_date_reported.id }}/cases_new"> + cases new + </a> + </th> + <th scope="col"> + <a href="/who/date_reported/{{ who_date_reported.id }}/deaths_cumulative"> + deaths cumulative + </a> + </th> + <th scope="col"> + <a href="/who/date_reported/{{ who_date_reported.id }}/cases_cumulative"> + cases cumulative + </a> + </th> + <th scope="col">country code</th> + <th scope="col">country</th> + <th scope="col">region</th> + </tr> + </thead> + <tbody> + {% for who_global_data in page_data.items %} + <tr> + <th> + {{ who_global_data.date_reported.date_reported }} + </th> + <td> + {{ who_global_data.deaths_new }} + </td> + <td> + {{ who_global_data.cases_new }} + </td> + <td> + {{ who_global_data.deaths_cumulative }} + </td> + <td> + {{ who_global_data.cases_cumulative }} + </td> + <td> + <a href="/who/country/{{ who_global_data.country.id }}"> + {{ who_global_data.country.country_code }} + </a> + </td> + <td> + <a href="/who/country/{{ who_global_data.country.id }}"> + {{ who_global_data.country.country }} + </a> + </td> + <th> + <a href="/who/region/{{ who_global_data.country.region.id }}"> + {{ who_global_data.country.region.region }} + </a> + </th> + </tr> + {% endfor %} + </tbody> + </table> \ No newline at end of file diff --git a/templates/who/who_date_reported_one.html b/templates/who/who_date_reported_one.html index 9ddad9e1..a824eede 100644 --- a/templates/who/who_date_reported_one.html +++ b/templates/who/who_date_reported_one.html @@ -57,7 +57,7 @@ </ul> {% endif %} - {% include 'who/fragment_who_global_data_table.html' %} + {% include 'who/fragment_who_global_data_table_date_reported.html' %} {% endblock %} diff --git a/templates/who/who_date_reported_one_cases_cumulative.html b/templates/who/who_date_reported_one_cases_cumulative.html new file mode 100644 index 00000000..b0f789cb --- /dev/null +++ b/templates/who/who_date_reported_one_cases_cumulative.html @@ -0,0 +1,70 @@ +{% extends 'page_layout.html' %} + +{% include 'fragment_pagination.html' %} + +{% block navigation_breadcrumb %} + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a href="/">Home</a></li> + <li class="breadcrumb-item"><a href="/who/region/all">Regions</a></li> + <li class="breadcrumb-item active" aria-current="page">Countries</li> + </ol> + </nav> +{% endblock %} + +{% block navigation_navtabs %} + {% include 'fragment_navtabs_who.html' %} +{% endblock %} + + +{% block main_container %} + + {% if page_data.pages > 1 %} + <!-- previous page --> + <ul class="pagination"> + {% if page_data.has_prev %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_deaths_cumulative', + date_reported_id=who_date_reported.id, page=page_data.prev_num) }}">Previous</a> + </li> + {% endif %} + <!-- all page numbers --> + {% for page_num in page_data.iter_pages() %} + {% if page_num %} + {% if page_num != page_data.page %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_deaths_cumulative', + date_reported_id=who_date_reported.id, page=page_num) }}">{{ page_num }}</a> + </li> + {% else %} + <li class="page-item active"> + <a class="page-link" href="#">{{ page_num }}</a> + </li> + {% endif %} + {% else %} + <li class="page-item"> + <span class="ellipsis page-link my-page-item-ellipsis-page-link">…</span> + </li> + {% endif %} + {% endfor %} + <!-- next page --> + {% if page_data.has_next %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_deaths_cumulative', + date_reported_id=who_date_reported.id, page=page_data.next_num) }}">Next</a> + </li> + {% endif %} + </ul> + {% endif %} + + {% include 'who/fragment_who_global_data_table_date_reported.html' %} + +{% endblock %} + +{% block footer_container %} + <div> + {% for error in errors %} + <h4>{{ error }}</h4> + {% endfor %} + </div> +{% endblock %} \ No newline at end of file diff --git a/templates/who/who_date_reported_one_cases_new.html b/templates/who/who_date_reported_one_cases_new.html new file mode 100644 index 00000000..7f4529e3 --- /dev/null +++ b/templates/who/who_date_reported_one_cases_new.html @@ -0,0 +1,70 @@ +{% extends 'page_layout.html' %} + +{% include 'fragment_pagination.html' %} + +{% block navigation_breadcrumb %} + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a href="/">Home</a></li> + <li class="breadcrumb-item"><a href="/who/region/all">Regions</a></li> + <li class="breadcrumb-item active" aria-current="page">Countries</li> + </ol> + </nav> +{% endblock %} + +{% block navigation_navtabs %} + {% include 'fragment_navtabs_who.html' %} +{% endblock %} + + +{% block main_container %} + + {% if page_data.pages > 1 %} + <!-- previous page --> + <ul class="pagination"> + {% if page_data.has_prev %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_cases_new', + date_reported_id=who_date_reported.id, page=page_data.prev_num) }}">Previous</a> + </li> + {% endif %} + <!-- all page numbers --> + {% for page_num in page_data.iter_pages() %} + {% if page_num %} + {% if page_num != page_data.page %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_cases_new', + date_reported_id=who_date_reported.id, page=page_num) }}">{{ page_num }}</a> + </li> + {% else %} + <li class="page-item active"> + <a class="page-link" href="#">{{ page_num }}</a> + </li> + {% endif %} + {% else %} + <li class="page-item"> + <span class="ellipsis page-link my-page-item-ellipsis-page-link">…</span> + </li> + {% endif %} + {% endfor %} + <!-- next page --> + {% if page_data.has_next %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_cases_new', + date_reported_id=who_date_reported.id, page=page_data.next_num) }}">Next</a> + </li> + {% endif %} + </ul> + {% endif %} + + {% include 'who/fragment_who_global_data_table_date_reported.html' %} + +{% endblock %} + +{% block footer_container %} + <div> + {% for error in errors %} + <h4>{{ error }}</h4> + {% endfor %} + </div> +{% endblock %} \ No newline at end of file diff --git a/templates/who/who_date_reported_one_deaths_cumulative.html b/templates/who/who_date_reported_one_deaths_cumulative.html new file mode 100644 index 00000000..b0f789cb --- /dev/null +++ b/templates/who/who_date_reported_one_deaths_cumulative.html @@ -0,0 +1,70 @@ +{% extends 'page_layout.html' %} + +{% include 'fragment_pagination.html' %} + +{% block navigation_breadcrumb %} + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a href="/">Home</a></li> + <li class="breadcrumb-item"><a href="/who/region/all">Regions</a></li> + <li class="breadcrumb-item active" aria-current="page">Countries</li> + </ol> + </nav> +{% endblock %} + +{% block navigation_navtabs %} + {% include 'fragment_navtabs_who.html' %} +{% endblock %} + + +{% block main_container %} + + {% if page_data.pages > 1 %} + <!-- previous page --> + <ul class="pagination"> + {% if page_data.has_prev %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_deaths_cumulative', + date_reported_id=who_date_reported.id, page=page_data.prev_num) }}">Previous</a> + </li> + {% endif %} + <!-- all page numbers --> + {% for page_num in page_data.iter_pages() %} + {% if page_num %} + {% if page_num != page_data.page %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_deaths_cumulative', + date_reported_id=who_date_reported.id, page=page_num) }}">{{ page_num }}</a> + </li> + {% else %} + <li class="page-item active"> + <a class="page-link" href="#">{{ page_num }}</a> + </li> + {% endif %} + {% else %} + <li class="page-item"> + <span class="ellipsis page-link my-page-item-ellipsis-page-link">…</span> + </li> + {% endif %} + {% endfor %} + <!-- next page --> + {% if page_data.has_next %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_deaths_cumulative', + date_reported_id=who_date_reported.id, page=page_data.next_num) }}">Next</a> + </li> + {% endif %} + </ul> + {% endif %} + + {% include 'who/fragment_who_global_data_table_date_reported.html' %} + +{% endblock %} + +{% block footer_container %} + <div> + {% for error in errors %} + <h4>{{ error }}</h4> + {% endfor %} + </div> +{% endblock %} \ No newline at end of file diff --git a/templates/who/who_date_reported_one_deaths_new.html b/templates/who/who_date_reported_one_deaths_new.html new file mode 100644 index 00000000..e9b05d8e --- /dev/null +++ b/templates/who/who_date_reported_one_deaths_new.html @@ -0,0 +1,70 @@ +{% extends 'page_layout.html' %} + +{% include 'fragment_pagination.html' %} + +{% block navigation_breadcrumb %} + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a href="/">Home</a></li> + <li class="breadcrumb-item"><a href="/who/region/all">Regions</a></li> + <li class="breadcrumb-item active" aria-current="page">Countries</li> + </ol> + </nav> +{% endblock %} + +{% block navigation_navtabs %} + {% include 'fragment_navtabs_who.html' %} +{% endblock %} + + +{% block main_container %} + + {% if page_data.pages > 1 %} + <!-- previous page --> + <ul class="pagination"> + {% if page_data.has_prev %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_deaths_new', + date_reported_id=who_date_reported.id, page=page_data.prev_num) }}">Previous</a> + </li> + {% endif %} + <!-- all page numbers --> + {% for page_num in page_data.iter_pages() %} + {% if page_num %} + {% if page_num != page_data.page %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_deaths_new', + date_reported_id=who_date_reported.id, page=page_num) }}">{{ page_num }}</a> + </li> + {% else %} + <li class="page-item active"> + <a class="page-link" href="#">{{ page_num }}</a> + </li> + {% endif %} + {% else %} + <li class="page-item"> + <span class="ellipsis page-link my-page-item-ellipsis-page-link">…</span> + </li> + {% endif %} + {% endfor %} + <!-- next page --> + {% if page_data.has_next %} + <li class="page-item"> + <a class="page-link" href="{{ url_for('url_who_date_reported_deaths_new', + date_reported_id=who_date_reported.id, page=page_data.next_num) }}">Next</a> + </li> + {% endif %} + </ul> + {% endif %} + + {% include 'who/fragment_who_global_data_table_date_reported.html' %} + +{% endblock %} + +{% block footer_container %} + <div> + {% for error in errors %} + <h4>{{ error }}</h4> + {% endfor %} + </div> +{% endblock %} \ No newline at end of file diff --git a/who_date_reported_one_cases_new.html b/who_date_reported_one_cases_new.html new file mode 100644 index 00000000..e69de29b -- GitLab