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 c519bba3a24800d814b5e2b851a3c6c2918fd65f..f450330a745c4b50d1c5733468be9b45c48037c9 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_model_import.py +++ b/src/flask_covid19/blueprints/data_rki/rki_model_import.py @@ -1,5 +1,6 @@ from datetime import date from sqlalchemy.orm import Bundle +from sqlalchemy import and_ from database import db, ITEMS_PER_PAGE from flask_covid19.blueprints.app_all.all_model import AllImport, AllFlat @@ -143,6 +144,13 @@ class RkiImport(AllImport): .order_by(cls.landkreis.asc()) \ .all() + @classmethod + def find_by_meldedatum_and_landkreis(cls, my_datum: str, my_landkreis: str): + return db.session.query(cls) \ + .filter(and_(cls.datum == my_datum), (cls.landkreis == my_landkreis)) \ + .order_by(cls.landkreis.asc()) \ + .all() + class RkiFlat(AllFlat): __tablename__ = 'rki_import_flat' diff --git a/src/flask_covid19/blueprints/data_rki/rki_service_update.py b/src/flask_covid19/blueprints/data_rki/rki_service_update.py index 3fcdbffd26263baaf79a44aea0fa9fa8f43edeac..9a4d6923f84c9ab61c7a4b52772d6b1407087066 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_service_update.py +++ b/src/flask_covid19/blueprints/data_rki/rki_service_update.py @@ -189,7 +189,7 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): i = 0 d = 0 k = 0 - dict_locations = RkiLandkreis.find_all_as_dict() + # dict_locations = RkiLandkreis.find_all_as_dict() dict_altersgruppen = RkiAltersgruppe.find_all_as_dict() dict_ref_datum = RkiRefDatum.find_all_as_dict() dict_datenstand = RkiDatenstand.find_all_as_dict() @@ -198,55 +198,58 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): # app.logger.info("------------------------------------------------------------") for my_meldedatum in RkiMeldedatum.find_all(): my_meldedatum_datum = my_meldedatum.datum - # app.logger.info(" my_meldedatum: " + str(my_meldedatum) + " " + d.isoformat()) - # app.logger.info("------------------------------------------------------------") - list_imports = RkiImport.find_by_datum(my_datum=my_meldedatum_datum) - # if l_imports is None: - # app.logger.info("list_imports is None ") - # else: - # nr = len(list_imports) - # app.logger.info("len(list_imports): " + str(nr)) - # app.logger.info("------------------------------------------------------------") - for o_import in list_imports: - # app.logger.info("o_import.landkreis " + o_import.landkreis) - key_location = o_import.landkreis - key_altersgruppen = o_import.altersgruppe - key_datenstand = o_import.datenstand - key_ref_datum = o_import.ref_datum - my_altersgruppe = dict_altersgruppen[key_altersgruppen] - my_landkreis = dict_locations[key_location] - my_datenstand = dict_datenstand[key_datenstand] - my_ref_datum = dict_ref_datum[key_ref_datum] - # app.logger.info(str(my_landkreis)) - o = RkiData( - date_reported=my_meldedatum, - datenstand=my_datenstand, - location=my_landkreis, - ref_datum=my_ref_datum, - altersgruppe=my_altersgruppe, - fid=o_import.fid, - geschlecht=o_import.geschlecht, - # - anzahl_fall=o_import.anzahl_fall, - anzahl_todesfall=o_import.anzahl_todesfall, - neuer_fall=o_import.neuer_fall, - neuer_todesfall=o_import.neuer_todesfall, - neu_genesen=o_import.neu_genesen, - anzahl_genesen=o_import.anzahl_genesen, - ist_erkrankungsbeginn=o_import.ist_erkrankungsbeginn, - altersgruppe2=o_import.altersgruppe2, - processed_update=False, - processed_full_update=True, - ) - db.session.add(o) - k += 1 - i += 1 - d += 1 - if d % 7 == 0: - db.session.commit() - sd = str(my_meldedatum) - app.logger.info(" full update RKI data ... " + str(i) + " rows ... " + sd + " (" + str(k) + ")") - k = 0 + for my_landkreis in RkiLandkreis.find_all(): + my_landkreis_key = my_landkreis.location_type() + " " + my_landkreis.location + # app.logger.info(" my_meldedatum: " + str(my_meldedatum) + " " + d.isoformat()) + # app.logger.info("------------------------------------------------------------") + list_imports = RkiImport.find_by_meldedatum_and_landkreis( + my_datum=my_meldedatum_datum, my_landkreis=my_landkreis_key) + # if l_imports is None: + # app.logger.info("list_imports is None ") + # else: + # nr = len(list_imports) + # app.logger.info("len(list_imports): " + str(nr)) + # app.logger.info("------------------------------------------------------------") + for o_import in list_imports: + # app.logger.info("o_import.landkreis " + o_import.landkreis) + # key_location = o_import.landkreis + key_altersgruppen = o_import.altersgruppe + key_datenstand = o_import.datenstand + key_ref_datum = o_import.ref_datum + my_altersgruppe = dict_altersgruppen[key_altersgruppen] + # my_landkreis = dict_locations[key_location] + my_datenstand = dict_datenstand[key_datenstand] + my_ref_datum = dict_ref_datum[key_ref_datum] + # app.logger.info(str(my_landkreis)) + o = RkiData( + date_reported=my_meldedatum, + datenstand=my_datenstand, + location=my_landkreis, + ref_datum=my_ref_datum, + altersgruppe=my_altersgruppe, + fid=o_import.fid, + geschlecht=o_import.geschlecht, + # + anzahl_fall=o_import.anzahl_fall, + anzahl_todesfall=o_import.anzahl_todesfall, + neuer_fall=o_import.neuer_fall, + neuer_todesfall=o_import.neuer_todesfall, + neu_genesen=o_import.neu_genesen, + anzahl_genesen=o_import.anzahl_genesen, + ist_erkrankungsbeginn=o_import.ist_erkrankungsbeginn, + altersgruppe2=o_import.altersgruppe2, + processed_update=False, + processed_full_update=True, + ) + db.session.add(o) + k += 1 + i += 1 + d += 1 + if d % 7 == 0: + db.session.commit() + sd = str(my_meldedatum) + app.logger.info(" full update RKI data ... " + str(i) + " rows ... " + sd + " (" + str(k) + ")") + k = 0 db.session.commit() app.logger.info(" full update RKI data ... " + str(i) + " total rows") app.logger.info("")