diff --git a/project/data_ecdc/model/ecdc_model_import_dao.py b/project/data_ecdc/model/ecdc_model_import_dao.py index e69de29b..02d7616c 100644 --- a/project/data_ecdc/model/ecdc_model_import_dao.py +++ b/project/data_ecdc/model/ecdc_model_import_dao.py @@ -0,0 +1,92 @@ +from datetime import date +from sqlalchemy.sql import text + +from project.data.database import db, items_per_page +from project.data_all.model.all_model_mixins import AllImportMixin + + +class EcdcImportDao(AllImportMixin): + + @classmethod + def count(cls): + s = text( + 'select count(*) as number from ecdc_import_pandas' + ) + return db.session.execute(s).first() + + @classmethod + def find_by_datum(cls, datum: date): + return cls.find_by_datum_str(datum) + + @classmethod + def find_by_datum_str(cls, datum: date): + s = text( + 'select * from ecdc_import_pandas where Date_reported = :day' + ) + return db.session.execute(s, {"day": datum.isoformat()}).fetchall() + + @classmethod + def find_by_datum_reported(cls, datum: date): + return cls.find_by_datum(datum) + + @classmethod + def get_datum_list(cls): + s = text( + 'select "Date_reported" from ecdc_import_pandas' + + ' group by "Date_reported" order by "Date_reported"' + ) + return db.session.execute(s).fetchall() + + @classmethod + def get_regions(cls): + s = text( + 'select "WHO_region" from who_import_pandas ' + + 'group by "WHO_region" order by "WHO_region"' + ) + return db.session.execute(s).fetchall() + + @classmethod + def get_all_countries(cls): + s = text( + 'select "Country","Country_code","WHO_region" from ecdc_import_pandas ' + + 'group by "Country","Country_code","WHO_region" ' + + 'order by "Country"' + ) + return db.session.execute(s).fetchall() + + @classmethod + def get_dates_reported(cls): + return cls.get_datum_list() + + @classmethod + def get_for_one_day(cls, day: str): + s = text( + 'select * from ecdc_import_pandas where Date_reported = :day' + ) + return db.session.execute(s, {"day": day}).fetchall() + + @classmethod + def get_dates_reported_as_string_array(cls): + return cls.get_datum_list() + + @classmethod + def countries(cls): + return cls.get_all_countries() + + @classmethod + def get_datum_of_all_who_import(cls): + return cls.get_datum_list() + + @classmethod + def find_by_datum_and_country(cls, date_reported: str, country: str): + s = text( + 'select * from ecdc_import_pandas ' + + 'where Date_reported = :day and Country = :country' + ) + return db.session.execute( + s, {"day": date_reported, "country": country} + ).fetchall() + + @classmethod + def get_by_datum_and_country(cls, date_reported: str, country: str): + return cls.find_by_datum_and_country(date_reported, country) diff --git a/project/data_owid/model/owid_model_import_dao.py b/project/data_owid/model/owid_model_import_dao.py index e69de29b..0fe4368a 100644 --- a/project/data_owid/model/owid_model_import_dao.py +++ b/project/data_owid/model/owid_model_import_dao.py @@ -0,0 +1,92 @@ +from datetime import date +from sqlalchemy.sql import text + +from project.data.database import db, items_per_page +from project.data_all.model.all_model_mixins import AllImportMixin + + +class EcdcImportDao(AllImportMixin): + + @classmethod + def count(cls): + s = text( + 'select count(*) as number from owid_import_pandas' + ) + return db.session.execute(s).first() + + @classmethod + def find_by_datum(cls, datum: date): + return cls.find_by_datum_str(datum) + + @classmethod + def find_by_datum_str(cls, datum: date): + s = text( + 'select * from owid_import_pandas where Date_reported = :day' + ) + return db.session.execute(s, {"day": datum.isoformat()}).fetchall() + + @classmethod + def find_by_datum_reported(cls, datum: date): + return cls.find_by_datum(datum) + + @classmethod + def get_datum_list(cls): + s = text( + 'select "Date_reported" from owid_import_pandas' + + ' group by "Date_reported" order by "Date_reported"' + ) + return db.session.execute(s).fetchall() + + @classmethod + def get_regions(cls): + s = text( + 'select "WHO_region" from owid_import_pandas ' + + 'group by "WHO_region" order by "WHO_region"' + ) + return db.session.execute(s).fetchall() + + @classmethod + def get_all_countries(cls): + s = text( + 'select "Country","Country_code","WHO_region" from owid_import_pandas ' + + 'group by "Country","Country_code","WHO_region" ' + + 'order by "Country"' + ) + return db.session.execute(s).fetchall() + + @classmethod + def get_dates_reported(cls): + return cls.get_datum_list() + + @classmethod + def get_for_one_day(cls, day: str): + s = text( + 'select * from owid_import_pandas where Date_reported = :day' + ) + return db.session.execute(s, {"day": day}).fetchall() + + @classmethod + def get_dates_reported_as_string_array(cls): + return cls.get_datum_list() + + @classmethod + def countries(cls): + return cls.get_all_countries() + + @classmethod + def get_datum_of_all_who_import(cls): + return cls.get_datum_list() + + @classmethod + def find_by_datum_and_country(cls, date_reported: str, country: str): + s = text( + 'select * from owid_import_pandas ' + + 'where Date_reported = :day and Country = :country' + ) + return db.session.execute( + s, {"day": date_reported, "country": country} + ).fetchall() + + @classmethod + def get_by_datum_and_country(cls, date_reported: str, country: str): + return cls.find_by_datum_and_country(date_reported, country) diff --git a/project/data_who/model/who_model_import_dao.py b/project/data_who/model/who_model_import_dao.py index 5868b67c..b8fb034d 100644 --- a/project/data_who/model/who_model_import_dao.py +++ b/project/data_who/model/who_model_import_dao.py @@ -5,7 +5,7 @@ from project.data_all.model.all_model_mixins import AllImportMixin -class WhoImportPandas(AllImportMixin): +class WhoImportDao(AllImportMixin): @classmethod def count(cls): diff --git a/project/data_who/services/who_service.py b/project/data_who/services/who_service.py index 5fe40b12..51c0cfc3 100644 --- a/project/data_who/services/who_service.py +++ b/project/data_who/services/who_service.py @@ -7,7 +7,7 @@ from project.data_all.services.all_service_mixins import AllServiceMixin from project.data_all_notifications.notifications_model import Notification from project.data_who.model.who_model_date_reported import WhoDateReported -from project.data_who.model.who_model_import_dao import WhoImportPandas +from project.data_who.model.who_model_import_dao import WhoImportDao from project.data_who.services.who_service_import import WhoServiceImport from project.data_who.services.who_service_update import WhoServiceUpdate from project.data_who.services.who_service_update_full import WhoServiceUpdateFull @@ -127,7 +127,7 @@ def get_all_imported(self, page: int): def get_new_dates_as_array(self): new_dates_as_array = [] old_dates = WhoDateReported.find_all_as_str() - for news_date in WhoImportPandas.get_datum_list(): + for news_date in WhoImportDao.get_datum_list(): nd = news_date["Date_reported"] if nd not in old_dates: new_dates_as_array.append(nd) diff --git a/project/data_who/services/who_service_import.py b/project/data_who/services/who_service_import.py index 17db6413..df48be27 100644 --- a/project/data_who/services/who_service_import.py +++ b/project/data_who/services/who_service_import.py @@ -9,7 +9,7 @@ from project.data_all.services.all_service_config import AllServiceConfig from project.data_all.services.all_service_mixins import AllServiceMixinImport from project.data_all_notifications.notifications_model import Notification -from project.data_who.model.who_model_import_dao import WhoImportPandas +from project.data_who.model.who_model_import_dao import WhoImportDao app = covid19_application.app db = covid19_application.db @@ -52,7 +52,7 @@ def import_file(self): # keyDate_reported = "Date_reported" self.log_line() app.logger.info(" WhoImport.remove_all() START") - WhoImportPandas.remove_all() + WhoImportDao.remove_all() app.logger.info(" WhoImport.remove_all() DONE") self.log_line() app.logger.info(" who_import_pandas START") diff --git a/project/data_who/services/who_service_update_full.py b/project/data_who/services/who_service_update_full.py index 923dea30..8d7170a7 100644 --- a/project/data_who/services/who_service_update_full.py +++ b/project/data_who/services/who_service_update_full.py @@ -10,7 +10,7 @@ from project.data_who.model.who_model_data import WhoData from project.data_who.model.who_model_data import WhoDataFactory from project.data_who.model.who_model_date_reported import WhoDateReported -from project.data_who.model.who_model_import_dao import WhoImportPandas +from project.data_who.model.who_model_import_dao import WhoImportDao from project.data_who.model.who_model_location import WhoCountry from project.data_who.model.who_model_location import WhoCountryFactory from project.data_who.model.who_model_location_group import WhoCountryRegion @@ -39,7 +39,7 @@ def __full_update_date_reported(self): self.log_line() log_lines = [] i = 0 - for s_date_reported in WhoImportPandas.get_datum_list(): + for s_date_reported in WhoImportDao.get_datum_list(): i += 1 o = AllDateReportedFactory.create_new_object_for_who( my_date_reported=s_date_reported["Date_reported"] @@ -70,7 +70,7 @@ def __full_update_region(self): self.log_line() log_lines = [] i = 0 - for region_str in WhoImportPandas.get_regions(): + for region_str in WhoImportDao.get_regions(): i += 1 o = WhoCountryRegionFactory.create_new( location_group_str=region_str["WHO_region"] @@ -102,7 +102,7 @@ def __full_update_country(self): self.log_line() log_lines = [] i = 0 - for country_item in WhoImportPandas.countries(): + for country_item in WhoImportDao.countries(): i += 1 str_country_code = country_item["Country_code"] str_country = country_item["Country"] @@ -150,7 +150,7 @@ def __full_update_data(self): who_country_dict = WhoCountry.find_all_as_dict() for who_date_reported in WhoDateReported.find_all(): # app.logger.info(" my_date: " + str(my_date)) - for who_import in WhoImportPandas.find_by_datum(who_date_reported.datum): + for who_import in WhoImportDao.find_by_datum(who_date_reported.datum): app.logger.info("who_import: " + str(who_import)) who_country = who_country_dict[who_import["Country"]] o = WhoDataFactory.create_new( diff --git a/project/data_who/who_views.py b/project/data_who/who_views.py index 974440cf..288ca9f7 100644 --- a/project/data_who/who_views.py +++ b/project/data_who/who_views.py @@ -14,7 +14,7 @@ from project.data.database import db from project.data_who.services.who_service import WhoService from project.web.model.web_model_transient import WebPageContent -from project.data_who.model.who_model_import_dao import WhoImportPandas +from project.data_who.model.who_model_import_dao import WhoImportDao from project.data_who.model.who_model_data import WhoData from project.data_who.model.who_model_date_reported import WhoDateReported from project.data_who.model.who_model_location import WhoCountry @@ -426,7 +426,7 @@ def url_who_mytest(): flash("url_who_mytest - START: WhoImport.countries()") app.logger.info("url_who_mytest - START: WhoImport.countries()") i = 0 - for c in WhoImportPandas.countries(): + for c in WhoImportDao.countries(): i += 1 line =" | {} | {} | {} | {} | ".format( str(i), c["Country_code"], c["Country"], c["WHO_region"] @@ -716,7 +716,7 @@ def url_who_test_who_import_countries(): flash("url_who_mytest - START: WhoImport.countries()") app.logger.info("url_who_mytest - START: WhoImport.countries()") i = 0 - for c in WhoImportPandas.get_all_countries(): + for c in WhoImportDao.get_all_countries(): i += 1 line = ( " | " @@ -780,7 +780,7 @@ def url_who_test_who_data_get_datum_of_all_who_import(): flash( "url_who_test_who_data_get_datum_of_all_who_import - START: WhoImport.get_datum_of_all_who_import()" ) - for datum in WhoImportPandas.get_datum_of_all_who_import(): + for datum in WhoImportDao.get_datum_of_all_who_import(): app.logger.info(str(datum)) flash( "url_who_test_who_data_get_datum_of_all_who_import - DONE: WhoImport.get_datum_of_all_who_import()"