From a7a75153112fb14224e36ecd60cfbc676621ed3f Mon Sep 17 00:00:00 2001
From: thomaswoehlke <thomas.woehlke@gmail.com>
Date: Fri, 5 Feb 2021 22:34:54 +0100
Subject: [PATCH] work

---
 src/covid19/blueprints/common/common_model.py |  4 +---
 src/covid19/blueprints/europe/europe_model.py | 21 +++++++++++++++++--
 .../europe/europe_service_update.py           |  3 +--
 src/covid19/blueprints/rki/rki_model.py       |  7 ++++---
 src/covid19/blueprints/who/who_model.py       | 21 +++++++++++++++++--
 .../blueprints/who/who_service_import.py      |  3 +--
 6 files changed, 45 insertions(+), 14 deletions(-)

diff --git a/src/covid19/blueprints/common/common_model.py b/src/covid19/blueprints/common/common_model.py
index 01407a7d..14044515 100644
--- a/src/covid19/blueprints/common/common_model.py
+++ b/src/covid19/blueprints/common/common_model.py
@@ -12,9 +12,7 @@ class CommonDateReported(db.Model):
         'polymorphic_on': type
     }
     __table_args__ = (
-        db.UniqueConstraint('type', 'date_reported', name='unique_common_date_reported_1'),
-        db.UniqueConstraint('type', 'datum', name='unique_common_date_reported_2'),
-        db.UniqueConstraint('type', 'year_week', name='unique_common_date_reported_3')
+        db.UniqueConstraint('type', 'date_reported', 'datum', 'year_week', name='unique_common_date_reported'),
     )
     #
     id = db.Column(db.Integer, primary_key=True)
diff --git a/src/covid19/blueprints/europe/europe_model.py b/src/covid19/blueprints/europe/europe_model.py
index 0055a938..f654f7ab 100644
--- a/src/covid19/blueprints/europe/europe_model.py
+++ b/src/covid19/blueprints/europe/europe_model.py
@@ -1,4 +1,5 @@
 from sqlalchemy import and_
+from datetime import date
 from database import db, ITEMS_PER_PAGE
 from covid19.blueprints.common.common_model import CommonDateReported, CommonRegion
 
@@ -8,8 +9,24 @@ class EuropeDateReported(CommonDateReported):
 
     @classmethod
     def create_new_object_factory(cls, my_date_rep):
-        o = CommonDateReported.create_new_object_factory(my_date_rep)
-        return EuropeDateReported(o)
+        my_datum = date.fromisoformat(my_date_rep)
+        (my_iso_year, week_number, weekday) = my_datum.isocalendar()
+        my_year_week = "" + str(my_iso_year)
+        if week_number < 10:
+            my_year_week += "-0"
+        else:
+            my_year_week += "-"
+        my_year_week += str(week_number)
+        return EuropeDateReported(
+            date_reported=my_date_rep,
+            datum=my_datum,
+            year=my_datum.year,
+            month=my_datum.month,
+            day_of_month=my_datum.day,
+            day_of_week=weekday,
+            week_of_year=week_number,
+            year_week=my_year_week
+        )
 
 
 class EuropeContinent(CommonRegion):
diff --git a/src/covid19/blueprints/europe/europe_service_update.py b/src/covid19/blueprints/europe/europe_service_update.py
index c3da65cb..cd24b6b1 100644
--- a/src/covid19/blueprints/europe/europe_service_update.py
+++ b/src/covid19/blueprints/europe/europe_service_update.py
@@ -24,8 +24,7 @@ class EuropeServiceUpdate:
             my_date_rep = result_item['date_rep']
             my_year_week = result_item['year_week']
             o = EuropeDateReported.create_new_object_factory(
-                my_date_rep=my_date_rep,
-                my_year_week=my_year_week
+                my_date_rep=my_date_rep
             )
             db.session.add(o)
             app.logger.info("| " + my_date_rep + " | " + my_year_week + " | " + str(k) + " rows ")
diff --git a/src/covid19/blueprints/rki/rki_model.py b/src/covid19/blueprints/rki/rki_model.py
index e32fe2d0..ac30def3 100644
--- a/src/covid19/blueprints/rki/rki_model.py
+++ b/src/covid19/blueprints/rki/rki_model.py
@@ -2,7 +2,6 @@ from sqlalchemy import and_
 from datetime import date
 from sqlalchemy.orm import joinedload
 
-from covid19.blueprints.common.common_model import CommonDateReported
 from database import db, ITEMS_PER_PAGE
 from covid19.blueprints.common.common_model import CommonDateReported, CommonRegion
 
@@ -14,10 +13,12 @@ class RkiDateReported(CommonDateReported):
     def create_new_object_factory(cls, my_date_rep):
         my_datum = date.fromisoformat(my_date_rep)
         (my_iso_year, week_number, weekday) = my_datum.isocalendar()
+        my_year_week = "" + str(my_iso_year)
         if week_number < 10:
-            my_year_week = "" + str(my_iso_year) + "-0" + str(week_number)
+            my_year_week += "-0"
         else:
-            my_year_week = "" + str(my_iso_year) + "-" + str(week_number)
+            my_year_week += "-"
+        my_year_week += str(week_number)
         return RkiDateReported(
             date_reported=my_date_rep,
             datum=my_datum,
diff --git a/src/covid19/blueprints/who/who_model.py b/src/covid19/blueprints/who/who_model.py
index 683757ac..5887ef59 100644
--- a/src/covid19/blueprints/who/who_model.py
+++ b/src/covid19/blueprints/who/who_model.py
@@ -1,4 +1,5 @@
 from sqlalchemy import and_, func
+from datetime import date
 from database import db, ITEMS_PER_PAGE
 from sqlalchemy.orm import joinedload
 from covid19.blueprints.common.common_model import CommonDateReported, CommonRegion
@@ -9,8 +10,24 @@ class WhoDateReported(CommonDateReported):
 
     @classmethod
     def create_new_object_factory(cls, my_date_rep):
-        o = cls.create_new_object_factory(my_date_rep)
-        return WhoDateReported(o)
+        my_datum = date.fromisoformat(my_date_rep)
+        (my_iso_year, week_number, weekday) = my_datum.isocalendar()
+        my_year_week = "" + str(my_iso_year)
+        if week_number < 10:
+            my_year_week += "-0"
+        else:
+            my_year_week += "-"
+        my_year_week += str(week_number)
+        return WhoDateReported(
+            date_reported=my_date_rep,
+            datum=my_datum,
+            year=my_datum.year,
+            month=my_datum.month,
+            day_of_month=my_datum.day,
+            day_of_week=weekday,
+            week_of_year=week_number,
+            year_week=my_year_week
+        )
 
 
 class WhoRegion(CommonRegion):
diff --git a/src/covid19/blueprints/who/who_service_import.py b/src/covid19/blueprints/who/who_service_import.py
index 37a37288..ed80e710 100644
--- a/src/covid19/blueprints/who/who_service_import.py
+++ b/src/covid19/blueprints/who/who_service_import.py
@@ -43,8 +43,7 @@ class WhoServiceImport:
                         new_cases=row['New_cases'],
                         cumulative_cases=row['Cumulative_cases'],
                         new_deaths=row['New_deaths'],
-                        cumulative_deaths=row['Cumulative_deaths'],
-                        row_imported=False
+                        cumulative_deaths=row['Cumulative_deaths']
                     )
                     db.session.add(o)
                     k += 1
-- 
GitLab