diff --git a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py index d7e4e5fdc5d12461cbc964c4dbefb37ddcca948e..5665bece11279bba71b4def2901f076cd01f9c91 100644 --- a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py +++ b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py @@ -108,13 +108,13 @@ class EcdcCountry(BlueprintLocation): @classmethod def find_by_location_group(cls, location_group: EcdcContinent): return db.session.query(cls)\ - .filter(cls.location_group == location_group)\ + .filter(cls.location_group_id == location_group.id)\ .all() @classmethod def get_by_location_group(cls, location_group: EcdcContinent, page: int): return db.session.query(cls)\ - .filter(cls.location_group == location_group)\ + .filter(cls.location_group_id == location_group.id)\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod @@ -150,17 +150,20 @@ class EcdcData(BlueprintFactTable): @classmethod def __query_by_date_reported(cls, date_reported: EcdcDateReported): - return db.session.query(cls).filter(cls.date_reported_id == date_reported.id) \ + return db.session.query(cls)\ + .filter(cls.date_reported_id == date_reported.id) \ .order_by(cls.cumulative_number_for_14_days_of_covid19_cases_per_100000.desc()) @classmethod def __query_by_date_reported_order_by_notification_rate(cls, date_reported: EcdcDateReported): - return db.session.query(cls).filter(cls.date_reported_id == date_reported.id) \ + return db.session.query(cls)\ + .filter(cls.date_reported_id == date_reported.id) \ .order_by(cls.cumulative_number_for_14_days_of_covid19_cases_per_100000.desc()) @classmethod def __query_by_date_reported_order_by_deaths(cls, date_reported: EcdcDateReported): - return db.session.query(cls).filter(cls.date_reported_id == date_reported.id) \ + return db.session.query(cls)\ + .filter(cls.date_reported_id == date_reported.id) \ .order_by(cls.deaths.desc()) @classmethod @@ -172,8 +175,7 @@ class EcdcData(BlueprintFactTable): @classmethod def __query_by_location(cls, location: EcdcCountry): return db.session.query(cls)\ - .filter(cls.location_id == location.id) \ - .order_by(cls.date_reported.desc()) + .filter(cls.location_id == location.id) @classmethod def __query_by_date_reported_and_location(cls, date_reported: EcdcDateReported, location: EcdcCountry): @@ -232,3 +234,10 @@ class EcdcData(BlueprintFactTable): def get_by_date_reported_and_location(cls, date_reported: EcdcDateReported, location: EcdcCountry, page: int): return cls.__query_by_date_reported_and_location(date_reported, location).one() + @classmethod + def delete_data_for_one_day(cls, date_reported: EcdcDateReported): + for data in cls.find_by_date_reported(date_reported): + db.session.delete(data) + db.session.delete(date_reported) + db.session.commit() + diff --git a/src/flask_covid19/blueprints/data_owid/owid_model.py b/src/flask_covid19/blueprints/data_owid/owid_model.py index 36449d2d494162511165df5e01bc2dba7c95fa21..44448137ea2682b0671008dbfc1def41f9cd24f1 100644 --- a/src/flask_covid19/blueprints/data_owid/owid_model.py +++ b/src/flask_covid19/blueprints/data_owid/owid_model.py @@ -265,7 +265,7 @@ class OwidData(BlueprintFactTable): @classmethod def delete_data_for_one_day(cls, date_reported: OwidDateReported): - for data in cls.get_data_for_one_day(date_reported): + for data in cls.find_by_date_reported(date_reported): db.session.delete(data) db.session.delete(date_reported) db.session.commit() diff --git a/src/flask_covid19/blueprints/data_rki/rki_model.py b/src/flask_covid19/blueprints/data_rki/rki_model.py index 51b8912411ce86504114e7a44b1775cffe0cfea0..fa1b819ed0e4e0e9d27643ee2a80795a2ea3ebe4 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_model.py +++ b/src/flask_covid19/blueprints/data_rki/rki_model.py @@ -246,7 +246,7 @@ class RkiData(BlueprintFactTable): lazy='joined', cascade='save-update', order_by='desc(RkiAltersgruppe.altersgruppe)') - neuer_fall = db.Column(db.String(255), nullable=False) + # neuer_fall = db.Column(db.String(255), nullable=False) geschlecht = db.Column(db.String(255), nullable=False) anzahl_fall = db.Column(db.String(255), nullable=False) anzahl_todesfall = db.Column(db.String(255), nullable=False) @@ -272,12 +272,6 @@ class RkiData(BlueprintFactTable): ist_erkrankungsbeginn = db.Column(db.String(255), nullable=False) altersgruppe2 = db.Column(db.String(255), nullable=False) - @classmethod - def find_by_date_reported_and_location(cls, date_reported: RkiMeldedatum, location: RkiLandkreis): - return db.session.query(cls).filter( - and_((cls.date_reported == date_reported), (cls.location == location)) - ).one_or_none() - @classmethod def delete_all(cls): db.session.query(cls).delete() @@ -286,14 +280,33 @@ class RkiData(BlueprintFactTable): @classmethod def get_by_location(cls, location: RkiLandkreis, page: int): - return db.session.query(cls).filter(cls.location == location).paginate(page, per_page=ITEMS_PER_PAGE) + return db.session.query(cls)\ + .filter(cls.location_id == location.id)\ + .order_by(cls.date_reported)\ + .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod def find_by_location(cls, location: RkiLandkreis): - return db.session.query(cls).filter(cls.location == location).all() + return db.session.query(cls)\ + .filter(cls.location_id == location.id)\ + .order_by(cls.date_reported)\ + .all() @classmethod - def get_by_date_reported_and_location(cls, date_reported: RkiMeldedatum, location: RkiLandkreis): + def find_by_date_reported_and_location(cls, date_reported: RkiMeldedatum, location: RkiLandkreis): return db.session.query(cls)\ - .filter(and_((cls.date_reported == date_reported), (cls.location == location)))\ + .filter(and_((cls.date_reported_id == date_reported.id), (cls.location_id == location.id)))\ .all() + + @classmethod + def get_by_date_reported_and_location(cls, date_reported: RkiMeldedatum, location: RkiLandkreis, page: int): + return db.session.query(cls)\ + .filter(and_((cls.date_reported_id == date_reported.id), (cls.location_id == location.id)))\ + .paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def delete_data_for_one_day(cls, date_reported: RkiMeldedatum): + for data in cls.find_by_date_reported(date_reported): + db.session.delete(data) + db.session.delete(date_reported) + db.session.commit() diff --git a/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py b/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py index 2e7229d53c846dd00d294e5c09c3e98a272eb1bf..eb6ede6f4f88b721346c87d003da29528318e2ca 100644 --- a/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py +++ b/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py @@ -77,3 +77,10 @@ class VaccinationData(BlueprintFactTableTimeSeries): return db.session.query(cls) \ .filter(cls.date_reported_id == date_reported.id) \ .one_or_none() + + @classmethod + def delete_data_for_one_day(cls, date_reported: VaccinationDateReported): + for data in cls.find_by_date_reported(date_reported): + db.session.delete(data) + db.session.delete(date_reported) + db.session.commit() diff --git a/src/flask_covid19/blueprints/data_who/who_model.py b/src/flask_covid19/blueprints/data_who/who_model.py index c537854296f22c7edba28eea28b6d5a89a213345..704904ca6dab65c7e0c0b69b65a9b441ffd5d433 100644 --- a/src/flask_covid19/blueprints/data_who/who_model.py +++ b/src/flask_covid19/blueprints/data_who/who_model.py @@ -308,3 +308,10 @@ class WhoData(BlueprintFactTable): @classmethod def find_by_location_order_by_deaths_cumulative(cls, location: WhoDateReported): return cls.__query_by_location_order_by_deaths_cumulative(location).all() + + @classmethod + def delete_data_for_one_day(cls, date_reported: WhoDateReported): + for data in cls.find_by_date_reported(date_reported): + db.session.delete(data) + db.session.delete(date_reported) + db.session.commit()