diff --git a/src/covid19/blueprints/application/application_model.py b/src/covid19/blueprints/application/application_model.py index 7fa4adfb3c154cf2a5e20f13f2ea72d6dbc23f8a..44a2f0250b136723be2256447d7e93316cbdf41e 100644 --- a/src/covid19/blueprints/application/application_model.py +++ b/src/covid19/blueprints/application/application_model.py @@ -7,11 +7,11 @@ from sqlalchemy.orm import joinedload class ApplicationDateReported(db.Model): __tablename__ = 'application_datereported' __table_args__ = ( - db.UniqueConstraint('date_reported', 'datum', name="uix_application_datereported"), + db.UniqueConstraint('date_reported_import_str', 'datum', name="uix_application_datereported"), ) # id = db.Column(db.Integer, primary_key=True) - date_reported = db.Column(db.String(255), nullable=False, unique=True) + date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) year_week = db.Column(db.String(255), nullable=False) datum = db.Column(db.Date, nullable=False, unique=True) year = db.Column(db.Integer, nullable=False) diff --git a/src/covid19/blueprints/ecdc/ecdc_model.py b/src/covid19/blueprints/ecdc/ecdc_model.py index 97b2912e2737635b711e2158c77ba79273b4895b..067c8a2ea0ae84f8caf37f4fedb4e4fddd2c0e7e 100644 --- a/src/covid19/blueprints/ecdc/ecdc_model.py +++ b/src/covid19/blueprints/ecdc/ecdc_model.py @@ -8,11 +8,11 @@ class EcdcDateReported(ApplicationDateReported): __tablename__ = 'ecdc_datereported' __mapper_args__ = {'concrete': True} __table_args__ = ( - db.UniqueConstraint('date_reported', 'datum', name="uix_ecdc_datereported"), + db.UniqueConstraint('date_reported_import_str', 'datum', name="uix_ecdc_datereported"), ) id = db.Column(db.Integer, primary_key=True) - date_reported = db.Column(db.String(255), nullable=False, unique=True) + date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) year_week = db.Column(db.String(255), nullable=False) datum = db.Column(db.Date, nullable=False, unique=True) year = db.Column(db.Integer, nullable=False) @@ -64,7 +64,7 @@ class EcdcDateReported(ApplicationDateReported): (my_iso_year, week_number, weekday) = my_datum.isocalendar() my_year_week = super().my_year_week(my_iso_year, week_number) return EcdcDateReported( - date_reported=date_reported, + date_reported_import_str=date_reported, datum=my_datum, year=my_datum.year, month=my_datum.month, diff --git a/src/covid19/blueprints/owid/owid_model.py b/src/covid19/blueprints/owid/owid_model.py index 0c57f6a68558d9aed82967cce1b038917a1cf419..2d5e529bb6cc8a2213870760802aa8b2ec75fa39 100644 --- a/src/covid19/blueprints/owid/owid_model.py +++ b/src/covid19/blueprints/owid/owid_model.py @@ -9,11 +9,11 @@ class OwidDateReported(ApplicationDateReported): __tablename__ = 'owid_datereported' __mapper_args__ = {'concrete': True} __table_args__ = ( - db.UniqueConstraint('date_reported', 'datum', name="uix_owid_datereported"), + db.UniqueConstraint('date_reported_import_str', 'datum', name="uix_owid_datereported"), ) id = db.Column(db.Integer, primary_key=True) - date_reported = db.Column(db.String(255), nullable=False, unique=True) + date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) year_week = db.Column(db.String(255), nullable=False) datum = db.Column(db.Date, nullable=False, unique=True) year = db.Column(db.Integer, nullable=False) @@ -33,7 +33,7 @@ class OwidDateReported(ApplicationDateReported): my_year_week += "-" my_year_week += str(week_number) return OwidDateReported( - date_reported=my_date_rep, + date_reported_import_str=my_date_rep, datum=my_datum, year=my_datum.year, month=my_datum.month, diff --git a/src/covid19/blueprints/rki/rki_vaccination/rki_vaccination_model.py b/src/covid19/blueprints/rki/rki_vaccination/rki_vaccination_model.py index 64bf7b1803bc673acc71e71cee3ddc07212e9fe9..f90e5f991da36618252d4ac1c8c87cef379df4fb 100644 --- a/src/covid19/blueprints/rki/rki_vaccination/rki_vaccination_model.py +++ b/src/covid19/blueprints/rki/rki_vaccination/rki_vaccination_model.py @@ -10,11 +10,11 @@ class RkiVaccinationDateReported(ApplicationDateReported): 'concrete': True } __table_args__ = ( - db.UniqueConstraint('date_reported', 'datum', name="uix_rki_vaccination_datereported"), + db.UniqueConstraint('date_reported_import_str', 'datum', name="uix_rki_vaccination_datereported"), ) id = db.Column(db.Integer, primary_key=True) - date_reported = db.Column(db.String(255), nullable=False, unique=True) + date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) year_week = db.Column(db.String(255), nullable=False) datum = db.Column(db.Date, nullable=False, unique=True) year = db.Column(db.Integer, nullable=False) @@ -34,7 +34,7 @@ class RkiVaccinationDateReported(ApplicationDateReported): my_year_week += "-" my_year_week += str(week_number) return RkiVaccinationDateReported( - date_reported=my_date_rep, + date_reported_import_str=my_date_rep, datum=my_datum, year=my_datum.year, month=my_datum.month, diff --git a/src/covid19/blueprints/who/who_model.py b/src/covid19/blueprints/who/who_model.py index 2abc2964031cb69cbb9e003c82a8cba1ddb19913..b75afba53f465712e6f5b515d2590e7bd13829e9 100644 --- a/src/covid19/blueprints/who/who_model.py +++ b/src/covid19/blueprints/who/who_model.py @@ -1,7 +1,7 @@ from sqlalchemy import and_, func from datetime import date from database import db, ITEMS_PER_PAGE -from sqlalchemy.orm import joinedload +from sqlalchemy.orm import joinedload, load_only from covid19.blueprints.application.application_model import ApplicationDateReported, ApplicationRegion @@ -9,11 +9,11 @@ class WhoDateReported(ApplicationDateReported): __tablename__ = 'who_datereported' __mapper_args__ = {'concrete': True} __table_args__ = ( - db.UniqueConstraint('date_reported', 'datum', name="uix_who_datereported"), + db.UniqueConstraint('date_reported_import_str', 'datum', name="uix_who_datereported"), ) id = db.Column(db.Integer, primary_key=True) - date_reported = db.Column(db.String(255), nullable=False, unique=True) + date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) year_week = db.Column(db.String(255), nullable=False) datum = db.Column(db.Date, nullable=False, unique=True) year = db.Column(db.Integer, nullable=False) @@ -22,6 +22,22 @@ class WhoDateReported(ApplicationDateReported): day_of_week = db.Column(db.Integer, nullable=False) week_of_year = db.Column(db.Integer, nullable=False) + ### + # select + # distinct + # who_datereported.date_reported + # from + # who + # left join + # who_datereported + # on + # who.date_reported_id=who_datereported.id + # group by + # who_datereported.date_reported + # order by + # who_datereported.date_reported desc + ### + @classmethod def create_new_object_factory(cls, my_date_rep): my_datum = date.fromisoformat(my_date_rep) @@ -33,7 +49,7 @@ class WhoDateReported(ApplicationDateReported): my_year_week += "-" my_year_week += str(week_number) return WhoDateReported( - date_reported=my_date_rep, + date_reported_import_str=my_date_rep, datum=my_datum, year=my_datum.year, month=my_datum.month, @@ -183,6 +199,14 @@ class WhoData(db.Model): cascade='save-update', order_by='asc(WhoCountry.country)') + @classmethod + def get_datum_of_all_who_data(cls): + return db.session.query(WhoData)\ + .join(WhoDateReported, WhoData.date_reported)\ + .options(load_only(WhoDateReported.date_reported))\ + .group_by(WhoDateReported.date_reported)\ + .all() + @classmethod def remove_all(cls): for one in cls.get_all(): diff --git a/src/covid19/blueprints/who/who_model_import.py b/src/covid19/blueprints/who/who_model_import.py index cf4f463c73487890894ee48e2040d0e71e4a9c62..f220dd5e5df4495265de4b25a7e3b482ea8591cf 100644 --- a/src/covid19/blueprints/who/who_model_import.py +++ b/src/covid19/blueprints/who/who_model_import.py @@ -149,7 +149,8 @@ class WhoImport(db.Model): @classmethod def get_new_dates_as_array(cls): - return cls.__get_new_dates_as_array_sql() + #return cls.__get_new_dates_as_array_sql() + return cls.__get_new_dates_as_array_orm() @classmethod def countries(cls): diff --git a/src/covid19/blueprints/who_test/templates/who_test/who_tests.html b/src/covid19/blueprints/who_test/templates/who_test/who_tests.html index 3be40b562ef553ead9217f5eead53a6212949602..2ec993054c54e23b05291edb09db7a1259ecc6e1 100644 --- a/src/covid19/blueprints/who_test/templates/who_test/who_tests.html +++ b/src/covid19/blueprints/who_test/templates/who_test/who_tests.html @@ -24,6 +24,9 @@ <a class="btn btn-danger btn-lg btn-block text-left" href="{{ url_for( 'who_test.url_who_test_who_import_get_new_dates_as_array') }}" role="button">url_who_test_who_import_get_new_dates_as_array</a> + <a class="btn btn-primary btn-lg btn-block text-left" + href="{{ url_for( 'who_test.url_who_test_who_data_get_datum_of_all_who_data') }}" + role="button">url_who_test_who_data_get_datum_of_all_who_data</a> </div> </div> <div class="col"> diff --git a/src/covid19/blueprints/who_test/who_test_views.py b/src/covid19/blueprints/who_test/who_test_views.py index 732ad7d215252f291fd213896899cfb8ab8746da..abcc2089f9477d8b626f7303c06f9fc4c67c3538 100644 --- a/src/covid19/blueprints/who_test/who_test_views.py +++ b/src/covid19/blueprints/who_test/who_test_views.py @@ -80,3 +80,16 @@ def url_who_test_who_import_get_new_dates_as_array(): flash("url_who_mytest - DONE: WhoImport.get_new_dates_as_array()") app.logger.info("url_who_mytest - DONE: WhoImport.get_new_dates_as_array()") return redirect(url_for('who_test.url_who_test_tests')) + +@app_who_test.route('/who_data/get_datum_of_all_who_data') +@login_required +def url_who_test_who_data_get_datum_of_all_who_data(): + app.logger.info("url_who_test_who_data_get_datum_of_all_who_data - DONE: WhoData.get_datum_of_all_who_data()") + flash("url_who_test_who_data_get_datum_of_all_who_data - START: WhoData.get_datum_of_all_who_data()") + for datum in WhoData.get_datum_of_all_who_data(): + app.logger.info(str(datum.date_reported)) + flash("url_who_test_who_data_get_datum_of_all_who_data - DONE: WhoData.get_datum_of_all_who_data()") + app.logger.info("url_who_test_who_data_get_datum_of_all_who_data - DONE: WhoData.get_datum_of_all_who_data()") + return redirect(url_for('who_test.url_who_test_tests')) + +