diff --git a/src/covid19/blueprints/europe/europe_model_import.py b/src/covid19/blueprints/europe/europe_model_import.py index 74fc93e737e24e9161b7b7703793ae1bb9c9d74f..e7faac64783f128434b83ba9c59228a660f96d2a 100644 --- a/src/covid19/blueprints/europe/europe_model_import.py +++ b/src/covid19/blueprints/europe/europe_model_import.py @@ -59,7 +59,8 @@ class EuropeDataImportTable(db.Model): my_continent_exp = my_continent.region my_params = {} my_params['my_continent_param'] = my_continent_exp - # TODO: SQLalchemy instead of SQL + #TODO: SQLalchemy instead of SQL + #TODO: BUG: change to ORM ClassHierarchy sql = """ select distinct countries_and_territories, diff --git a/src/covid19/blueprints/europe/europe_service.py b/src/covid19/blueprints/europe/europe_service.py index 0b4f836397eb4af938d93ccb906ea8986cc1fcfb..a4b48d5215f636de5f59ac4e724d52a4388cfef7 100644 --- a/src/covid19/blueprints/europe/europe_service.py +++ b/src/covid19/blueprints/europe/europe_service.py @@ -6,6 +6,7 @@ from covid19.blueprints.europe.europe_service_import import EuropeServiceImport from covid19.blueprints.europe.europe_service_update import EuropeServiceUpdate +# TODO: refactor to new method scheme itroduced 07.02.2021 class EuropeService: def __init__(self, database): app.logger.debug("------------------------------------------------------------") @@ -28,6 +29,34 @@ class EuropeService: self.europe_service_update.update_db_short() return self + def run_download_only(self): + self.europe_service_download.download() + return self + + def run_import_only(self): + self.europe_service_import.import_datafile_to_db() + return self + + def run_update_dimension_tables_only(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self + + def run_update_fact_table_incremental_only(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self + + def run_update_fact_table_initial_only(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self + + def run_update_star_schema_incremental(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self + + def run_update_star_schema_initial(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self + def download(self): app.logger.info(" download [begin]") app.logger.info("------------------------------------------------------------") diff --git a/src/covid19/blueprints/europe/europe_service_update.py b/src/covid19/blueprints/europe/europe_service_update.py index d23a2afe4cf65f5e558bb71d367b8c353555511d..af132e8ead3515b68160e65f0a5aa16199431f6a 100644 --- a/src/covid19/blueprints/europe/europe_service_update.py +++ b/src/covid19/blueprints/europe/europe_service_update.py @@ -156,3 +156,22 @@ class EuropeServiceUpdate: app.logger.info("------------------------------------------------------------") return self + def update_dimension_tables_only(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self + + def update_fact_table_incremental_only(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self + + def update_fact_table_initial_only(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self + + def update_star_schema_incremental(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self + + def update_star_schema_initial(self): + # TODO: refactor to new method scheme itroduced 07.02.2021 + return self diff --git a/src/covid19/blueprints/rki/rki_model.py b/src/covid19/blueprints/rki/rki_model.py index aecc29c70efd51d7521a43c5d9da7e17ba476dfc..4dc19d5e851f386cca27cfda346acbb922d89c46 100644 --- a/src/covid19/blueprints/rki/rki_model.py +++ b/src/covid19/blueprints/rki/rki_model.py @@ -7,7 +7,7 @@ from covid19.blueprints.common.common_model import CommonDateReported, CommonReg class RkiDateReported(CommonDateReported): - __mapper_args__ = {'polymorphic_identity': 'RkiDateReported'} + __mapper_args__ = {'polymorphic_identity': 'rki_date_reported'} @classmethod def create_new_object_factory(cls, my_date_rep): @@ -100,8 +100,10 @@ class RkiCountry(db.Model): ).order_by(cls.country).paginate(page, per_page=ITEMS_PER_PAGE) +# TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? +# TODO: RkiGermanyData rename to RkiBundeslaender class RkiGermanyData(db.Model): - __tablename__ = 'rki_global_data' + __tablename__ = 'rki_bundeslsaender' id = db.Column(db.Integer, primary_key=True) cases_new = db.Column(db.Integer, nullable=False) @@ -167,3 +169,50 @@ class RkiGermanyData(db.Model): cls.deaths_cumulative.desc(), cls.cases_cumulative.desc() ).paginate(page, per_page=ITEMS_PER_PAGE) + + +# TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? +# TODO: RkiLandkreise +class RkiLandkreise(db.Model): + __tablename__ = 'rki_landkreise' + + id = db.Column(db.Integer, primary_key=True) + + OBJECTID_1 = db.Column(db.String(255), nullable=False) + LAN_ew_AGS = db.Column(db.String(255), nullable=False) + LAN_ew_GEN = db.Column(db.String(255), nullable=False) + LAN_ew_BEZ = db.Column(db.String(255), nullable=False) + LAN_ew_EWZ = db.Column(db.String(255), nullable=False) + OBJECTID = db.Column(db.String(255), nullable=False) + Fallzahl = db.Column(db.String(255), nullable=False) + Aktualisierung = db.Column(db.String(255), nullable=False) + AGS_TXT = db.Column(db.String(255), nullable=False) + GlobalID = db.Column(db.String(255), nullable=False) + faelle_100000_EW = db.Column(db.String(255), nullable=False) + Death = db.Column(db.String(255), nullable=False) + cases7_bl_per_100k = db.Column(db.String(255), nullable=False) + cases7_bl = db.Column(db.String(255), nullable=False) + death7_bl = db.Column(db.String(255), nullable=False) + cases7_bl_per_100k_txt = db.Column(db.String(255), nullable=False) + AdmUnitId = db.Column(db.String(255), nullable=False) + SHAPE_Length = db.Column(db.String(255), nullable=False) + SHAPE_Area = db.Column(db.String(255), nullable=False) + + @classmethod + def remove_all(cls): + for one in cls.get_all(): + db.session.delete(one) + db.session.commit() + return None + + @classmethod + def get_all_as_page(cls, page): + return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_all(cls): + return db.session.query(cls).all() + + @classmethod + def get_by_id(cls, other_id): + return db.session.query(cls).filter(cls.id == other_id).one() diff --git a/src/covid19/blueprints/rki/rki_model_import.py b/src/covid19/blueprints/rki/rki_model_import.py index 09a32eeb059a26a5f190f41aac5e77208fc1f174..313e9bfbc173e2670b373d624e2eb225b1997937 100644 --- a/src/covid19/blueprints/rki/rki_model_import.py +++ b/src/covid19/blueprints/rki/rki_model_import.py @@ -2,6 +2,9 @@ from database import db, ITEMS_PER_PAGE # OBJECTID_1,LAN_ew_AGS,LAN_ew_GEN,LAN_ew_BEZ,LAN_ew_EWZ,OBJECTID,Fallzahl,Aktualisierung,AGS_TXT,GlobalID,faelle_100000_EW,Death,cases7_bl_per_100k,cases7_bl,death7_bl,cases7_bl_per_100k_txt,AdmUnitId,SHAPE_Length,SHAPE_Area + +# TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? +# TODO: RkiBundeslaenderImport class RkiBundeslaenderImport(db.Model): __tablename__ = 'rki_bundeslsaender_import' @@ -46,7 +49,14 @@ class RkiBundeslaenderImport(db.Model): def get_by_id(cls, other_id): return db.session.query(cls).filter(cls.id == other_id).one() + @classmethod + def get_dates_reported(self): + #TODO: implement RkiBundeslaenderImport.get_dates_reported + return self + +# TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? +# TODO: add fields from csv to RkiLandkreiseImport class RkiLandkreiseImport(db.Model): __tablename__ = 'rki_landkreise_import' @@ -93,6 +103,7 @@ class RkiLandkreiseImport(db.Model): @classmethod def get_new_dates_as_array(cls): + #TODO: BUG: change to ORM ClassHierarchy sql_query = """ select date_reported @@ -119,3 +130,79 @@ class RkiLandkreiseImport(db.Model): for item in db.session.execute(sql_query): new_dates.append(item['date_reported']) return new_dates + + +# TODO: remove RkiGermanyDataImportTable +class RkiGermanyDataImportTable(db.Model): + __tablename__ = 'rki_germany_data_import' + + id = db.Column(db.Integer, primary_key=True) + date_reported = db.Column(db.String(255), nullable=False) + country_code = db.Column(db.String(255), nullable=False) + country = db.Column(db.String(255), nullable=False) + who_region = db.Column(db.String(255), nullable=False) + new_cases = db.Column(db.String(255), nullable=False) + cumulative_cases = db.Column(db.String(255), nullable=False) + new_deaths = db.Column(db.String(255), nullable=False) + cumulative_deaths = db.Column(db.String(255), nullable=False) + + @classmethod + def remove_all(cls): + for one in cls.get_all(): + db.session.delete(one) + db.session.commit() + return None + + @classmethod + def get_all_as_page(cls, page): + return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_all(cls): + return db.session.query(cls).all() + + @classmethod + def get_by_id(cls, other_id): + return db.session.query(cls).filter(cls.id == other_id).one() + + @classmethod + def get_regions(cls): + return db.session.query(cls.who_region).distinct() + + @classmethod + def get_dates_reported(cls): + return db.session.query(cls.date_reported).distinct() + + @classmethod + def get_for_one_day(cls, day): + return db.session.query(cls).filter(cls.date_reported == day).all() + + @classmethod + def get_new_dates_as_array(cls): + #TODO: BUG: change to ORM ClassHierarchy + sql_query = """ + select + date_reported + from + rki_germany_data_import + where + date_reported + not in ( + select + distinct + who_date_reported.date_reported + from + who_global_data + left join + who_date_reported + on + who_global_data.date_reported_id=who_date_reported.id + ) + group by + rki_germany_data_import.date_reported + order by date_reported desc + """ + new_dates = [] + for item in db.session.execute(sql_query): + new_dates.append(item['date_reported']) + return new_dates diff --git a/src/covid19/blueprints/rki/rki_service.py b/src/covid19/blueprints/rki/rki_service.py index 4cf7f4a3c63e81cc5b2f104419ebcee4a05ffba1..eef903b791140576f2606c491f9eff04464082f7 100644 --- a/src/covid19/blueprints/rki/rki_service.py +++ b/src/covid19/blueprints/rki/rki_service.py @@ -6,6 +6,7 @@ from covid19.blueprints.rki.rki_service_import import RkiServiceImport from covid19.blueprints.rki.rki_service_update import RkiServiceUpdate +# TODO: refactor RkiService to new method scheme introduced 07.02.2021 class RkiService: def __init__(self, database): app.logger.debug("------------------------------------------------------------") @@ -21,14 +22,48 @@ class RkiService: def pretask_database_drop_create(self): flash("rki_service.run_download started") - success = self.service_download.download_file() + self.service_download.download_file() return self def task_database_drop_create(self): + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 + # TODO: implement RkiService.task_database_drop_create + return self + + def run_download_only(self): + self.service_download.download_file() + return self + + def run_import_only(self): self.service_import.import_file() - self.service_update.update_db_short() return self + def run_update_dimension_tables_only(self): + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 + # TODO: implement RkiService.run_update_dimension_tables_only + return self + + def run_update_fact_table_incremental_only(self): + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 + # TODO: implement RkiService.run_update_fact_table_incremental_only + return self + + def run_update_fact_table_initial_only(self): + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 + # TODO: implement RkiService.run_update_fact_table_initial_only + return self + + def run_update_star_schema_incremental(self): + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 + # TODO: implement RkiService.run_update_star_schema_incremental + return self + + def run_update_star_schema_initial(self): + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 + # TODO: implement RkiService.run_update_star_schema_initial + return self + + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 def run_download(self): app.logger.info(" run update [begin]") app.logger.info("------------------------------------------------------------") @@ -38,6 +73,7 @@ class RkiService: app.logger.info("------------------------------------------------------------") return success + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 def run_update(self, import_file=True): app.logger.info(" run update [begin]") app.logger.info("------------------------------------------------------------") @@ -49,6 +85,7 @@ class RkiService: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 def run_update_short(self, import_file=True): app.logger.info(" run update short [begin]") app.logger.info("------------------------------------------------------------") @@ -60,6 +97,7 @@ class RkiService: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiService to new method scheme introduced 07.02.2021 def run_update_initial(self, import_file=True): app.logger.info(" run update initial [begin]") app.logger.info("------------------------------------------------------------") diff --git a/src/covid19/blueprints/rki/rki_service_download.py b/src/covid19/blueprints/rki/rki_service_download.py index 3d71833668fb7f25237c538b49b4f59545570e45..510eaf21c81b7227481fa36bb7516e2d9be41c22 100644 --- a/src/covid19/blueprints/rki/rki_service_download.py +++ b/src/covid19/blueprints/rki/rki_service_download.py @@ -5,7 +5,8 @@ from flask import flash from database import app - +# TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? +# TODO: refactor RkiServiceDownload to new method scheme introduced 07.02.2021 class RkiServiceDownload: def __init__(self, database): app.logger.debug("------------------------------------------------------------") @@ -24,6 +25,7 @@ class RkiServiceDownload: app.logger.debug("------------------------------------------------------------") app.logger.debug(" RKI Service Download [ready]") + # TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? def __download_file(self, datascope, cvsfile_name, url_src): src_cvsfile_path = ".." + os.sep + ".." + os.sep + "data" + os.sep + cvsfile_name app.logger.info(" download - RKI "+datascope+" [begin] ") @@ -57,6 +59,7 @@ class RkiServiceDownload: flash(msg) return self + # TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? def download_file(self): app.logger.info(" download - RKI [begin] ") app.logger.info("------------------------------------------------------------") diff --git a/src/covid19/blueprints/rki/rki_service_import.py b/src/covid19/blueprints/rki/rki_service_import.py index e7151fa34c15cbac5ff211a1f8cae2ab25e8ec38..8dbf0caee27ce22cdd93666be4919afdaedf9c86 100644 --- a/src/covid19/blueprints/rki/rki_service_import.py +++ b/src/covid19/blueprints/rki/rki_service_import.py @@ -5,9 +5,10 @@ import psycopg2 from database import db, app +# TODO: move WhoGlobalDataImportTable to RKI from covid19.blueprints.who.who_model_import import WhoGlobalDataImportTable - +# TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? class RkiServiceImport: def __init__(self, database): app.logger.debug("------------------------------------------------------------") @@ -22,6 +23,7 @@ class RkiServiceImport: app.logger.debug("------------------------------------------------------------") app.logger.debug(" RKI Service Import [ready]") + # TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? def import_file(self): app.logger.info(" import RKI [begin]") app.logger.info("------------------------------------------------------------") @@ -34,11 +36,13 @@ class RkiServiceImport: else: keyDate_reported = 'Date_reported' try: + # TODO: move WhoGlobalDataImportTable to RKI WhoGlobalDataImportTable.remove_all() with open(self.__src_who_cvsfile_name, newline='\n') as csv_file: file_reader = csv.DictReader(csv_file, delimiter=',', quotechar='"') k = 0 for row in file_reader: + # TODO: move WhoGlobalDataImportTable to RKI o = WhoGlobalDataImportTable( date_reported=row[keyDate_reported], country_code=row['Country_code'], @@ -47,8 +51,7 @@ class RkiServiceImport: new_cases=row['New_cases'], cumulative_cases=row['Cumulative_cases'], new_deaths=row['New_deaths'], - cumulative_deaths=row['Cumulative_deaths'], - row_imported=False + cumulative_deaths=row['Cumulative_deaths'] ) db.session.add(o) if (k % 2000) == 0: diff --git a/src/covid19/blueprints/rki/rki_service_update.py b/src/covid19/blueprints/rki/rki_service_update.py index 26c5751b2701eb95a0fcbe60e8b62bf83bb63a40..54cd78a3aff23f149f4db462192be1763551c17f 100644 --- a/src/covid19/blueprints/rki/rki_service_update.py +++ b/src/covid19/blueprints/rki/rki_service_update.py @@ -1,12 +1,12 @@ from database import db, app from covid19.blueprints.rki.rki_model import RkiRegion, RkiDateReported, RkiCountry, RkiGermanyData -from covid19.blueprints.rki.rki_model_import import RkiBundeslaenderImport - +from covid19.blueprints.rki.rki_model_import import RkiBundeslaenderImport, RkiLandkreiseImport +from covid19.blueprints.rki.rki_model_import import RkiGermanyDataImportTable rki_service_update = None - +# TODO: question: Split RkiService into two Services, one for bundeslaender and one for landkreise? class RkiServiceUpdate: def __init__(self, database): app.logger.debug("------------------------------------------------------------") @@ -17,6 +17,7 @@ class RkiServiceUpdate: app.logger.debug("------------------------------------------------------------") app.logger.debug(" RKI Service Update [ready]") + # TODO: refactor RkiServiceUpdate.__update_who_date_reported def __update_who_date_reported(self): app.logger.info(" update who_date_reported [begin]") app.logger.info("------------------------------------------------------------") @@ -37,6 +38,7 @@ class RkiServiceUpdate: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiServiceUpdate.__update_who_region def __update_who_region(self): app.logger.info(" update who_region [begin]") app.logger.info("------------------------------------------------------------") @@ -58,6 +60,7 @@ class RkiServiceUpdate: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiServiceUpdate.__update_who_country def __update_who_country(self): app.logger.info(" update who_country [begin]") app.logger.info("------------------------------------------------------------") @@ -99,6 +102,7 @@ class RkiServiceUpdate: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiServiceUpdate.__update_who_global_data def __update_who_global_data(self): app.logger.info(" update WHO [begin]") app.logger.info("------------------------------------------------------------") @@ -134,6 +138,7 @@ class RkiServiceUpdate: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiServiceUpdate.__update_who_global_data_short def __update_who_global_data_short(self): app.logger.info(" update RKI short [begin]") app.logger.info("------------------------------------------------------------") @@ -164,6 +169,7 @@ class RkiServiceUpdate: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiServiceUpdate.__update_who_global_data_initial def __update_who_global_data_initial(self): app.logger.info(" update RKI initial [begin]") app.logger.info("------------------------------------------------------------") @@ -195,6 +201,7 @@ class RkiServiceUpdate: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiServiceUpdate.update_db def update_db(self): app.logger.info(" update db [begin]") app.logger.info("------------------------------------------------------------") @@ -206,6 +213,7 @@ class RkiServiceUpdate: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiServiceUpdate.update_db_short def update_db_short(self): app.logger.info(" update db short [begin]") app.logger.info("------------------------------------------------------------") @@ -217,6 +225,7 @@ class RkiServiceUpdate: app.logger.info("------------------------------------------------------------") return self + # TODO: refactor RkiServiceUpdate.update_db_initial def update_db_initial(self): app.logger.info(" update db initial [begin]") app.logger.info("------------------------------------------------------------") @@ -228,6 +237,23 @@ class RkiServiceUpdate: app.logger.info("------------------------------------------------------------") return self - def update_who_country(self): - self.__update_who_country() + def update_dimension_tables_only(self): + #TODO: implement RkiServiceUpdate.update_dimension_tables_only + return self + + def update_fact_table_incremental_only(self): + #TODO: implement RkiServiceUpdate.update_fact_table_incremental_only + return self + + def update_fact_table_initial_only(self): + #TODO: implement RkiServiceUpdate.update_fact_table_initial_only + return self + + def update_star_schema_incremental(self): + #TODO: implement RkiServiceUpdate.update_star_schema_incremental return self + + def update_star_schema_initial(self): + #TODO: implement RkiServiceUpdate.update_star_schema_initial + return self + diff --git a/src/covid19/blueprints/rki/rki_views.py b/src/covid19/blueprints/rki/rki_views.py index 3d39f5503d031decc707af4c6cc54ff42eb0ca4d..80ddb36eb1a0993cc2018e45a9603127ad8ca757 100644 --- a/src/covid19/blueprints/rki/rki_views.py +++ b/src/covid19/blueprints/rki/rki_views.py @@ -46,3 +46,5 @@ def url_rki_imported(page=1): 'rki/rki_imported.html', page_data=page_data, page_info=page_info) + +# TODO add Tasks and URLs for starting Tasks to rki_views diff --git a/src/covid19/blueprints/vaccination/vaccination_model.py b/src/covid19/blueprints/vaccination/vaccination_model.py index 517409ac8775e0b54ab0622cbf98afb0d31ba493..88c2fb70102d5aa40b1946d107f254667289f7be 100644 --- a/src/covid19/blueprints/vaccination/vaccination_model.py +++ b/src/covid19/blueprints/vaccination/vaccination_model.py @@ -1,2 +1,95 @@ +from datetime import date + from database import db, ITEMS_PER_PAGE +from covid19.blueprints.common.common_model import CommonDateReported + + +class VaccinationDateReported(CommonDateReported): + __mapper_args__ = {'polymorphic_identity': 'vaccination_date_reported'} + + @classmethod + def create_new_object_factory(cls, my_date_rep): + my_datum = date.fromisoformat(my_date_rep) + (my_iso_year, week_number, weekday) = my_datum.isocalendar() + my_year_week = "" + str(my_iso_year) + if week_number < 10: + my_year_week += "-0" + else: + my_year_week += "-" + my_year_week += str(week_number) + return VaccinationDateReported( + date_reported=my_date_rep, + datum=my_datum, + year=my_datum.year, + month=my_datum.month, + day_of_month=my_datum.day, + day_of_week=weekday, + week_of_year=week_number, + year_week=my_year_week + ) + + +# TODO: rename VaccinationGermanyTimelineAAA to Vaccination +class VaccinationGermanyTimelineAAA(db.Model): + __tablename__ = 'vaccination_germany_timeline' + + id = db.Column(db.Integer, primary_key=True) + # TODO: change to: Vaccination.datum many to one VaccinationDateReported + datum = db.Column(db.String(255), nullable=False) + dosen_kumulativ = db.Column(db.Integer, nullable=False) + dosen_differenz_zum_vortag = db.Column(db.Integer, nullable=False) + dosen_biontech_kumulativ = db.Column(db.Integer, nullable=False) + dosen_moderna_kumulativ = db.Column(db.Integer, nullable=False) + personen_erst_kumulativ = db.Column(db.Integer, nullable=False) + personen_voll_kumulativ = db.Column(db.Integer, nullable=False) + impf_quote_erst = db.Column(db.Float, nullable=False) + impf_quote_voll = db.Column(db.Float, nullable=False) + indikation_alter_dosen = db.Column(db.Integer, nullable=False) + indikation_beruf_dosen = db.Column(db.Integer, nullable=False) + indikation_medizinisch_dosen = db.Column(db.Integer, nullable=False) + indikation_pflegeheim_dosen = db.Column(db.Integer, nullable=False) + indikation_alter_erst = db.Column(db.Integer, nullable=False) + indikation_beruf_erst = db.Column(db.Integer, nullable=False) + indikation_medizinisch_erst = db.Column(db.Integer, nullable=False) + indikation_pflegeheim_erst = db.Column(db.Integer, nullable=False) + indikation_alter_voll = db.Column(db.Integer, nullable=False) + indikation_beruf_voll = db.Column(db.Integer, nullable=False) + indikation_medizinisch_voll = db.Column(db.Integer, nullable=False) + indikation_pflegeheim_voll = db.Column(db.Integer, nullable=False) + + @classmethod + def remove_all(cls): + for one in cls.get_all(): + db.session.delete(one) + db.session.commit() + return None + + @classmethod + def get_all_as_page(cls, page): + return db.session.query(cls)\ + .order_by(cls.datum.desc())\ + .paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_all(cls): + return db.session.query(cls)\ + .order_by(cls.datum.desc())\ + .all() + + @classmethod + def get_by_id(cls, other_id): + return db.session.query(cls)\ + .filter(cls.id == other_id)\ + .one() + + @classmethod + def find_by_id(cls, other_id): + return db.session.query(cls) \ + .filter(cls.id == other_id) \ + .one_or_none() + @classmethod + def find_by_datum(cls, other_datum): + return db.session.query(cls) \ + .filter(cls.datum == other_datum) \ + .one_or_none() diff --git a/src/covid19/blueprints/vaccination/vaccination_model_import.py b/src/covid19/blueprints/vaccination/vaccination_model_import.py index 162e77dbf1a656b0b54e372bb5bbcd58f5c638b8..dc4478d60659b7f6f0d8fdb596e156f280b55b98 100644 --- a/src/covid19/blueprints/vaccination/vaccination_model_import.py +++ b/src/covid19/blueprints/vaccination/vaccination_model_import.py @@ -1,8 +1,10 @@ from database import db, ITEMS_PER_PAGE +#TODO: rename VaccinationGermanyTimeline to VaccinationImport +#TODO change tablename from vaccination_germany_timeline_import to vaccination_import class VaccinationGermanyTimeline(db.Model): - __tablename__ = 'vaccination_germany_timeline' + __tablename__ = 'vaccination_germany_timeline_import' id = db.Column(db.Integer, primary_key=True) datum = db.Column(db.String(255), nullable=False) diff --git a/src/covid19/blueprints/vaccination/vaccination_service.py b/src/covid19/blueprints/vaccination/vaccination_service.py index aa09dc4e2091558a84ad1f8bccd61d530eb91f8f..5c0906359be3dc6a398aa712dad3ac76a7ce35ca 100644 --- a/src/covid19/blueprints/vaccination/vaccination_service.py +++ b/src/covid19/blueprints/vaccination/vaccination_service.py @@ -6,6 +6,7 @@ from covid19.blueprints.vaccination.vaccination_service_import import Vaccinatio from covid19.blueprints.vaccination.vaccination_service_config import VaccinationServiceDownloadConfig +# TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 class VaccinationService: def __init__(self, database): app.logger.debug("------------------------------------------------------------") @@ -27,6 +28,42 @@ class VaccinationService: self.vaccination_service_import.import_file() return self + def run_download_only(self): + # TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 + #TODO implement VaccinationService.run_download_only + return self + + def run_import_only(self): + # TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 + # TODO implement VaccinationService.run_import_only + return self + + def run_update_dimension_tables_only(self): + # TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 + # TODO implement VaccinationService.run_update_dimension_tables_only + return self + + def run_update_fact_table_incremental_only(self): + # TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 + # TODO implement VaccinationService.run_update_fact_table_incremental_only + return self + + def run_update_fact_table_initial_only(self): + # TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 + # TODO implement VaccinationService.run_update_fact_table_initial_only + return self + + def run_update_star_schema_incremental(self): + # TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 + # TODO implement VaccinationService.run_update_star_schema_incremental + return self + + def run_update_star_schema_initial(self): + # TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 + # TODO implement VaccinationService.run_update_star_schema_initial + return self + + # TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 def run_download(self): app.logger.info(" run update [begin]") app.logger.info("------------------------------------------------------------") @@ -36,6 +73,7 @@ class VaccinationService: app.logger.info("------------------------------------------------------------") return success + # TODO: refactor VaccinationService to new method scheme introduced 07.02.2021 def run_update_initial(self): app.logger.info(" run update initial [begin]") app.logger.info("------------------------------------------------------------") diff --git a/src/covid19/blueprints/vaccination/vaccination_service_download.py b/src/covid19/blueprints/vaccination/vaccination_service_download.py index 33b9856c552bc31d96412a3926ab21b0c276e729..c65114217b3c548bff329febc81ff10ca207656e 100644 --- a/src/covid19/blueprints/vaccination/vaccination_service_download.py +++ b/src/covid19/blueprints/vaccination/vaccination_service_download.py @@ -5,6 +5,7 @@ from database import app from covid19.blueprints.vaccination.vaccination_service_config import VaccinationServiceDownloadConfig +# TODO: refactor VaccinationServiceDownload to new method scheme introduced 07.02.2021 class VaccinationServiceDownload: def __init__(self, database): app.logger.debug("------------------------------------------------------------") diff --git a/src/covid19/blueprints/vaccination/vaccination_service_import.py b/src/covid19/blueprints/vaccination/vaccination_service_import.py index c9e4d56f0f9b7a5a9ffe8bded0f68e6561ba1751..a0c251be42cf789e11a29c08c6e7ca9be639b934 100644 --- a/src/covid19/blueprints/vaccination/vaccination_service_import.py +++ b/src/covid19/blueprints/vaccination/vaccination_service_import.py @@ -7,6 +7,7 @@ from covid19.blueprints.vaccination.vaccination_model_import import VaccinationG from covid19.blueprints.vaccination.vaccination_service_config import VaccinationServiceDownloadConfig +# TODO: refactor VaccinationServiceImport to new method scheme introduced 07.02.2021 class VaccinationServiceImport: def __init__(self, database): app.logger.debug("------------------------------------------------------------") diff --git a/src/covid19/blueprints/vaccination/vaccination_service_update.py b/src/covid19/blueprints/vaccination/vaccination_service_update.py new file mode 100644 index 0000000000000000000000000000000000000000..73ed9b4a866d8f3c2e352d2c2ae2b165811d1c8a --- /dev/null +++ b/src/covid19/blueprints/vaccination/vaccination_service_update.py @@ -0,0 +1,136 @@ +from database import db, app + +from covid19.blueprints.vaccination.vaccination_service_config import VaccinationServiceDownloadConfig +from covid19.blueprints.vaccination.vaccination_model_import import VaccinationGermanyTimeline +from covid19.blueprints.vaccination.vaccination_model import VaccinationDateReported, VaccinationGermanyTimelineAAA + + +# TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 +class VaccinationsServiceUpdate: + def __init__(self, database): + app.logger.debug("------------------------------------------------------------") + app.logger.debug(" Europe Service Update [init]") + app.logger.debug("------------------------------------------------------------") + self.__database = database + self.cfg = VaccinationServiceDownloadConfig() + app.logger.debug("------------------------------------------------------------") + app.logger.debug(" Europe Service Update [ready] ") + + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + def __update_date_reported(self): + app.logger.info(" __update_date_reported [begin]") + app.logger.info("------------------------------------------------------------") + result_date_rep = VaccinationGermanyTimeline.get_date_rep() + k = 0 + for result_item in result_date_rep: + k += 1 + my_date_rep = result_item['date_rep'] + my_year_week = result_item['year_week'] + o = VaccinationGermanyTimelineAAA.create_new_object_factory( + my_date_rep=my_date_rep + ) + db.session.add(o) + app.logger.info("| " + my_date_rep + " | " + my_year_week + " | " + str(k) + " rows ") + db.session.commit() + app.logger.info(" __update_date_reported [done]") + app.logger.info("------------------------------------------------------------") + return self + + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + def __update_data_initial(self): + app.logger.info(" __update_data_initial [begin]") + app.logger.info("------------------------------------------------------------") + result_date_rep = VaccinationGermanyTimeline.get_date_rep() + i = 0 + for item_date_rep in result_date_rep: + europe_date_reported = VaccinationDateReported.find_by_date_reported( + i_date_reported=item_date_rep['date_rep'] + ) + if europe_date_reported is None: + o = VaccinationDateReported.create_new_object_factory(item_date_rep['date_rep']) + europe_date_reported = o + result_europe_data_import = VaccinationGermanyTimeline.find_by_date_reported(europe_date_reported) + for item_europe_data_import in result_europe_data_import: + #my_d = int(item_europe_data_import.deaths_weekly) + #my_e = int(item_europe_data_import.cases_weekly) + #if item_europe_data_import.notification_rate_per_100000_population_14days == '': + # my_f = 0.0 + #else: + # my_f = float(item_europe_data_import.notification_rate_per_100000_population_14days) + o = VaccinationGermanyTimelineAAA( + #europe_country=europe_country, + #europe_date_reported=europe_date_reported, + #deaths_weekly=my_d, + #cases_weekly=my_e, + #notification_rate_per_100000_population_14days=my_f + ) + db.session.add(o) + item_europe_data_import.row_imported = True + db.session.add(item_europe_data_import) + i += 1 + if i % 500 == 0: + app.logger.info(" update Europa initial ... " + str(i) + " rows") + db.session.commit() + db.session.commit() + app.logger.info(" update Europa initial ... " + str(i) + " rows total") + app.logger.info(" __update_data_initial [done]") + app.logger.info("------------------------------------------------------------") + return self + + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + def __update_data_short(self): + app.logger.info(" __update_data_initial [begin]") + app.logger.info("------------------------------------------------------------") + app.logger.info(" ... ") + app.logger.info(" __update_data_initial [done]") + app.logger.info("------------------------------------------------------------") + return self + + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + def update_db_initial(self): + app.logger.info(" update_db_initial [begin]") + app.logger.info("------------------------------------------------------------") + VaccinationDateReported.remove_all() + VaccinationGermanyTimelineAAA.remove_all() + self.__update_date_reported() + self.__update_data_initial() + app.logger.info(" update_db_initial [done]") + app.logger.info("------------------------------------------------------------") + return self + + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + def update_db_short(self): + app.logger.info(" update_db_short [begin]") + app.logger.info("------------------------------------------------------------") + VaccinationDateReported.remove_all() + VaccinationGermanyTimelineAAA.remove_all() + self.__update_date_reported() + self.__update_data_short() + app.logger.info(" update_db_short [done]") + app.logger.info("------------------------------------------------------------") + return self + + def update_dimension_tables_only(self): + # TODO: implement VaccinationsServiceUpdate.update_dimension_tables_only + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + return self + + def update_fact_table_incremental_only(self): + # TODO: implement VaccinationsServiceUpdate.update_fact_table_incremental_only + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + return self + + def update_fact_table_initial_only(self): + # TODO: implement VaccinationsServiceUpdate.update_fact_table_initial_only + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + return self + + def update_star_schema_incremental(self): + # TODO: implement VaccinationsServiceUpdate.update_star_schema_incremental + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + return self + + def update_star_schema_initial(self): + # TODO: implement VaccinationsServiceUpdate.update_star_schema_initial + # TODO: refactor VaccinationsServiceUpdate to new method scheme introduced 07.02.2021 + return self diff --git a/src/covid19/blueprints/vaccination/vaccination_views.py b/src/covid19/blueprints/vaccination/vaccination_views.py index 767bebb8f21452dee4984560dce5a8110038efe0..35a5d67492ad5ef865d6f2d0e3630e5e074169e4 100644 --- a/src/covid19/blueprints/vaccination/vaccination_views.py +++ b/src/covid19/blueprints/vaccination/vaccination_views.py @@ -68,3 +68,4 @@ def url_vaccination_timeline_germany(page=1): page_data=page_data, page_info=page_info) +# TODO add Tasks and URLs for starting Tasks to vaccination_views diff --git a/src/covid19/blueprints/who/who_model.py b/src/covid19/blueprints/who/who_model.py index 733a06d934f9a1809622ec4bb7f1630b93f0a8b9..275496f7f805d897cc3ac0446ee71ccaf26f4b02 100644 --- a/src/covid19/blueprints/who/who_model.py +++ b/src/covid19/blueprints/who/who_model.py @@ -125,7 +125,8 @@ class WhoCountry(db.Model): cls.region == region ).order_by(cls.country).paginate(page, per_page=ITEMS_PER_PAGE) - +# TODO: rename WhoGlobalData to WhoData +# TODO: rename tablename from who_global_data to who_data class WhoGlobalData(db.Model): __tablename__ = 'who_global_data' diff --git a/src/covid19/blueprints/who/who_model_import.py b/src/covid19/blueprints/who/who_model_import.py index 984dcc66f6b41295766c99ab3c4cc6ca38da43e5..763d21a106e0ff66bc86db14e5119c5acd1cfd3d 100644 --- a/src/covid19/blueprints/who/who_model_import.py +++ b/src/covid19/blueprints/who/who_model_import.py @@ -1,6 +1,8 @@ from database import db, ITEMS_PER_PAGE +#TODO: rename WhoGlobalDataImportTable to WhoImport +#TODO change tablename from who_global_data_import to who_import class WhoGlobalDataImportTable(db.Model): __tablename__ = 'who_global_data_import' @@ -62,7 +64,8 @@ class WhoGlobalDataImportTable(db.Model): @classmethod def get_new_dates_as_array(cls): - # TODO: SQLalchemy instead of SQL + #TODO: BUG: change to ORM ClassHierarchy + #TODO: SQLalchemy instead of SQL sql_query = """ select date_reported diff --git a/src/covid19/blueprints/who/who_service.py b/src/covid19/blueprints/who/who_service.py index 2fdac80b25a948e950507ebc9f43205d9d1607ad..ab1bf42288ad02dc7420d17e35670881daeae05b 100644 --- a/src/covid19/blueprints/who/who_service.py +++ b/src/covid19/blueprints/who/who_service.py @@ -20,7 +20,7 @@ class WhoService: def pretask_database_drop_create(self): flash("who_service.run_download started") - success = self.who_service_download.download_file() + self.who_service_download.download_file() return self def task_database_drop_create(self): @@ -29,14 +29,22 @@ class WhoService: self.who_service_update.update_fact_table_incremental_only() return self + #def run_download_only(self): + #def run_import_only(self): + #def run_update_dimension_tables_only(self): + #def run_update_fact_table_incremental_only(self): + #def run_update_fact_table_initial_only(self): + #def run_update_star_schema_incremental(self): + #def run_update_star_schema_initial(self): + def run_download_only(self): app.logger.info(" run_download_only [begin]") app.logger.info("------------------------------------------------------------") - success = self.who_service_download.download_file() + self.who_service_download.download_file() app.logger.info("") app.logger.info(" run_download_only [done]") app.logger.info("------------------------------------------------------------") - return success + return self def run_import_only(self): app.logger.info(" run_import_only [begin]") diff --git a/src/covid19/blueprints/who/who_service_update.py b/src/covid19/blueprints/who/who_service_update.py index b86db02c9b25d5124143c3fe21c27e1aa42d71e1..843779f146f13370521812562a524e57c5f7195a 100644 --- a/src/covid19/blueprints/who/who_service_update.py +++ b/src/covid19/blueprints/who/who_service_update.py @@ -207,3 +207,9 @@ class WhoServiceUpdate: app.logger.info(" update_star_schema_initial [done]") app.logger.info("------------------------------------------------------------") return self + + #def update_dimension_tables_only(self): + #def update_fact_table_incremental_only(self): + #def update_fact_table_initial_only(self): + #def update_star_schema_incremental(self): + #def update_star_schema_initial(self):