From 18df9a8792c7f29cefd16508a3b56f6d09faea82 Mon Sep 17 00:00:00 2001 From: thomaswoehlke <thomas.woehlke@gmail.com> Date: Fri, 28 May 2021 23:03:06 +0200 Subject: [PATCH] work --- .../blueprints/data_ecdc/ecdc_model.py | 11 ++++--- .../blueprints/data_owid/owid_model.py | 12 ++++--- .../blueprints/data_rki/rki_model.py | 26 ++++++++++----- .../blueprints/data_rki/rki_model_import.py | 33 ++++++------------- .../data_vaccination/vaccination_model.py | 9 ++--- .../blueprints/data_who/who_model.py | 18 ++++++---- .../blueprints/data_who/who_model_import.py | 14 +++++--- 7 files changed, 67 insertions(+), 56 deletions(-) diff --git a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py index 01dad0b5..cfe1e18f 100644 --- a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py +++ b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py @@ -18,7 +18,8 @@ class EcdcDateReported(BlueprintDateReported): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) id = db.Column(db.Integer, primary_key=True) # @@ -54,7 +55,7 @@ class EcdcContinent(BlueprintLocationGroup): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s)" % (self.__class__.__name__, self.location_group) id = db.Column(db.Integer, primary_key=True) location_group = db.Column(db.String(255), nullable=False, unique=True) @@ -75,7 +76,9 @@ class EcdcCountry(BlueprintLocation): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s, %s; %s, %s)" % (self.__class__.__name__, + self.location_group.__repr__(), + self.location_code, self.location, self.pop_data_2019, self.geo_id) def __str__(self): return " " + self.location_group.location_group \ @@ -148,7 +151,7 @@ class EcdcData(BlueprintFactTable): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s)" % (self.__class__.__name__, self.date_reported_id, self.location_id) id = db.Column(db.Integer, primary_key=True) date_reported_id = db.Column(db.Integer, db.ForeignKey('ecdc_date_reported.id'), nullable=False) diff --git a/src/flask_covid19/blueprints/data_owid/owid_model.py b/src/flask_covid19/blueprints/data_owid/owid_model.py index 26f0dac6..48307e17 100644 --- a/src/flask_covid19/blueprints/data_owid/owid_model.py +++ b/src/flask_covid19/blueprints/data_owid/owid_model.py @@ -1,5 +1,5 @@ from sqlalchemy import and_ -from sqlalchemy.orm import joinedload, subqueryload +from sqlalchemy.orm import joinedload from database import db, ITEMS_PER_PAGE, cache from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported, BlueprintLocationGroup @@ -19,7 +19,8 @@ class OwidDateReported(BlueprintDateReported): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) id = db.Column(db.Integer, primary_key=True) # @@ -48,7 +49,7 @@ class OwidContinent(BlueprintLocationGroup): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s)" % (self.__class__.__name__, self.location_group) def __str__(self): result = "" + self.location_group + " " @@ -68,7 +69,8 @@ class OwidCountry(BlueprintLocation): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.location_group.__repr__(), self.location_code, self.location) def __str__(self): result = "" + self.location_group.__str__() + " : " + self.location_code + " | " + self.location + " " @@ -145,7 +147,7 @@ class OwidData(BlueprintFactTable): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s)" % (self.__class__.__name__, self.date_reported_id, self.location_id) id = db.Column(db.Integer, primary_key=True) date_reported_id = db.Column(db.Integer, db.ForeignKey('owid_date_reported.id'), nullable=False) diff --git a/src/flask_covid19/blueprints/data_rki/rki_model.py b/src/flask_covid19/blueprints/data_rki/rki_model.py index 4658a2ce..3cd239d1 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_model.py +++ b/src/flask_covid19/blueprints/data_rki/rki_model.py @@ -19,7 +19,8 @@ class RkiMeldedatum(BlueprintDateReported): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) id = db.Column(db.Integer, primary_key=True) # @@ -63,7 +64,8 @@ class RkiDatenstand(BlueprintDateReported): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) id = db.Column(db.Integer, primary_key=True) # @@ -97,7 +99,8 @@ class RkiRefDatum(BlueprintDateReported): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) id = db.Column(db.Integer, primary_key=True) # @@ -126,7 +129,7 @@ class RkiBundesland(BlueprintLocationGroup): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s)" % (self.__class__.__name__, self.location_group, self.id_bundesland) def __str__(self): return " " + self.location_group + " " @@ -146,7 +149,8 @@ class RkiLandkreis(BlueprintLocation): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s %s)" % (self.__class__.__name__, + self.location_group.__repr__(), self.location, self.id_landkreis) def __str__(self): return " " + str(self.location_group) + " : " + self.location + " ( " + self.id_landkreis + " ) " @@ -203,9 +207,12 @@ class RkiLandkreis(BlueprintLocation): class RkiAltersgruppe(BlueprintEntity): __tablename__ = 'rki_altersgruppe' __mapper_args__ = {'concrete': True} + __table_args__ = ( + db.UniqueConstraint('altersgruppe', name="uix_rki_altersgruppe"), + ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s)" % (self.__class__.__name__, self.altersgruppe) def __str__(self): return " " + self.altersgruppe + " " @@ -213,7 +220,7 @@ class RkiAltersgruppe(BlueprintEntity): id = db.Column(db.Integer, primary_key=True) processed_update = db.Column(db.Boolean, nullable=False) processed_full_update = db.Column(db.Boolean, nullable=False) - altersgruppe = db.Column(db.String(255), nullable=False) + altersgruppe = db.Column(db.String(255), nullable=False, unique=True) @classmethod @cache.memoize(50) @@ -250,7 +257,10 @@ class RkiData(BlueprintFactTable): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s %s %s %s %s %s)" % (self.__class__.__name__, + self.fid, self.geschlecht, self.date_reported_id, + self.datenstand_id, self.location_id, + self.ref_datum_id, self.altersgruppe_id) id = db.Column(db.Integer, primary_key=True) processed_update = db.Column(db.Boolean, nullable=False) diff --git a/src/flask_covid19/blueprints/data_rki/rki_model_import.py b/src/flask_covid19/blueprints/data_rki/rki_model_import.py index 76c62836..a3e1c161 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_model_import.py +++ b/src/flask_covid19/blueprints/data_rki/rki_model_import.py @@ -10,7 +10,10 @@ class RkiImport(AllImport): __mapper_args__ = {'concrete': True} def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s %s %s %s %s %s %s %s)" % (self.__class__.__name__, + self.fid, self.geschlecht, self.date_reported_import_str, + self.datum.isoformat(), self.datenstand_id, self.bundesland, + self.landkreis, self.ref_datum_id, self.altersgruppe) id = db.Column(db.Integer, primary_key=True) date_reported_import_str = db.Column(db.String(255), nullable=False) @@ -39,12 +42,8 @@ class RkiImport(AllImport): @classmethod def remove_all(cls): - num_rows_deleted = 0 - try: - num_rows_deleted = db.session.query(cls).delete() - db.session.commit() - except Exception: - db.session.rollback() + num_rows_deleted = db.session.query(cls).delete() + db.session.commit() return num_rows_deleted @classmethod @@ -57,21 +56,6 @@ class RkiImport(AllImport): def get_all(cls): return db.session.query(cls).all() - @classmethod - @cache.memoize(50) - def get_aktualisierungen_as_array(cls): - return [] - - @classmethod - @cache.memoize(50) - def find_by_aktualisierung(cls, aktualisierung_from_import: str): - return [] - - @classmethod - @cache.memoize(50) - def get_new_aktualisierungen_as_array(cls): - return [] - @classmethod @cache.memoize(50) def get_date_datenstand_of_all_import(cls): @@ -175,7 +159,10 @@ class RkiFlat(AllFlat): __mapper_args__ = {'concrete': True} def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s %s %s %s %s %s %s %s)" % (self.__class__.__name__, + self.fid, self.geschlecht, self.date_reported_import_str, + self.datum.isoformat(), self.datenstand, self.bundesland, + self.landkreis, self.ref_datum, self.altersgruppe) id = db.Column(db.Integer, primary_key=True) # diff --git a/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py b/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py index 5ade3717..8fbb0980 100644 --- a/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py +++ b/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py @@ -1,5 +1,5 @@ -from database import db, ITEMS_PER_PAGE +from database import db, cache from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported, BlueprintFactTableTimeSeries @@ -18,7 +18,8 @@ class VaccinationDateReported(BlueprintDateReported): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) id = db.Column(db.Integer, primary_key=True) # @@ -47,7 +48,7 @@ class VaccinationData(BlueprintFactTableTimeSeries): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s)" % (self.__class__.__name__, self.date_reported_id) id = db.Column(db.Integer, primary_key=True) date_reported_id = db.Column(db.Integer, db.ForeignKey('vaccination_date_reported.id'), nullable=False) @@ -80,8 +81,8 @@ class VaccinationData(BlueprintFactTableTimeSeries): indikation_medizinisch_voll = db.Column(db.Integer, nullable=False) indikation_pflegeheim_voll = db.Column(db.Integer, nullable=False) - @classmethod + @cache.memoize(50) def find_by_date_reported(cls, date_reported: VaccinationDateReported): return db.session.query(cls) \ .filter(cls.date_reported_id == date_reported.id) \ diff --git a/src/flask_covid19/blueprints/data_who/who_model.py b/src/flask_covid19/blueprints/data_who/who_model.py index 1ba6f127..ffcf76e7 100644 --- a/src/flask_covid19/blueprints/data_who/who_model.py +++ b/src/flask_covid19/blueprints/data_who/who_model.py @@ -18,7 +18,8 @@ class WhoDateReported(BlueprintDateReported): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) def __str__(self): return self.datum.isoformat() @@ -47,7 +48,7 @@ class WhoCountryRegion(BlueprintLocationGroup): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s)" % (self.__class__.__name__, self.location_group) def __str__(self): return " " + self.location_group + " " @@ -66,10 +67,11 @@ class WhoCountry(BlueprintLocation): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s %s)" % (self.__class__.__name__, + self.location_group.__repr__(), self.location_code, self.location) def __str__(self): - return self.location_group.__str__() + " : "+ self.location_code + " | " + self.location + return self.location_group.__str__() + " : " + self.location_code + " | " + self.location id = db.Column(db.Integer, primary_key=True) location_code = db.Column(db.String(255), unique=True, nullable=False) @@ -85,7 +87,8 @@ class WhoCountry(BlueprintLocation): @classmethod @cache.memoize(50) - def find_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, location_group: WhoCountryRegion): + def find_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, + location_group: WhoCountryRegion): return db.session.query(cls).filter( and_( cls.location_code == location_code, @@ -96,7 +99,8 @@ class WhoCountry(BlueprintLocation): @classmethod @cache.memoize(50) - def get_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, location_group: WhoCountryRegion): + def get_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, + location_group: WhoCountryRegion): return db.session.query(cls).filter( and_( cls.location_code == location_code, @@ -148,7 +152,7 @@ class WhoData(BlueprintFactTable): ) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s)" % (self.__class__.__name__, self.date_reported_id, self.location_id) id = db.Column(db.Integer, primary_key=True) date_reported_id = db.Column(db.Integer, db.ForeignKey('who_date_reported.id'), nullable=False) diff --git a/src/flask_covid19/blueprints/data_who/who_model_import.py b/src/flask_covid19/blueprints/data_who/who_model_import.py index ffdfe6b0..d9567acc 100644 --- a/src/flask_covid19/blueprints/data_who/who_model_import.py +++ b/src/flask_covid19/blueprints/data_who/who_model_import.py @@ -1,5 +1,5 @@ from sqlalchemy.orm import Bundle -from database import db, ITEMS_PER_PAGE, cache +from database import db, cache from flask_covid19.blueprints.app_all.all_model import AllImport, AllFlat @@ -8,7 +8,9 @@ class WhoImport(AllImport): __mapper_args__ = {'concrete': True} def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s %s %s %s)" % (self.__class__.__name__, + self.datum.isoformat(), self.date_reported, + self.country_code, self.country, self.who_region) def __str__(self): return self.datum.isoformat() + " " + self.country_code + " " + self.country + " " + str(self.row_imported) @@ -58,7 +60,7 @@ class WhoImport(AllImport): .distinct().all() for my_datum_item in myresultset: my_datum = my_datum_item.datum.isoformat() - if not my_datum in myresultarray: + if my_datum not in myresultarray: myresultarray.append(my_datum) return myresultarray @@ -137,7 +139,7 @@ class WhoImport(AllImport): @classmethod @cache.memoize(50) 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 @@ -163,7 +165,9 @@ class WhoFlat(AllFlat): __mapper_args__ = {'concrete': True} def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, self.id) + return "%s(%s %s %s %s %s)" % (self.__class__.__name__, + self.datum.isoformat(), self.date_reported_import_str, + self.location_code, self.location, self.location_group) def __str__(self): return self.datum.isoformat() + " " + self.location_code + " " + self.location + " " + str(self.location_group) -- GitLab