diff --git a/covid19/oodm/common/common_model.py b/covid19/oodm/common/common_model.py index 66217d8c1b289466b94b3596a52083bbf819523d..dc6ab1448525355597eddaf054f0df35775db169 100644 --- a/covid19/oodm/common/common_model.py +++ b/covid19/oodm/common/common_model.py @@ -22,7 +22,7 @@ class CommonDatum(db.Model): # load if already exists old = db.session.query(cls).filter(cls.date_string == date_string).one_or_none() if old is None: - o = CommonDatum(date_string=date_string, datum=transform_datum(date_string)) + o = CommonDatum(date_string=date_string) # put year # put month # put datum diff --git a/covid19/oodm/europe/europe_service_update.py b/covid19/oodm/europe/europe_service_update.py index b3f3474a30fe719e830d041c55e1adec03772e48..5fa70eb63f6ae4cc87d1140ce3406937efb0d292 100644 --- a/covid19/oodm/europe/europe_service_update.py +++ b/covid19/oodm/europe/europe_service_update.py @@ -11,7 +11,6 @@ class EuropeServiceUpdate: app.logger.debug("------------------------------------------------------------") self.__database = database self.cfg = EuropeServiceDownloadConfig() - self.__url_src_data = "https://opendata.ecdc.europa.eu/covid19/casedistribution/csv/" app.logger.debug("------------------------------------------------------------") app.logger.debug(" Europe Service Update [ready] ") @@ -91,7 +90,7 @@ class EuropeServiceUpdate: ) 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=='': + 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) diff --git a/covid19/oodm/who/who_model.py b/covid19/oodm/who/who_model.py index 10cb003ea446ecfc4989c5c8aba0706c59e18c4a..5b6d7d9a28ad79326a5e99368b6b5cdb2a3d3d39 100644 --- a/covid19/oodm/who/who_model.py +++ b/covid19/oodm/who/who_model.py @@ -132,10 +132,9 @@ class WhoRegion(db.Model): @classmethod def find_by_region(cls, i_who_region): - my_region = db.session.query(cls)\ + return db.session.query(cls)\ .filter(cls.region == i_who_region)\ .one_or_none() - return my_region class WhoCountry(db.Model): diff --git a/covid19/oodm/who/who_model_import.py b/covid19/oodm/who/who_model_import.py index 625fc7a7663c69216a68a5b981f9991c3461ab85..944178b748a2bc843ee88ffb751fac7fc66e04c5 100644 --- a/covid19/oodm/who/who_model_import.py +++ b/covid19/oodm/who/who_model_import.py @@ -78,3 +78,14 @@ class WhoGlobalDataImportTable(db.Model): for item in db.session.execute(sql_query): new_dates.append(item['date_reported']) return new_dates + + @classmethod + def countries(cls): + sql_query = """ + select distinct + who_global_data_import.country_code, + who_global_data_import.country, + who_global_data_import.who_region + from who_global_data_import + """ + return db.session.execute(sql_query).fetchall() diff --git a/covid19/oodm/who/who_service_import.py b/covid19/oodm/who/who_service_import.py index e1a717e055a68a754ce427de188805ec109b3eb4..5d96ff721a6d5d6017431e174e305bed006a98c6 100644 --- a/covid19/oodm/who/who_service_import.py +++ b/covid19/oodm/who/who_service_import.py @@ -6,8 +6,6 @@ from database import db, app from covid19.oodm.who.who_model_import import WhoGlobalDataImportTable from covid19.oodm.who.who_service_download import WhoServiceDownloadConfig -#who_service_import = None - class WhoServiceImport: def __init__(self, database): diff --git a/covid19/oodm/who/who_service_update.py b/covid19/oodm/who/who_service_update.py index d16c75e6d60bfab3b9be897f44483bac93e5d0e4..84181cbbc5d1ce621fa7c872d0f13d0f19d12d90 100644 --- a/covid19/oodm/who/who_service_update.py +++ b/covid19/oodm/who/who_service_update.py @@ -38,10 +38,9 @@ class WhoServiceUpdate: app.logger.info(" update who_region [begin]") app.logger.info("------------------------------------------------------------") i = 0 - #TODO: Queries to Model-Classes - for i_who_region, in db.session.query(WhoGlobalDataImportTable.who_region).distinct(): - c = db.session.query(WhoRegion).filter(WhoRegion.region == i_who_region).count() - if c == 0: + for i_who_region, in WhoGlobalDataImportTable.get_regions(): + c = WhoRegion.find_by_region() + if c is None: o = WhoRegion(region=i_who_region) db.session.add(o) app.logger.info(i_who_region + " added NEW ") @@ -59,15 +58,7 @@ class WhoServiceUpdate: def __update_who_country(self): app.logger.info(" update who_country [begin]") app.logger.info("------------------------------------------------------------") - # TODO: Queries to Model-Classes - sql_text = """ - select distinct - who_global_data_import.country_code, - who_global_data_import.country, - who_global_data_import.who_region - from who_global_data_import - """ - result = db.session.execute(sql_text).fetchall() + result = WhoGlobalDataImportTable.countries() for result_item in result: i_country_code = result_item.country_code i_country = result_item.country @@ -102,7 +93,6 @@ class WhoServiceUpdate: app.logger.info(" update WHO [begin]") app.logger.info("------------------------------------------------------------") dates_reported = WhoDateReported.get_all_as_dict() - #regions = WhoRegion.get_all_as_dict() countries = WhoCountry.get_all_as_dict() i = 0 result = WhoGlobalDataImportTable.get_all()