diff --git a/app.py b/app.py index 1a189826f6fd1d8dc130d6031bc91d188aee416e..6452f141d5359b2f2269bc22b342afe61e6b34f1 100644 --- a/app.py +++ b/app.py @@ -491,13 +491,6 @@ def url_who_update_initial_run(): return redirect(url_for('home')) -@app.route('/test/who/update/countries') -def url_update_data_countries(): - who_service.run_update_countries() - flash("who_service.run_update_countries started") - return redirect(url_for('home')) - - ################################################################################################################## # # Europe diff --git a/org/woehlke/covid19/common/__init__.py b/org/woehlke/covid19/common/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/org/woehlke/covid19/common/common_model.py b/org/woehlke/covid19/common/common_model.py new file mode 100644 index 0000000000000000000000000000000000000000..1b92a315d144d4b3be2c4848d3cda972de58b375 --- /dev/null +++ b/org/woehlke/covid19/common/common_model.py @@ -0,0 +1,72 @@ +from flask_sqlalchemy import Pagination +from sqlalchemy import and_, func +from database import db, ITEMS_PER_PAGE +from sqlalchemy.orm import joinedload, raiseload + + +class CommonDatum(db.Model): + __tablename__ = 'common_datum' + + id = db.Column(db.Integer, primary_key=True) + date_string = db.Column(db.String(255), nullable=False, unique=True, primary_key=True) + year_week = db.Column(db.String(255), nullable=True, unique=True) + year_day_of_year = db.Column(db.String(255), nullable=True, unique=True) + year = db.Column(db.Integer, nullable=True) + month = db.Column(db.Integer, nullable=True) + day_of_week = db.Column(db.Integer, nullable=True) + day_of_month = db.Column(db.Integer, nullable=True) + day_of_year = db.Column(db.Integer, nullable=True) + week_of_year = db.Column(db.Integer, nullable=True) + + @classmethod + def create_rw_datum_factory(cls, date_string): + # check date_string syntax + # 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) + # put year + # put month + # day_of_month + # compute day_of_year + # compute week_of_year + # put year_week + db.session.add(o) + db.session.commit() + return o + + @classmethod + def remove_all(cls): + # TODO: SQLalchemy instead of SQL + db.session.execute("delete from " + cls.__tablename__) + db.session.commit() + return None + + @classmethod + def get_all_as_page(cls, page): + return db.session.query(cls)\ + .order_by(cls.date_string.desc())\ + .paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_all(cls): + return db.session.query(cls).all() + + @classmethod + def get_all_as_dict(cls): + common_dates = {} + for my_common_datum in cls.get_all(): + common_dates[my_common_datum.date_string] = my_common_datum + return common_dates + + @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() diff --git a/org/woehlke/covid19/common/common_service.py b/org/woehlke/covid19/common/common_service.py new file mode 100644 index 0000000000000000000000000000000000000000..0ccae753e432bc835e30a2a31c3cc984261a0779 --- /dev/null +++ b/org/woehlke/covid19/common/common_service.py @@ -0,0 +1,24 @@ +import os +from database import app +from org.woehlke.covid19.vaccination.vaccination_service_download import VaccinationServiceDownload +from org.woehlke.covid19.vaccination.vaccination_service_import import VaccinationServiceImport +from org.woehlke.covid19.vaccination.vaccination_service_update import VaccinationServiceUpdate + +common_service = None + + +class CommonService: + def __init__(self, database): + app.logger.info("------------------------------------------------------------") + app.logger.info(" Common Service [init]") + app.logger.info("------------------------------------------------------------") + self.__database = database + self.limit_nr = 20 + self.vaccination_service_download = VaccinationServiceDownload(database) + self.vaccination_service_import = VaccinationServiceImport(database) + self.vaccination_service_update = VaccinationServiceUpdate(database) + app.logger.info("------------------------------------------------------------") + app.logger.info(" Vaccination Service [ready]") + + def add_new_datum(self, date_string): + return self \ No newline at end of file diff --git a/org/woehlke/covid19/who/who_service.py b/org/woehlke/covid19/who/who_service.py index 754d35f5689ae0fa2492068b431997795829c296..761b42fdc5d7b5728de27fc894965afab80469ab 100644 --- a/org/woehlke/covid19/who/who_service.py +++ b/org/woehlke/covid19/who/who_service.py @@ -66,11 +66,3 @@ class WhoService: app.logger.info("------------------------------------------------------------") return self - def run_update_countries(self): - app.logger.info(" run update countries [begin]") - app.logger.info("------------------------------------------------------------") - self.who_service_update.update_who_country() - app.logger.info("") - app.logger.info(" run update countries [done]") - app.logger.info("------------------------------------------------------------") - return self