diff --git a/src/covid19/blueprints/common/common_model.py b/src/covid19/blueprints/common/common_model.py index 01407a7dedb8ee1937b2d9cda1ce74fd0166622f..1404451522d7224706bcba298aac85f90a1c2c7f 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 0055a9383b12c5f03a2400ba8c96a402377c64dd..f654f7ab73b625b20b49b898881ad361d61a01ae 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 c3da65cb899c3f9939c614ad5d676839153dff61..cd24b6b17fc76c854c6dba5faf1f6f52e37e81d5 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 e32fe2d075c9885255b6737e49a4a3b61d10d5cd..ac30def3eaca75e248aca94152bc62ae87971b5d 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 683757acf0c619e87b28e5ad67e46e1543fb5063..5887ef594b1f376068476dba33d27534659764d7 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 37a37288f3f718b4bc5cf73de7b4be7cdb21d3b5..ed80e71075f59a577d602bc86178bdeb2912bf7c 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