Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswoehlke committed Feb 23, 2022
1 parent 0d2188e commit 50b159a
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 14 deletions.
92 changes: 92 additions & 0 deletions project/data_ecdc/model/ecdc_model_import_dao.py
Original file line number Diff line number Diff line change
@@ -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)
92 changes: 92 additions & 0 deletions project/data_owid/model/owid_model_import_dao.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion project/data_who/model/who_model_import_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from project.data_all.model.all_model_mixins import AllImportMixin


class WhoImportPandas(AllImportMixin):
class WhoImportDao(AllImportMixin):

@classmethod
def count(cls):
Expand Down
4 changes: 2 additions & 2 deletions project/data_who/services/who_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions project/data_who/services/who_service_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions project/data_who/services/who_service_update_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions project/data_who/who_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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 = (
" | "
Expand Down Expand Up @@ -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()"
Expand Down

0 comments on commit 50b159a

Please sign in to comment.