Skip to content
Snippets Groups Projects
Commit 7884d597 authored by thomaswoehlke's avatar thomaswoehlke
Browse files

Refactoring: vaccination

parent df82a86d
No related branches found
No related tags found
1 merge request!162Refactoring 2021 05 20 start
......@@ -3,7 +3,7 @@ from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported
from flask_covid19.blueprints.data_divi.divi_model import DiviDateReported
from flask_covid19.blueprints.data_ecdc.ecdc_model import EcdcDateReported
from flask_covid19.blueprints.data_owid.owid_model import OwidDateReported
from flask_covid19.blueprints.data_rki.rki_model import RkiMeldedatum
from flask_covid19.blueprints.data_rki.rki_model import RkiMeldedatum, RkiDatenstand, RkiRefDatum
from flask_covid19.blueprints.data_vaccination.vaccination_model import VaccinationDateReported
from flask_covid19.blueprints.data_who.who_model import WhoDateReported
......@@ -168,6 +168,42 @@ class BlueprintDateReportedFactory:
processed_full_update=False,
)
@classmethod
def __get_rki_date_datenstand(cls, o: BlueprintDateReported):
return RkiDatenstand(
date_reported_import_str=o.date_reported_import_str,
datum=o.datum,
year_day_of_year=o.year_day_of_year,
year_month=o.year_month,
year_week=o.year_week,
year=o.year,
month=o.month,
day_of_month=o.day_of_month,
day_of_week=o.day_of_week,
day_of_year=o.day_of_year,
week_of_year=o.week_of_year,
processed_update=False,
processed_full_update=False,
)
@classmethod
def __get_rki_ref_datum(cls, o: BlueprintDateReported):
return RkiRefDatum(
date_reported_import_str=o.date_reported_import_str,
datum=o.datum,
year_day_of_year=o.year_day_of_year,
year_month=o.year_month,
year_week=o.year_week,
year=o.year,
month=o.month,
day_of_month=o.day_of_month,
day_of_week=o.day_of_week,
day_of_year=o.day_of_year,
week_of_year=o.week_of_year,
processed_update=False,
processed_full_update=False,
)
@classmethod
def __get_vaccination(cls, o: BlueprintDateReported):
return VaccinationDateReported(
......@@ -226,6 +262,20 @@ class BlueprintDateReportedFactory:
o = cls.__create_new_object_factory(date_reported_import_str=my_date_rep, my_datum=my_datum)
return cls.__get_rki(o)
@classmethod
def create_new_object_for_rki_date_datenstand(cls, my_date_rep: str):
(my_year, my_month, my_day) = cls.__get_datetime_parts(my_date_rep)
my_datum = date(my_year, my_month, my_day)
o = cls.__create_new_object_factory(date_reported_import_str=my_date_rep, my_datum=my_datum)
return cls.__get_rki_date_datenstand(o)
@classmethod
def create_new_object_for_rki_ref_datum(cls, my_date_rep: str):
(my_year, my_month, my_day) = cls.__get_datetime_parts(my_date_rep)
my_datum = date(my_year, my_month, my_day)
o = cls.__create_new_object_factory(date_reported_import_str=my_date_rep, my_datum=my_datum)
return cls.__get_rki_ref_datum(o)
@classmethod
def create_new_object_for_vaccination(cls, my_date_rep: str):
o = cls.__create_new_object_factory_for_isoformat(my_date_rep)
......
......@@ -63,6 +63,26 @@ class RkiImport(AllImport):
def get_new_aktualisierungen_as_array(cls):
return []
@classmethod
def get_date_datenstand_of_all_import(cls):
dates_reported = []
bu = Bundle('datenstand', cls.datenstand)
for meldedatum in db.session.query(bu).distinct().order_by(cls.datenstand.desc()):
item = meldedatum[0][0]
if not item in dates_reported:
dates_reported.append(item)
return dates_reported
@classmethod
def get_date_ref_datum_of_all_import(cls):
dates_reported = []
bu = Bundle('ref_datum', cls.ref_datum)
for meldedatum in db.session.query(bu).distinct().order_by(cls.ref_datum.desc()):
item = meldedatum[0][0]
if not item in dates_reported:
dates_reported.append(item)
return dates_reported
@classmethod
def get_datum_of_all_import(cls):
dates_reported = []
......@@ -83,6 +103,16 @@ class RkiImport(AllImport):
bundesland_list.append(item)
return bundesland_list
@classmethod
def get_altersgruppe_list(cls):
altersgruppe_list = []
bu = Bundle('altersgruppe', cls.altersgruppe)
for altersgruppe_row in db.session.query(bu).distinct().order_by(cls.altersgruppe.asc()):
item = altersgruppe_row[0]
if not item in altersgruppe_list:
altersgruppe_list.append(item)
return altersgruppe_list
@classmethod
def find_by_datun(cls, datum: date):
return db.session.query(cls)\
......
......@@ -2,7 +2,7 @@ from database import db, app
from flask_covid19.blueprints.app_all.all_config import BlueprintConfig
from flask_covid19.blueprints.app_web.web_model_factory import BlueprintDateReportedFactory
from flask_covid19.blueprints.data_rki.rki_model import RkiData, RkiMeldedatum, RkiBundesland, RkiLandkreis
from flask_covid19.blueprints.data_rki.rki_model import RkiData, RkiMeldedatum, RkiDatenstand, RkiRefDatum, RkiAltersgruppe, RkiBundesland, RkiLandkreis
from flask_covid19.blueprints.data_rki.rki_model_import import RkiImport
......@@ -19,6 +19,46 @@ class RkiServiceUpdateBase:
class RkiServiceUpdateFull(RkiServiceUpdateBase):
def __full_update_date_datenstand(self):
app.logger.info(" RkiServiceUpdateFull.__full_update_date_datenstand [begin]")
app.logger.info("------------------------------------------------------------")
RkiDatenstand.remove_all()
i = 0
output_lines = []
for datum_of_import in RkiImport.get_date_datenstand_of_all_import():
i += 1
o = BlueprintDateReportedFactory.create_new_object_for_rki_date_datenstand(my_date_rep=datum_of_import)
db.session.add(o)
output = " [ " + str(i) + " ] full update RKI date_datenstand ... " + str(o)
output_lines.append(output)
db.session.commit()
for output in output_lines:
app.logger.info(output)
app.logger.info("")
app.logger.info(" RkiServiceUpdateFull.__full_update_date_datenstand [done]")
app.logger.info("------------------------------------------------------------")
return self
def __full_update_date_ref_datum(self):
app.logger.info(" RkiServiceUpdateFull.__full_update_date_ref_datum [begin]")
app.logger.info("------------------------------------------------------------")
RkiRefDatum.remove_all()
i = 0
output_lines = []
for datum_of_import in RkiImport.get_date_ref_datum_of_all_import():
i += 1
o = BlueprintDateReportedFactory.create_new_object_for_rki_ref_datum(my_date_rep=datum_of_import)
db.session.add(o)
output = " [ " + str(i) + " ] full update RKI date_ref_datum ... " + str(o)
output_lines.append(output)
db.session.commit()
for output in output_lines:
app.logger.info(output)
app.logger.info("")
app.logger.info(" RkiServiceUpdateFull.__full_update_date_ref_datum [done]")
app.logger.info("------------------------------------------------------------")
return self
def __full_update_date_reported(self):
app.logger.info(" RkiServiceUpdateFull.__full_update_date_reported [begin]")
app.logger.info("------------------------------------------------------------")
......@@ -39,6 +79,31 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase):
app.logger.info("------------------------------------------------------------")
return self
def __full_update_altersgruppe(self):
app.logger.info(" RkiServiceUpdateFull.__full_update_altersgruppe [begin]")
app.logger.info("------------------------------------------------------------")
RkiBundesland.remove_all()
app.logger.info("")
i = 0
output_lines = []
for altersgruppe_of_import in RkiImport.get_altersgruppe_list():
i += 1
my_altersgruppe = altersgruppe_of_import[0]
o = RkiAltersgruppe(
altersgruppe=my_altersgruppe,
processed_update=False,
processed_full_update=False,
)
db.session.add(o)
output = " [ " + str(i) + " ] full update RKI altersgruppe ... " + str(o)
output_lines.append(output)
db.session.commit()
for output in output_lines:
app.logger.info(output)
app.logger.info(" RkiServiceUpdateFull.__full_update_altersgruppe [done]")
app.logger.info("------------------------------------------------------------")
return self
def __full_update_bundesland(self):
app.logger.info(" RkiServiceUpdateFull.__full_update_bundesland [begin]")
app.logger.info("------------------------------------------------------------")
......@@ -160,6 +225,8 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase):
def full_update_dimension_tables(self):
RkiData.remove_all()
self.__full_update_date_reported()
self.__full_update_date_datenstand()
self.__full_update_date_ref_datum()
self.__full_update_landkreis()
return self
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment