From f22843d4850422309c653d0ca3a03edbab0482fb Mon Sep 17 00:00:00 2001 From: thomaswoehlke <thomas.woehlke@gmail.com> Date: Sun, 25 Apr 2021 16:02:55 +0200 Subject: [PATCH] work --- .../application/application_model.py | 4 +-- src/covid19/blueprints/ecdc/ecdc_model.py | 6 ++-- src/covid19/blueprints/owid/owid_model.py | 6 ++-- .../rki_vaccination/rki_vaccination_model.py | 6 ++-- src/covid19/blueprints/who/who_model.py | 32 ++++++++++++++++--- .../blueprints/who/who_model_import.py | 3 +- .../templates/who_test/who_tests.html | 3 ++ .../blueprints/who_test/who_test_views.py | 13 ++++++++ 8 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src/covid19/blueprints/application/application_model.py b/src/covid19/blueprints/application/application_model.py index 7fa4adfb..44a2f025 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 97b2912e..067c8a2e 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 0c57f6a6..2d5e529b 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 64bf7b18..f90e5f99 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 2abc2964..b75afba5 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 cf4f463c..f220dd5e 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 3be40b56..2ec99305 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 732ad7d2..abcc2089 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')) + + -- GitLab