diff --git a/Makefile b/Makefile index 27f8a850db36b9c18dc6d3523e09edbe1b717ece..85bde6e5b7b3cb21dd8ae23f57ddb43f258683d4 100644 --- a/Makefile +++ b/Makefile @@ -112,13 +112,23 @@ vcs_commit: git add . git commit -m "git_commit_and_push via make" -vcs_push: +vcs_checkin: git push -vcs_pull: +vcs_checkout: + git submodule update git pull -vcs: vcs_commit vcs_push vcs_pull +vcs_setup: + git config pull.rebase false + git submodule init + git submodule update + git config --global diff.submodule log + git submodule update --remote --merge + +vcs_push: vcs_setup vcs_commit vcs_checkin vcs_checkout + +vcs_pull: vcs_setup vcs_checkout love: @echo "not war!" diff --git a/etc/TODO.md b/etc/TODO.md index b232c17cf442d204ec85c97f35d87e8d2df374f8..0093ff590d9ada2bcbe4f851584d59606a0f4d9e 100644 --- a/etc/TODO.md +++ b/etc/TODO.md @@ -66,6 +66,7 @@ * https://mariadb-corporation.github.io/mariadb-connector-python/ * https://mariadb.com/docs/clients/connector-python/ +* https://jinja.palletsprojects.com/en/2.11.x/templates/ ### git setup * https://git-scm.com/book/en/v2/Git-Tools-Submodules diff --git a/etc/db/mysql/create_user_anddb.sql b/etc/db/mysql/create_user_anddb.sql index da33c85207bf56a094bbd7b7f385081ef0802b50..71f6cbcbade2f57c48323cc48542956eae8afdfd 100644 --- a/etc/db/mysql/create_user_anddb.sql +++ b/etc/db/mysql/create_user_anddb.sql @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:489d32e94c0012a18a259dbcc0754036ab3bb24e222a05ed2a2cef1c839ad3c5 -size 503 +oid sha256:2593acd4bc32739e7cc0ae99e3c5332767c49fd015687b445d6f663798edf9be +size 524 diff --git a/etc/requirements.txt b/etc/requirements.txt index cd4bd393ec57c96e259c403d6ea08030ea60f01b..459ff55c884d2735f448f31756cecbb9eb062e45 100644 --- a/etc/requirements.txt +++ b/etc/requirements.txt @@ -72,6 +72,7 @@ Pillow==8.2.0 pip-licenses==3.3.1 pip-tools==6.1.0 pipenv==2020.11.15 +pkg-resources==0.0.0 plantuml==0.3.0 plantuml-gentools==0.1.2 plantuml-markdown==3.4.2 diff --git a/requirements/dev.in b/requirements/dev.in index 11298cdfe099ce3d525ddd0f3f65987b00593258..7a215654dc888420f6eb34fefdaff3626c30ad56 100644 --- a/requirements/dev.in +++ b/requirements/dev.in @@ -10,8 +10,8 @@ Flask-Caching>=1.10.1 celery[redis]>=5.0.5 SQLAlchemy>=1.4.15 memcache>=0.5.1 -PyMySQL>=1.0.2 -psycopg2-binary>=2.8.6 +mysql-connector-python>=8.0.25 +# psycopg2-binary>=2.8.6 wget>=3.2 pyecharts>=1.9.0 pyecharts-extras>=0.0.5 diff --git a/src/config.py b/src/config.py index d537674ea58d8099cb452d4147a43270931ee809..7a81ce5c3597c6fa6cc62cd2278500aeb46f8953 100644 --- a/src/config.py +++ b/src/config.py @@ -5,15 +5,16 @@ CELERY_CONF_WORKER_SEND_TASK_EVENTS = True CELERY_CONF_TASK_SEND_SENT_EVENT = True CELERY_LOG_REDIRECT = '1' CELERY_LOG_REDIRECT_LEVEL = 'INFO' -SQLALCHEMY_DATABASE_USER = 'covid19data' -SQLALCHEMY_DATABASE_PW = 'covid19datapwd' +SQLALCHEMY_DATABASE_USER = 'flask_covid19' +SQLALCHEMY_DATABASE_PW = 'flask_covid19pwd' SQLALCHEMY_DATABASE_HOST = 'localhost' -SQLALCHEMY_DATABASE_DB = 'covid19data' +SQLALCHEMY_DATABASE_DB = 'flask_covid19' CACHE_TYPE = 'MemcachedCache' CACHE_MEMCACHED_SERVERS = '127.0.0.1:11211' -CACHE_DEFAULT_TIMEOUT = 120 +CACHE_DEFAULT_TIMEOUT = 50 +CACHE_THRESHOLD = 100000 CACHE_KEY_PREFIX = 'flask_covid19_' -SQLALCHEMY_ITEMS_PER_PAGE = 20 +SQLALCHEMY_ITEMS_PER_PAGE = 10 SQLALCHEMY_TRACK_MODIFICATIONS = True FLASK_ADMIN_SWATCH = 'superhero' FLASK_APP_DEBUGGER_ACTIVE = True diff --git a/src/database.py b/src/database.py index 5f34eeb5e25b2e1d07ce87efd3c6d0b0134a1ec3..20dc2a7f5fd80711bf9ba7241ac28dad872cbe56 100644 --- a/src/database.py +++ b/src/database.py @@ -44,7 +44,8 @@ def create_app(): login_manager.login_view = 'usr.login' login_manager.init_app(my_app) my_app.config.from_object("config") - my_db_url = 'postgresql+psycopg2://{user}:{pw}@{url}/{db}'.format( + # my_db_url = 'postgresql+psycopg2://{user}:{pw}@{url}/{db}'.format( + my_db_url = 'mysql://{user}:{pw}@{url}/{db}'.format( user=my_app.config['SQLALCHEMY_DATABASE_USER'], pw=my_app.config['SQLALCHEMY_DATABASE_PW'], url=my_app.config['SQLALCHEMY_DATABASE_HOST'], diff --git a/src/flask_covid19/blueprints/app_all/all_model.py b/src/flask_covid19/blueprints/app_all/all_model.py index 2c5a8cec4025cc2b9c993fd143f343722ec70777..3afa46b69e196a294a830808c2d817ac10f9d11e 100644 --- a/src/flask_covid19/blueprints/app_all/all_model.py +++ b/src/flask_covid19/blueprints/app_all/all_model.py @@ -1,5 +1,5 @@ from datetime import date -from database import db, ITEMS_PER_PAGE +from database import db, ITEMS_PER_PAGE, cache from sqlalchemy.orm import subqueryload from sqlalchemy import not_, and_ @@ -13,12 +13,8 @@ class BlueprintEntity(db.Model): @classmethod def remove_all(cls): - num_rows_deleted = 0 - try: - num_rows_deleted = db.session.query(cls).delete() - db.session.commit() - except Exception: - db.session.rollback() + num_rows_deleted = db.session.query(cls).delete() + db.session.commit() return num_rows_deleted @classmethod @@ -28,15 +24,18 @@ class BlueprintEntity(db.Model): return None @classmethod + @cache.memoize(50) def get_all_as_page(cls, page: int): return db.session.query(cls)\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_all(cls, page: int): return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.cached(timeout=50) def find_all(cls): return db.session.query(cls).all() @@ -45,14 +44,17 @@ class BlueprintEntity(db.Model): pass @classmethod + @cache.memoize(50) def get_by_id(cls, other_id): return db.session.query(cls).filter(cls.id == other_id).one() @classmethod + @cache.memoize(50) def find_by_id(cls, other_id): return db.session.query(cls).filter(cls.id == other_id).one_or_none() @classmethod + @cache.cached(timeout=50) def set_all_processed_full_update(cls): for o in cls.find_by_not_processed_full_update(): o.set_processed_full_update() @@ -76,10 +78,12 @@ class BlueprintEntity(db.Model): return self @classmethod + @cache.cached(timeout=50) def find_by_not_processed_update(cls): return db.session.query(cls).filter(not_(cls.processed_update)).all() @classmethod + @cache.cached(timeout=50) def find_by_not_processed_full_update(cls): return db.session.query(cls).filter(not_(cls.processed_full_update)).all() @@ -120,6 +124,7 @@ class BlueprintDateReported(BlueprintEntity): return self.get_names_for_weekday()[self.day_of_week] @classmethod + @cache.cached(timeout=50) def get_names_for_weekday(cls): return {1: "Montag", 2: "Dienstag", 3: "Mittwoch", 4: "Donnerstag", 5: "Freitag", 6: "Samstag", 7: "Sonntag"} @@ -128,11 +133,13 @@ class BlueprintDateReported(BlueprintEntity): return self.get_names_for_months()[self.month] @classmethod + @cache.cached(timeout=50) def get_names_for_months(cls): return {1: "Januar", 2: "Februar", 3: "März", 4: "April", 5: "Mai", 6: "Juni", 7: "Juli", 8: "August", 9: "September", 10: "Oktober", 11: "November", 12: "Dezember"} @classmethod + @cache.memoize(50) def get_by_datum(cls, datum: date): return db.session.query(cls).filter(cls.datum == datum).one() @@ -143,24 +150,28 @@ class BlueprintDateReported(BlueprintEntity): .one() @classmethod + @cache.memoize(50) def find_by_date_reported(cls, date_reported_import_str: str): return db.session.query(cls)\ .filter(cls.date_reported_import_str == date_reported_import_str)\ .one_or_none() @classmethod + @cache.memoize(50) def find_by_year_week(cls, year_week: str): return db.session.query(cls)\ .filter(cls.year_week == year_week)\ .all() @classmethod + @cache.cached(timeout=50) def get_joungest_datum(cls): return db.session.query(cls)\ .order_by(cls.datum.desc())\ .first() @classmethod + @cache.cached(timeout=50) def set_all_processed_update(cls): for o in cls.find_by_not_processed_update(): o.set_processed_update() @@ -196,32 +207,38 @@ class BlueprintLocationGroup(BlueprintEntity): location_group = db.Column(db.String(255), nullable=False, unique=True) @classmethod + @cache.cached(timeout=50) def get_last(cls): return db.session.query(cls).order_by(cls.location_group).all().pop() @classmethod + @cache.memoize(50) def get_by_location_group(cls, location_group: str): return db.session.query(cls)\ .filter(cls.location_group == location_group)\ .one() @classmethod + # @cache.memoize(50) def find_by_location_group(cls, location_group: str): return db.session.query(cls) \ .filter(cls.location_group == location_group) \ .one_or_none() @classmethod + @cache.memoize(50) def get_all_as_page(cls, page: int): return db.session.query(cls)\ .order_by(cls.location_group)\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.cached(timeout=50) def find_all(cls): return db.session.query(cls).order_by(cls.location_group).all() @classmethod + @cache.cached(timeout=50) def find_all_as_dict(cls): dates_reported = {} for my_location_group in cls.find_all(): @@ -252,38 +269,45 @@ class BlueprintLocation(BlueprintEntity): order_by='BlueprintLocationGroup.location_group') @classmethod + @cache.memoize(50) def find_by_location_code(cls, location_code: str): return db.session.query(cls).filter(cls.location_code == location_code)\ .one_or_none() @classmethod + @cache.memoize(50) def get_by_location_code(cls, location_code: str): return db.session.query(cls).filter(cls.location_code == location_code)\ .one() @classmethod + @cache.memoize(50) def find_by_location(cls, location: str): return db.session.query(cls).filter(cls.location == location)\ .one_or_none() @classmethod + @cache.memoize(50) def get_by_location(cls, location: str): return db.session.query(cls).filter(cls.location == location)\ .one() @classmethod + @cache.memoize(50) def find_by_location_group(cls, location_group: BlueprintLocationGroup): return db.session.query(cls).filter(cls.location_group == location_group)\ .order_by(cls.location)\ .all() @classmethod + @cache.memoize(50) def get_by_location_group(cls, location_group: BlueprintLocationGroup, page: int): return db.session.query(cls).filter(cls.location_group == location_group)\ .order_by(cls.location)\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, location_group: BlueprintLocationGroup): return db.session.query(cls).filter( @@ -295,6 +319,7 @@ class BlueprintLocation(BlueprintEntity): ).one_or_none() @classmethod + @cache.memoize(50) def get_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, location_group: BlueprintLocationGroup): return db.session.query(cls).filter( @@ -306,6 +331,7 @@ class BlueprintLocation(BlueprintEntity): ).one() @classmethod + @cache.memoize(50) def find_by_location_code_and_location(cls, location_code: str, location: str): return db.session.query(cls)\ .filter(and_(cls.location_code == location_code, cls.location == location))\ @@ -313,15 +339,18 @@ class BlueprintLocation(BlueprintEntity): .one_or_none() @classmethod + @cache.memoize(50) def get_by_location_code_and_location(cls, location_code: str, location: str): return db.session.query(cls).filter(and_(cls.location_code == location_code, cls.location == location)) \ .one() @classmethod + @cache.cached(timeout=50) def find_all(cls): return db.session.query(cls).order_by(cls.location).all() @classmethod + @cache.cached(timeout=50) def find_all_as_dict(cls): dates_reported = {} for my_location in cls.find_all(): @@ -329,6 +358,7 @@ class BlueprintLocation(BlueprintEntity): return dates_reported @classmethod + @cache.memoize(50) def get_all_as_page(cls, page: int): return db.session.query(cls)\ .order_by(cls.location)\ @@ -356,6 +386,7 @@ class BlueprintFactTableTimeSeries(BlueprintEntity): order_by='desc(BlueprintDateReported.datum)') @classmethod + @cache.cached(timeout=50) def get_date_reported_list(cls): date_reported_list = [] for data in db.session.query(cls).options(subqueryload("date_reported").load_only("datum")): @@ -366,6 +397,7 @@ class BlueprintFactTableTimeSeries(BlueprintEntity): return date_reported_list @classmethod + @cache.cached(timeout=50) def get_joungest_date_reported(cls): data = cls.get_date_reported_list() if len(data) > 0: @@ -425,7 +457,7 @@ class BlueprintFactTable(BlueprintFactTableTimeSeries): pass @classmethod - def get_by_date_reported_and_location(cls, date_reported: BlueprintDateReported, location: BlueprintLocation): + def get_by_date_reported_and_location(cls, date_reported: BlueprintDateReported, location: BlueprintLocation, page: int): pass @@ -452,6 +484,7 @@ class AllImport(BlueprintEntity): .all() @classmethod + @cache.cached(timeout=50) def get_datum_list(cls): return db.session.query(cls.datum) \ .order_by(cls.datum.desc()) \ diff --git a/src/flask_covid19/blueprints/app_web/user_model.py b/src/flask_covid19/blueprints/app_web/user_model.py index f15590698e51a62d67244915a392667cad62b9cd..5f8a0e1cfaaf8047d53bc6544d65a7eb92783bd2 100644 --- a/src/flask_covid19/blueprints/app_web/user_model.py +++ b/src/flask_covid19/blueprints/app_web/user_model.py @@ -10,9 +10,9 @@ class User(UserMixin, db.Model): __tablename__ = 'usr' id = db.Column(db.Integer, primary_key=True) - email = db.Column(db.Unicode, nullable=False, unique=True) - password_hash = db.Column(db.String, nullable=False) - name = db.Column(db.String(1000), nullable=False) + email = db.Column(db.Unicode(512), nullable=False, unique=True) + password_hash = db.Column(db.String(2048), nullable=False) + name = db.Column(db.String(512), nullable=False) def set_password(self, password): self.password_hash = generate_password_hash(password) diff --git a/src/flask_covid19/blueprints/data_divi/divi_service_import.py b/src/flask_covid19/blueprints/data_divi/divi_service_import.py index 29c7a6b0d6e27738c4670d9589df2b768b76f240..f0e99fb0fd50f2ea669bcd7d757357c84c55419e 100644 --- a/src/flask_covid19/blueprints/data_divi/divi_service_import.py +++ b/src/flask_covid19/blueprints/data_divi/divi_service_import.py @@ -1,6 +1,6 @@ import sys import csv -import psycopg2 +# import psycopg2 from database import db, app from flask_covid19.blueprints.app_all.all_config import BlueprintConfig diff --git a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py index 0f7d1f30fe46b9fa01d78ae02aaba08f30a588ba..856d5aa05ca858831defc52a94363b683c0e11a5 100644 --- a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py +++ b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py @@ -1,5 +1,6 @@ from sqlalchemy import and_ -from database import db, ITEMS_PER_PAGE +from sqlalchemy.orm import joinedload +from database import db, ITEMS_PER_PAGE, cache from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported, BlueprintLocationGroup from flask_covid19.blueprints.app_all.all_model import BlueprintLocation, BlueprintFactTable @@ -16,23 +17,36 @@ class EcdcDateReported(BlueprintDateReported): ), ) + def __repr__(self): + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, + self.datum.isoformat(), + self.year_day_of_year) + id = db.Column(db.Integer, primary_key=True) # - date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) - datum = db.Column(db.Date, nullable=False, unique=True) - year_day_of_year = db.Column(db.String(255), nullable=False, unique=True) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) + date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True, index=True) + datum = db.Column(db.Date, nullable=False, unique=True, index=True) + year_day_of_year = db.Column(db.String(255), nullable=False, unique=True, index=True) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) - day_of_year = db.Column(db.Integer, nullable=True) - week_of_year = db.Column(db.Integer, nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) + day_of_year = db.Column(db.Integer, nullable=True, index=True) + week_of_year = db.Column(db.Integer, nullable=False, index=True) # - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) + + @classmethod + @cache.memoize(50) + def get_all_as_page(cls, page: int): + return db.session.query(cls)\ + .order_by(cls.datum.desc())\ + .paginate(page, per_page=ITEMS_PER_PAGE) class EcdcContinent(BlueprintLocationGroup): @@ -42,10 +56,13 @@ class EcdcContinent(BlueprintLocationGroup): db.UniqueConstraint('location_group', name="uix_ecdc_country_continent"), ) + def __repr__(self): + return "%s(%s)" % (self.__class__.__name__, self.location_group) + id = db.Column(db.Integer, primary_key=True) - location_group = db.Column(db.String(255), nullable=False, unique=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + location_group = db.Column(db.String(255), nullable=False, unique=True, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) class EcdcCountry(BlueprintLocation): @@ -60,6 +77,14 @@ class EcdcCountry(BlueprintLocation): ), ) + def __repr__(self): + return "%s(%s, %s, %s; %s, %s)" % (self.__class__.__name__, + self.location_group.__repr__(), + self.location_code, + self.location, + self.pop_data_2019, + self.geo_id) + def __str__(self): return " " + self.location_group.location_group \ + " : " + self.location_code \ @@ -69,21 +94,19 @@ class EcdcCountry(BlueprintLocation): id = db.Column(db.Integer, primary_key=True) # country_territory_code = db.Column(db.String(255), nullable=False) - location_code = db.Column(db.String(255), nullable=True) + location_code = db.Column(db.String(255), nullable=True, index=True) # countries_and_territories = db.Column(db.String(255), nullable=False) - location = db.Column(db.String(255), nullable=False) + location = db.Column(db.String(255), nullable=False, index=True) location_group_id = db.Column(db.Integer, db.ForeignKey('ecdc_country_continent.id'), nullable=False) location_group = db.relationship( 'EcdcContinent', lazy='subquery', cascade="all, delete", order_by='asc(EcdcContinent.location_group)' ) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - pop_data_2019 = db.Column(db.String(255), nullable=False) - geo_id = db.Column(db.String(255), nullable=False) - - + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) + pop_data_2019 = db.Column(db.String(255), nullable=False, index=True) + geo_id = db.Column(db.String(255), nullable=False, index=True) @classmethod def get_by(cls, location: str = '', geo_id: str = '', location_code: str = ''): @@ -94,6 +117,7 @@ class EcdcCountry(BlueprintLocation): )).one() @classmethod + @cache.memoize(50) def find_by(cls, location: str = '', geo_id: str = '', location_code: str = ''): return db.session.query(cls).filter(and_( (cls.location == location), @@ -102,12 +126,21 @@ class EcdcCountry(BlueprintLocation): )).one_or_none() @classmethod - def find_by_location_group(cls, location_group: EcdcContinent, page: int): + @cache.memoize(50) + def find_by_location_group(cls, location_group: EcdcContinent): + return db.session.query(cls)\ + .filter(cls.location_group_id == location_group.id)\ + .all() + + @classmethod + @cache.memoize(50) + def get_by_location_group(cls, location_group: EcdcContinent, page: int): return db.session.query(cls)\ .filter(cls.location_group_id == location_group.id)\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_germany(cls): return db.session.query(cls) \ .filter(cls.location_code == 'DEU') \ @@ -117,6 +150,12 @@ class EcdcCountry(BlueprintLocation): class EcdcData(BlueprintFactTable): __tablename__ = 'ecdc' __mapper_args__ = {'concrete': True} + __table_args__ = ( + db.UniqueConstraint('date_reported_id', 'location_id', name="uix_ecdc"), + ) + + def __repr__(self): + return "%s(%s %s)" % (self.__class__.__name__, self.date_reported.__repr__(), self.location.__repr__()) id = db.Column(db.Integer, primary_key=True) date_reported_id = db.Column(db.Integer, db.ForeignKey('ecdc_date_reported.id'), nullable=False) @@ -124,51 +163,126 @@ class EcdcData(BlueprintFactTable): 'EcdcDateReported', lazy='joined', cascade='save-update', - order_by='desc(OwidDateReported.datum)') + order_by='desc(EcdcDateReported.datum)') location_id = db.Column(db.Integer, db.ForeignKey('ecdc_country.id'), nullable=False) location = db.relationship( 'EcdcCountry', lazy='joined', cascade='save-update', order_by='asc(EcdcCountry.location)') - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - deaths = db.Column(db.Integer, nullable=False) - cases = db.Column(db.Integer, nullable=False) - cumulative_number_for_14_days_of_covid19_cases_per_100000 = db.Column(db.Float, nullable=False) + deaths = db.Column(db.Integer, nullable=False, index=True) + cases = db.Column(db.Integer, nullable=False, index=True) + cumulative_number_for_14_days_of_covid19_cases_per_100000 = db.Column(db.Float, nullable=False, index=True) @classmethod - def find_by_date_reported(cls, date_reported: EcdcDateReported, page: int): + def __query_by_date_reported(cls, date_reported: EcdcDateReported): return db.session.query(cls).filter( - cls.date_reported_id == date_reported.id)\ - .order_by(cls.cumulative_number_for_14_days_of_covid19_cases_per_100000.desc())\ - .paginate(page, per_page=ITEMS_PER_PAGE) + cls.date_reported_id == date_reported.id + ).populate_existing().options( + joinedload(cls.location).joinedload(EcdcDateReported.location_group), + joinedload(cls.date_reported) + ) @classmethod - def find_by_date_reported_order_by_notification_rate(cls, date_reported: EcdcDateReported, page: int): + def __query_by_location(cls, location: EcdcCountry): return db.session.query(cls).filter( - cls.date_reported_id == date_reported.id) \ - .order_by(cls.cumulative_number_for_14_days_of_covid19_cases_per_100000.desc()) \ + cls.location_id == location.id + ).populate_existing().options( + joinedload(cls.location).joinedload(EcdcCountry.location_group), + joinedload(cls.date_reported) + ) + + @classmethod + def __query_by_date_reported_order_by_notification_rate(cls, date_reported: EcdcDateReported): + return cls.__query_by_date_reported(date_reported) \ + .order_by(cls.cumulative_number_for_14_days_of_covid19_cases_per_100000.desc()) + + @classmethod + def __query_by_date_reported_order_by_deaths(cls, date_reported: EcdcDateReported): + return cls.__query_by_date_reported(date_reported) \ + .order_by(cls.deaths.desc()) + + @classmethod + def __query_by_date_reported_order_by_cases(cls, date_reported: EcdcDateReported): + return cls.__query_by_date_reported(date_reported) \ + .order_by(cls.cases.desc()) + + @classmethod + def __query_by_date_reported_and_location(cls, date_reported: EcdcDateReported, location: EcdcCountry): + return db.session.query(cls) \ + .filter(and_((cls.location_id == location.id), (cls.date_reported_id == date_reported.id))) + + @classmethod + @cache.memoize(50) + def find_by_date_reported(cls, date_reported: EcdcDateReported): + return cls.__query_by_date_reported(date_reported).all() + + @classmethod + @cache.memoize(50) + def get_by_date_reported(cls, date_reported: EcdcDateReported, page: int): + return cls.__query_by_date_reported(date_reported)\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod - def find_by_date_reported_order_by_deaths_weekly(cls, date_reported: EcdcDateReported, page: int): - return db.session.query(cls).filter( - cls.date_reported_id == date_reported.id) \ - .order_by(cls.deaths.desc()) \ + @cache.memoize(50) + def find_by_date_reported_order_by_notification_rate(cls, date_reported: EcdcDateReported): + return cls.__query_by_date_reported_order_by_notification_rate(date_reported).all() + + @classmethod + @cache.memoize(50) + def get_by_date_reported_order_by_notification_rate(cls, date_reported: EcdcDateReported, page: int): + return cls.__query_by_date_reported_order_by_notification_rate(date_reported)\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod - def find_by_date_reported_order_by_cases_weekly(cls, date_reported: EcdcDateReported, page: int): - return db.session.query(cls).filter( - cls.date_reported_id == date_reported.id) \ - .order_by(cls.cases.desc()) \ + @cache.memoize(50) + def find_by_date_reported_order_by_deaths(cls, date_reported: EcdcDateReported): + return cls.__query_by_date_reported_order_by_deaths_weekly(date_reported).all() + + @classmethod + @cache.memoize(50) + def get_by_date_reported_order_by_deaths(cls, date_reported: EcdcDateReported, page: int): + return cls.__query_by_date_reported_order_by_deaths_weekly(date_reported)\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod - def find_by_location(cls, location: EcdcCountry, page: int): - return db.session.query(cls).filter( - cls.location_id == location.id) \ - .order_by(cls.date_reported.desc()) \ + @cache.memoize(50) + def find_by_date_reported_order_by_cases(cls, date_reported: EcdcDateReported): + return cls.__query_by_date_reported_order_by_cases_weekly(date_reported).all() + + @classmethod + @cache.memoize(50) + def get_by_date_reported_order_by_cases(cls, date_reported: EcdcDateReported, page: int): + return cls.__query_by_date_reported_order_by_cases_weekly(date_reported)\ .paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + @cache.memoize(50) + def find_by_location(cls, location: EcdcCountry): + return cls.__query_by_location(location).all() + + @classmethod + @cache.memoize(50) + def get_by_location(cls, location: EcdcCountry, page: int): + return cls.__query_by_location(location).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + @cache.memoize(50) + def find_by_date_reported_and_location(cls, date_reported: EcdcDateReported, location: EcdcCountry): + return cls.__query_by_date_reported_and_location(date_reported, location).one_or_none() + + @classmethod + @cache.memoize(50) + def get_by_date_reported_and_location(cls, date_reported: EcdcDateReported, location: EcdcCountry, page: int): + return cls.__query_by_date_reported_and_location(date_reported, location).one() + + @classmethod + def delete_data_for_one_day(cls, date_reported: EcdcDateReported): + for data in cls.find_by_date_reported(date_reported): + db.session.delete(data) + db.session.delete(date_reported) + db.session.commit() + diff --git a/src/flask_covid19/blueprints/data_ecdc/ecdc_model_import.py b/src/flask_covid19/blueprints/data_ecdc/ecdc_model_import.py index 5a49015b4b5aebb8de97d0bbdf22c553980f3cb5..8d914dc13170f2e90460e94ebf0b568704fc0734 100644 --- a/src/flask_covid19/blueprints/data_ecdc/ecdc_model_import.py +++ b/src/flask_covid19/blueprints/data_ecdc/ecdc_model_import.py @@ -1,4 +1,4 @@ -from database import db, ITEMS_PER_PAGE +from database import db, ITEMS_PER_PAGE, cache from flask_covid19.blueprints.app_all.all_model import AllImport, AllFlat @@ -6,29 +6,37 @@ class EcdcImport(AllImport): __tablename__ = 'ecdc_import' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s %s %s %s)" % (self.__class__.__name__, + self.date_reported_import_str, + self.datum.isoformat(), + self.countries_and_territories, + self.continent_exp) + id = db.Column(db.Integer, primary_key=True) - date_reported_import_str = db.Column(db.String(255), nullable=False) - datum = db.Column(db.Date, nullable=False) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + date_reported_import_str = db.Column(db.String(255), nullable=False, index=True) + datum = db.Column(db.Date, nullable=False, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - date_rep = db.Column(db.String(255), nullable=False) - day = db.Column(db.String(255), nullable=False) - month = db.Column(db.String(255), nullable=False) - year = db.Column(db.String(255), nullable=False) + date_rep = db.Column(db.String(255), nullable=False, index=True) + day = db.Column(db.String(255), nullable=False, index=True) + month = db.Column(db.String(255), nullable=False, index=True) + year = db.Column(db.String(255), nullable=False, index=True) # - cases = db.Column(db.String(255), nullable=False) - deaths = db.Column(db.String(255), nullable=False) - pop_data_2019 = db.Column(db.String(255), nullable=False) + cases = db.Column(db.String(255), nullable=False, index=True) + deaths = db.Column(db.String(255), nullable=False, index=True) + pop_data_2019 = db.Column(db.String(255), nullable=False, index=True) # - countries_and_territories = db.Column(db.String(255), nullable=False) - geo_id = db.Column(db.String(255), nullable=False) - country_territory_code = db.Column(db.String(255), nullable=False) - continent_exp = db.Column(db.String(255), nullable=False) + countries_and_territories = db.Column(db.String(255), nullable=False, index=True) + geo_id = db.Column(db.String(255), nullable=False, index=True) + country_territory_code = db.Column(db.String(255), nullable=False, index=True) + continent_exp = db.Column(db.String(255), nullable=False, index=True) # - cumulative_number_for_14_days_of_covid19_cases_per_100000 = db.Column(db.String(255), nullable=False) + cumulative_number_for_14_days_of_covid19_cases_per_100000 = db.Column(db.String(255), nullable=False, index=True) @classmethod + @cache.memoize(50) def remove_all(cls): num_rows_deleted = 0 try: @@ -39,6 +47,7 @@ class EcdcImport(AllImport): return num_rows_deleted @classmethod + @cache.memoize(50) def get_all_as_page(cls, page: int): return db.session.query(cls).order_by( cls.year, @@ -48,6 +57,7 @@ class EcdcImport(AllImport): ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_all(cls): return db.session.query(cls).order_by( cls.year, @@ -57,6 +67,7 @@ class EcdcImport(AllImport): ).all() @classmethod + @cache.memoize(50) def get_by_id(cls, other_id: int): return db.session.query(cls).filter(cls.id == other_id).one() @@ -71,6 +82,7 @@ class EcdcImport(AllImport): .all() @classmethod + @cache.memoize(50) def get_continent(cls): # sql = "select distinct continent_exp from edcd_import order by continent_exp asc" #return db.session.execute(sql).fetchall() @@ -81,6 +93,7 @@ class EcdcImport(AllImport): .all() @classmethod + @cache.memoize(50) def get_countries_of_continent(cls, my_continent): my_continent_exp = my_continent.location_group my_params = {} @@ -134,30 +147,37 @@ class EcdcFlat(AllFlat): __tablename__ = 'ecdc_import_flat' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s %s %s %s)" % (self.__class__.__name__, + self.date_reported_import_str, + self.datum.isoformat(), + self.location, + self.location_group.__repr__()) + id = db.Column(db.Integer, primary_key=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - date_reported_import_str = db.Column(db.String(255), nullable=False) - datum = db.Column(db.Date, nullable=False) - location = db.Column(db.String(255), nullable=False) - location_group = db.Column(db.String(255), nullable=False) - location_code = db.Column(db.String(255), nullable=False) + date_reported_import_str = db.Column(db.String(255), nullable=False, index=True) + datum = db.Column(db.Date, nullable=False, index=True) + location = db.Column(db.String(255), nullable=False, index=True) + location_group = db.Column(db.String(255), nullable=False, index=True) + location_code = db.Column(db.String(255), nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) - year_day_of_year = db.Column(db.String(255), nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) + year_day_of_year = db.Column(db.String(255), nullable=False, index=True) # - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) - week_of_year = db.Column(db.Integer, nullable=False) - day_of_year = db.Column(db.Integer, nullable=False) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) + week_of_year = db.Column(db.Integer, nullable=False, index=True) + day_of_year = db.Column(db.Integer, nullable=False, index=True) # - cases = db.Column(db.String(255), nullable=False) - deaths = db.Column(db.String(255), nullable=False) - geo_id = db.Column(db.String(255), nullable=False) - pop_data_2019 = db.Column(db.String(255), nullable=False) - cumulative_number_for_14_days_of_covid19_cases_per_100000 = db.Column(db.String(255), nullable=False) + cases = db.Column(db.String(255), nullable=False, index=True) + deaths = db.Column(db.String(255), nullable=False, index=True) + geo_id = db.Column(db.String(255), nullable=False, index=True) + pop_data_2019 = db.Column(db.String(255), nullable=False, index=True) + cumulative_number_for_14_days_of_covid19_cases_per_100000 = db.Column(db.String(255), nullable=False, index=True) diff --git a/src/flask_covid19/blueprints/data_ecdc/ecdc_service_import.py b/src/flask_covid19/blueprints/data_ecdc/ecdc_service_import.py index 68c9c7970a7c32da46890da34de73339701408b8..498fd6c77eaf93cd3bf279616aeb27203a13e14d 100644 --- a/src/flask_covid19/blueprints/data_ecdc/ecdc_service_import.py +++ b/src/flask_covid19/blueprints/data_ecdc/ecdc_service_import.py @@ -1,5 +1,5 @@ import csv -import psycopg2 +# import psycopg2 from database import db, app from flask_covid19.blueprints.app_all.all_config import BlueprintConfig diff --git a/src/flask_covid19/blueprints/data_ecdc/ecdc_views.py b/src/flask_covid19/blueprints/data_ecdc/ecdc_views.py index fac176d8f768e3a9b0752f34df8935302cfa528b..e4d5a4b60e5405f3aa520954536917292d3dcb09 100644 --- a/src/flask_covid19/blueprints/data_ecdc/ecdc_views.py +++ b/src/flask_covid19/blueprints/data_ecdc/ecdc_views.py @@ -29,7 +29,7 @@ admin.add_view(ModelView(EcdcData, db.session, category="ECDC")) @app_ecdc.route('/info') def url_ecdc_info(): - page_info = WebPageContent('Europe', "Info") + page_info = WebPageContent('ECDC', "Info") return render_template( 'ecdc/ecdc_info.html', title='Europe', @@ -38,7 +38,7 @@ def url_ecdc_info(): @app_ecdc.route('/tasks') def url_ecdc_tasks(): - page_info = WebPageContent('Europe', "Tasks") + page_info = WebPageContent('ECDC', "Tasks") return render_template( 'ecdc/ecdc_tasks.html', title='Europe Tasks', @@ -47,8 +47,8 @@ def url_ecdc_tasks(): @app_ecdc.route('/imported/page/<int:page>') @app_ecdc.route('/imported') -def url_ecdc_data_imported(page=1): - page_info = WebPageContent('Europe', "Last Import") +def url_ecdc_imported(page=1): + page_info = WebPageContent('ECDC', "Last Import") page_data = EcdcImport.get_all_as_page(page) return render_template( 'ecdc/imported/ecdc_imported.html', @@ -56,54 +56,64 @@ def url_ecdc_data_imported(page=1): page_info=page_info) +@app_ecdc.route('/flat/page/<int:page>') +@app_ecdc.route('/flat') +def url_ecdc_flat(page=1): + page_info = WebPageContent('ECDC', "flat") + page_data = EcdcFlat.get_all_as_page(page) + return render_template( + 'ecdc/flat/ecdc_flat.html', + page_data=page_data, + page_info=page_info) + + @app_ecdc.route('/date_reported/all/page/<int:page>') @app_ecdc.route('/date_reported/all') def url_ecdc_date_reported_all(page=1): - page_info = WebPageContent('Europe', "date_reported") + page_info = WebPageContent('ECDC', "date_reported") page_data = EcdcDateReported.get_all_as_page(page) return render_template( - 'ecdc/date_reported/ecdc_date_reported_all.html', + 'ecdc/date_reported/all/ecdc_date_reported_all.html', page_data=page_data, page_info=page_info) - -@app_ecdc.route('/date_reported/<int:europe_date_reported_id>/page/<int:page>') -@app_ecdc.route('/date_reported/<int:europe_date_reported_id>') -@app_ecdc.route('/date_reported/notification_rate/<int:europe_date_reported_id>/page/<int:page>') -@app_ecdc.route('/date_reported/notification_rate/<int:europe_date_reported_id>') -def url_ecdc_date_reported_one_notification_rate(europe_date_reported_id, page=1): - page_info = WebPageContent('Europe', "date_reported") - europe_date_reported = EcdcDateReported.get_by_id(europe_date_reported_id) - page_data = EcdcData.find_by_date_reported_notification_rate(europe_date_reported, page) +@app_ecdc.route('/date_reported/<int:date_reported_id>/page/<int:page>') +@app_ecdc.route('/date_reported/<int:date_reported_id>') +@app_ecdc.route('/date_reported/notification_rate/<int:date_reported_id>/page/<int:page>') +@app_ecdc.route('/date_reported/notification_rate/<int:date_reported_id>') +def url_ecdc_date_reported_one_notification_rate(date_reported_id, page=1): + page_info = WebPageContent('ECDC', "date_reported") + ecdc_date_reported = EcdcDateReported.get_by_id(date_reported_id) + page_data = EcdcData.get_by_date_reported_order_by_notification_rate(ecdc_date_reported, page) return render_template( - 'ecdc/date_reported/ecdc_date_reported_one_notification_rate.html', - europe_date_reported=europe_date_reported, + 'ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate.html', + ecdc_date_reported=ecdc_date_reported, page_data=page_data, page_info=page_info) -@app_ecdc.route('/date_reported/deaths_weekly/<int:europe_date_reported_id>/page/<int:page>') -@app_ecdc.route('/date_reported/deaths_weekly/<int:europe_date_reported_id>') -def url_ecdc_date_reported_one_deaths_weekly(europe_date_reported_id, page=1): - page_info = WebPageContent('Europe', "date_reported") - europe_date_reported = EcdcDateReported.get_by_id(europe_date_reported_id) - page_data = EcdcData.find_by_date_reported_deaths_weekly(europe_date_reported, page) +@app_ecdc.route('/date_reported/deaths_weekly/<int:date_reported_id>/page/<int:page>') +@app_ecdc.route('/date_reported/deaths_weekly/<int:date_reported_id>') +def url_ecdc_date_reported_one_deaths_weekly(date_reported_id, page=1): + page_info = WebPageContent('ECDC', "date_reported") + ecdc_date_reported = EcdcDateReported.get_by_id(date_reported_id) + page_data = EcdcData.get_by_date_reported_order_by_deaths(ecdc_date_reported, page) return render_template( - 'ecdc/date_reported/ecdc_date_reported_one_deaths_weekly.html', - europe_date_reported=europe_date_reported, + 'ecdc/date_reported/deaths/ecdc_date_reported_one_deaths_weekly.html', + ecdc_date_reported=ecdc_date_reported, page_data=page_data, page_info=page_info) -@app_ecdc.route('/date_reported/cases_weekly/<int:europe_date_reported_id>/page/<int:page>') -@app_ecdc.route('/date_reported/cases_weekly/<int:europe_date_reported_id>') -def url_ecdc_date_reported_one_cases_weekly(europe_date_reported_id, page=1): - page_info = WebPageContent('Europe', "date_reported") - europe_date_reported = EcdcDateReported.get_by_id(europe_date_reported_id) - page_data = EcdcData.find_by_date_reported_cases_weekly(europe_date_reported, page) +@app_ecdc.route('/date_reported/cases_weekly/<int:date_reported_id>/page/<int:page>') +@app_ecdc.route('/date_reported/cases_weekly/<int:date_reported_id>') +def url_ecdc_date_reported_one_cases_weekly(date_reported_id, page=1): + page_info = WebPageContent('ECDC', "date_reported") + ecdc_date_reported = EcdcDateReported.get_by_id(date_reported_id) + page_data = EcdcData.get_by_date_reported_order_by_cases(ecdc_date_reported, page) return render_template( - 'ecdc/date_reported/ecdc_date_reported_one_cases_weekly.html', - europe_date_reported=europe_date_reported, + 'ecdc/date_reported/cases/ecdc_date_reported_one_cases_weekly.html', + ecdc_date_reported=ecdc_date_reported, page_data=page_data, page_info=page_info) @@ -111,22 +121,22 @@ def url_ecdc_date_reported_one_cases_weekly(europe_date_reported_id, page=1): @app_ecdc.route('/continent/all/page/<int:page>') @app_ecdc.route('/continent/all') def url_ecdc_continent_all(page=1): - page_info = WebPageContent('Europe', "continent") + page_info = WebPageContent('ECDC', "continent") page_data = EcdcContinent.get_all_as_page(page) return render_template( - 'ecdc/continent/ecdc_continent_all.html', + 'ecdc/continent/all/ecdc_continent_all.html', page_data=page_data, page_info=page_info) @app_ecdc.route('/continent/<int:continent_id>/page/<int:page>') @app_ecdc.route('/continent/<int:continent_id>') -def url_ecdc_continent_one(continent_id, page=1): - page_info = WebPageContent('Europe', "continent") +def url_ecdc_continent_one(continent_id: int, page=1): + page_info = WebPageContent('ECDC', "continent") continent = EcdcContinent.get_by_id(continent_id) - page_data = EcdcCountry.find_by_continent(continent, page) + page_data = EcdcCountry.get_by_location_group(continent, page) return render_template( - 'ecdc/continent/ecdc_continent_one.html', + 'ecdc/continent/one/ecdc_continent_one.html', continent=continent, page_data=page_data, page_info=page_info) @@ -135,10 +145,10 @@ def url_ecdc_continent_one(continent_id, page=1): @app_ecdc.route('/country/all/page/<int:page>') @app_ecdc.route('/country/all') def url_ecdc_country_all(page=1): - page_info = WebPageContent('Europe', "country") + page_info = WebPageContent('ECDC', "country") page_data = EcdcCountry.get_all_as_page(page) return render_template( - 'ecdc/country/ecdc_country_all.html', + 'ecdc/country/all/ecdc_country_all.html', page_data=page_data, page_info=page_info) @@ -146,11 +156,11 @@ def url_ecdc_country_all(page=1): @app_ecdc.route('/country/<int:country_id>/page/<int:page>') @app_ecdc.route('/country/<int:country_id>') def url_ecdc_country_one(country_id, page=1): - page_info = WebPageContent('Europe', "country") + page_info = WebPageContent('ECDC', "country") europe_country = EcdcCountry.get_by_id(country_id) - page_data = EcdcData.find_by_country(europe_country, page) + page_data = EcdcData.get_by_location(europe_country, page) return render_template( - 'ecdc/country/ecdc_country_one.html', + 'ecdc/country/one/ecdc_country_one.html', europe_country=europe_country, page_data=page_data, page_info=page_info) @@ -159,14 +169,14 @@ def url_ecdc_country_one(country_id, page=1): @app_ecdc.route('/country/germany/page/<int:page>') @app_ecdc.route('/country/germany') def url_ecdc_country_germany(page=1): - page_info = WebPageContent('Europe', "country: Germany") - europe_country = EcdcCountry.get_germany() + page_info = WebPageContent('ECDC', "country: Germany") + europe_country = EcdcCountry.find_germany() if europe_country is None: flash('country: Germany not found in Database', category='error') return redirect(url_for('ecdc.url_ecdc_tasks')) - page_data = EcdcData.find_by_country(europe_country, page) + page_data = EcdcData.get_by_location(europe_country, page) return render_template( - 'ecdc/country/ecdc_country_germany.html', + 'ecdc/country/germany/ecdc_country_germany.html', europe_country=europe_country, page_data=page_data, page_info=page_info) diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_all.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/all/ecdc_continent_all.html similarity index 70% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_all.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/all/ecdc_continent_all.html index b981ae215c3bb07bf7b96c0909e7848a5c0943da..6df9b85df27e24690476237ab803322a9269fd21 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_all.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/all/ecdc_continent_all.html @@ -7,20 +7,21 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_all_pagination.html' %} + {% include 'ecdc/continent/all/ecdc_continent_all_pagination.html' %} </div> </div> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_all_table.html' %} + {% include 'ecdc/continent/all/ecdc_continent_all_table.html' %} </div> </div> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_all_pagination.html' %} + {% include 'ecdc/continent/all/ecdc_continent_all_pagination.html' %} </div> </div> </div> + {% endblock %} diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_all_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/all/ecdc_continent_all_pagination.html similarity index 100% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_all_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/all/ecdc_continent_all_pagination.html diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_all_table.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/all/ecdc_continent_all_table.html similarity index 72% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_all_table.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/all/ecdc_continent_all_table.html index 7deeec25a63974567c246fdc6f96b8bd4d4007ac..b7df855da45bbe43f88fbd1a29826e1d97fa1d59 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_all_table.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/all/ecdc_continent_all_table.html @@ -5,11 +5,11 @@ </tr> </thead> <tbody> - {% for europe_continent in page_data.items %} + {% for ecdc_continent in page_data.items %} <tr> <td> - <a href="{{ url_for( 'ecdc.url_ecdc_continent_one', continent_id=europe_continent.id) }}"> - {{ europe_continent.location_group }} + <a href="{{ url_for( 'ecdc.url_ecdc_continent_one', continent_id=ecdc_continent.id) }}"> + {{ ecdc_continent.location_group }} </a> </td> </tr> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_all.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/one/ecdc_continent_one.html similarity index 69% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_all.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/one/ecdc_continent_one.html index 6efea371afcf9564eb7020573218d2c8c90cfdc5..6aa62e11de61671abdd23e0d9715ac3b0c359582 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_all.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/one/ecdc_continent_one.html @@ -7,17 +7,17 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/country/ecdc_country_all_pagination.html' %} + {% include 'ecdc/continent/one/ecdc_continent_one_pagination.html' %} </div> </div> <div class="row"> <div class="col"> - {% include 'ecdc/country/ecdc_country_all_table.html' %} + {% include 'ecdc/country/all/ecdc_country_all_table.html' %} </div> - </div>ecdc_country_all_ + </div> <div class="row"> <div class="col"> - {% include 'ecdc/country/ecdc_country_all_pagination.html' %} + {% include 'ecdc/continent/one/ecdc_continent_one_pagination.html' %} </div> </div> </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_one_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/one/ecdc_continent_one_pagination.html similarity index 100% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_one_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/one/ecdc_continent_one_pagination.html diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_all.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/all/ecdc_country_all.html similarity index 74% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_all.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/all/ecdc_country_all.html index 4b766bb190bef5fa4524ee6f45e622f7dce5d230..43d979933930c21fd04a90084def06a73112986a 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_all.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/all/ecdc_country_all.html @@ -7,17 +7,17 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/continent/ecdc_continent_all_pagination.html' %} + {% include 'ecdc/country/all/ecdc_country_all_pagination.html' %} </div> </div> <div class="row"> <div class="col"> - {% include 'ecdc/continent/ecdc_continent_all_table.html' %} + {% include 'ecdc/country/all/ecdc_country_all_table.html' %} </div> - </div> + </div>ecdc_country_all_ <div class="row"> <div class="col"> - {% include 'ecdc/continent/ecdc_continent_all_pagination.html' %} + {% include 'ecdc/country/all/ecdc_country_all_pagination.html' %} </div> </div> </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_all_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/all/ecdc_country_all_pagination.html similarity index 100% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_all_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/all/ecdc_country_all_pagination.html diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_all_table.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/all/ecdc_country_all_table.html similarity index 96% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_all_table.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/all/ecdc_country_all_table.html index 8a1907260cc7820dd2e45fae43f995153d2cb745..beded7b492349e7800ee182f891c3dba794b6a44 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_all_table.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/all/ecdc_country_all_table.html @@ -29,7 +29,7 @@ </a> </td> <td> - <a href="{{ url_for('ecdc.url_ecdc_continent_one', country_id=europe_country.location_group.id) }}"> + <a href="{{ url_for('ecdc.url_ecdc_continent_one', continent_id=europe_country.location_group.id) }}"> {{ europe_country.location_group.location_group }} </a> </td> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_germany.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/germany/ecdc_country_germany.html similarity index 79% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_germany.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/germany/ecdc_country_germany.html index 3f8ff339c2434ddc82171cec0fbf90075bb676da..04b06b1a485842ad8dfa78c5ee9c99236ace0245 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_germany.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/germany/ecdc_country_germany.html @@ -7,7 +7,7 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/country/ecdc_country_germany_pagination.html' %} + {% include 'ecdc/country/germany/ecdc_country_germany_pagination.html' %} </div> </div> <div class="row"> @@ -17,7 +17,7 @@ </div> <div class="row"> <div class="col"> - {% include 'ecdc/country/ecdc_country_germany_pagination.html' %} + {% include 'ecdc/country/germany/ecdc_country_germany_pagination.html' %} </div> </div> </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_germany_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/germany/ecdc_country_germany_pagination.html similarity index 100% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_germany_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/germany/ecdc_country_germany_pagination.html diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_one.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/one/ecdc_country_one.html similarity index 80% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_one.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/one/ecdc_country_one.html index bea38ab46eb1c548c9191dff72369f9fe1d81254..27a9f8e9afd1ec7e924ca196ddce927d0795118d 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_one.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/one/ecdc_country_one.html @@ -7,7 +7,7 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/country/ecdc_country_one_pagination.html' %} + {% include 'ecdc/country/one/ecdc_country_one_pagination.html' %} </div> </div> <div class="row"> @@ -17,7 +17,7 @@ </div> <div class="row"> <div class="col"> - {% include 'ecdc/country/ecdc_country_one_pagination.html' %} + {% include 'ecdc/country/one/ecdc_country_one_pagination.html' %} </div> </div> </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_one_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/one/ecdc_country_one_pagination.html similarity index 100% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/ecdc_country_one_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/country/one/ecdc_country_one_pagination.html diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/all/ecdc_date_reported_all.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/all/ecdc_date_reported_all.html new file mode 100644 index 0000000000000000000000000000000000000000..cd1737a88850a5734ee57ba89fcf5953a54d7c90 --- /dev/null +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/all/ecdc_date_reported_all.html @@ -0,0 +1,33 @@ +{% extends 'app_application/layout/page_layout.html' %} + +{% block content %} + {{super()}} + {% include 'ecdc/navigation/ecdc_navtabs.html' %} + + <div class="container"> + <div class="row"> + <div class="col"> + {% include 'ecdc/date_reported/all/ecdc_date_reported_all_pagination.html' %} + </div> + </div> + <div class="row"> + <div class="col"> + {% include 'ecdc/date_reported/all/ecdc_date_reported_all_table.html' %} + </div> + </div> + <div class="row"> + <div class="col"> + {% include 'ecdc/date_reported/all/ecdc_date_reported_all_pagination.html' %} + </div> + </div> + </div> +{% endblock %} + + +{% block footer_container %} + <div> + {% for error in errors %} + <h4>{{ error }}</h4> + {% endfor %} + </div> +{% endblock %} \ No newline at end of file diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_all_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/all/ecdc_date_reported_all_pagination.html similarity index 100% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_all_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/all/ecdc_date_reported_all_pagination.html diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_all_table.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/all/ecdc_date_reported_all_table.html similarity index 76% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_all_table.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/all/ecdc_date_reported_all_table.html index fc0c499ec638e01ca6233f872a182ebb12749327..61e9b4fb2dd3c35d7726fd7dd51591e5a4f70121 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_all_table.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/all/ecdc_date_reported_all_table.html @@ -9,24 +9,24 @@ </tr> </thead> <tbody> - {% for europe_date_reported in page_data.items %} + {% for ecdc_date_reported in page_data.items %} <tr> <td class="text-right"> - {{ europe_date_reported.get_name_for_weekday() }} + {{ ecdc_date_reported.get_name_for_weekday() }} </td> <td class="text-left"> - <a href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_notification_rate', europe_date_reported_id=europe_date_reported.id) }}"> - {{ europe_date_reported }} + <a href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_notification_rate', date_reported_id=ecdc_date_reported.id) }}"> + {{ ecdc_date_reported }} </a> </td> <td class="text-right"> - {{ europe_date_reported.week_of_year }} + {{ ecdc_date_reported.week_of_year }} </td> <td class="text-left"> - {{ europe_date_reported.year }} + {{ ecdc_date_reported.year }} </td> <td class="text-left"> - {{ europe_date_reported.day_of_year }} + {{ ecdc_date_reported.day_of_year }} </td> </tr> {% endfor %} diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_cases_weekly.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/cases/ecdc_date_reported_one_cases_weekly.html similarity index 76% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_cases_weekly.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/cases/ecdc_date_reported_one_cases_weekly.html index 6ea3c5e1c30b0ffeeb69dd2d263083c2f572a17e..594707a9679f819b4ae507811bcce8ef9e6aed2d 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_cases_weekly.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/cases/ecdc_date_reported_one_cases_weekly.html @@ -7,7 +7,7 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_one_cases_weekly_pagination.html' %} + {% include 'ecdc/date_reported/cases/ecdc_date_reported_one_cases_weekly_pagination.html' %} </div> </div> <div class="row"> @@ -17,7 +17,7 @@ </div> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_one_cases_weekly_pagination.html' %} + {% include 'ecdc/date_reported/cases/ecdc_date_reported_one_cases_weekly_pagination.html' %} </div> </div> </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_cases_weekly_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/cases/ecdc_date_reported_one_cases_weekly_pagination.html similarity index 100% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_cases_weekly_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/cases/ecdc_date_reported_one_cases_weekly_pagination.html diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_deaths_weekly.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/deaths/ecdc_date_reported_one_deaths_weekly.html similarity index 75% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_deaths_weekly.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/deaths/ecdc_date_reported_one_deaths_weekly.html index 2396d9222a9262f85ddebf4784af372e1eda215a..cbddd8eef6dedf772a711814512d1924d0aff53b 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_deaths_weekly.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/deaths/ecdc_date_reported_one_deaths_weekly.html @@ -7,7 +7,7 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_one_deaths_weekly_pagination.html' %} + {% include 'ecdc/date_reported/deaths/ecdc_date_reported_one_deaths_weekly_pagination.html' %} </div> </div> <div class="row"> @@ -17,7 +17,7 @@ </div> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_one_deaths_weekly_pagination.html' %} + {% include 'ecdc/date_reported/deaths/ecdc_date_reported_one_deaths_weekly_pagination.html' %} </div> </div> </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_deaths_weekly_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/deaths/ecdc_date_reported_one_deaths_weekly_pagination.html similarity index 100% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_deaths_weekly_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/deaths/ecdc_date_reported_one_deaths_weekly_pagination.html diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_notification_rate.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate.html similarity index 74% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_notification_rate.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate.html index c7e13294b7f2d8e0681eea5c413dffe219bc9fa8..1dcc6c0c6ec1c9ce6e03c88f738f6687c5fdea87 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_notification_rate.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate.html @@ -7,7 +7,7 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_one_notification_rate_pagination.html' %} + {% include 'ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate_pagination.html' %} </div> </div> <div class="row"> @@ -17,7 +17,7 @@ </div> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_one_notification_rate_pagination.html' %} + {% include 'ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate_pagination.html' %} </div> </div> </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_notification_rate_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate_pagination.html similarity index 85% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_notification_rate_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate_pagination.html index 06e66841d94f3901f8d865173255cb00c193aa8b..10755f52e49cb897aa0b0d9eb90d8c5ef71a8dde 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_notification_rate_pagination.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/notification/ecdc_date_reported_one_notification_rate_pagination.html @@ -4,8 +4,7 @@ <li class="page-item"> <a class="page-link" href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_notification_rate', - europe_date_reported_id=europe_date_reported.id, - page=page_data.prev_num) }}"> + date_reported_id=ecdc_date_reported.id, page=page_data.prev_num) }}"> Previous </a> </li> @@ -16,7 +15,7 @@ <li class="page-item"> <a class="page-link" href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_notification_rate', - europe_date_reported_id=europe_date_reported.id, + date_reported_id=ecdc_date_reported.id, page=page_num) }}"> {{ page_num }} </a> @@ -36,7 +35,7 @@ <li class="page-item"> <a class="page-link" href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_notification_rate', - europe_date_reported_id=europe_date_reported.id, page=page_data.next_num) }}"> + date_reported_id=ecdc_date_reported.id, page=page_data.next_num) }}"> Next </a> </li> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/one/ecdc_date_reported_one.html similarity index 78% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/one/ecdc_date_reported_one.html index 3eaf7d49672fe0ecef468ebfa89ec9dfad490afe..5e07037ea0b5b46ce6dde03fc27ff8776adb1826 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/one/ecdc_date_reported_one.html @@ -7,7 +7,7 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_one_pagination.html' %} + {% include 'ecdc/date_reported/one/ecdc_date_reported_one_pagination.html' %} </div> </div> <div class="row"> @@ -17,7 +17,7 @@ </div> <div class="row"> <div class="col"> - {% include 'ecdc/date_reported/ecdc_date_reported_one_pagination.html' %} + {% include 'ecdc/date_reported/one/ecdc_date_reported_one_pagination.html' %} </div> </div> </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/one/ecdc_date_reported_one_pagination.html similarity index 100% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/ecdc_date_reported_one_pagination.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/date_reported/one/ecdc_date_reported_one_pagination.html diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/ecdc_data/ecdc_data_table.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/ecdc_data/ecdc_data_table.html index 10a134b59c707e872f8e903e12367f1dbe112fa4..990d9350c43b65af5c00555040d829ed159e1ad7 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/ecdc_data/ecdc_data_table.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/ecdc_data/ecdc_data_table.html @@ -1,109 +1,48 @@ <table class="table table-hover table-striped table-dark"> <thead class="table-secondary"> - <tr> - <th scope="col"> - <a href="{{ url_for('ecdc.url_ecdc_date_reported_all') }}"> - date rep - </a> - </th> - <th scope="col">year_week</th> - <th scope="col"> - {% if europe_date_reported %} - <a href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_cases_weekly', - europe_date_reported_id=europe_date_reported.id, - page=page_data.page) }}"> - deaths weekly - </a> - {% endif %} - {% if europe_country %} - deaths weekly - {% endif %} - </th> - <th scope="col"> - {% if europe_date_reported %} - <a href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_cases_weekly', - europe_date_reported_id=europe_date_reported.id, - page=page_data.page) }}"> - cases weekly - </a> - {% endif %} - {% if europe_country %} - cases weekly - {% endif %} - </th> - <th scope="col"> - {% if europe_date_reported %} - <a href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_cases_weekly', - europe_date_reported_id=europe_date_reported.id, - page=page_data.page) }}"> - notification rate per 100000 population 14days - </a> - {% endif %} - {% if europe_country %} - notification rate per 100000 population 14days - {% endif %} - </th> - <th scope="col"> - <a href="/ecdc/country/all"> - countries and territories - </a> - </th> - <th scope="col">population data 2019</th> - <th scope="col"> - <a href="{{ url_for('ecdc.url_ecdc_country_all') }}"> - geo id - </a> - </th> - <th scope="col"> - <a href="{{ url_for('ecdc.url_ecdc_country_all') }}"> - country territory code - </a> - </th> - <th scope="col"> - <a href="{{ url_for('ecdc.url_ecdc_continent_all') }}"> - continent - </a> - </th> - </tr> + {% include 'ecdc/ecdc_data/ecdc_data_table_head.html' %} </thead> <tbody> {% for ecdc_data in page_data.items %} <tr> <td> - <a href="/ecdc/date_reported/{{ ecdc_data.ecdc_datereported.id }}"> - {{ ecdc_data.ecdc_datereported.get_name_for_datum() }} + <a href="/ecdc/date_reported/{{ ecdc_data.date_reported.id }}"> + {{ ecdc_data.date_reported.datum }} </a> </td> <td> - <a href="/ecdc/date_reported/{{ ecdc_data.ecdc_datereported.id }}"> - {{ ecdc_data.ecdc_datereported.year_week }} + <a href="/ecdc/date_reported/{{ ecdc_data.date_reported.id }}"> + {{ ecdc_data.date_reported.year_week }} </a> </td> <td>{{ ecdc_data.deaths }}</td> <td>{{ ecdc_data.cases }}</td> <td>{{ ecdc_data.cumulative_number_for_14_days_of_covid19_cases_per_100000 }}</td> <td> - <a href="/ecdc/country/{{ ecdc_data.ecdc_country.id }}"> - {{ ecdc_data.ecdc_country.countries_and_territories }} + <a href="/ecdc/country/{{ ecdc_data.location.id }}"> + {{ ecdc_data.location.location }} </a> </td> - <td>{{ ecdc_data.ecdc_country.pop_data_2019 }}</td> + <td>{{ ecdc_data.location.pop_data_2019 }}</td> <td> - <a href="/ecdc/country/{{ ecdc_data.ecdc_country.id }}"> - {{ ecdc_data.ecdc_country.geo_id }} + <a href="/ecdc/country/{{ ecdc_data.location.id }}"> + {{ ecdc_data.location.geo_id }} </a> </td> <td> - <a href="/ecdc/country/{{ ecdc_data.ecdc_country.id }}"> - {{ ecdc_data.ecdc_country.country_territory_code }} + <a href="/ecdc/country/{{ ecdc_data.location.id }}"> + {{ ecdc_data.location.location_code }} </a> </td> <td> - <a href="/ecdc/continent/{{ ecdc_data.ecdc_country.continent.id }}"> - {{ ecdc_data.ecdc_country.continent.region }} + <a href="/ecdc/continent/{{ ecdc_data.location.location_group.id }}"> + {{ ecdc_data.location.location_group.location_group }} </a> </td> </tr> {% endfor %} </tbody> + <tfoot> + {% include 'ecdc/ecdc_data/ecdc_data_table_head.html' %} + </tfoot> </table> \ No newline at end of file diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/ecdc_data/ecdc_data_table_head.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/ecdc_data/ecdc_data_table_head.html new file mode 100644 index 0000000000000000000000000000000000000000..edaabb3099129359ab69660c9cf96b5646b0a224 --- /dev/null +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/ecdc_data/ecdc_data_table_head.html @@ -0,0 +1,65 @@ + <tr> + <th scope="col"> + <a href="{{ url_for('ecdc.url_ecdc_date_reported_all') }}"> + date rep + </a> + </th> + <th scope="col">year_week</th> + <th scope="col"> + {% if europe_date_reported %} + <a href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_cases_weekly', + europe_date_reported_id=europe_date_reported.id, + page=page_data.page) }}"> + deaths weekly + </a> + {% endif %} + {% if europe_country %} + deaths weekly + {% endif %} + </th> + <th scope="col"> + {% if europe_date_reported %} + <a href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_cases_weekly', + date_reported_id=date_reported.id, + page=page_data.page) }}"> + cases weekly + </a> + {% endif %} + {% if europe_country %} + cases weekly + {% endif %} + </th> + <th scope="col"> + {% if europe_date_reported %} + <a href="{{ url_for( 'ecdc.url_ecdc_date_reported_one_cases_weekly', + date_reported_id=date_reported.id, + page=page_data.page) }}"> + notification rate per 100000 population 14days + </a> + {% endif %} + {% if europe_country %} + notification rate per 100000 population 14days + {% endif %} + </th> + <th scope="col"> + <a href="{{ url_for( 'ecdc.url_ecdc_country_all') }}"> + countries and territories + </a> + </th> + <th scope="col">population data 2019</th> + <th scope="col"> + <a href="{{ url_for('ecdc.url_ecdc_country_all') }}"> + geo id + </a> + </th> + <th scope="col"> + <a href="{{ url_for('ecdc.url_ecdc_country_all') }}"> + country territory code + </a> + </th> + <th scope="col"> + <a href="{{ url_for('ecdc.url_ecdc_continent_all') }}"> + continent + </a> + </th> + </tr> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_one.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat.html similarity index 72% rename from src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_one.html rename to src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat.html index 9d018625b1c881a63081f856d0a053cf339cddff..9658216a64d37d866eb59690f187e565ed184a96 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/continent/ecdc_continent_one.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat.html @@ -7,24 +7,23 @@ <div class="container"> <div class="row"> <div class="col"> - {% include 'ecdc/continent/ecdc_continent_one_pagination.html' %} + {% include 'ecdc/flat/ecdc_flat_pagination.html' %} </div> </div> <div class="row"> <div class="col"> - {% include 'ecdc/country/ecdc_country_all_table.html' %} + {% include 'ecdc/flat/ecdc_flat_table.html' %} </div> </div> <div class="row"> <div class="col"> - {% include 'ecdc/continent/ecdc_continent_one_pagination.html' %} + {% include 'ecdc/flat/ecdc_flat_pagination.html' %} </div> </div> </div> {% endblock %} - {% block footer_container %} <div> {% for error in errors %} diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat_pagination.html new file mode 100644 index 0000000000000000000000000000000000000000..6713e99ea7da9a6b2a7ff09af7803c71cb444fb9 --- /dev/null +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat_pagination.html @@ -0,0 +1,37 @@ + {% if page_data.pages > 1 %} + <!-- previous page --> + <ul class="pagination"> + {% if page_data.has_prev %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for('ecdc.url_ecdc_flat', page=page_data.prev_num) }}">Previous</a> + </li> + {% endif %} + <!-- all page numbers --> + {% for page_num in page_data.iter_pages() %} + {% if page_num %} + {% if page_num != page_data.page %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for('ecdc.url_ecdc_flat', page=page_num) }}">{{ page_num }}</a> + </li> + {% else %} + <li class="page-item active"> + <a class="page-link" href="#">{{ page_num }}</a> + </li> + {% endif %} + {% else %} + <li class="page-item"> + <span class="ellipsis page-link my-page-item-ellipsis-page-link">…</span> + </li> + {% endif %} + {% endfor %} + <!-- next page --> + {% if page_data.has_next %} + <li class="page-item"> + <a class="page-link" + href="{{ url_for('ecdc.url_ecdc_flat', page=page_data.next_num) }}">Next</a> + </li> + {% endif %} + </ul> + {% endif %} diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat_table.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat_table.html new file mode 100644 index 0000000000000000000000000000000000000000..0ac9e868a0fbfcb44cea61790b941e1c39a4943a --- /dev/null +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat_table.html @@ -0,0 +1,28 @@ + <div class="table-responsive"> + <table class="table table-hover table-striped table-dark"> + <thead class="table-secondary"> + {% include 'ecdc/flat/ecdc_flat_table_head.html' %} + </thead> + <tbody> + {% for o in page_data.items %} + <tr> + <td>{{ o.datum }}</td> + <td>{{ o.year }}</td> + <td>{{ o.month }}</td> + <td>{{ o.day_of_month }}</td> + <td>{{ o.cases }}</td> + <td>{{ o.deaths }}</td> + <td>{{ o.pop_data_2019 }}</td> + <td>{{ o.location }}</td> + <td>{{ o.geo_id }}</td> + <td>{{ o.location_code }}</td> + <td>{{ o.location_group }}</td> + <td>{{ o.cumulative_number_for_14_days_of_covid19_cases_per_100000 }}</td> + </tr> + {% endfor %} + </tbody> + <tfoot class="table-secondary"> + {% include 'ecdc/flat/ecdc_flat_table_head.html' %} + </tfoot> + </table> + </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat_table_head.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat_table_head.html new file mode 100644 index 0000000000000000000000000000000000000000..f7e19c4606a11c94aa2dc5242c633a07804bded6 --- /dev/null +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/flat/ecdc_flat_table_head.html @@ -0,0 +1,14 @@ + <tr> + <th scope="col">date reported</th> + <th scope="col">date rep year</th> + <th scope="col">date rep month</th> + <th scope="col">date rep day</th> + <th scope="col">cases weekly</th> + <th scope="col">deaths weekly</th> + <th scope="col">population data 2019</th> + <th scope="col">countries and territories</th> + <th scope="col">geo id</th> + <th scope="col">country territory code</th> + <th scope="col">continent</th> + <th scope="col">notification rate per 100000 population 14days</th> + </tr> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_pagination.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_pagination.html index 40548e261d0a3af944dde726c7cff34382ff6b42..e5d8a589d6ed52e4e0a2191e15fbd233d59a1cae 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_pagination.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_pagination.html @@ -4,7 +4,7 @@ {% if page_data.has_prev %} <li class="page-item"> <a class="page-link" - href="{{ url_for('ecdc.url_ecdc_data_imported', page=page_data.prev_num) }}">Previous</a> + href="{{ url_for('ecdc.url_ecdc_imported', page=page_data.prev_num) }}">Previous</a> </li> {% endif %} <!-- all page numbers --> @@ -13,7 +13,7 @@ {% if page_num != page_data.page %} <li class="page-item"> <a class="page-link" - href="{{ url_for('ecdc.url_ecdc_data_imported', page=page_num) }}">{{ page_num }}</a> + href="{{ url_for('ecdc.url_ecdc_imported', page=page_num) }}">{{ page_num }}</a> </li> {% else %} <li class="page-item active"> @@ -30,7 +30,7 @@ {% if page_data.has_next %} <li class="page-item"> <a class="page-link" - href="{{ url_for('ecdc.url_ecdc_data_imported', page=page_data.next_num) }}">Next</a> + href="{{ url_for('ecdc.url_ecdc_imported', page=page_data.next_num) }}">Next</a> </li> {% endif %} </ul> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_table.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_table.html index b6a794f336b02e2885d848eaf9d4c5a0bcefb281..7b060ad8680817a60a0b795840bb0bac3d795875 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_table.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_table.html @@ -1,27 +1,15 @@ + <div class="table-responsive"> <table class="table table-hover table-striped table-dark"> <thead class="table-secondary"> - <tr> - <th scope="col">date reported</th> - <th scope="col">date rep year</th> - <th scope="col">date rep month</th> - <th scope="col">date rep day</th> - <th scope="col">cases weekly</th> - <th scope="col">deaths weekly</th> - <th scope="col">population data 2019</th> - <th scope="col">countries and territories</th> - <th scope="col">geo id</th> - <th scope="col">country territory code</th> - <th scope="col">continent</th> - <th scope="col">notification rate per 100000 population 14days</th> - </tr> + {% include 'ecdc/imported/ecdc_imported_table_head.html' %} </thead> <tbody> {% for o in page_data.items %} <tr> <td>{{ o.date_rep }}</td> - <td>{{ o.date_rep_year }}</td> - <td>{{ o.date_rep_month }}</td> - <td>{{ o.date_rep_day }}</td> + <td>{{ o.year }}</td> + <td>{{ o.month }}</td> + <td>{{ o.day }}</td> <td>{{ o.cases }}</td> <td>{{ o.deaths }}</td> <td>{{ o.pop_data_2019 }}</td> @@ -33,4 +21,8 @@ </tr> {% endfor %} </tbody> - </table> \ No newline at end of file + <tfoot class="table-secondary"> + {% include 'ecdc/imported/ecdc_imported_table_head.html' %} + </tfoot> + </table> + </div> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_table_head.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_table_head.html new file mode 100644 index 0000000000000000000000000000000000000000..f7e19c4606a11c94aa2dc5242c633a07804bded6 --- /dev/null +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/imported/ecdc_imported_table_head.html @@ -0,0 +1,14 @@ + <tr> + <th scope="col">date reported</th> + <th scope="col">date rep year</th> + <th scope="col">date rep month</th> + <th scope="col">date rep day</th> + <th scope="col">cases weekly</th> + <th scope="col">deaths weekly</th> + <th scope="col">population data 2019</th> + <th scope="col">countries and territories</th> + <th scope="col">geo id</th> + <th scope="col">country territory code</th> + <th scope="col">continent</th> + <th scope="col">notification rate per 100000 population 14days</th> + </tr> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/navigation/ecdc_navbar_dropdown.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/navigation/ecdc_navbar_dropdown.html index ddadab92d7e714d41f612008da3f113fb46d2a78..e72901f670e7010a4b171ffb9c680be08a019107 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/navigation/ecdc_navbar_dropdown.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/navigation/ecdc_navbar_dropdown.html @@ -35,7 +35,7 @@ <div class="dropdown-divider"></div> </li> <li> - <a class="dropdown-item" href="{{ url_for( 'ecdc.url_ecdc_data_imported') }}"> + <a class="dropdown-item" href="{{ url_for( 'ecdc.url_ecdc_imported') }}"> ECDC imported </a> </li> diff --git a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/navigation/ecdc_navtabs.html b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/navigation/ecdc_navtabs.html index 6d31235a5bc96137ac1b4ded252d85f86273ff2b..033ac94e0fc1b828cb64160fa45aa955868979bf 100644 --- a/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/navigation/ecdc_navtabs.html +++ b/src/flask_covid19/blueprints/data_ecdc/templates/ecdc/navigation/ecdc_navtabs.html @@ -13,9 +13,13 @@ </li> <li class="nav-item"> <a class="nav-link" - href="{{ url_for( 'ecdc.url_ecdc_data_imported') }}">ECDC imported</a> + href="{{ url_for( 'ecdc.url_ecdc_imported') }}">ECDC imported</a> </li> {% endif %} + <li class="nav-item"> + <a class="nav-link" + href="{{ url_for( 'ecdc.url_ecdc_flat') }}">ECDC flat</a> + </li> <li class="nav-item"> <a class="nav-link" href="{{ url_for( 'ecdc.url_ecdc_date_reported_all') }}">ECDC date_reported</a> diff --git a/src/flask_covid19/blueprints/data_owid/owid_model.py b/src/flask_covid19/blueprints/data_owid/owid_model.py index 36449d2d494162511165df5e01bc2dba7c95fa21..9b45038a1ae51f6f5a78468d9e3bb49359c15aef 100644 --- a/src/flask_covid19/blueprints/data_owid/owid_model.py +++ b/src/flask_covid19/blueprints/data_owid/owid_model.py @@ -1,7 +1,7 @@ from sqlalchemy import and_ -from sqlalchemy.orm import joinedload, subqueryload +from sqlalchemy.orm import joinedload -from database import db, ITEMS_PER_PAGE +from database import db, ITEMS_PER_PAGE, cache from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported, BlueprintLocationGroup from flask_covid19.blueprints.app_all.all_model import BlueprintLocation, BlueprintFactTable @@ -18,23 +18,27 @@ class OwidDateReported(BlueprintDateReported): ), ) + def __repr__(self): + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) + id = db.Column(db.Integer, primary_key=True) # date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) datum = db.Column(db.Date, nullable=False, unique=True) year_day_of_year = db.Column(db.String(255), nullable=False, unique=True) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) day_of_year = db.Column(db.Integer, nullable=True) - week_of_year = db.Column(db.Integer, nullable=False) + week_of_year = db.Column(db.Integer, nullable=False, index=True) # - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) class OwidContinent(BlueprintLocationGroup): @@ -44,14 +48,17 @@ class OwidContinent(BlueprintLocationGroup): db.UniqueConstraint('location_group', name="uix_owid_country_continent"), ) + def __repr__(self): + return "%s(%s)" % (self.__class__.__name__, self.location_group) + def __str__(self): result = "" + self.location_group + " " return result id = db.Column(db.Integer, primary_key=True) location_group = db.Column(db.String(255), nullable=False, unique=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) class OwidCountry(BlueprintLocation): @@ -61,37 +68,43 @@ class OwidCountry(BlueprintLocation): db.UniqueConstraint('location_code', 'location', name="uix_owid_country"), ) + def __repr__(self): + return "%s(%s %s %s)" % (self.__class__.__name__, + self.location_group.__repr__(), + self.location_code, + self.location) + def __str__(self): result = "" + self.location_group.__str__() + " : " + self.location_code + " | " + self.location + " " return result id = db.Column(db.Integer, primary_key=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - location_group_id = db.Column(db.Integer, db.ForeignKey('owid_country_continent.id'), nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) + location_group_id = db.Column(db.Integer, db.ForeignKey('owid_country_continent.id'), nullable=False, index=True) location_group = db.relationship( 'OwidContinent', lazy='joined', cascade='save-update', order_by='desc(OwidContinent.location_group)') - # iso_code = db.Column(db.String(255), nullable=False) - location_code = db.Column(db.String(255), nullable=False) - location = db.Column(db.String(255), nullable=False) - population = db.Column(db.String(255), nullable=False) - population_density = db.Column(db.String(255), nullable=False) - median_age = db.Column(db.String(255), nullable=False) - aged_65_older = db.Column(db.String(255), nullable=False) - aged_70_older = db.Column(db.String(255), nullable=False) - gdp_per_capita = db.Column(db.String(255), nullable=False) - extreme_poverty = db.Column(db.String(255), nullable=False) - cardiovasc_death_rate = db.Column(db.String(255), nullable=False) - diabetes_prevalence = db.Column(db.String(255), nullable=False) - female_smokers = db.Column(db.String(255), nullable=False) - male_smokers = db.Column(db.String(255), nullable=False) - handwashing_facilities = db.Column(db.String(255), nullable=False) - hospital_beds_per_thousand = db.Column(db.String(255), nullable=False) - life_expectancy = db.Column(db.String(255), nullable=False) - human_development_index = db.Column(db.String(255), nullable=False) + # iso_code = db.Column(db.String(255), nullable=False, index=True) + location_code = db.Column(db.String(255), nullable=False, index=True) + location = db.Column(db.String(255), nullable=False, index=True) + population = db.Column(db.String(255), nullable=False, index=True) + population_density = db.Column(db.String(255), nullable=False, index=True) + median_age = db.Column(db.String(255), nullable=False, index=True) + aged_65_older = db.Column(db.String(255), nullable=False, index=True) + aged_70_older = db.Column(db.String(255), nullable=False, index=True) + gdp_per_capita = db.Column(db.String(255), nullable=False, index=True) + extreme_poverty = db.Column(db.String(255), nullable=False, index=True) + cardiovasc_death_rate = db.Column(db.String(255), nullable=False, index=True) + diabetes_prevalence = db.Column(db.String(255), nullable=False, index=True) + female_smokers = db.Column(db.String(255), nullable=False, index=True) + male_smokers = db.Column(db.String(255), nullable=False, index=True) + handwashing_facilities = db.Column(db.String(255), nullable=False, index=True) + hospital_beds_per_thousand = db.Column(db.String(255), nullable=False, index=True) + life_expectancy = db.Column(db.String(255), nullable=False, index=True) + human_development_index = db.Column(db.String(255), nullable=False, index=True) @classmethod def delete_all_countries_for_continent(cls, owid_continent_one): @@ -101,24 +114,28 @@ class OwidCountry(BlueprintLocation): return None @classmethod + @cache.memoize(50) def get_germany(cls): iso_code = 'DEU' location = 'Germany' return cls.find_by_location_code_and_location(location_code=iso_code, location=location) @classmethod + @cache.memoize(50) def get_countries_for_continent(cls, owid_continent_one: OwidContinent, page: int): - return db.session.query(cls).filter(cls.continent == owid_continent_one).paginate(page, per_page=ITEMS_PER_PAGE) + return db.session.query(cls).filter(cls.location_group == owid_continent_one).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_all_countries_for_continent(cls, owid_continent_one: OwidContinent): - return db.session.query(cls).filter(cls.continent == owid_continent_one).all() + return db.session.query(cls).filter(cls.location_group == owid_continent_one).all() @classmethod def find_by_iso_code_and_location(cls, iso_code, location): return db.session.query(cls).filter(and_((cls.location_code == iso_code), (cls.location == location))).one_or_none() @classmethod + @cache.memoize(50) def get_by_iso_code_and_location(cls, iso_code, location): return db.session.query(cls).filter(and_((cls.location_code == iso_code), (cls.location == location))).one() @@ -126,103 +143,112 @@ class OwidCountry(BlueprintLocation): class OwidData(BlueprintFactTable): __tablename__ = 'owid' __mapper_args__ = {'concrete': True} + __table_args__ = ( + db.UniqueConstraint('date_reported_id', 'location_id', name="uix_owid"), + ) + + def __repr__(self): + return "%s(%s %s)" % (self.__class__.__name__, self.date_reported.__repr__(), self.location.__repr__()) id = db.Column(db.Integer, primary_key=True) - date_reported_id = db.Column(db.Integer, db.ForeignKey('owid_date_reported.id'), nullable=False) + date_reported_id = db.Column(db.Integer, db.ForeignKey('owid_date_reported.id'), nullable=False, index=True) date_reported = db.relationship( 'OwidDateReported', lazy='joined', cascade='save-update', order_by='desc(OwidDateReported.datum)') - location_id = db.Column(db.Integer, db.ForeignKey('owid_country.id'), nullable=False) + location_id = db.Column(db.Integer, db.ForeignKey('owid_country.id'), nullable=False, index=True) location = db.relationship( 'OwidCountry', lazy='joined', cascade='save-update', order_by='asc(OwidCountry.location)') - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - total_cases = db.Column(db.String(255), nullable=False) - new_cases = db.Column(db.String(255), nullable=False) - new_cases_smoothed = db.Column(db.String(255), nullable=False) - total_deaths = db.Column(db.String(255), nullable=False) - new_deaths = db.Column(db.String(255), nullable=False) - new_deaths_smoothed = db.Column(db.String(255), nullable=False) - total_cases_per_million = db.Column(db.String(255), nullable=False) - new_cases_per_million = db.Column(db.String(255), nullable=False) - new_cases_smoothed_per_million = db.Column(db.String(255), nullable=False) - total_deaths_per_million = db.Column(db.String(255), nullable=False) - new_deaths_per_million = db.Column(db.String(255), nullable=False) - new_deaths_smoothed_per_million = db.Column(db.String(255), nullable=False) - reproduction_rate = db.Column(db.String(255), nullable=False) - icu_patients = db.Column(db.String(255), nullable=False) - icu_patients_per_million = db.Column(db.String(255), nullable=False) - hosp_patients = db.Column(db.String(255), nullable=False) - hosp_patients_per_million = db.Column(db.String(255), nullable=False) - weekly_icu_admissions = db.Column(db.String(255), nullable=False) - weekly_icu_admissions_per_million = db.Column(db.String(255), nullable=False) - weekly_hosp_admissions = db.Column(db.String(255), nullable=False) - weekly_hosp_admissions_per_million = db.Column(db.String(255), nullable=False) - new_tests = db.Column(db.String(255), nullable=False) - total_tests = db.Column(db.String(255), nullable=False) - total_tests_per_thousand = db.Column(db.String(255), nullable=False) - new_tests_per_thousand = db.Column(db.String(255), nullable=False) - new_tests_smoothed = db.Column(db.String(255), nullable=False) - new_tests_smoothed_per_thousand = db.Column(db.String(255), nullable=False) - positive_rate = db.Column(db.String(255), nullable=False) - tests_per_case = db.Column(db.String(255), nullable=False) - tests_units = db.Column(db.String(255), nullable=False) - total_vaccinations = db.Column(db.String(255), nullable=False) - people_vaccinated = db.Column(db.String(255), nullable=False) - people_fully_vaccinated = db.Column(db.String(255), nullable=False) - new_vaccinations = db.Column(db.String(255), nullable=False) - new_vaccinations_smoothed = db.Column(db.String(255), nullable=False) - total_vaccinations_per_hundred = db.Column(db.String(255), nullable=False) - people_vaccinated_per_hundred = db.Column(db.String(255), nullable=False) - people_fully_vaccinated_per_hundred = db.Column(db.String(255), nullable=False) - new_vaccinations_smoothed_per_million = db.Column(db.String(255), nullable=False) - stringency_index = db.Column(db.String(255), nullable=False) + total_cases = db.Column(db.String(255), nullable=False, index=True) + new_cases = db.Column(db.String(255), nullable=False, index=True) + new_cases_smoothed = db.Column(db.String(255), nullable=False, index=True) + total_deaths = db.Column(db.String(255), nullable=False, index=True) + new_deaths = db.Column(db.String(255), nullable=False, index=True) + new_deaths_smoothed = db.Column(db.String(255), nullable=False, index=True) + total_cases_per_million = db.Column(db.String(255), nullable=False, index=True) + new_cases_per_million = db.Column(db.String(255), nullable=False, index=True) + new_cases_smoothed_per_million = db.Column(db.String(255), nullable=False, index=True) + total_deaths_per_million = db.Column(db.String(255), nullable=False, index=True) + new_deaths_per_million = db.Column(db.String(255), nullable=False, index=True) + new_deaths_smoothed_per_million = db.Column(db.String(255), nullable=False, index=True) + reproduction_rate = db.Column(db.String(255), nullable=False, index=True) + icu_patients = db.Column(db.String(255), nullable=False, index=True) + icu_patients_per_million = db.Column(db.String(255), nullable=False, index=True) + hosp_patients = db.Column(db.String(255), nullable=False, index=True) + hosp_patients_per_million = db.Column(db.String(255), nullable=False, index=True) + weekly_icu_admissions = db.Column(db.String(255), nullable=False, index=True) + weekly_icu_admissions_per_million = db.Column(db.String(255), nullable=False, index=True) + weekly_hosp_admissions = db.Column(db.String(255), nullable=False, index=True) + weekly_hosp_admissions_per_million = db.Column(db.String(255), nullable=False, index=True) + new_tests = db.Column(db.String(255), nullable=False, index=True) + total_tests = db.Column(db.String(255), nullable=False, index=True) + total_tests_per_thousand = db.Column(db.String(255), nullable=False, index=True) + new_tests_per_thousand = db.Column(db.String(255), nullable=False, index=True) + new_tests_smoothed = db.Column(db.String(255), nullable=False, index=True) + new_tests_smoothed_per_thousand = db.Column(db.String(255), nullable=False, index=True) + positive_rate = db.Column(db.String(255), nullable=False, index=True) + tests_per_case = db.Column(db.String(255), nullable=False, index=True) + tests_units = db.Column(db.String(255), nullable=False, index=True) + total_vaccinations = db.Column(db.String(255), nullable=False, index=True) + people_vaccinated = db.Column(db.String(255), nullable=False, index=True) + people_fully_vaccinated = db.Column(db.String(255), nullable=False, index=True) + new_vaccinations = db.Column(db.String(255), nullable=False, index=True) + new_vaccinations_smoothed = db.Column(db.String(255), nullable=False, index=True) + total_vaccinations_per_hundred = db.Column(db.String(255), nullable=False, index=True) + people_vaccinated_per_hundred = db.Column(db.String(255), nullable=False, index=True) + people_fully_vaccinated_per_hundred = db.Column(db.String(255), nullable=False, index=True) + new_vaccinations_smoothed_per_million = db.Column(db.String(255), nullable=False, index=True) + stringency_index = db.Column(db.String(255), nullable=False, index=True) @classmethod - def delete_by_location(cls, location: OwidCountry): - db.session.query(cls).filter( + def __query_by_location(cls, location: OwidCountry): + return db.session.query(cls).filter( cls.location_id == location.id ).populate_existing().options( - joinedload(cls.country), - joinedload(cls.date_reported), - ).delete() - db.session.commit() - return None + joinedload(cls.location).joinedload(OwidCountry.location_group), + joinedload(cls.date_reported) + ) @classmethod - def find_by_location(cls, location: OwidCountry): + def __query_by_date_reported(cls, date_reported: OwidDateReported): return db.session.query(cls).filter( - cls.location_id == location.id + cls.date_reported_id == date_reported.id ).populate_existing().options( - joinedload(cls.country), - joinedload(cls.date_reported), - ).all() + joinedload(cls.location).joinedload(OwidCountry.location_group), + joinedload(cls.date_reported) + ) + + @classmethod + @cache.memoize(50) + def find_by_location(cls, location: OwidCountry): + return cls.__query_by_location(location)\ + .order_by(cls.date_reported.datum.desc())\ + .all() @classmethod + @cache.memoize(50) def get_by_location(cls, location: OwidCountry, page: int): - return db.session.query(cls).filter( - cls.location_id == location.id - ).populate_existing().options( - joinedload(cls.location), - joinedload(cls.date_reported), - ).order_by( - cls.date_reported.desc() - ).paginate(page, per_page=ITEMS_PER_PAGE) + return cls.__query_by_location(location) \ + .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) + def delete_by_location(cls, location: OwidCountry): + cls.__query_by_location(location).delete() + db.session.commit() + return None + + @classmethod + @cache.memoize(50) def find_by_date_reported(cls, date_reported: OwidDateReported): - return db.session.query(cls).filter( - cls.date_reported_id == date_reported.id - ).populate_existing().options( - joinedload(cls.date_reported), - joinedload(cls.country), - ).order_by( + return cls.__query_by_date_reported(date_reported).order_by( cls.new_deaths_per_million.desc(), cls.new_cases_per_million.desc(), cls.new_deaths.desc(), @@ -230,13 +256,9 @@ class OwidData(BlueprintFactTable): ).all() @classmethod + @cache.memoize(50) def get_by_date_reported(cls, date_reported: OwidDateReported, page: int): - return db.session.query(cls).filter( - cls.date_reported_id == date_reported.id - ).populate_existing().options( - joinedload(cls.date_reported), - joinedload(cls.country), - ).order_by( + return cls.__query_by_date_reported(date_reported).order_by( cls.new_deaths_per_million.desc(), cls.new_cases_per_million.desc(), cls.new_deaths.desc(), @@ -244,28 +266,49 @@ class OwidData(BlueprintFactTable): ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_by_date_reported_order_by_deaths_new(cls, date_reported: OwidDateReported, page: int): - # TODO - pass + return cls.__query_by_date_reported(date_reported).order_by( + cls.new_deaths.desc(), + cls.new_deaths_per_million.desc(), + cls.new_cases.desc(), + cls.new_cases_per_million.desc(), + ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_by_date_reported_order_by_deaths_cumulative(cls, date_reported: OwidDateReported, page: int): - # TODO - pass + return cls.__query_by_date_reported(date_reported).order_by( + cls.new_deaths_per_million.desc(), + cls.new_deaths.desc(), + cls.new_cases_per_million.desc(), + cls.new_cases.desc(), + ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_by_date_reported_order_by_cases_new(cls, date_reported: OwidDateReported, page: int): - # TODO - pass + return cls.__query_by_date_reported(date_reported).order_by( + cls.new_cases.desc(), + cls.new_cases_per_million.desc(), + cls.new_deaths.desc(), + cls.new_deaths_per_million.desc(), + ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_by_date_reported_order_by_cases_cumulative(cls, date_reported: OwidDateReported, page: int): - # TODO - pass + return cls.__query_by_date_reported(date_reported).order_by( + cls.new_cases_per_million.desc(), + cls.new_cases.desc(), + cls.new_deaths_per_million.desc(), + cls.new_deaths.desc(), + ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def delete_data_for_one_day(cls, date_reported: OwidDateReported): - for data in cls.get_data_for_one_day(date_reported): + for data in cls.find_by_date_reported(date_reported): db.session.delete(data) db.session.delete(date_reported) db.session.commit() diff --git a/src/flask_covid19/blueprints/data_owid/owid_model_import.py b/src/flask_covid19/blueprints/data_owid/owid_model_import.py index f792fd1c0d97a3caf6eec549eec9241a6dc1a14e..8f629551d57f6986d69fcf2b053de2d89b4fe76e 100644 --- a/src/flask_covid19/blueprints/data_owid/owid_model_import.py +++ b/src/flask_covid19/blueprints/data_owid/owid_model_import.py @@ -8,74 +8,77 @@ class OwidImport(AllImport): __tablename__ = 'owid_import' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s)" % (self.__class__.__name__, self.id) + def __str__(self): return self.datum.isoformat() + " " + self.iso_code + " " + self.location + " " + str(self.continent) id = db.Column(db.Integer, primary_key=True) - date_reported_import_str = db.Column(db.String(255), nullable=False) - datum = db.Column(db.Date, nullable=False) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + date_reported_import_str = db.Column(db.String(255), nullable=False, index=True) + datum = db.Column(db.Date, nullable=False, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - iso_code = db.Column(db.String(255), nullable=False) - continent = db.Column(db.String(255), nullable=False) - location = db.Column(db.String(255), nullable=False) - date = db.Column(db.String(255), nullable=False) - total_cases = db.Column(db.String(255), nullable=False) - new_cases = db.Column(db.String(255), nullable=False) - new_cases_smoothed = db.Column(db.String(255), nullable=False) - total_deaths = db.Column(db.String(255), nullable=False) - new_deaths = db.Column(db.String(255), nullable=False) - new_deaths_smoothed = db.Column(db.String(255), nullable=False) - total_cases_per_million = db.Column(db.String(255), nullable=False) - new_cases_per_million = db.Column(db.String(255), nullable=False) - new_cases_smoothed_per_million = db.Column(db.String(255), nullable=False) - total_deaths_per_million = db.Column(db.String(255), nullable=False) - new_deaths_per_million = db.Column(db.String(255), nullable=False) - new_deaths_smoothed_per_million = db.Column(db.String(255), nullable=False) - reproduction_rate = db.Column(db.String(255), nullable=False) - icu_patients = db.Column(db.String(255), nullable=False) - icu_patients_per_million = db.Column(db.String(255), nullable=False) - hosp_patients = db.Column(db.String(255), nullable=False) - hosp_patients_per_million = db.Column(db.String(255), nullable=False) - weekly_icu_admissions = db.Column(db.String(255), nullable=False) - weekly_icu_admissions_per_million = db.Column(db.String(255), nullable=False) - weekly_hosp_admissions = db.Column(db.String(255), nullable=False) - weekly_hosp_admissions_per_million = db.Column(db.String(255), nullable=False) - new_tests = db.Column(db.String(255), nullable=False) - total_tests = db.Column(db.String(255), nullable=False) - total_tests_per_thousand = db.Column(db.String(255), nullable=False) - new_tests_per_thousand = db.Column(db.String(255), nullable=False) - new_tests_smoothed = db.Column(db.String(255), nullable=False) - new_tests_smoothed_per_thousand = db.Column(db.String(255), nullable=False) - positive_rate = db.Column(db.String(255), nullable=False) - tests_per_case = db.Column(db.String(255), nullable=False) - tests_units = db.Column(db.String(255), nullable=False) - total_vaccinations = db.Column(db.String(255), nullable=False) - people_vaccinated = db.Column(db.String(255), nullable=False) - people_fully_vaccinated = db.Column(db.String(255), nullable=False) - new_vaccinations = db.Column(db.String(255), nullable=False) - new_vaccinations_smoothed = db.Column(db.String(255), nullable=False) - total_vaccinations_per_hundred = db.Column(db.String(255), nullable=False) - people_vaccinated_per_hundred = db.Column(db.String(255), nullable=False) - people_fully_vaccinated_per_hundred = db.Column(db.String(255), nullable=False) - new_vaccinations_smoothed_per_million = db.Column(db.String(255), nullable=False) - stringency_index = db.Column(db.String(255), nullable=False) - population = db.Column(db.String(255), nullable=False) - population_density = db.Column(db.String(255), nullable=False) - median_age = db.Column(db.String(255), nullable=False) - aged_65_older = db.Column(db.String(255), nullable=False) - aged_70_older = db.Column(db.String(255), nullable=False) - gdp_per_capita = db.Column(db.String(255), nullable=False) - extreme_poverty = db.Column(db.String(255), nullable=False) - cardiovasc_death_rate = db.Column(db.String(255), nullable=False) - diabetes_prevalence = db.Column(db.String(255), nullable=False) - female_smokers = db.Column(db.String(255), nullable=False) - male_smokers = db.Column(db.String(255), nullable=False) - handwashing_facilities = db.Column(db.String(255), nullable=False) - hospital_beds_per_thousand = db.Column(db.String(255), nullable=False) - life_expectancy = db.Column(db.String(255), nullable=False) - human_development_index = db.Column(db.String(255), nullable=False) + iso_code = db.Column(db.String(255), nullable=False, index=True) + continent = db.Column(db.String(255), nullable=False, index=True) + location = db.Column(db.String(255), nullable=False, index=True) + date = db.Column(db.String(255), nullable=False, index=True) + total_cases = db.Column(db.String(255), nullable=False, index=True) + new_cases = db.Column(db.String(255), nullable=False, index=True) + new_cases_smoothed = db.Column(db.String(255), nullable=False, index=True) + total_deaths = db.Column(db.String(255), nullable=False, index=True) + new_deaths = db.Column(db.String(255), nullable=False, index=True) + new_deaths_smoothed = db.Column(db.String(255), nullable=False, index=True) + total_cases_per_million = db.Column(db.String(255), nullable=False, index=True) + new_cases_per_million = db.Column(db.String(255), nullable=False, index=True) + new_cases_smoothed_per_million = db.Column(db.String(255), nullable=False, index=True) + total_deaths_per_million = db.Column(db.String(255), nullable=False, index=True) + new_deaths_per_million = db.Column(db.String(255), nullable=False, index=True) + new_deaths_smoothed_per_million = db.Column(db.String(255), nullable=False, index=True) + reproduction_rate = db.Column(db.String(255), nullable=False, index=True) + icu_patients = db.Column(db.String(255), nullable=False, index=True) + icu_patients_per_million = db.Column(db.String(255), nullable=False, index=True) + hosp_patients = db.Column(db.String(255), nullable=False, index=True) + hosp_patients_per_million = db.Column(db.String(255), nullable=False, index=True) + weekly_icu_admissions = db.Column(db.String(255), nullable=False, index=True) + weekly_icu_admissions_per_million = db.Column(db.String(255), nullable=False, index=True) + weekly_hosp_admissions = db.Column(db.String(255), nullable=False, index=True) + weekly_hosp_admissions_per_million = db.Column(db.String(255), nullable=False, index=True) + new_tests = db.Column(db.String(255), nullable=False, index=True) + total_tests = db.Column(db.String(255), nullable=False, index=True) + total_tests_per_thousand = db.Column(db.String(255), nullable=False, index=True) + new_tests_per_thousand = db.Column(db.String(255), nullable=False, index=True) + new_tests_smoothed = db.Column(db.String(255), nullable=False, index=True) + new_tests_smoothed_per_thousand = db.Column(db.String(255), nullable=False, index=True) + positive_rate = db.Column(db.String(255), nullable=False, index=True) + tests_per_case = db.Column(db.String(255), nullable=False, index=True) + tests_units = db.Column(db.String(255), nullable=False, index=True) + total_vaccinations = db.Column(db.String(255), nullable=False, index=True) + people_vaccinated = db.Column(db.String(255), nullable=False, index=True) + people_fully_vaccinated = db.Column(db.String(255), nullable=False, index=True) + new_vaccinations = db.Column(db.String(255), nullable=False, index=True) + new_vaccinations_smoothed = db.Column(db.String(255), nullable=False, index=True) + total_vaccinations_per_hundred = db.Column(db.String(255), nullable=False, index=True) + people_vaccinated_per_hundred = db.Column(db.String(255), nullable=False, index=True) + people_fully_vaccinated_per_hundred = db.Column(db.String(255), nullable=False, index=True) + new_vaccinations_smoothed_per_million = db.Column(db.String(255), nullable=False, index=True) + stringency_index = db.Column(db.String(255), nullable=False, index=True) + population = db.Column(db.String(255), nullable=False, index=True) + population_density = db.Column(db.String(255), nullable=False, index=True) + median_age = db.Column(db.String(255), nullable=False, index=True) + aged_65_older = db.Column(db.String(255), nullable=False, index=True) + aged_70_older = db.Column(db.String(255), nullable=False, index=True) + gdp_per_capita = db.Column(db.String(255), nullable=False, index=True) + extreme_poverty = db.Column(db.String(255), nullable=False, index=True) + cardiovasc_death_rate = db.Column(db.String(255), nullable=False, index=True) + diabetes_prevalence = db.Column(db.String(255), nullable=False, index=True) + female_smokers = db.Column(db.String(255), nullable=False, index=True) + male_smokers = db.Column(db.String(255), nullable=False, index=True) + handwashing_facilities = db.Column(db.String(255), nullable=False, index=True) + hospital_beds_per_thousand = db.Column(db.String(255), nullable=False, index=True) + life_expectancy = db.Column(db.String(255), nullable=False, index=True) + human_development_index = db.Column(db.String(255), nullable=False, index=True) @classmethod def get_dates(cls): @@ -263,82 +266,85 @@ class OwidFlat(AllFlat): __tablename__ = 'owid_import_flat' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s)" % (self.__class__.__name__, self.id) + def __str__(self): return self.datum.isoformat() + " " + self.location_code + " " + self.location + " " + str(self.location_group) id = db.Column(db.Integer, primary_key=True) # - date_reported_import_str = db.Column(db.String(255), nullable=False) - datum = db.Column(db.Date, nullable=False) + date_reported_import_str = db.Column(db.String(255), nullable=False, index=True) + datum = db.Column(db.Date, nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) - year_day_of_year = db.Column(db.String(255), nullable=False) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) + year_day_of_year = db.Column(db.String(255), nullable=False, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) - week_of_year = db.Column(db.Integer, nullable=False) - day_of_year = db.Column(db.Integer, nullable=False) - location = db.Column(db.String(255), nullable=False) - location_group = db.Column(db.String(255), nullable=False) - location_code = db.Column(db.String(255), nullable=False) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) + week_of_year = db.Column(db.Integer, nullable=False, index=True) + day_of_year = db.Column(db.Integer, nullable=False, index=True) + location = db.Column(db.String(255), nullable=False, index=True) + location_group = db.Column(db.String(255), nullable=False, index=True) + location_code = db.Column(db.String(255), nullable=False, index=True) # - total_cases = db.Column(db.String(255), nullable=False) - new_cases = db.Column(db.String(255), nullable=False) - new_cases_smoothed = db.Column(db.String(255), nullable=False) - total_deaths = db.Column(db.String(255), nullable=False) - new_deaths = db.Column(db.String(255), nullable=False) - new_deaths_smoothed = db.Column(db.String(255), nullable=False) - total_cases_per_million = db.Column(db.String(255), nullable=False) - new_cases_per_million = db.Column(db.String(255), nullable=False) - new_cases_smoothed_per_million = db.Column(db.String(255), nullable=False) - total_deaths_per_million = db.Column(db.String(255), nullable=False) - new_deaths_per_million = db.Column(db.String(255), nullable=False) - new_deaths_smoothed_per_million = db.Column(db.String(255), nullable=False) - reproduction_rate = db.Column(db.String(255), nullable=False) - icu_patients = db.Column(db.String(255), nullable=False) - icu_patients_per_million = db.Column(db.String(255), nullable=False) - hosp_patients = db.Column(db.String(255), nullable=False) - hosp_patients_per_million = db.Column(db.String(255), nullable=False) - weekly_icu_admissions = db.Column(db.String(255), nullable=False) - weekly_icu_admissions_per_million = db.Column(db.String(255), nullable=False) - weekly_hosp_admissions = db.Column(db.String(255), nullable=False) - weekly_hosp_admissions_per_million = db.Column(db.String(255), nullable=False) - new_tests = db.Column(db.String(255), nullable=False) - total_tests = db.Column(db.String(255), nullable=False) - total_tests_per_thousand = db.Column(db.String(255), nullable=False) - new_tests_per_thousand = db.Column(db.String(255), nullable=False) - new_tests_smoothed = db.Column(db.String(255), nullable=False) - new_tests_smoothed_per_thousand = db.Column(db.String(255), nullable=False) - positive_rate = db.Column(db.String(255), nullable=False) - tests_per_case = db.Column(db.String(255), nullable=False) - tests_units = db.Column(db.String(255), nullable=False) - total_vaccinations = db.Column(db.String(255), nullable=False) - people_vaccinated = db.Column(db.String(255), nullable=False) - people_fully_vaccinated = db.Column(db.String(255), nullable=False) - new_vaccinations = db.Column(db.String(255), nullable=False) - new_vaccinations_smoothed = db.Column(db.String(255), nullable=False) - total_vaccinations_per_hundred = db.Column(db.String(255), nullable=False) - people_vaccinated_per_hundred = db.Column(db.String(255), nullable=False) - people_fully_vaccinated_per_hundred = db.Column(db.String(255), nullable=False) - new_vaccinations_smoothed_per_million = db.Column(db.String(255), nullable=False) - stringency_index = db.Column(db.String(255), nullable=False) - population = db.Column(db.String(255), nullable=False) - population_density = db.Column(db.String(255), nullable=False) - median_age = db.Column(db.String(255), nullable=False) - aged_65_older = db.Column(db.String(255), nullable=False) - aged_70_older = db.Column(db.String(255), nullable=False) - gdp_per_capita = db.Column(db.String(255), nullable=False) - extreme_poverty = db.Column(db.String(255), nullable=False) - cardiovasc_death_rate = db.Column(db.String(255), nullable=False) - diabetes_prevalence = db.Column(db.String(255), nullable=False) - female_smokers = db.Column(db.String(255), nullable=False) - male_smokers = db.Column(db.String(255), nullable=False) - handwashing_facilities = db.Column(db.String(255), nullable=False) - hospital_beds_per_thousand = db.Column(db.String(255), nullable=False) - life_expectancy = db.Column(db.String(255), nullable=False) - human_development_index = db.Column(db.String(255), nullable=False) + total_cases = db.Column(db.String(255), nullable=False, index=True) + new_cases = db.Column(db.String(255), nullable=False, index=True) + new_cases_smoothed = db.Column(db.String(255), nullable=False, index=True) + total_deaths = db.Column(db.String(255), nullable=False, index=True) + new_deaths = db.Column(db.String(255), nullable=False, index=True) + new_deaths_smoothed = db.Column(db.String(255), nullable=False, index=True) + total_cases_per_million = db.Column(db.String(255), nullable=False, index=True) + new_cases_per_million = db.Column(db.String(255), nullable=False, index=True) + new_cases_smoothed_per_million = db.Column(db.String(255), nullable=False, index=True) + total_deaths_per_million = db.Column(db.String(255), nullable=False, index=True) + new_deaths_per_million = db.Column(db.String(255), nullable=False, index=True) + new_deaths_smoothed_per_million = db.Column(db.String(255), nullable=False, index=True) + reproduction_rate = db.Column(db.String(255), nullable=False, index=True) + icu_patients = db.Column(db.String(255), nullable=False, index=True) + icu_patients_per_million = db.Column(db.String(255), nullable=False, index=True) + hosp_patients = db.Column(db.String(255), nullable=False, index=True) + hosp_patients_per_million = db.Column(db.String(255), nullable=False, index=True) + weekly_icu_admissions = db.Column(db.String(255), nullable=False, index=True) + weekly_icu_admissions_per_million = db.Column(db.String(255), nullable=False, index=True) + weekly_hosp_admissions = db.Column(db.String(255), nullable=False, index=True) + weekly_hosp_admissions_per_million = db.Column(db.String(255), nullable=False, index=True) + new_tests = db.Column(db.String(255), nullable=False, index=True) + total_tests = db.Column(db.String(255), nullable=False, index=True) + total_tests_per_thousand = db.Column(db.String(255), nullable=False, index=True) + new_tests_per_thousand = db.Column(db.String(255), nullable=False, index=True) + new_tests_smoothed = db.Column(db.String(255), nullable=False, index=True) + new_tests_smoothed_per_thousand = db.Column(db.String(255), nullable=False, index=True) + positive_rate = db.Column(db.String(255), nullable=False, index=True) + tests_per_case = db.Column(db.String(255), nullable=False, index=True) + tests_units = db.Column(db.String(255), nullable=False, index=True) + total_vaccinations = db.Column(db.String(255), nullable=False, index=True) + people_vaccinated = db.Column(db.String(255), nullable=False, index=True) + people_fully_vaccinated = db.Column(db.String(255), nullable=False, index=True) + new_vaccinations = db.Column(db.String(255), nullable=False, index=True) + new_vaccinations_smoothed = db.Column(db.String(255), nullable=False, index=True) + total_vaccinations_per_hundred = db.Column(db.String(255), nullable=False, index=True) + people_vaccinated_per_hundred = db.Column(db.String(255), nullable=False, index=True) + people_fully_vaccinated_per_hundred = db.Column(db.String(255), nullable=False, index=True) + new_vaccinations_smoothed_per_million = db.Column(db.String(255), nullable=False, index=True) + stringency_index = db.Column(db.String(255), nullable=False, index=True) + population = db.Column(db.String(255), nullable=False, index=True) + population_density = db.Column(db.String(255), nullable=False, index=True) + median_age = db.Column(db.String(255), nullable=False, index=True) + aged_65_older = db.Column(db.String(255), nullable=False, index=True) + aged_70_older = db.Column(db.String(255), nullable=False, index=True) + gdp_per_capita = db.Column(db.String(255), nullable=False, index=True) + extreme_poverty = db.Column(db.String(255), nullable=False, index=True) + cardiovasc_death_rate = db.Column(db.String(255), nullable=False, index=True) + diabetes_prevalence = db.Column(db.String(255), nullable=False, index=True) + female_smokers = db.Column(db.String(255), nullable=False, index=True) + male_smokers = db.Column(db.String(255), nullable=False, index=True) + handwashing_facilities = db.Column(db.String(255), nullable=False, index=True) + hospital_beds_per_thousand = db.Column(db.String(255), nullable=False, index=True) + life_expectancy = db.Column(db.String(255), nullable=False, index=True) + human_development_index = db.Column(db.String(255), nullable=False, index=True) diff --git a/src/flask_covid19/blueprints/data_owid/owid_service_import.py b/src/flask_covid19/blueprints/data_owid/owid_service_import.py index f96afab5146a4a9619cfaf19bdcc7f682719e353..dbf37c9c673253e589ce007bf1c25b0b06136cf7 100644 --- a/src/flask_covid19/blueprints/data_owid/owid_service_import.py +++ b/src/flask_covid19/blueprints/data_owid/owid_service_import.py @@ -1,5 +1,5 @@ import csv -import psycopg2 +# import psycopg2 from database import db, app from flask_covid19.blueprints.app_all.all_config import BlueprintConfig diff --git a/src/flask_covid19/blueprints/data_owid/owid_views.py b/src/flask_covid19/blueprints/data_owid/owid_views.py index a8735e0c7f9c81899ddccc7a721675f1527742e8..8e93d611118fdd4fc6181dd84704f7bfdbb8ca25 100644 --- a/src/flask_covid19/blueprints/data_owid/owid_views.py +++ b/src/flask_covid19/blueprints/data_owid/owid_views.py @@ -99,7 +99,7 @@ def url_owid_date_reported_one(date_reported_id: int, page: int = 1): "data of all reported countries for OWID date reported " + str(date_reported) + " " ) try: - page_data = OwidData.get_data_for_day(date_reported, page) + page_data = OwidData.get_by_date_reported(date_reported, page) except OperationalError: flash("No data in the database.") page_data = None @@ -120,7 +120,7 @@ def url_owid_date_reported_one_cases_new(date_reported_id: int, page: int = 1): "data of all reported countries for OWID date reported " + str(date_reported) + " " ) try: - page_data = OwidData.get_data_for_day_order_by_cases_new(date_reported, page) + page_data = OwidData.find_by_date_reported_order_by_cases_new(date_reported, page) except OperationalError: flash("No data in the database.") page_data = None @@ -141,7 +141,7 @@ def url_owid_date_reported_one_cases_cumulative(date_reported_id: int, page: int "data of all reported countries for OWID date reported " + str(date_reported) + " " ) try: - page_data = OwidData.get_data_for_day_order_by_cases_cumulative(date_reported, page) + page_data = OwidData.find_by_date_reported_order_by_cases_cumulative(date_reported, page) except OperationalError: flash("No data in the database.") page_data = None @@ -162,7 +162,7 @@ def url_owid_date_reported_one_deaths_new(date_reported_id: int, page: int = 1): "data of all reported countries for OWID date reported " + str(date_reported) + " " ) try: - page_data = OwidData.get_data_for_day_order_by_deaths_new(date_reported, page) + page_data = OwidData.find_by_date_reported_order_by_deaths_new(date_reported, page) except OperationalError: flash("No data in the database.") page_data = None @@ -183,7 +183,7 @@ def url_owid_date_reported_one_deaths_cumulative(date_reported_id: int, page: in "data of all reported countries for OWID date reported " + str(date_reported) + " " ) try: - page_data = OwidData.get_data_for_day_order_by_deaths_cumulative(date_reported, page) + page_data = OwidData.find_by_date_reported_order_by_deaths_cumulative(date_reported, page) except OperationalError: flash("No data in the database.") page_data = None @@ -217,9 +217,9 @@ def url_owid_continent_all(page: int = 1): def url_owid_continent_one(continent_id: int, page: int = 1): owid_continent_one = OwidContinent.get_by_id(continent_id) page_info = WebPageContent( - "continent: " + owid_continent_one.region, + "continent: " + owid_continent_one.location_group, 'OWID', - "countries for OWID continent " + owid_continent_one.region + " " + "countries for OWID continent " + owid_continent_one.location_group + " " ) try: page_data = OwidCountry.get_countries_for_continent(owid_continent_one, page) @@ -258,10 +258,10 @@ def url_owid_country_one(country_id: int, page: int = 1): page_info = WebPageContent( "country: " + owid_country_one.location, 'OWID', - "on continent " + owid_country_one.continent.region + " " + "on continent " + owid_country_one.location_group.location_group + " " ) try: - page_data = OwidData.get_data_for_country(owid_country_one, page) + page_data = OwidData.get_by_location(owid_country_one, page) except OperationalError: flash("No data in the database.") page_data = None diff --git a/src/flask_covid19/blueprints/data_owid/templates/owid/continent/all/owid_continent_all_table.html b/src/flask_covid19/blueprints/data_owid/templates/owid/continent/all/owid_continent_all_table.html index 801f92995e5c9c79a78da673e5cd1692eadf5bd0..79b3cafeb193ff7da7074849b54b6ae1c999f64d 100644 --- a/src/flask_covid19/blueprints/data_owid/templates/owid/continent/all/owid_continent_all_table.html +++ b/src/flask_covid19/blueprints/data_owid/templates/owid/continent/all/owid_continent_all_table.html @@ -1,6 +1,6 @@ <div class="table-responsive"> <table class="table table-hover table-striped table-dark"> - <thead> + <thead class="table-secondary"> <tr> <th scope="col">continent</th> </tr> @@ -10,13 +10,13 @@ <tr> <td> <a href="{{ url_for('owid.url_owid_continent_one', continent_id=data_item.id) }}"> - {{ data_item.region }} + {{ data_item.location_group }} </a> </td> </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> <tr> <th scope="col">continent</th> </tr> diff --git a/src/flask_covid19/blueprints/data_owid/templates/owid/country/all/owid_country_all_table.html b/src/flask_covid19/blueprints/data_owid/templates/owid/country/all/owid_country_all_table.html index a9696453cd4a5ba00d0d74e36c538868a0b22594..c6c85bfd07f38ae38a9d904245ecbc76d7e62425 100644 --- a/src/flask_covid19/blueprints/data_owid/templates/owid/country/all/owid_country_all_table.html +++ b/src/flask_covid19/blueprints/data_owid/templates/owid/country/all/owid_country_all_table.html @@ -8,12 +8,12 @@ <tr> <td> <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid_country.id) }}"> - {{ owid_country.iso_code }} + {{ owid_country.location_code }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_continent_one', continent_id=owid_country.continent.id) }}"> - {{ owid_country.continent.region }} + <a href="{{ url_for( 'owid.url_owid_continent_one', continent_id=owid_country.location_group.id) }}"> + {{ owid_country.location_group.location_group }} </a> </td> <td> @@ -39,7 +39,7 @@ </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> {% include 'owid/country/all/owid_country_all_table_head.html' %} </tfoot> </table> diff --git a/src/flask_covid19/blueprints/data_owid/templates/owid/flat/owid_flat_table.html b/src/flask_covid19/blueprints/data_owid/templates/owid/flat/owid_flat_table.html index 5c6b5159609adb5d7f66338442e41f96c0d07f72..bf7eed1b8de24f751abcf1d96693a9a98c912e01 100644 --- a/src/flask_covid19/blueprints/data_owid/templates/owid/flat/owid_flat_table.html +++ b/src/flask_covid19/blueprints/data_owid/templates/owid/flat/owid_flat_table.html @@ -1,6 +1,6 @@ <div class="table-responsive"> <table class="table table-hover table-striped table-dark"> - <thead> + <thead class="table-secondary"> {% include 'owid/flat/owid_flat_table_header.html' %} </thead> <tbody> @@ -68,7 +68,7 @@ </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> {% include 'owid/flat/owid_flat_table_header.html' %} </tfoot> </table> diff --git a/src/flask_covid19/blueprints/data_owid/templates/owid/imported/owid_imported_table.html b/src/flask_covid19/blueprints/data_owid/templates/owid/imported/owid_imported_table.html index ac8c1c073898d473f96aada57c453d3019af0194..d3be58ddb767c2160f542d1399b751645c8220fe 100644 --- a/src/flask_covid19/blueprints/data_owid/templates/owid/imported/owid_imported_table.html +++ b/src/flask_covid19/blueprints/data_owid/templates/owid/imported/owid_imported_table.html @@ -1,6 +1,6 @@ <div class="table-responsive"> <table class="table table-hover table-striped table-dark"> - <thead> + <thead class="table-secondary"> {% include 'owid/imported/owid_imported_table_head.html' %} </thead> <tbody> @@ -68,7 +68,7 @@ </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> {% include 'owid/imported/owid_imported_table_head.html' %} </tfoot> </table> diff --git a/src/flask_covid19/blueprints/data_owid/templates/owid/owid_data/owid_data_table.html b/src/flask_covid19/blueprints/data_owid/templates/owid/owid_data/owid_data_table.html index 243d9463eb6b6310370b709ceb5697c2f1b7ffb7..e03f2b0494d0dbee069b8759a36c87e788bac4be 100644 --- a/src/flask_covid19/blueprints/data_owid/templates/owid/owid_data/owid_data_table.html +++ b/src/flask_covid19/blueprints/data_owid/templates/owid/owid_data/owid_data_table.html @@ -7,18 +7,18 @@ {% for owid in page_data.items %} <tr> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.iso_code }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.location_code }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_continent_one', continent_id=owid.country.continent.id) }}"> - {{ owid.country.continent.region }} + <a href="{{ url_for( 'owid.url_owid_continent_one', continent_id=owid.location.location_group.id) }}"> + {{ owid.location.location_group.location_group }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.location }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.location }} </a> </td> <td> @@ -67,84 +67,84 @@ <td>{{ owid.new_vaccinations_smoothed_per_million }}</td> <td>{{ owid.stringency_index }}</td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.population }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.population }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.population_density }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.population_density }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.median_age }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.median_age }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.aged_65_older }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.aged_65_older }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.aged_70_older }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.aged_70_older }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.gdp_per_capita }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.gdp_per_capita }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.extreme_poverty }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.extreme_poverty }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.cardiovasc_death_rate }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.cardiovasc_death_rate }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.diabetes_prevalence }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.diabetes_prevalence }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.female_smokers }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.female_smokers }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.male_smokers }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.male_smokers }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.handwashing_facilities }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.handwashing_facilities }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.hospital_beds_per_thousand }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.hospital_beds_per_thousand }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.life_expectancy }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.life_expectancy }} </a> </td> <td> - <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.country.id) }}"> - {{ owid.country.human_development_index }} + <a href="{{ url_for( 'owid.url_owid_country_one', country_id=owid.location.id) }}"> + {{ owid.location.human_development_index }} </a> </td> </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> {% include 'owid/owid_data/owid_data_table_head.html' %} </tfoot> </table> diff --git a/src/flask_covid19/blueprints/data_rki/rki_model.py b/src/flask_covid19/blueprints/data_rki/rki_model.py index 95a7666a16bf65d436b1c97a0bd20360a0fcb6f9..a52c12396971d2cc71993e209edd7809a4b80092 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_model.py +++ b/src/flask_covid19/blueprints/data_rki/rki_model.py @@ -1,6 +1,7 @@ from sqlalchemy import and_ +from sqlalchemy.orm import joinedload -from database import db, ITEMS_PER_PAGE +from database import db, ITEMS_PER_PAGE, cache from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported, BlueprintLocationGroup from flask_covid19.blueprints.app_all.all_model import BlueprintLocation, BlueprintFactTable, BlueprintEntity @@ -17,23 +18,27 @@ class RkiMeldedatum(BlueprintDateReported): ), ) + def __repr__(self): + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) + id = db.Column(db.Integer, primary_key=True) # date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) datum = db.Column(db.Date, nullable=False, unique=True) year_day_of_year = db.Column(db.String(255), nullable=False, unique=True) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) day_of_year = db.Column(db.Integer, nullable=True) - week_of_year = db.Column(db.Integer, nullable=False) + week_of_year = db.Column(db.Integer, nullable=False, index=True) # - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) @classmethod def remove_all(cls): @@ -58,23 +63,27 @@ class RkiDatenstand(BlueprintDateReported): ), ) + def __repr__(self): + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) + id = db.Column(db.Integer, primary_key=True) # date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) datum = db.Column(db.Date, nullable=False, unique=True) year_day_of_year = db.Column(db.String(255), nullable=False, unique=True) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) day_of_year = db.Column(db.Integer, nullable=True) - week_of_year = db.Column(db.Integer, nullable=False) + week_of_year = db.Column(db.Integer, nullable=False, index=True) # - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) class RkiRefDatum(BlueprintDateReported): @@ -89,23 +98,27 @@ class RkiRefDatum(BlueprintDateReported): ), ) + def __repr__(self): + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) + id = db.Column(db.Integer, primary_key=True) # date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) datum = db.Column(db.Date, nullable=False, unique=True) year_day_of_year = db.Column(db.String(255), nullable=False, unique=True) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) day_of_year = db.Column(db.Integer, nullable=True) - week_of_year = db.Column(db.Integer, nullable=False) + week_of_year = db.Column(db.Integer, nullable=False, index=True) # - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) class RkiBundesland(BlueprintLocationGroup): @@ -115,14 +128,17 @@ class RkiBundesland(BlueprintLocationGroup): db.UniqueConstraint('id_bundesland', 'location_group', name="uix_rki_landkreis_bundesland"), ) + def __repr__(self): + return "%s(%s %s)" % (self.__class__.__name__, self.location_group, self.id_bundesland) + def __str__(self): return " " + self.location_group + " " id = db.Column(db.Integer, primary_key=True) - id_bundesland = db.Column(db.String(255), nullable=False) - location_group = db.Column(db.String(255), nullable=False) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + id_bundesland = db.Column(db.String(255), nullable=False, index=True) + location_group = db.Column(db.String(255), nullable=False, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) class RkiLandkreis(BlueprintLocation): @@ -132,23 +148,27 @@ class RkiLandkreis(BlueprintLocation): db.UniqueConstraint('location', 'id_landkreis', name="uix_rki_landkreis"), ) + def __repr__(self): + return "%s(%s %s)" % (self.__class__.__name__, self.location, self.id_landkreis) + def __str__(self): return " " + str(self.location_group) + " : " + self.location + " ( " + self.id_landkreis + " ) " id = db.Column(db.Integer, primary_key=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - location = db.Column(db.String(255), nullable=False) - location_group_id = db.Column(db.Integer, db.ForeignKey('rki_landkreis_bundesland.id'), nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) + location = db.Column(db.String(255), nullable=False, index=True) + location_group_id = db.Column(db.Integer, db.ForeignKey('rki_landkreis_bundesland.id'), nullable=False, index=True) location_group = db.relationship( 'RkiBundesland', lazy='joined', cascade='save-update', order_by='RkiBundesland.location_group') - id_landkreis = db.Column(db.String(255), nullable=False) - location_type = db.Column(db.String(255), nullable=False) + id_landkreis = db.Column(db.String(255), nullable=False, index=True) + location_type = db.Column(db.String(255), nullable=False, index=True) @classmethod + @cache.memoize(50) def get_bochum(cls): return db.session.query(cls)\ .filter(cls.location == 'SK Bochum')\ @@ -159,18 +179,21 @@ class RkiLandkreis(BlueprintLocation): return db.session.query(cls).order_by(cls.location).all() @classmethod + @cache.memoize(50) def find_by_location_group(cls, location_group: RkiBundesland): return db.session.query(cls).filter( cls.location_group == location_group ).order_by(cls.location).all() @classmethod + @cache.memoize(50) def get_by_location_group(cls, location_group: RkiBundesland, page: int): return db.session.query(cls).filter( cls.location_group == location_group ).order_by(cls.location).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_all_as_dict(cls): rki_landkreis_dict = {} for my_rki_landkreis in cls.find_all(): @@ -182,26 +205,35 @@ class RkiLandkreis(BlueprintLocation): class RkiAltersgruppe(BlueprintEntity): __tablename__ = 'rki_altersgruppe' __mapper_args__ = {'concrete': True} + __table_args__ = ( + db.UniqueConstraint('altersgruppe', name="uix_rki_altersgruppe"), + ) + + def __repr__(self): + return "%s(%s)" % (self.__class__.__name__, self.altersgruppe) def __str__(self): return " " + self.altersgruppe + " " id = db.Column(db.Integer, primary_key=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - altersgruppe = db.Column(db.String(255), nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) + altersgruppe = db.Column(db.String(255), nullable=False, unique=True) @classmethod + @cache.memoize(50) def get_all_as_page(cls, page: int): return db.session.query(cls) \ .order_by(cls.altersgruppe)\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_all(cls, page: int): return db.session.query(cls).order_by(cls.altersgruppe).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_all(cls): return db.session.query(cls).order_by(cls.altersgruppe).all() @@ -217,69 +249,119 @@ class RkiData(BlueprintFactTable): __tablename__ = 'rki' __mapper_args__ = {'concrete': True} __table_args__ = ( - db.UniqueConstraint('fid', 'geschlecht', 'date_reported_id', 'datenstand_id', 'location_id', - 'ref_datum_id', 'altersgruppe_id', name="uix_rki"), + db.UniqueConstraint( + 'fid', + name="uix_rki"), ) + def __repr__(self): + return "%s(%s %s %s %s %s %s %s)" % (self.__class__.__name__, + self.fid, self.geschlecht, self.date_reported_id, + self.datenstand_id, self.location_id, + self.ref_datum_id, self.altersgruppe_id) + id = db.Column(db.Integer, primary_key=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - date_reported_id = db.Column(db.Integer, db.ForeignKey('rki_date_reported.id'), nullable=False) + date_reported_id = db.Column(db.Integer, db.ForeignKey('rki_date_reported.id'), nullable=False, index=True) date_reported = db.relationship( 'RkiMeldedatum', lazy='joined', cascade='save-update', order_by='desc(RkiMeldedatum.datum)') - location_id = db.Column(db.Integer, db.ForeignKey('rki_landkreis.id'), nullable=False) + location_id = db.Column(db.Integer, db.ForeignKey('rki_landkreis.id'), nullable=False, index=True) location = db.relationship( 'RkiLandkreis', lazy='joined', cascade='save-update', order_by='asc(RkiLandkreis.location)') # - fid = db.Column(db.String(255), nullable=False) - # altersgruppe = db.Column(db.String(255), nullable=False) - altersgruppe_id = db.Column(db.Integer, db.ForeignKey('rki_altersgruppe.id'), nullable=False) + fid = db.Column(db.String(255), nullable=False, index=True) + # altersgruppe = db.Column(db.String(255), nullable=False, index=True) + altersgruppe_id = db.Column(db.Integer, db.ForeignKey('rki_altersgruppe.id'), nullable=False, index=True) altersgruppe = db.relationship( 'RkiAltersgruppe', lazy='joined', cascade='save-update', order_by='desc(RkiAltersgruppe.altersgruppe)') - neuer_fall = db.Column(db.String(255), nullable=False) - geschlecht = db.Column(db.String(255), nullable=False) - anzahl_fall = db.Column(db.String(255), nullable=False) - anzahl_todesfall = db.Column(db.String(255), nullable=False) - # meldedatum = db.Column(db.String(255), nullable=False) - # datenstand = db.Column(db.String(255), nullable=False) - datenstand_id = db.Column(db.Integer, db.ForeignKey('rki_date_datenstand.id'), nullable=False) + # neuer_fall = db.Column(db.String(255), nullable=False, index=True) + geschlecht = db.Column(db.String(255), nullable=False, index=True) + anzahl_fall = db.Column(db.String(255), nullable=False, index=True) + anzahl_todesfall = db.Column(db.String(255), nullable=False, index=True) + # meldedatum = db.Column(db.String(255), nullable=False, index=True) + # datenstand = db.Column(db.String(255), nullable=False, index=True) + datenstand_id = db.Column(db.Integer, db.ForeignKey('rki_date_datenstand.id'), nullable=False, index=True) datenstand = db.relationship( 'RkiDatenstand', lazy='joined', cascade='save-update', order_by='desc(RkiDatenstand.datum)') - neuer_fall = db.Column(db.String(255), nullable=False) - neuer_todesfall = db.Column(db.String(255), nullable=False) - # ref_datum = db.Column(db.String(255), nullable=False) - ref_datum_id = db.Column(db.Integer, db.ForeignKey('rki_date_ref_datum.id'), nullable=False) + neuer_fall = db.Column(db.String(255), nullable=False, index=True) + neuer_todesfall = db.Column(db.String(255), nullable=False, index=True) + # ref_datum = db.Column(db.String(255), nullable=False, index=True) + ref_datum_id = db.Column(db.Integer, db.ForeignKey('rki_date_ref_datum.id'), nullable=False, index=True) ref_datum = db.relationship( 'RkiRefDatum', lazy='joined', cascade='save-update', order_by='desc(RkiRefDatum.datum)') - neu_genesen = db.Column(db.String(255), nullable=False) - anzahl_genesen = db.Column(db.String(255), nullable=False) - ist_erkrankungsbeginn = db.Column(db.String(255), nullable=False) - altersgruppe2 = db.Column(db.String(255), nullable=False) - - @classmethod - def find_by_date_reported_and_location(cls, date_reported: RkiMeldedatum, location: RkiLandkreis): - return db.session.query(cls).filter( - and_((cls.date_reported == date_reported), (cls.location == location)) - ).one_or_none() + neu_genesen = db.Column(db.String(255), nullable=False, index=True) + anzahl_genesen = db.Column(db.String(255), nullable=False, index=True) + ist_erkrankungsbeginn = db.Column(db.String(255), nullable=False, index=True) + altersgruppe2 = db.Column(db.String(255), nullable=False, index=True) @classmethod def delete_all(cls): db.session.query(cls).delete() db.session.commit() return None + + @classmethod + def __query_by_location(cls, location: RkiLandkreis): + return db.session.query(cls).filter( + cls.location_id == location.id + ).populate_existing().options( + joinedload(cls.location).joinedload(RkiLandkreis.location_group), + joinedload(cls.date_reported) + ) + + @classmethod + def __query_by_date_reported(cls, date_reported: RkiMeldedatum): + return db.session.query(cls).filter( + cls.date_reported_id == date_reported.id + ).populate_existing().options( + joinedload(cls.location).joinedload(RkiMeldedatum.location_group), + joinedload(cls.date_reported) + ) + + @classmethod + @cache.memoize(50) + def get_by_location(cls, location: RkiLandkreis, page: int): + return cls.__query_by_location(location).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + @cache.memoize(50) + def find_by_location(cls, location: RkiLandkreis): + return cls.__query_by_location(location).all() + + @classmethod + @cache.memoize(50) + def find_by_date_reported_and_location(cls, date_reported: RkiMeldedatum, location: RkiLandkreis): + return db.session.query(cls)\ + .filter(and_((cls.date_reported_id == date_reported.id), (cls.location_id == location.id)))\ + .all() + + @classmethod + @cache.memoize(50) + def get_by_date_reported_and_location(cls, date_reported: RkiMeldedatum, location: RkiLandkreis, page: int): + return db.session.query(cls)\ + .filter(and_((cls.date_reported_id == date_reported.id), (cls.location_id == location.id)))\ + .paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def delete_data_for_one_day(cls, date_reported: RkiMeldedatum): + for data in cls.find_by_date_reported(date_reported): + db.session.delete(data) + db.session.delete(date_reported) + db.session.commit() diff --git a/src/flask_covid19/blueprints/data_rki/rki_model_import.py b/src/flask_covid19/blueprints/data_rki/rki_model_import.py index f450330a745c4b50d1c5733468be9b45c48037c9..d90b0b159da33e88c54ec6a9fcdc1a77f6579941 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_model_import.py +++ b/src/flask_covid19/blueprints/data_rki/rki_model_import.py @@ -1,7 +1,7 @@ from datetime import date from sqlalchemy.orm import Bundle from sqlalchemy import and_ -from database import db, ITEMS_PER_PAGE +from database import db, ITEMS_PER_PAGE, cache from flask_covid19.blueprints.app_all.all_model import AllImport, AllFlat @@ -9,62 +9,55 @@ class RkiImport(AllImport): __tablename__ = 'rki_import' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s %s %s %s %s %s %s %s %s)" % (self.__class__.__name__, + self.fid, self.geschlecht, self.date_reported_import_str, + self.datum.isoformat(), self.datenstand_id, self.bundesland, + self.landkreis, self.ref_datum_id, self.altersgruppe) + id = db.Column(db.Integer, primary_key=True) - date_reported_import_str = db.Column(db.String(255), nullable=False) - datum = db.Column(db.Date, nullable=False) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + date_reported_import_str = db.Column(db.String(255), nullable=False, index=True) + datum = db.Column(db.Date, nullable=False, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - fid = db.Column(db.String(255), nullable=False) - id_bundesland = db.Column(db.String(255), nullable=False) - bundesland = db.Column(db.String(255), nullable=False) - landkreis = db.Column(db.String(255), nullable=False) - altersgruppe = db.Column(db.String(255), nullable=False) - geschlecht = db.Column(db.String(255), nullable=False) - anzahl_fall = db.Column(db.String(255), nullable=False) - anzahl_todesfall = db.Column(db.String(255), nullable=False) - meldedatum = db.Column(db.String(255), nullable=False) - id_landkreis = db.Column(db.String(255), nullable=False) - datenstand = db.Column(db.String(255), nullable=False) - neuer_fall = db.Column(db.String(255), nullable=False) - neuer_todesfall = db.Column(db.String(255), nullable=False) - ref_datum = db.Column(db.String(255), nullable=False) - neu_genesen = db.Column(db.String(255), nullable=False) - anzahl_genesen = db.Column(db.String(255), nullable=False) - ist_erkrankungsbeginn = db.Column(db.String(255), nullable=False) - altersgruppe2 = db.Column(db.String(255), nullable=False) + fid = db.Column(db.String(255), nullable=False, index=True) + id_bundesland = db.Column(db.String(255), nullable=False, index=True) + bundesland = db.Column(db.String(255), nullable=False, index=True) + landkreis = db.Column(db.String(255), nullable=False, index=True) + altersgruppe = db.Column(db.String(255), nullable=False, index=True) + geschlecht = db.Column(db.String(255), nullable=False, index=True) + anzahl_fall = db.Column(db.String(255), nullable=False, index=True) + anzahl_todesfall = db.Column(db.String(255), nullable=False, index=True) + meldedatum = db.Column(db.String(255), nullable=False, index=True) + id_landkreis = db.Column(db.String(255), nullable=False, index=True) + datenstand = db.Column(db.String(255), nullable=False, index=True) + neuer_fall = db.Column(db.String(255), nullable=False, index=True) + neuer_todesfall = db.Column(db.String(255), nullable=False, index=True) + ref_datum = db.Column(db.String(255), nullable=False, index=True) + neu_genesen = db.Column(db.String(255), nullable=False, index=True) + anzahl_genesen = db.Column(db.String(255), nullable=False, index=True) + ist_erkrankungsbeginn = db.Column(db.String(255), nullable=False, index=True) + altersgruppe2 = db.Column(db.String(255), nullable=False, index=True) @classmethod def remove_all(cls): - num_rows_deleted = 0 - try: - num_rows_deleted = db.session.query(cls).delete() - db.session.commit() - except Exception: - db.session.rollback() + num_rows_deleted = db.session.query(cls).delete() + db.session.commit() return num_rows_deleted @classmethod + @cache.memoize(50) def get_all_as_page(cls, page: int): return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_all(cls): return db.session.query(cls).all() @classmethod - def get_aktualisierungen_as_array(cls): - return [] - - @classmethod - def find_by_aktualisierung(cls, aktualisierung_from_import: str): - return [] - - @classmethod - def get_new_aktualisierungen_as_array(cls): - return [] - - @classmethod + @cache.memoize(50) def get_date_datenstand_of_all_import(cls): dates_reported = [] bu = Bundle('datenstand', cls.datenstand) @@ -75,6 +68,7 @@ class RkiImport(AllImport): return dates_reported @classmethod + @cache.memoize(50) def get_date_ref_datum_of_all_import(cls): dates_reported = [] bu = Bundle('ref_datum', cls.ref_datum) @@ -85,6 +79,7 @@ class RkiImport(AllImport): return dates_reported @classmethod + @cache.memoize(50) def get_datum_of_all_import(cls): dates_reported = [] bu = Bundle('meldedatum', cls.meldedatum) @@ -95,6 +90,7 @@ class RkiImport(AllImport): return dates_reported @classmethod + @cache.memoize(50) def get_meldedatum_list(cls): return db.session.query(cls.meldedatum)\ .distinct()\ @@ -103,6 +99,7 @@ class RkiImport(AllImport): .all() @classmethod + @cache.memoize(50) def get_bundesland_list(cls): bundesland_list = [] bu = Bundle('bundesland', cls.bundesland, cls.id_bundesland) @@ -113,6 +110,7 @@ class RkiImport(AllImport): return bundesland_list @classmethod + @cache.memoize(50) def get_altersgruppe_list(cls): altersgruppe_list = [] bu = Bundle('altersgruppe', cls.altersgruppe) @@ -123,6 +121,7 @@ class RkiImport(AllImport): return altersgruppe_list @classmethod + @cache.memoize(50) def find_by_datun(cls, datum: date): return db.session.query(cls)\ .filter(cls.datum == datum) \ @@ -130,6 +129,7 @@ class RkiImport(AllImport): .all() @classmethod + @cache.memoize(50) def get_landkreis_for_bundesland(cls, bundesland:str): return db.session.query(cls.landkreis, cls.id_landkreis) \ .filter(cls.bundesland == bundesland) \ @@ -138,6 +138,7 @@ class RkiImport(AllImport): .all() @classmethod + @cache.memoize(50) def find_by_datum(cls, my_datum: date): return db.session.query(cls) \ .filter(cls.datum == my_datum) \ @@ -145,9 +146,14 @@ class RkiImport(AllImport): .all() @classmethod - def find_by_meldedatum_and_landkreis(cls, my_datum: str, my_landkreis: str): + def find_by_meldedatum_and_landkreis(cls, my_datum: date, my_landkreis: str): return db.session.query(cls) \ - .filter(and_(cls.datum == my_datum), (cls.landkreis == my_landkreis)) \ + .filter( + and_( + (cls.datum == my_datum), + (cls.landkreis == my_landkreis) + ) + )\ .order_by(cls.landkreis.asc()) \ .all() @@ -156,45 +162,51 @@ class RkiFlat(AllFlat): __tablename__ = 'rki_import_flat' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s %s %s %s %s %s %s %s %s)" % (self.__class__.__name__, + self.fid, self.geschlecht, self.date_reported_import_str, + self.datum.isoformat(), self.datenstand, self.bundesland, + self.landkreis, self.ref_datum, self.altersgruppe) + id = db.Column(db.Integer, primary_key=True) # - date_reported_import_str = db.Column(db.String(255), nullable=False) - datum = db.Column(db.Date, nullable=False) + date_reported_import_str = db.Column(db.String(255), nullable=False, index=True) + datum = db.Column(db.Date, nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) - year_day_of_year = db.Column(db.String(255), nullable=False) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) + year_day_of_year = db.Column(db.String(255), nullable=False, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) - week_of_year = db.Column(db.Integer, nullable=False) - day_of_year = db.Column(db.Integer, nullable=False) - location = db.Column(db.String(255), nullable=False) - location_group = db.Column(db.String(255), nullable=False) - location_code = db.Column(db.String(255), nullable=False) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) + week_of_year = db.Column(db.Integer, nullable=False, index=True) + day_of_year = db.Column(db.Integer, nullable=False, index=True) + location = db.Column(db.String(255), nullable=False, index=True) + location_group = db.Column(db.String(255), nullable=False, index=True) + location_code = db.Column(db.String(255), nullable=False, index=True) # - fid = db.Column(db.String(255), nullable=False) - id_bundesland = db.Column(db.String(255), nullable=False) - bundesland = db.Column(db.String(255), nullable=False) - landkreis = db.Column(db.String(255), nullable=False) - altersgruppe = db.Column(db.String(255), nullable=False) - geschlecht = db.Column(db.String(255), nullable=False) - anzahl_fall = db.Column(db.String(255), nullable=False) - anzahl_todesfall = db.Column(db.String(255), nullable=False) - meldedatum = db.Column(db.String(255), nullable=False) - id_landkreis = db.Column(db.String(255), nullable=False) - datenstand = db.Column(db.String(255), nullable=False) - neuer_fall = db.Column(db.String(255), nullable=False) - neuer_todesfall = db.Column(db.String(255), nullable=False) - ref_datum = db.Column(db.String(255), nullable=False) - neu_genesen = db.Column(db.String(255), nullable=False) - anzahl_genesen = db.Column(db.String(255), nullable=False) - ist_erkrankungsbeginn = db.Column(db.String(255), nullable=False) - altersgruppe2 = db.Column(db.String(255), nullable=False) + fid = db.Column(db.String(255), nullable=False, index=True) + id_bundesland = db.Column(db.String(255), nullable=False, index=True) + bundesland = db.Column(db.String(255), nullable=False, index=True) + landkreis = db.Column(db.String(255), nullable=False, index=True) + altersgruppe = db.Column(db.String(255), nullable=False, index=True) + geschlecht = db.Column(db.String(255), nullable=False, index=True) + anzahl_fall = db.Column(db.String(255), nullable=False, index=True) + anzahl_todesfall = db.Column(db.String(255), nullable=False, index=True) + meldedatum = db.Column(db.String(255), nullable=False, index=True) + id_landkreis = db.Column(db.String(255), nullable=False, index=True) + datenstand = db.Column(db.String(255), nullable=False, index=True) + neuer_fall = db.Column(db.String(255), nullable=False, index=True) + neuer_todesfall = db.Column(db.String(255), nullable=False, index=True) + ref_datum = db.Column(db.String(255), nullable=False, index=True) + neu_genesen = db.Column(db.String(255), nullable=False, index=True) + anzahl_genesen = db.Column(db.String(255), nullable=False, index=True) + ist_erkrankungsbeginn = db.Column(db.String(255), nullable=False, index=True) + altersgruppe2 = db.Column(db.String(255), nullable=False, index=True) @classmethod def remove_all(cls): diff --git a/src/flask_covid19/blueprints/data_rki/rki_service_import.py b/src/flask_covid19/blueprints/data_rki/rki_service_import.py index 860a79ebb543177d2a4c3fd8aa85941634b0b5e0..d7f0a21cb55adda3aebce074e7ea6efd13be9fc4 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_service_import.py +++ b/src/flask_covid19/blueprints/data_rki/rki_service_import.py @@ -1,5 +1,5 @@ import csv -import psycopg2 +# import psycopg2 from database import db, app from flask_covid19.blueprints.app_all.all_config import BlueprintConfig @@ -101,8 +101,6 @@ class RkiServiceImport: if (k % 2000) == 0: db.session.commit() app.logger.info(" import RKI ... " + str(k) + " rows") - # if k == 230091: - # break db.session.commit() app.logger.info(" import RKI ... " + str(k) + " rows total") except KeyError as error: @@ -111,7 +109,7 @@ class RkiServiceImport: for item_key, item_value in row.items(): app.logger.warning(str(item_key)+" : "+str(item_value)) app.logger.warning("WARN:import RKI [end]") - except (Exception, psycopg2.DatabaseError) as error: + except Exception as error: app.logger.warning("WARN:import RKI [begin]") app.logger.warning(error) app.logger.warning("WARN:import RKI [end]") diff --git a/src/flask_covid19/blueprints/data_rki/rki_service_update.py b/src/flask_covid19/blueprints/data_rki/rki_service_update.py index d5121e2a78d716a8a9b8797757b453e4afa235dd..caca8407be8b849374a9325a50102f78cdeaaef5 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_service_update.py +++ b/src/flask_covid19/blueprints/data_rki/rki_service_update.py @@ -1,4 +1,4 @@ -from database import db, app +from database import db, app, cache from flask_covid19.blueprints.app_all.all_config import BlueprintConfig from flask_covid19.blueprints.app_web.web_model_factory import BlueprintDateReportedFactory @@ -23,6 +23,8 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): app.logger.info(" RkiServiceUpdateFull.__full_update_date_datenstand [begin]") app.logger.info("------------------------------------------------------------") RkiDatenstand.delete_all() + with app.app_context(): + cache.clear() i = 0 output_lines = [] for datum_of_import in RkiImport.get_date_datenstand_of_all_import(): @@ -43,6 +45,8 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): app.logger.info(" RkiServiceUpdateFull.__full_update_date_ref_datum [begin]") app.logger.info("------------------------------------------------------------") RkiRefDatum.delete_all() + with app.app_context(): + cache.clear() i = 0 output_lines = [] for datum_of_import in RkiImport.get_date_ref_datum_of_all_import(): @@ -63,6 +67,8 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): app.logger.info(" RkiServiceUpdateFull.__full_update_meldedatum [begin]") app.logger.info("------------------------------------------------------------") RkiMeldedatum.delete_all() + with app.app_context(): + cache.clear() i = 0 output_lines = [] for datum_of_import in RkiImport.get_meldedatum_list(): @@ -86,6 +92,8 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): app.logger.info(" RkiServiceUpdateFull.__full_update_altersgruppe [begin]") app.logger.info("------------------------------------------------------------") RkiAltersgruppe.delete_all() + with app.app_context(): + cache.clear() app.logger.info("") i = 0 output_lines = [] @@ -115,6 +123,8 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): app.logger.info(" RkiServiceUpdateFull.__full_update_bundesland [begin]") app.logger.info("------------------------------------------------------------") RkiBundesland.delete_all() + with app.app_context(): + cache.clear() app.logger.info("") i = 0 output_lines = [] @@ -146,6 +156,8 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): def __full_update_landkreis(self): RkiLandkreis.delete_all() self.__full_update_bundesland() + with app.app_context(): + cache.clear() app.logger.info(" RkiServiceUpdateFull.__full_update_landkreis [begin]") app.logger.info("------------------------------------------------------------") i = 0 @@ -186,6 +198,8 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): app.logger.info(" RkiServiceUpdateFull.__full_update_data [begin]") app.logger.info("------------------------------------------------------------") RkiData.delete_all() + with app.app_context(): + cache.clear() i = 0 d = 0 k = 0 @@ -202,7 +216,8 @@ class RkiServiceUpdateFull(RkiServiceUpdateBase): # app.logger.info(" my_meldedatum: " + str(my_meldedatum) + " " + d.isoformat()) # app.logger.info("------------------------------------------------------------") list_imports = RkiImport.find_by_meldedatum_and_landkreis( - my_datum=my_meldedatum_datum, my_landkreis=my_landkreis_key) + my_datum=my_meldedatum_datum, + my_landkreis=my_landkreis_key) # if l_imports is None: # app.logger.info("list_imports is None ") # else: diff --git a/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py b/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py index 2e7229d53c846dd00d294e5c09c3e98a272eb1bf..62bcf0c5c31cea77de50bd488e99490026ad3562 100644 --- a/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py +++ b/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py @@ -1,5 +1,5 @@ -from database import db, ITEMS_PER_PAGE +from database import db, cache from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported, BlueprintFactTableTimeSeries @@ -17,28 +17,40 @@ class VaccinationDateReported(BlueprintDateReported): ), ) + def __repr__(self): + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, + self.datum.isoformat(), + self.year_day_of_year) + id = db.Column(db.Integer, primary_key=True) # date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) datum = db.Column(db.Date, nullable=False, unique=True) year_day_of_year = db.Column(db.String(255), nullable=False, unique=True) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) - day_of_year = db.Column(db.Integer, nullable=True) - week_of_year = db.Column(db.Integer, nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) + day_of_year = db.Column(db.Integer, nullable=True, index=True) + week_of_year = db.Column(db.Integer, nullable=False, index=True) # - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) class VaccinationData(BlueprintFactTableTimeSeries): __tablename__ = 'vaccination' __mapper_args__ = {'concrete': True} + __table_args__ = ( + db.UniqueConstraint('date_reported_id', name="uix_vaccination"), + ) + + def __repr__(self): + return "%s(%s)" % (self.__class__.__name__, self.date_reported.__repr__()) id = db.Column(db.Integer, primary_key=True) date_reported_id = db.Column(db.Integer, db.ForeignKey('vaccination_date_reported.id'), nullable=False) @@ -47,33 +59,40 @@ class VaccinationData(BlueprintFactTableTimeSeries): lazy='joined', cascade='save-update', order_by='desc(VaccinationDateReported.datum)') - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - dosen_kumulativ = db.Column(db.Integer, nullable=False) - dosen_differenz_zum_vortag = db.Column(db.Integer, nullable=False) - dosen_biontech_kumulativ = db.Column(db.Integer, nullable=False) - dosen_moderna_kumulativ = db.Column(db.Integer, nullable=False) - personen_erst_kumulativ = db.Column(db.Integer, nullable=False) - personen_voll_kumulativ = db.Column(db.Integer, nullable=False) - impf_quote_erst = db.Column(db.Float, nullable=False) - impf_quote_voll = db.Column(db.Float, nullable=False) - indikation_alter_dosen = db.Column(db.Integer, nullable=False) - indikation_beruf_dosen = db.Column(db.Integer, nullable=False) - indikation_medizinisch_dosen = db.Column(db.Integer, nullable=False) - indikation_pflegeheim_dosen = db.Column(db.Integer, nullable=False) - indikation_alter_erst = db.Column(db.Integer, nullable=False) - indikation_beruf_erst = db.Column(db.Integer, nullable=False) - indikation_medizinisch_erst = db.Column(db.Integer, nullable=False) - indikation_pflegeheim_erst = db.Column(db.Integer, nullable=False) - indikation_alter_voll = db.Column(db.Integer, nullable=False) - indikation_beruf_voll = db.Column(db.Integer, nullable=False) - indikation_medizinisch_voll = db.Column(db.Integer, nullable=False) - indikation_pflegeheim_voll = db.Column(db.Integer, nullable=False) - + dosen_kumulativ = db.Column(db.Integer, nullable=False, index=True) + dosen_differenz_zum_vortag = db.Column(db.Integer, nullable=False, index=True) + dosen_biontech_kumulativ = db.Column(db.Integer, nullable=False, index=True) + dosen_moderna_kumulativ = db.Column(db.Integer, nullable=False, index=True) + personen_erst_kumulativ = db.Column(db.Integer, nullable=False, index=True) + personen_voll_kumulativ = db.Column(db.Integer, nullable=False, index=True) + impf_quote_erst = db.Column(db.Float, nullable=False, index=True) + impf_quote_voll = db.Column(db.Float, nullable=False, index=True) + indikation_alter_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_beruf_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_medizinisch_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_pflegeheim_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_alter_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_beruf_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_medizinisch_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_pflegeheim_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_alter_voll = db.Column(db.Integer, nullable=False, index=True) + indikation_beruf_voll = db.Column(db.Integer, nullable=False, index=True) + indikation_medizinisch_voll = db.Column(db.Integer, nullable=False, index=True) + indikation_pflegeheim_voll = db.Column(db.Integer, nullable=False, index=True) @classmethod + @cache.memoize(50) def find_by_date_reported(cls, date_reported: VaccinationDateReported): return db.session.query(cls) \ .filter(cls.date_reported_id == date_reported.id) \ .one_or_none() + + @classmethod + def delete_data_for_one_day(cls, date_reported: VaccinationDateReported): + for data in cls.find_by_date_reported(date_reported): + db.session.delete(data) + db.session.delete(date_reported) + db.session.commit() diff --git a/src/flask_covid19/blueprints/data_vaccination/vaccination_model_import.py b/src/flask_covid19/blueprints/data_vaccination/vaccination_model_import.py index 0551eaacd75e9f4309349d4e17d7e514f39cba2f..e7eb056516d172bd85d2b8e16f8675ead5da7fbf 100644 --- a/src/flask_covid19/blueprints/data_vaccination/vaccination_model_import.py +++ b/src/flask_covid19/blueprints/data_vaccination/vaccination_model_import.py @@ -1,36 +1,41 @@ -from database import db, ITEMS_PER_PAGE -from flask_covid19.blueprints.app_all.all_model import AllImport, AllFlat +from database import db, ITEMS_PER_PAGE, cache +from flask_covid19.blueprints.app_all.all_model import AllImport class VaccinationImport(AllImport): __tablename__ = 'vaccination_import' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s %s)" % (self.__class__.__name__, + self.date_reported_import_str, + self.datum.isoformat()) + id = db.Column(db.Integer, primary_key=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - datum = db.Column(db.Date, nullable=False) - date_reported_import_str = db.Column(db.String(255), nullable=False) - dosen_kumulativ = db.Column(db.Integer, nullable=False) - dosen_differenz_zum_vortag = db.Column(db.Integer, nullable=False) - dosen_biontech_kumulativ = db.Column(db.Integer, nullable=False) - dosen_moderna_kumulativ = db.Column(db.Integer, nullable=False) - personen_erst_kumulativ = db.Column(db.Integer, nullable=False) - personen_voll_kumulativ = db.Column(db.Integer, nullable=False) - impf_quote_erst = db.Column(db.Float, nullable=False) - impf_quote_voll = db.Column(db.Float, nullable=False) - indikation_alter_dosen = db.Column(db.Integer, nullable=False) - indikation_beruf_dosen = db.Column(db.Integer, nullable=False) - indikation_medizinisch_dosen = db.Column(db.Integer, nullable=False) - indikation_pflegeheim_dosen = db.Column(db.Integer, nullable=False) - indikation_alter_erst = db.Column(db.Integer, nullable=False) - indikation_beruf_erst = db.Column(db.Integer, nullable=False) - indikation_medizinisch_erst = db.Column(db.Integer, nullable=False) - indikation_pflegeheim_erst = db.Column(db.Integer, nullable=False) - indikation_alter_voll = db.Column(db.Integer, nullable=False) - indikation_beruf_voll = db.Column(db.Integer, nullable=False) - indikation_medizinisch_voll = db.Column(db.Integer, nullable=False) - indikation_pflegeheim_voll = db.Column(db.Integer, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) + datum = db.Column(db.Date, nullable=False, index=True) + date_reported_import_str = db.Column(db.String(255), nullable=False, index=True) + dosen_kumulativ = db.Column(db.Integer, nullable=False, index=True) + dosen_differenz_zum_vortag = db.Column(db.Integer, nullable=False, index=True) + dosen_biontech_kumulativ = db.Column(db.Integer, nullable=False, index=True) + dosen_moderna_kumulativ = db.Column(db.Integer, nullable=False, index=True) + personen_erst_kumulativ = db.Column(db.Integer, nullable=False, index=True) + personen_voll_kumulativ = db.Column(db.Integer, nullable=False, index=True) + impf_quote_erst = db.Column(db.Float, nullable=False, index=True) + impf_quote_voll = db.Column(db.Float, nullable=False, index=True) + indikation_alter_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_beruf_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_medizinisch_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_pflegeheim_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_alter_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_beruf_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_medizinisch_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_pflegeheim_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_alter_voll = db.Column(db.Integer, nullable=False, index=True) + indikation_beruf_voll = db.Column(db.Integer, nullable=False, index=True) + indikation_medizinisch_voll = db.Column(db.Integer, nullable=False, index=True) + indikation_pflegeheim_voll = db.Column(db.Integer, nullable=False, index=True) @classmethod def remove_all(cls): @@ -40,36 +45,42 @@ class VaccinationImport(AllImport): return None @classmethod + @cache.memoize(50) def get_all_as_page(cls, page: int): return db.session.query(cls)\ .order_by(cls.datum.desc())\ .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_all(cls): return db.session.query(cls)\ .order_by(cls.datum)\ .all() @classmethod + @cache.memoize(50) def get_by_id(cls, other_id: int): return db.session.query(cls)\ .filter(cls.id == other_id)\ .one() @classmethod + @cache.memoize(50) def find_by_id(cls, other_id: int): return db.session.query(cls) \ .filter(cls.id == other_id) \ .one_or_none() @classmethod + @cache.memoize(50) def find_by_datum(cls, other_datum: str): return db.session.query(cls) \ .filter(cls.datum == other_datum) \ .all() @classmethod + @cache.memoize(50) def get_date_rep(cls): return db.session.query(cls.datum)\ .group_by(cls.datum)\ @@ -78,6 +89,7 @@ class VaccinationImport(AllImport): .all() @classmethod + @cache.memoize(50) def get_date_reported_as_array(cls): resultarray = [] resultset = db.session.query(cls.datum)\ @@ -130,44 +142,49 @@ class VaccinationFlat(AllImport): __tablename__ = 'vaccination_import_flat' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s %s)" % (self.__class__.__name__, + self.date_reported_import_str, + self.datum.isoformat()) + id = db.Column(db.Integer, primary_key=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - date_reported_import_str = db.Column(db.String(255), nullable=False) - datum = db.Column(db.Date, nullable=False) + date_reported_import_str = db.Column(db.String(255), nullable=False, index=True) + datum = db.Column(db.Date, nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) - year_day_of_year = db.Column(db.String(255), nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) + year_day_of_year = db.Column(db.String(255), nullable=False, index=True) # - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) - week_of_year = db.Column(db.Integer, nullable=False) - day_of_year = db.Column(db.Integer, nullable=False) - location = db.Column(db.String(255), nullable=False) - location_group = db.Column(db.String(255), nullable=False) - location_code = db.Column(db.String(255), nullable=False) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) + week_of_year = db.Column(db.Integer, nullable=False, index=True) + day_of_year = db.Column(db.Integer, nullable=False, index=True) + location = db.Column(db.String(255), nullable=False, index=True) + location_group = db.Column(db.String(255), nullable=False, index=True) + location_code = db.Column(db.String(255), nullable=False, index=True) # - dosen_kumulativ = db.Column(db.Integer, nullable=False) - dosen_differenz_zum_vortag = db.Column(db.Integer, nullable=False) - dosen_biontech_kumulativ = db.Column(db.Integer, nullable=False) - dosen_moderna_kumulativ = db.Column(db.Integer, nullable=False) - personen_erst_kumulativ = db.Column(db.Integer, nullable=False) - personen_voll_kumulativ = db.Column(db.Integer, nullable=False) - impf_quote_erst = db.Column(db.Float, nullable=False) - impf_quote_voll = db.Column(db.Float, nullable=False) - indikation_alter_dosen = db.Column(db.Integer, nullable=False) - indikation_beruf_dosen = db.Column(db.Integer, nullable=False) - indikation_medizinisch_dosen = db.Column(db.Integer, nullable=False) - indikation_pflegeheim_dosen = db.Column(db.Integer, nullable=False) - indikation_alter_erst = db.Column(db.Integer, nullable=False) - indikation_beruf_erst = db.Column(db.Integer, nullable=False) - indikation_medizinisch_erst = db.Column(db.Integer, nullable=False) - indikation_pflegeheim_erst = db.Column(db.Integer, nullable=False) - indikation_alter_voll = db.Column(db.Integer, nullable=False) - indikation_beruf_voll = db.Column(db.Integer, nullable=False) - indikation_medizinisch_voll = db.Column(db.Integer, nullable=False) - indikation_pflegeheim_voll = db.Column(db.Integer, nullable=False) + dosen_kumulativ = db.Column(db.Integer, nullable=False, index=True) + dosen_differenz_zum_vortag = db.Column(db.Integer, nullable=False, index=True) + dosen_biontech_kumulativ = db.Column(db.Integer, nullable=False, index=True) + dosen_moderna_kumulativ = db.Column(db.Integer, nullable=False, index=True) + personen_erst_kumulativ = db.Column(db.Integer, nullable=False, index=True) + personen_voll_kumulativ = db.Column(db.Integer, nullable=False, index=True) + impf_quote_erst = db.Column(db.Float, nullable=False, index=True) + impf_quote_voll = db.Column(db.Float, nullable=False, index=True) + indikation_alter_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_beruf_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_medizinisch_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_pflegeheim_dosen = db.Column(db.Integer, nullable=False, index=True) + indikation_alter_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_beruf_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_medizinisch_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_pflegeheim_erst = db.Column(db.Integer, nullable=False, index=True) + indikation_alter_voll = db.Column(db.Integer, nullable=False, index=True) + indikation_beruf_voll = db.Column(db.Integer, nullable=False, index=True) + indikation_medizinisch_voll = db.Column(db.Integer, nullable=False, index=True) + indikation_pflegeheim_voll = db.Column(db.Integer, nullable=False, index=True) diff --git a/src/flask_covid19/blueprints/data_vaccination/vaccination_service_import.py b/src/flask_covid19/blueprints/data_vaccination/vaccination_service_import.py index 733ff6b9960438abf14a5189b6128fe7500a0bea..f38562ec41a97991d87c0ac82883568ff3f3fc0f 100644 --- a/src/flask_covid19/blueprints/data_vaccination/vaccination_service_import.py +++ b/src/flask_covid19/blueprints/data_vaccination/vaccination_service_import.py @@ -1,5 +1,5 @@ import csv -import psycopg2 +# import psycopg2 from database import db, app diff --git a/src/flask_covid19/blueprints/data_vaccination/vaccination_service_update.py b/src/flask_covid19/blueprints/data_vaccination/vaccination_service_update.py index fcdd0e2c6187ed46b645277b407b1d49bfbb6d32..e9de9e8bf38669a74765ec5a2b6c3c5b8068b238 100644 --- a/src/flask_covid19/blueprints/data_vaccination/vaccination_service_update.py +++ b/src/flask_covid19/blueprints/data_vaccination/vaccination_service_update.py @@ -1,4 +1,4 @@ -from database import db, app +from database import db, app, cache 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_vaccination.vaccination_model_import import VaccinationImport @@ -23,6 +23,8 @@ class VaccinationServiceUpdateFull(VaccinationServiceUpdateBase): app.logger.info(" VaccinationServiceUpdateFull.__full_update_date_reported [begin]") app.logger.info("------------------------------------------------------------") VaccinationDateReported.remove_all() + with app.app_context(): + cache.clear() date_reported_list = VaccinationImport.get_date_reported_as_array() i = 0 for one_date_reported in date_reported_list: diff --git a/src/flask_covid19/blueprints/data_who/templates/who/country/one/who_country_one_table.html b/src/flask_covid19/blueprints/data_who/templates/who/country/one/who_country_one_table.html index 8f5607536468fb9a8a496ac4570c09a9077b060b..33ac0705e07d51c1938263b6fcdd3d201d72f983 100644 --- a/src/flask_covid19/blueprints/data_who/templates/who/country/one/who_country_one_table.html +++ b/src/flask_covid19/blueprints/data_who/templates/who/country/one/who_country_one_table.html @@ -1,48 +1,7 @@ <div class="table-responsive"> <table class="table table-hover table-striped table-dark"> <thead class="table-secondary"> - <tr> - <th scope="col"> - <a href="{{ url_for('who.url_who_date_reported_all') }}"> - date reported - </a> - </th> - <th scope="col"> - <a href="{{ url_for('who.url_who_country_deaths_new',country_id=who_country.id) }}"> - deaths new - </a> - </th> - <th scope="col"> - <a href="{{ url_for('who.url_who_country_cases_new',country_id=who_country.id) }}"> - cases new - </a> - </th> - <th scope="col"> - <a href="{{ url_for('who.url_who_country_deaths_cumulative',country_id=who_country.id) }}"> - deaths cumulative - </a> - </th> - <th scope="col"> - <a href="{{ url_for('who.url_who_country_cases_cumulative',country_id=who_country.id) }}"> - cases cumulative - </a> - </th> - <th scope="col"> - <a href="{{ url_for('who.url_who_country_all') }}"> - country code - </a> - </th> - <th scope="col"> - <a href="{{ url_for('who.url_who_country_all') }}"> - country - </a> - </th> - <th scope="col"> - <a href="{{ url_for('who.url_who_region_all') }}"> - region - </a> - </th> - </tr> + {% include 'who/country/one/who_country_one_table_head.html' %} </thead> <tbody> {% for who_global_data in page_data.items %} @@ -83,7 +42,7 @@ {% endfor %} </tbody> <tfoot> - + {% include 'who/country/one/who_country_one_table_head.html' %} </tfoot> </table> </div> \ No newline at end of file diff --git a/src/flask_covid19/blueprints/data_who/templates/who/country/one/who_country_one_table_head.html b/src/flask_covid19/blueprints/data_who/templates/who/country/one/who_country_one_table_head.html index 1608036a7498a6d30c6e1139d5ead80a9797a146..a370849dc3c02b264203446ba0c12f40ac0909ef 100644 --- a/src/flask_covid19/blueprints/data_who/templates/who/country/one/who_country_one_table_head.html +++ b/src/flask_covid19/blueprints/data_who/templates/who/country/one/who_country_one_table_head.html @@ -1,4 +1,4 @@ - <tr> +<tr> <th scope="col"> <a href="{{ url_for('who.url_who_date_reported_all') }}"> date reported diff --git a/src/flask_covid19/blueprints/data_who/templates/who/data/who_table_global_data.html b/src/flask_covid19/blueprints/data_who/templates/who/data/who_table_global_data.html index 2a1df62095edd064af7c896bcec420419010167c..a18e192a377a8029ad4c1dc67ff4b6f463c80cbe 100644 --- a/src/flask_covid19/blueprints/data_who/templates/who/data/who_table_global_data.html +++ b/src/flask_covid19/blueprints/data_who/templates/who/data/who_table_global_data.html @@ -33,7 +33,7 @@ </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> {% include 'who/data/who_table_global_data_head.html' %} </tfoot> </table> diff --git a/src/flask_covid19/blueprints/data_who/templates/who/date_reported/one/who_date_reported_one_table.html b/src/flask_covid19/blueprints/data_who/templates/who/date_reported/one/who_date_reported_one_table.html index c44fb605ae84464317fccd3cec54cd7584da782d..491bf8d835f11d668d4e15e252607ae3012a2b8b 100644 --- a/src/flask_covid19/blueprints/data_who/templates/who/date_reported/one/who_date_reported_one_table.html +++ b/src/flask_covid19/blueprints/data_who/templates/who/date_reported/one/who_date_reported_one_table.html @@ -41,7 +41,7 @@ </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> {% include 'who/date_reported/one/who_date_reported_one_table_head.html' %} </tfoot> </table> diff --git a/src/flask_covid19/blueprints/data_who/templates/who/flat/who_flat_table.html b/src/flask_covid19/blueprints/data_who/templates/who/flat/who_flat_table.html index c28f75d8a190b11f1cc30f414ebbab8a668cbb2a..e79b2c5dc61f25aa2657cb6c5c4f6fc6368cc286 100644 --- a/src/flask_covid19/blueprints/data_who/templates/who/flat/who_flat_table.html +++ b/src/flask_covid19/blueprints/data_who/templates/who/flat/who_flat_table.html @@ -1,6 +1,6 @@ <div class="table-responsive"> <table class="table table-hover table-striped table-dark"> - <thead> + <thead class="table-secondary"> {% include 'who/flat/who_flat_table_head.html' %} </thead> <tbody> @@ -33,7 +33,7 @@ </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> {% include 'who/flat/who_flat_table_head.html' %} </tfoot> </table> diff --git a/src/flask_covid19/blueprints/data_who/templates/who/imported/who_imported_table.html b/src/flask_covid19/blueprints/data_who/templates/who/imported/who_imported_table.html index 6e1b392d35175d3351b9f4f88433f0033bcba84e..a5371d7d589fa179e1e7591681622764ffd2f61a 100644 --- a/src/flask_covid19/blueprints/data_who/templates/who/imported/who_imported_table.html +++ b/src/flask_covid19/blueprints/data_who/templates/who/imported/who_imported_table.html @@ -1,6 +1,6 @@ <div class="table-responsive"> <table class="table table-hover table-striped table-dark"> - <thead> + <thead class="table-secondary"> {% include 'who/imported/who_imported_table_head.html' %} </thead> <tbody> @@ -17,7 +17,7 @@ </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> {% include 'who/imported/who_imported_table_head.html' %} </tfoot> </table> diff --git a/src/flask_covid19/blueprints/data_who/templates/who/region/all/who_region_all_table.html b/src/flask_covid19/blueprints/data_who/templates/who/region/all/who_region_all_table.html index 4548c266062404fb63fce3ce8330b046b48d36b8..bbedbc468fa0ffebd285d1b1334be977f913490b 100644 --- a/src/flask_covid19/blueprints/data_who/templates/who/region/all/who_region_all_table.html +++ b/src/flask_covid19/blueprints/data_who/templates/who/region/all/who_region_all_table.html @@ -1,6 +1,6 @@ <div class="table-responsive"> <table class="table table-hover table-striped table-dark"> - <thead> + <thead class="table-secondary"> <tr> <th scope="col">who_region</th> </tr> @@ -16,7 +16,7 @@ </tr> {% endfor %} </tbody> - <tfoot> + <tfoot class="table-secondary"> <tr> <th scope="col">who_region</th> </tr> diff --git a/src/flask_covid19/blueprints/data_who/who_model.py b/src/flask_covid19/blueprints/data_who/who_model.py index c537854296f22c7edba28eea28b6d5a89a213345..88437deaa12a57616b31a609d9f9cfa15044de84 100644 --- a/src/flask_covid19/blueprints/data_who/who_model.py +++ b/src/flask_covid19/blueprints/data_who/who_model.py @@ -1,6 +1,6 @@ from sqlalchemy import and_ from sqlalchemy.orm import joinedload -from database import db, ITEMS_PER_PAGE +from database import db, ITEMS_PER_PAGE, cache from flask_covid19.blueprints.app_all.all_model import BlueprintDateReported, BlueprintFactTable, AllImport from flask_covid19.blueprints.app_all.all_model import BlueprintLocationGroup, BlueprintLocation, AllFlat @@ -17,23 +17,27 @@ class WhoDateReported(BlueprintDateReported): ), ) + def __repr__(self): + return "%s(%s, %s, %s)" % (self.__class__.__name__, + self.date_reported_import_str, self.datum.isoformat(), self.year_day_of_year) + def __str__(self): return self.datum.isoformat() id = db.Column(db.Integer, primary_key=True) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) - year_day_of_year = db.Column(db.String(255), nullable=False, unique=True) - date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) - datum = db.Column(db.Date, nullable=False, unique=True) - year = db.Column(db.Integer, nullable=False) - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) - week_of_year = db.Column(db.Integer, nullable=False) - day_of_year = db.Column(db.Integer, nullable=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) + year_day_of_year = db.Column(db.String(255), nullable=False, unique=True, index=True) + date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True, index=True) + datum = db.Column(db.Date, nullable=False, unique=True, index=True) + year = db.Column(db.Integer, nullable=False, index=True) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) + week_of_year = db.Column(db.Integer, nullable=False, index=True) + day_of_year = db.Column(db.Integer, nullable=True, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) class WhoCountryRegion(BlueprintLocationGroup): @@ -43,14 +47,17 @@ class WhoCountryRegion(BlueprintLocationGroup): db.UniqueConstraint('location_group', name="uix_who_country_region"), ) - id = db.Column(db.Integer, primary_key=True) - location_group = db.Column(db.String(255), nullable=False, unique=True) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + def __repr__(self): + return "%s(%s)" % (self.__class__.__name__, self.location_group) def __str__(self): return " " + self.location_group + " " + id = db.Column(db.Integer, primary_key=True) + location_group = db.Column(db.String(255), nullable=False, unique=True, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) + class WhoCountry(BlueprintLocation): __tablename__ = 'who_country' @@ -59,23 +66,28 @@ class WhoCountry(BlueprintLocation): db.UniqueConstraint('location_code', 'location', name="uix_who_country"), ) + def __repr__(self): + return "%s(%s %s)" % (self.__class__.__name__, self.location_code, self.location) + + def __str__(self): + return self.location_group.__str__() + " : " + self.location_code + " | " + self.location + id = db.Column(db.Integer, primary_key=True) - location_code = db.Column(db.String(255), unique=True, nullable=False) - location = db.Column(db.String(255), unique=True, nullable=False) + location_code = db.Column(db.String(255), unique=True, nullable=False, index=True) + location = db.Column(db.String(255), unique=True, nullable=False, index=True) location_group_id = db.Column(db.Integer, db.ForeignKey('who_country_region.id'), nullable=False) location_group = db.relationship( 'WhoCountryRegion', lazy='joined', cascade='save-update', order_by='WhoCountryRegion.location_group') - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - - def __str__(self): - return self.location_group.__str__() + " : "+ self.location_code + " | " + self.location + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) @classmethod - def find_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, location_group: WhoCountryRegion): + @cache.memoize(50) + def find_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, + location_group: WhoCountryRegion): return db.session.query(cls).filter( and_( cls.location_code == location_code, @@ -85,7 +97,9 @@ class WhoCountry(BlueprintLocation): ).one_or_none() @classmethod - def get_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, location_group: WhoCountryRegion): + @cache.memoize(50) + def get_by_location_code_and_location_and_location_group(cls, location_code: str, location: str, + location_group: WhoCountryRegion): return db.session.query(cls).filter( and_( cls.location_code == location_code, @@ -104,6 +118,7 @@ class WhoCountry(BlueprintLocation): ).one_or_none() @classmethod + @cache.memoize(50) def get_by_location_code_and_location(cls, location_code: str, location: str): return db.session.query(cls).filter( and_( @@ -113,12 +128,14 @@ class WhoCountry(BlueprintLocation): ).one() @classmethod + @cache.memoize(50) def find_by_location_group(cls, location_group: WhoCountryRegion): return db.session.query(cls).filter( cls.location_group == location_group ).order_by(cls.location).all() @classmethod + @cache.memoize(50) def get_by_location_group(cls, location_group: WhoCountryRegion, page: int): return db.session.query(cls).filter( cls.location_group == location_group @@ -128,6 +145,12 @@ class WhoCountry(BlueprintLocation): class WhoData(BlueprintFactTable): __tablename__ = 'who' __mapper_args__ = {'concrete': True} + __table_args__ = ( + db.UniqueConstraint('date_reported_id', 'location_id', name="uix_who"), + ) + + def __repr__(self): + return "%s(%s %s)" % (self.__class__.__name__, self.date_reported_id, self.location_id) id = db.Column(db.Integer, primary_key=True) date_reported_id = db.Column(db.Integer, db.ForeignKey('who_date_reported.id'), nullable=False) @@ -142,13 +165,13 @@ class WhoData(BlueprintFactTable): lazy='joined', cascade='save-update', order_by='asc(WhoCountry.location)') - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - cases_new = db.Column(db.Integer, nullable=False) - cases_cumulative = db.Column(db.Integer, nullable=False) - deaths_new = db.Column(db.Integer, nullable=False) - deaths_cumulative = db.Column(db.Integer, nullable=False) + cases_new = db.Column(db.Integer, nullable=False, index=True) + cases_cumulative = db.Column(db.Integer, nullable=False, index=True) + deaths_new = db.Column(db.Integer, nullable=False, index=True) + deaths_cumulative = db.Column(db.Integer, nullable=False, index=True) @classmethod def delete_by_datum(cls, datum: WhoDateReported): @@ -158,6 +181,7 @@ class WhoData(BlueprintFactTable): return None @classmethod + @cache.memoize(50) def __query_by_date_reported(cls, date_reported: WhoDateReported): return db.session.query(cls).filter( cls.date_reported_id == date_reported.id @@ -172,6 +196,7 @@ class WhoData(BlueprintFactTable): ) @classmethod + @cache.memoize(50) def __query_by_location(cls, location: WhoCountry): return db.session.query(cls).filter( cls.location_id == location.id @@ -181,6 +206,7 @@ class WhoData(BlueprintFactTable): ) @classmethod + @cache.memoize(50) def __query_by_date_reported_and_location(cls, date_reported: WhoDateReported, location: WhoCountry): return db.session.query(cls).filter( and_( @@ -190,30 +216,37 @@ class WhoData(BlueprintFactTable): ) @classmethod + @cache.memoize(50) def find_by_date_reported(cls, date_reported: WhoDateReported): return cls.__query_by_date_reported(date_reported).all() @classmethod + @cache.memoize(50) def get_by_date_reported(cls, date_reported: WhoDateReported, page: int): return cls.__query_by_date_reported(date_reported).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_by_location(cls, location: WhoCountry, page: int): return cls.__query_by_location(location).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_by_location(cls, location: WhoCountry): return cls.__query_by_location(location).all() @classmethod + @cache.memoize(50) def find_by_date_reported_and_location(cls, date_reported: WhoDateReported, location: WhoCountry): return cls.__query_by_date_reported_and_location(date_reported, location).one_or_none() @classmethod - def get_by_date_reported_and_location(cls, date_reported: WhoDateReported, location: WhoCountry): + @cache.memoize(50) + def get_by_date_reported_and_location(cls, date_reported: WhoDateReported, location: WhoCountry, page: int): return cls.__query_by_date_reported_and_location(date_reported, location).one() @classmethod + @cache.memoize(50) def get_by_date_reported_order_by_cases_new(cls, date_reported: WhoDateReported, page): return db.session.query(cls).filter( cls.date_reported_id == date_reported.id @@ -225,6 +258,7 @@ class WhoData(BlueprintFactTable): ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_by_date_reported_order_by_cases_cumulative(cls, date_reported: WhoDateReported, page): return db.session.query(cls).filter( cls.date_reported_id == date_reported.id @@ -236,6 +270,7 @@ class WhoData(BlueprintFactTable): ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_by_date_reported_order_by_deaths_new(cls, date_reported: WhoDateReported, page): return db.session.query(cls).filter( cls.date_reported_id == date_reported.id @@ -247,6 +282,7 @@ class WhoData(BlueprintFactTable): ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_by_date_reported_order_by_deaths_cumulative(cls, date_reported: WhoDateReported, page): return db.session.query(cls).filter( cls.date_reported_id == date_reported.id @@ -258,6 +294,7 @@ class WhoData(BlueprintFactTable): ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_by_location_order_by_cases_new(cls, location: WhoCountry, page): return db.session.query(cls).filter( cls.location_id == location.id @@ -269,6 +306,7 @@ class WhoData(BlueprintFactTable): ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def get_by_location_order_by_cases_cumulative(cls, location: WhoDateReported, page): return db.session.query(cls).filter( cls.location_id == location.id @@ -302,9 +340,18 @@ class WhoData(BlueprintFactTable): ) @classmethod + @cache.memoize(50) def get_by_location_order_by_deaths_cumulative(cls, location: WhoDateReported, page): return cls.__query_by_location_order_by_deaths_cumulative(location).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod + @cache.memoize(50) def find_by_location_order_by_deaths_cumulative(cls, location: WhoDateReported): return cls.__query_by_location_order_by_deaths_cumulative(location).all() + + @classmethod + def delete_data_for_one_day(cls, date_reported: WhoDateReported): + for data in cls.find_by_date_reported(date_reported): + db.session.delete(data) + db.session.delete(date_reported) + db.session.commit() diff --git a/src/flask_covid19/blueprints/data_who/who_model_import.py b/src/flask_covid19/blueprints/data_who/who_model_import.py index 920b796baec767b8ff5b67cecd5a5383826dd507..1acfdfa7206fa0582e84cb81f1fd0a1d6f69256b 100644 --- a/src/flask_covid19/blueprints/data_who/who_model_import.py +++ b/src/flask_covid19/blueprints/data_who/who_model_import.py @@ -1,5 +1,5 @@ from sqlalchemy.orm import Bundle -from database import db, ITEMS_PER_PAGE +from database import db, cache from flask_covid19.blueprints.app_all.all_model import AllImport, AllFlat @@ -7,37 +7,45 @@ class WhoImport(AllImport): __tablename__ = 'who_import' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s %s %s %s %s)" % (self.__class__.__name__, + self.datum.isoformat(), self.date_reported, + self.country_code, self.country, self.who_region) + def __str__(self): return self.datum.isoformat() + " " + self.country_code + " " + self.country + " " + str(self.row_imported) id = db.Column(db.Integer, primary_key=True) - datum = db.Column(db.Date, nullable=False) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + datum = db.Column(db.Date, nullable=False, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - new_cases = db.Column(db.String(255), nullable=False) - cumulative_cases = db.Column(db.String(255), nullable=False) - new_deaths = db.Column(db.String(255), nullable=False) - cumulative_deaths = db.Column(db.String(255), nullable=False) - country_code = db.Column(db.String(255), nullable=False) - country = db.Column(db.String(255), nullable=False) - who_region = db.Column(db.String(255), nullable=False) - date_reported = db.Column(db.String(255), nullable=False) + new_cases = db.Column(db.String(255), nullable=False, index=True) + cumulative_cases = db.Column(db.String(255), nullable=False, index=True) + new_deaths = db.Column(db.String(255), nullable=False, index=True) + cumulative_deaths = db.Column(db.String(255), nullable=False, index=True) + country_code = db.Column(db.String(255), nullable=False, index=True) + country = db.Column(db.String(255), nullable=False, index=True) + who_region = db.Column(db.String(255), nullable=False, index=True) + date_reported = db.Column(db.String(255), nullable=False, index=True) @classmethod + @cache.cached(timeout=50) def get_regions(cls): return db.session.query(cls.who_region)\ .order_by(cls.who_region)\ .distinct().all() @classmethod + @cache.cached(timeout=50) def get_dates_reported(cls): return db.session.query(cls.date_reported)\ .order_by(cls.date_reported.desc())\ .distinct().all() @classmethod - def get_for_one_day(cls, day): + @cache.memoize(50) + def get_for_one_day(cls, day: str): return db.session.query(cls)\ .filter(cls.date_reported == day)\ .order_by(cls.country.asc())\ @@ -51,7 +59,7 @@ class WhoImport(AllImport): .distinct().all() for my_datum_item in myresultset: my_datum = my_datum_item.datum.isoformat() - if not my_datum in myresultarray: + if my_datum not in myresultarray: myresultarray.append(my_datum) return myresultarray @@ -128,16 +136,19 @@ class WhoImport(AllImport): return new_dates @classmethod + @cache.cached(timeout=50) def get_new_dates_as_array(cls): - #return cls.__get_new_dates_as_array_sql() + # return cls.__get_new_dates_as_array_sql() return cls.__get_new_dates_as_array_orm() @classmethod + @cache.cached(timeout=50) def countries(cls): bu = Bundle('countries', cls.country_code, cls.country, cls.who_region) return db.session.query(bu).distinct() @classmethod + @cache.cached(timeout=50) def get_datum_of_all_who_import(cls): dates_reported = [] bu = Bundle('dates_reported', cls.date_reported) @@ -152,35 +163,40 @@ class WhoFlat(AllFlat): __tablename__ = 'who_import_flat' __mapper_args__ = {'concrete': True} + def __repr__(self): + return "%s(%s %s %s %s %s)" % (self.__class__.__name__, + self.datum.isoformat(), self.date_reported_import_str, + self.location_code, self.location, self.location_group) + def __str__(self): return self.datum.isoformat() + " " + self.location_code + " " + self.location + " " + str(self.location_group) id = db.Column(db.Integer, primary_key=True) # - date_reported_import_str = db.Column(db.String(255), nullable=False) - datum = db.Column(db.Date, nullable=False) + date_reported_import_str = db.Column(db.String(255), nullable=False, index=True) + datum = db.Column(db.Date, nullable=False, index=True) # - year = db.Column(db.Integer, nullable=False) - year_month = db.Column(db.String(255), nullable=False) - year_week = db.Column(db.String(255), nullable=False) - year_day_of_year = db.Column(db.String(255), nullable=False) - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) + year = db.Column(db.Integer, nullable=False, index=True) + year_month = db.Column(db.String(255), nullable=False, index=True) + year_week = db.Column(db.String(255), nullable=False, index=True) + year_day_of_year = db.Column(db.String(255), nullable=False, index=True) + processed_update = db.Column(db.Boolean, nullable=False, index=True) + processed_full_update = db.Column(db.Boolean, nullable=False, index=True) # - month = db.Column(db.Integer, nullable=False) - day_of_month = db.Column(db.Integer, nullable=False) - day_of_week = db.Column(db.Integer, nullable=False) - week_of_year = db.Column(db.Integer, nullable=False) - day_of_year = db.Column(db.Integer, nullable=False) - location = db.Column(db.String(255), nullable=False) - location_group = db.Column(db.String(255), nullable=False) - location_code = db.Column(db.String(255), nullable=False) + month = db.Column(db.Integer, nullable=False, index=True) + day_of_month = db.Column(db.Integer, nullable=False, index=True) + day_of_week = db.Column(db.Integer, nullable=False, index=True) + week_of_year = db.Column(db.Integer, nullable=False, index=True) + day_of_year = db.Column(db.Integer, nullable=False, index=True) + location = db.Column(db.String(255), nullable=False, index=True) + location_group = db.Column(db.String(255), nullable=False, index=True) + location_code = db.Column(db.String(255), nullable=False, index=True) # - new_cases = db.Column(db.String(255), nullable=False) - cumulative_cases = db.Column(db.String(255), nullable=False) - new_deaths = db.Column(db.String(255), nullable=False) - cumulative_deaths = db.Column(db.String(255), nullable=False) - country_code = db.Column(db.String(255), nullable=False) - country = db.Column(db.String(255), nullable=False) - who_region = db.Column(db.String(255), nullable=False) - date_reported = db.Column(db.String(255), nullable=False) + new_cases = db.Column(db.Integer, nullable=False, index=True) + cumulative_cases = db.Column(db.Integer, nullable=False, index=True) + new_deaths = db.Column(db.Integer, nullable=False, index=True) + cumulative_deaths = db.Column(db.Integer, nullable=False, index=True) + country_code = db.Column(db.String(255), nullable=False, index=True) + country = db.Column(db.String(255), nullable=False, index=True) + who_region = db.Column(db.String(255), nullable=False, index=True) + date_reported = db.Column(db.String(255), nullable=False, index=True) diff --git a/src/flask_covid19/blueprints/data_who/who_service_import.py b/src/flask_covid19/blueprints/data_who/who_service_import.py index 60386bcaf4320b2bfe74786823e243edafd4b46d..787031a481c23f78a4168e12e33010ab25d10c46 100644 --- a/src/flask_covid19/blueprints/data_who/who_service_import.py +++ b/src/flask_covid19/blueprints/data_who/who_service_import.py @@ -1,6 +1,6 @@ import sys import csv -import psycopg2 +# import psycopg2 from database import db, app from flask_covid19.blueprints.app_web.web_model_factory import BlueprintDateReportedFactory from flask_covid19.blueprints.app_all.all_config import BlueprintConfig @@ -51,6 +51,10 @@ class WhoServiceImport: processed_full_update=False, ) db.session.add(o) + my_new_cases = int(row['New_cases']) + my_cumulative_cases = int(row['Cumulative_cases']) + my_new_deaths = int(row['New_deaths']) + my_cumulative_deaths = int(row['Cumulative_deaths']) oo = WhoFlat( datum=d.datum, year=d.year, @@ -69,10 +73,10 @@ class WhoServiceImport: processed_update=False, processed_full_update=False, # - new_cases=row['New_cases'], - cumulative_cases=row['Cumulative_cases'], - new_deaths=row['New_deaths'], - cumulative_deaths=row['Cumulative_deaths'], + new_cases=my_new_cases, + cumulative_cases=my_cumulative_cases, + new_deaths=my_new_deaths, + cumulative_deaths=my_cumulative_deaths, country_code=row['Country_code'], country=row['Country'], who_region=row['WHO_region'], @@ -91,7 +95,7 @@ class WhoServiceImport: for item_key, item_value in row.items(): app.logger.warning(item_key+" : "+item_value) app.logger.warning("WARN: import WHO [end]") - except (Exception, psycopg2.DatabaseError) as error: + except Exception as error: app.logger.warning("WARN: import WHO [begin]") app.logger.warning(error) app.logger.warning("WARN: import WHO [end]") diff --git a/src/flask_covid19/blueprints/data_who/who_service_update.py b/src/flask_covid19/blueprints/data_who/who_service_update.py index 50e39556bb9440168948c0080a61b2555093d566..4b1388bd6fce6f66b5a63dc2a61e23c86c45f835 100644 --- a/src/flask_covid19/blueprints/data_who/who_service_update.py +++ b/src/flask_covid19/blueprints/data_who/who_service_update.py @@ -1,4 +1,4 @@ -from database import db, app +from database import db, app, cache 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_who.who_model import WhoCountryRegion, WhoDateReported, WhoCountry, WhoData @@ -22,6 +22,8 @@ class WhoServiceUpdateFull(WhoServiceUpdateBase): app.logger.info(" WhoServiceUpdateFull.__full_update_date_reported [begin]") app.logger.info("------------------------------------------------------------") WhoDateReported.remove_all() + with app.app_context(): + cache.clear() log_lines = [] i = 0 # myresultarray = [] @@ -81,6 +83,8 @@ class WhoServiceUpdateFull(WhoServiceUpdateBase): app.logger.info("------------------------------------------------------------") WhoCountry.remove_all() self.__full_update_region() + with app.app_context(): + cache.clear() result = WhoImport.countries() log_lines = [] i = 0 @@ -114,6 +118,8 @@ class WhoServiceUpdateFull(WhoServiceUpdateBase): app.logger.info("------------------------------------------------------------") app.logger.info(" WhoData.remove_all() [begin]") WhoData.remove_all() + with app.app_context(): + cache.clear() app.logger.info(" WhoData.remove_all() [done]") new_dates_reported_as_string_array = WhoImport.get_dates_reported_as_string_array() new_dates_reported_from_import = [] diff --git a/src/flask_covid19/blueprints/data_who/who_views.py b/src/flask_covid19/blueprints/data_who/who_views.py index 54c19e12379c528ad7ca9634f2f1ed037e8bc47c..e2afff1ec218d99e8c18a90b7496d498581b1897 100644 --- a/src/flask_covid19/blueprints/data_who/who_views.py +++ b/src/flask_covid19/blueprints/data_who/who_views.py @@ -5,7 +5,7 @@ from celery.utils.log import get_task_logger from flask_admin.contrib.sqla import ModelView from flask_login import login_required -from database import app, admin, db, celery +from database import app, admin, db, celery, cache from flask_covid19.blueprints.app_web.web_dispachter_matrix_service import who_service from flask_covid19.blueprints.app_web.web_model_transient import WebPageContent @@ -31,6 +31,7 @@ admin.add_view(ModelView(WhoData, db.session, category="WHO")) @app_who.route('/info') +@cache.cached(timeout=50) def url_who_info(): page_info = WebPageContent('WHO', "Info") return render_template( @@ -49,6 +50,7 @@ def url_who_tasks(): @app_who.route('/imported/page/<int:page>') @app_who.route('/imported') +@cache.memoize(50) @login_required def url_who_imported(page=1): page_info = WebPageContent('WHO', "Last Import") @@ -65,6 +67,7 @@ def url_who_imported(page=1): @app_who.route('/flat/page/<int:page>') @app_who.route('/flat') +@cache.memoize(50) @login_required def url_who_flat(page=1): page_info = WebPageContent('WHO', "Flat") @@ -95,6 +98,7 @@ def url_who_date_reported_all(page: int = 1): @app_who.route('/date_reported/<int:date_reported_id>/page/<int:page>') @app_who.route('/date_reported/<int:date_reported_id>') +@cache.memoize(50) def url_who_date_reported(date_reported_id: int, page: int = 1): date_reported = WhoDateReported.get_by_id(date_reported_id) page_info = WebPageContent( @@ -116,6 +120,7 @@ def url_who_date_reported(date_reported_id: int, page: int = 1): @app_who.route('/date_reported/<int:date_reported_id>/cases_new/page/<int:page>') @app_who.route('/date_reported/<int:date_reported_id>/cases_new') +@cache.memoize(50) def url_who_date_reported_cases_new(date_reported_id: int, page: int = 1): date_reported = WhoDateReported.get_by_id(date_reported_id) page_info = WebPageContent( @@ -137,6 +142,7 @@ def url_who_date_reported_cases_new(date_reported_id: int, page: int = 1): @app_who.route('/date_reported/<int:date_reported_id>/cases_cumulative/page/<int:page>') @app_who.route('/date_reported/<int:date_reported_id>/cases_cumulative') +@cache.memoize(50) def url_who_date_reported_cases_cumulative(date_reported_id: int, page: int = 1): date_reported = WhoDateReported.get_by_id(date_reported_id) page_info = WebPageContent( @@ -158,6 +164,7 @@ def url_who_date_reported_cases_cumulative(date_reported_id: int, page: int = 1) @app_who.route('/date_reported/<int:date_reported_id>/deaths_new/page/<int:page>') @app_who.route('/date_reported/<int:date_reported_id>/deaths_new') +@cache.memoize(50) def url_who_date_reported_deaths_new(date_reported_id: int, page: int = 1): date_reported = WhoDateReported.get_by_id(date_reported_id) page_info = WebPageContent( @@ -179,6 +186,7 @@ def url_who_date_reported_deaths_new(date_reported_id: int, page: int = 1): @app_who.route('/date_reported/<int:date_reported_id>/deaths_cumulative/page/<int:page>') @app_who.route('/date_reported/<int:date_reported_id>/deaths_cumulative') +@cache.memoize(50) def url_who_date_reported_deaths_cumulative(date_reported_id: int, page: int = 1): date_reported = WhoDateReported.get_by_id(date_reported_id) page_info = WebPageContent( @@ -200,6 +208,7 @@ def url_who_date_reported_deaths_cumulative(date_reported_id: int, page: int = 1 @app_who.route('/region/all/page/<int:page>') @app_who.route('/region/all') +@cache.memoize(50) def url_who_region_all(page: int = 1): page_info = WebPageContent('WHO', "Region", "All") try: @@ -236,6 +245,7 @@ def url_who_region(region_id: int, page: int = 1): @app_who.route('/country/all/page/<int:page>') @app_who.route('/country/all') +@cache.memoize(50) def url_who_country_all(page: int = 1): page_info = WebPageContent('WHO', "Countries", "All") try: @@ -251,6 +261,7 @@ def url_who_country_all(page: int = 1): @app_who.route('/country/<int:country_id>/page/<int:page>') @app_who.route('/country/<int:country_id>') +@cache.memoize(50) def url_who_country(country_id: int, page: int = 1): who_country = WhoCountry.get_by_id(country_id) page_data = WhoData.get_by_location(who_country, page) @@ -266,6 +277,7 @@ def url_who_country(country_id: int, page: int = 1): @app_who.route('/country/<int:country_id>/cases_new/page/<int:page>') @app_who.route('/country/<int:country_id>/cases_new') +@cache.memoize(50) def url_who_country_cases_new(country_id: int, page: int = 1): who_country = WhoCountry.get_by_id(country_id) page_data = WhoData.get_by_location_order_by_cases_new(who_country, page) @@ -281,6 +293,7 @@ def url_who_country_cases_new(country_id: int, page: int = 1): @app_who.route('/country/<int:country_id>/cases_cumulative/page/<int:page>') @app_who.route('/country/<int:country_id>/cases_cumulative') +@cache.memoize(50) def url_who_country_cases_cumulative(country_id: int, page: int = 1): who_country = WhoCountry.get_by_id(country_id) page_data = WhoData.get_by_location_order_by_cases_cumulative(who_country, page) @@ -296,6 +309,7 @@ def url_who_country_cases_cumulative(country_id: int, page: int = 1): @app_who.route('/country/<int:country_id>/deaths_new/page/<int:page>') @app_who.route('/country/<int:country_id>/deaths_new') +@cache.memoize(50) def url_who_country_deaths_new(country_id: int, page: int = 1): who_country = WhoCountry.get_by_id(country_id) page_data = WhoData.get_by_location_order_by_deaths_new(who_country, page) @@ -311,6 +325,7 @@ def url_who_country_deaths_new(country_id: int, page: int = 1): @app_who.route('/country/<int:country_id>/deaths_cumulative/page/<int:page>') @app_who.route('/country/<int:country_id>/deaths_cumulative') +@cache.memoize(50) def url_who_country_deaths_cumulative(country_id: int, page: int = 1): who_country = WhoCountry.get_by_id(country_id) page_data = WhoData.get_by_location_order_by_deaths_cumulative(who_country, page) @@ -326,6 +341,7 @@ def url_who_country_deaths_cumulative(country_id: int, page: int = 1): @app_who.route('/germany/page/<int:page>') @app_who.route('/germany') +@cache.memoize(50) def url_who_germany(page: int = 1): page_info = WebPageContent('WHO', "Germany") who_country_germany = WhoCountry.find_by_location_code("DE")