From a47943b740f00a4c4f89038910f188036d6c2fd2 Mon Sep 17 00:00:00 2001
From: thomaswoehlke <thomas.woehlke@gmail.com>
Date: Mon, 8 Feb 2021 09:59:42 +0100
Subject: [PATCH] work

---
 BACKLOG.md                                    |  2 +-
 docs/Domain_Model.md                          |  2 +-
 docs/uml_gaphor/covid19python_url.gaphor      |  2 +-
 src/covid19/blueprints/who/who_model.py       |  6 ++---
 .../blueprints/who/who_model_import.py        | 20 +++++++++-------
 .../blueprints/who/who_service_update.py      |  8 +++----
 src/covid19/blueprints/who/who_views.py       | 24 +++++++++----------
 7 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/BACKLOG.md b/BACKLOG.md
index b4a9e804..e2f7c8aa 100644
--- a/BACKLOG.md
+++ b/BACKLOG.md
@@ -123,7 +123,7 @@
 * Issue #82 BUG: change to ORM ClassHierarchy
 * Issue #83 SQLalchemy instead of SQL in WhoGlobalDataImportTable.get_new_dates_as_array
 * Issue #84 rename tablename from who_global_data to who_data
-* Issue #85 rename WhoGlobalData to WhoData
+* Issue #85 rename WhoData to WhoData
 * Fixed #86 rename VaccinationData to Vaccination
 * Issue #87 change to: Vaccination.datum many to one VaccinationDateReported
 * Issue #89 change tablename from vaccination_germany_timeline_import to vaccination_import
diff --git a/docs/Domain_Model.md b/docs/Domain_Model.md
index 1a752062..e581ad46 100644
--- a/docs/Domain_Model.md
+++ b/docs/Domain_Model.md
@@ -65,7 +65,7 @@ CREATE TABLE public.who_global_data (
 );
 ````
 ````python
-class WhoGlobalData(db.Model):
+class WhoData(db.Model):
     __tablename__ = 'who_global_data'
 
     id = db.Column(db.Integer, primary_key=True)
diff --git a/docs/uml_gaphor/covid19python_url.gaphor b/docs/uml_gaphor/covid19python_url.gaphor
index 46c603b6..28be6302 100644
--- a/docs/uml_gaphor/covid19python_url.gaphor
+++ b/docs/uml_gaphor/covid19python_url.gaphor
@@ -316,7 +316,7 @@
 <val>1</val>
 </isAbstract>
 <name>
-<val>WhoGlobalData</val>
+<val>WhoData</val>
 </name>
 <ownedAttribute>
 <reflist>
diff --git a/src/covid19/blueprints/who/who_model.py b/src/covid19/blueprints/who/who_model.py
index 576d1f47..7a9c3824 100644
--- a/src/covid19/blueprints/who/who_model.py
+++ b/src/covid19/blueprints/who/who_model.py
@@ -126,10 +126,10 @@ class WhoCountry(db.Model):
         ).order_by(cls.country).paginate(page, per_page=ITEMS_PER_PAGE)
 
 
-# TODO: #85 rename WhoGlobalData to WhoData
+# TODO: #85 rename WhoData to WhoData
 # TODO: #84 rename tablename from who_global_data to who_data
-class WhoGlobalData(db.Model):
-    __tablename__ = 'who_global_data'
+class WhoData(db.Model):
+    __tablename__ = 'who_data'
 
     id = db.Column(db.Integer, primary_key=True)
     cases_new = db.Column(db.Integer, nullable=False)
diff --git a/src/covid19/blueprints/who/who_model_import.py b/src/covid19/blueprints/who/who_model_import.py
index 22f0320d..546a740e 100644
--- a/src/covid19/blueprints/who/who_model_import.py
+++ b/src/covid19/blueprints/who/who_model_import.py
@@ -4,7 +4,7 @@ from database import db, ITEMS_PER_PAGE
 # TODO: #80 rename WhoGlobalDataImportTable to WhoImport
 # TODO: #81 change tablename from who_global_data_import to who_import
 class WhoGlobalDataImportTable(db.Model):
-    __tablename__ = 'who_global_data_import'
+    __tablename__ = 'who_import'
 
     id = db.Column(db.Integer, primary_key=True)
     date_reported = db.Column(db.String(255), nullable=False)
@@ -70,7 +70,7 @@ class WhoGlobalDataImportTable(db.Model):
             select
                 date_reported
             from
-                who_global_data_import
+                who_import
             where
                 date_reported
             not in (
@@ -78,14 +78,16 @@ class WhoGlobalDataImportTable(db.Model):
                 distinct
                     common_date_reported.date_reported
                 from
-                    who_global_data
+                    who_data
                 left join
                     common_date_reported
                 on
-                    who_global_data.date_reported_id=common_date_reported.id
+                    who_data.date_reported_id=common_date_reported.id
+                and
+                    common_date_reported.type='who_date_reported'
             )
             group by
-                who_global_data_import.date_reported
+                who_import.date_reported
             order by date_reported desc
             """
         new_dates = []
@@ -97,9 +99,9 @@ class WhoGlobalDataImportTable(db.Model):
     def countries(cls):
         sql_query = """
             select distinct 
-                who_global_data_import.country_code,
-                who_global_data_import.country,
-                who_global_data_import.who_region
-                from who_global_data_import
+                who_import.country_code,
+                who_import.country,
+                who_import.who_region
+                from who_import
             """
         return db.session.execute(sql_query).fetchall()
diff --git a/src/covid19/blueprints/who/who_service_update.py b/src/covid19/blueprints/who/who_service_update.py
index 843779f1..49fe6023 100644
--- a/src/covid19/blueprints/who/who_service_update.py
+++ b/src/covid19/blueprints/who/who_service_update.py
@@ -1,5 +1,5 @@
 from database import db, app
-from covid19.blueprints.who.who_model import WhoRegion, WhoDateReported, WhoCountry, WhoGlobalData
+from covid19.blueprints.who.who_model import WhoRegion, WhoDateReported, WhoCountry, WhoData
 from covid19.blueprints.who.who_model_import import WhoGlobalDataImportTable
 from covid19.blueprints.who.who_service_download import WhoServiceDownloadConfig
 
@@ -105,7 +105,7 @@ class WhoServiceUpdate:
                     my_country = WhoCountry.get_by_country(result_item.country)
                 else:
                     my_country = WhoCountry.get_by_country_code(result_item.country_code)
-                o = WhoGlobalData(
+                o = WhoData(
                     cases_new=int(result_item.new_cases),
                     cases_cumulative=int(result_item.cumulative_cases),
                     deaths_new=int(result_item.new_deaths),
@@ -128,7 +128,7 @@ class WhoServiceUpdate:
     def __update_fact_table_initial(self):
         app.logger.info(" __update_fact_table_initial [begin]")
         app.logger.info("------------------------------------------------------------")
-        WhoGlobalData.remove_all()
+        WhoData.remove_all()
         new_dates_reported_from_import = WhoGlobalDataImportTable.get_new_dates_as_array()
         i = 0
         for my_date_reported in new_dates_reported_from_import:
@@ -139,7 +139,7 @@ class WhoServiceUpdate:
                 my_date = myday
             for result_item in WhoGlobalDataImportTable.get_for_one_day(my_date_reported):
                 my_country = WhoCountry.find_by_country_code(result_item.country_code)
-                o = WhoGlobalData(
+                o = WhoData(
                     cases_new=int(result_item.new_cases),
                     cases_cumulative=int(result_item.cumulative_cases),
                     deaths_new=int(result_item.new_deaths),
diff --git a/src/covid19/blueprints/who/who_views.py b/src/covid19/blueprints/who/who_views.py
index 048835c3..9513fd11 100644
--- a/src/covid19/blueprints/who/who_views.py
+++ b/src/covid19/blueprints/who/who_views.py
@@ -8,7 +8,7 @@ from covid19.services import who_service
 from covid19.workers import celery
 
 from covid19.blueprints.who.who_model_import import WhoGlobalDataImportTable
-from covid19.blueprints.who.who_model import WhoRegion, WhoCountry, WhoDateReported, WhoGlobalData
+from covid19.blueprints.who.who_model import WhoRegion, WhoCountry, WhoDateReported, WhoData
 from covid19.blueprints.common.common_model_transient import ApplicationPage
 
 
@@ -242,7 +242,7 @@ def url_who_date_reported(date_reported_id, page=1):
         "data of all reported countries for WHO date reported " + date_reported.date_reported + " "
     )
     try:
-        page_data = WhoGlobalData.get_data_for_day(date_reported, page)
+        page_data = WhoData.get_data_for_day(date_reported, page)
     except OperationalError:
         flash("No data in the database.")
         page_data = None
@@ -263,7 +263,7 @@ def url_who_date_reported_cases_new(date_reported_id, page=1):
         "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)
+        page_data = WhoData.get_data_for_day_order_by_cases_new(date_reported, page)
     except OperationalError:
         flash("No data in the database.")
         page_data = None
@@ -284,7 +284,7 @@ def url_who_date_reported_cases_cumulative(date_reported_id, page=1):
         "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)
+        page_data = WhoData.get_data_for_day_order_by_cases_cumulative(date_reported, page)
     except OperationalError:
         flash("No data in the database.")
         page_data = None
@@ -305,7 +305,7 @@ def url_who_date_reported_deaths_new(date_reported_id, page=1):
         "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)
+        page_data = WhoData.get_data_for_day_order_by_deaths_new(date_reported, page)
     except OperationalError:
         flash("No data in the database.")
         page_data = None
@@ -326,7 +326,7 @@ def url_who_date_reported_deaths_cumulative(date_reported_id, page=1):
         "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)
+        page_data = WhoData.get_data_for_day_order_by_deaths_cumulative(date_reported, page)
     except OperationalError:
         flash("No data in the database.")
         page_data = None
@@ -392,7 +392,7 @@ def url_who_country_all(page=1):
 @app_who.route('/country/<int:country_id>')
 def url_who_country(country_id, page=1):
     who_country = WhoCountry.get_by_id(country_id)
-    page_data = WhoGlobalData.get_data_for_country(who_country, page)
+    page_data = WhoData.get_data_for_country(who_country, page)
     page_info = ApplicationPage(who_country.country,
            "Country "+who_country.country_code,
            "Data per Day in Country "+who_country.country+" of WHO Region "+who_country.region.region)
@@ -407,7 +407,7 @@ def url_who_country(country_id, page=1):
 @app_who.route('/country/<int:country_id>/cases_new')
 def url_who_country_cases_new(country_id, page=1):
     who_country = WhoCountry.get_by_id(country_id)
-    page_data = WhoGlobalData.get_data_for_country_order_by_cases_new(who_country, page)
+    page_data = WhoData.get_data_for_country_order_by_cases_new(who_country, page)
     page_info = ApplicationPage(who_country.country,
            "Country "+who_country.country_code,
            "Data per Day in Country "+who_country.country+" of WHO Region "+who_country.region.region)
@@ -422,7 +422,7 @@ def url_who_country_cases_new(country_id, page=1):
 @app_who.route('/country/<int:country_id>/cases_cumulative')
 def url_who_country_cases_cumulative(country_id, page=1):
     who_country = WhoCountry.get_by_id(country_id)
-    page_data = WhoGlobalData.get_data_for_country_order_by_cases_cumulative(who_country, page)
+    page_data = WhoData.get_data_for_country_order_by_cases_cumulative(who_country, page)
     page_info = ApplicationPage(who_country.country,
            "Country "+who_country.country_code,
            "Data per Day in Country "+who_country.country+" of WHO Region "+who_country.region.region)
@@ -437,7 +437,7 @@ def url_who_country_cases_cumulative(country_id, page=1):
 @app_who.route('/country/<int:country_id>/deaths_new')
 def url_who_country_deaths_new(country_id, page=1):
     who_country = WhoCountry.get_by_id(country_id)
-    page_data = WhoGlobalData.get_data_for_country_order_by_deaths_new(who_country, page)
+    page_data = WhoData.get_data_for_country_order_by_deaths_new(who_country, page)
     page_info = ApplicationPage(who_country.country,
            "Country "+who_country.country_code,
            "Data per Day in Country "+who_country.country+" of WHO Region "+who_country.region.region)
@@ -452,7 +452,7 @@ def url_who_country_deaths_new(country_id, page=1):
 @app_who.route('/country/<int:country_id>/deaths_cumulative')
 def url_who_country_deaths_cumulative(country_id, page=1):
     who_country = WhoCountry.get_by_id(country_id)
-    page_data = WhoGlobalData.get_data_for_country_order_by_deaths_cumulative(who_country, page)
+    page_data = WhoData.get_data_for_country_order_by_deaths_cumulative(who_country, page)
     page_info = ApplicationPage(who_country.country,
            "Country "+who_country.country_code,
            "Data per Day in Country "+who_country.country+" of WHO Region "+who_country.region.region)
@@ -471,7 +471,7 @@ def url_who_germany(page=1):
     if who_country_germany is None:
         flash('country: Germany not found in Database', category='error')
         return redirect(url_for('who.url_who_tasks'))
-    page_data = WhoGlobalData.get_data_for_country(who_country_germany, page)
+    page_data = WhoData.get_data_for_country(who_country_germany, page)
     return render_template(
         'who/country/who_country_germany.html',
         who_country=who_country_germany,
-- 
GitLab