diff --git a/src/flask_covid19/blueprints/app_all/all_model.py b/src/flask_covid19/blueprints/app_all/all_model.py index cae81bf960e6f8a9d758e5d5db491bf6a73a9f5e..fdd3ee5794e18a41da0d85674b9115b4e013649f 100644 --- a/src/flask_covid19/blueprints/app_all/all_model.py +++ b/src/flask_covid19/blueprints/app_all/all_model.py @@ -4,7 +4,81 @@ from sqlalchemy.orm import subqueryload from sqlalchemy import not_ -class BlueprintDateReported(db.Model): +class BlueprintEntity(db.Model): + + 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) + + @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() + return num_rows_deleted + + @classmethod + def get_all_as_page(cls, page: int): + return db.session.query(cls)\ + .order_by(cls.date_reported_import_str.desc())\ + .paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_all(cls, page: int): + return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def find_all(cls): + return db.session.query(cls).all() + + @classmethod + def find_all_as_dict(cls): + pass + + @classmethod + def get_by_id(cls, other_id): + return db.session.query(cls).filter(cls.id == other_id).one() + + @classmethod + def find_by_id(cls, other_id): + return db.session.query(cls).filter(cls.id == other_id).one_or_none() + + @classmethod + def set_all_processed_full_update(cls): + for o in cls.find_by_not_processed_full_update(): + o.set_processed_full_update() + db.session.commit() + return None + + def set_processed_update(self): + self.processed_update = True + return self + + def set_processed_full_update(self): + self.processed_full_update = True + return self + + def unset_processed_update(self): + self.processed_update = False + return self + + def unset_processed_full_update(self): + self.processed_full_update = False + return self + + @classmethod + def find_by_not_processed_update(cls): + return db.session.query(cls).filter(not_(cls.processed_update)).all() + + @classmethod + def find_by_not_processed_full_update(cls): + return db.session.query(cls).filter(not_(cls.processed_full_update)).all() + + +class BlueprintDateReported(BlueprintEntity): __tablename__ = 'blueprint_date_reported' __table_args__ = ( db.UniqueConstraint( @@ -19,6 +93,8 @@ class BlueprintDateReported(db.Model): return 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) # date_reported_import_str = db.Column(db.String(255), nullable=False, unique=True) datum = db.Column(db.Date, nullable=False, unique=True) @@ -32,9 +108,6 @@ class BlueprintDateReported(db.Model): 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) - # - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) def get_name_for_weekday(self): return self.get_names_for_weekday()[self.day_of_week] @@ -53,71 +126,26 @@ class BlueprintDateReported(db.Model): 7: "Juli", 8: "August", 9: "September", 10: "Oktober", 11: "November", 12: "Dezember"} @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() - return num_rows_deleted - - @classmethod - def get_all_as_page(cls, page: int): - return db.session.query(cls)\ - .order_by(cls.date_reported_import_str.desc())\ - .paginate(page, per_page=ITEMS_PER_PAGE) - - @classmethod - def get_all(cls): - return db.session.query(cls)\ - .order_by(cls.datum.desc())\ - .all() - - @classmethod - def get_all_as_dict(cls): - dates_reported = {} - for my_date_reported in cls.get_all(): - dates_reported[my_date_reported.date_reported_import_str] = my_date_reported - return dates_reported - - @classmethod - def get_by_id(cls, other_id: int): - return db.session.query(cls)\ - .filter(cls.id == other_id)\ - .one() - - @classmethod - def find_by_id(cls, other_id: int): - return db.session.query(cls)\ - .filter(cls.id == other_id)\ - .one_or_none() + def get_by_datum(cls, datum: date): + return db.session.query(cls).filter(cls.datum == datum).one() @classmethod - # @cache.memoize(50) - def get_by_date_reported(cls, s_date_reported_import_str: str): + def get_by_date_reported(cls, date_reported_import_str: str): return db.session.query(cls)\ - .filter(cls.date_reported_import_str == s_date_reported_import_str)\ + .filter(cls.date_reported_import_str == date_reported_import_str)\ .one() @classmethod - # @cache.memoize(50) - def find_by_date_reported(cls, s_date_reported_import_str: str): + def find_by_date_reported(cls, date_reported_import_str: str): return db.session.query(cls)\ - .filter(cls.date_reported_import_str == s_date_reported_import_str)\ + .filter(cls.date_reported_import_str == date_reported_import_str)\ .one_or_none() - @classmethod - def get_by_year_week(cls, year_week: str): - return db.session.query(cls)\ - .filter(cls.year_week == year_week)\ - .one() - @classmethod def find_by_year_week(cls, year_week: str): return db.session.query(cls)\ .filter(cls.year_week == year_week)\ - .one_or_none() + .all() @classmethod def get_joungest_datum(cls): @@ -126,94 +154,53 @@ class BlueprintDateReported(db.Model): .first() @classmethod - def set_all_to_processed(cls): - for o in cls.get_unprocessed(): - o.set_processed() + def set_all_processed_update(cls): + for o in cls.find_by_not_processed_update(): + o.set_processed_update() db.session.commit() return None - def set_processed(self): - self.processed = True - return self - - @classmethod - def get_unprocessed(cls): - return db.session.query(cls).filter(not_(cls.processed)).all() - @classmethod - def get_by_datum(cls, d_datum: date): - return db.session.query(cls).filter(cls.datum == d_datum).one() + def find_all_as_dict(cls): + dates_reported = {} + for my_date_reported in cls.find_all(): + dates_reported[my_date_reported.date_reported_import_str] = my_date_reported + return dates_reported -class BlueprintLocationGroup(db.Model): +class BlueprintLocationGroup(BlueprintEntity): __tablename__ = 'blueprint_location_group' __table_args__ = ( db.UniqueConstraint('location_group', name='uix_blueprint_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) def __str__(self): result = " " + self.location_group + " " return result - @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() - return num_rows_deleted - - @classmethod - def get_all(cls): - return db.session.query(cls).all() - - @classmethod - 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 - def get_all_as_dict(cls): - regions = {} - for my_region in cls.get_all(): - regions[my_region.location_group] = my_region - return regions - - @classmethod - # @cache.memoize(50) - def get_by_id(cls, other_id: int): - return db.session.query(cls)\ - .filter(cls.id == other_id)\ - .one() + 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 = db.Column(db.String(255), nullable=False, unique=True) @classmethod - def find_by_id(cls, other_id: int): - return db.session.query(cls)\ - .filter(cls.id == other_id)\ - .one_or_none() + def get_last(cls): + return db.session.query(cls).order_by(cls.location_group).all().pop() @classmethod - # @cache.memoize(50) - def get_by_region(cls, i_location_group: str): + def get_by_location_group(cls, location_group: str): return db.session.query(cls)\ - .filter(cls.location_group == i_location_group)\ + .filter(cls.location_group == location_group)\ .one() @classmethod - def find_by_region(cls, s_location_group: str): - return db.session.query(cls)\ - .filter(cls.location_group == s_location_group)\ + def find_by_location_group(cls, location_group: str): + return db.session.query(cls) \ + .filter(cls.location_group == location_group) \ .one_or_none() -class BlueprintLocation(db.Model): +class BlueprintLocation(BlueprintEntity): __tablename__ = 'blueprint_location' __table_args__ = ( db.UniqueConstraint('location', name='uix_blueprint_location'), @@ -223,6 +210,8 @@ class BlueprintLocation(db.Model): return self.location_group.__str__() + " : " + self.location_code + " | " + self.location 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_code = db.Column(db.String(255), unique=True, nullable=True) location = db.Column(db.String(255), nullable=False, unique=True) location_group_id = db.Column(db.Integer, db.ForeignKey('blueprint_location_group.id'), nullable=False) @@ -231,148 +220,89 @@ class BlueprintLocation(db.Model): lazy='joined', cascade='save-update', order_by='BlueprintLocationGroup.location_group') - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - - def __str__(self): - result = "" - result += self.location_code - result += " " - result += self.location - result += " " - result += self.location_group.location_group - result += " " - return result @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() - return num_rows_deleted - - @classmethod - def get_all_as_page(cls, page): - return db.session.query(cls)\ - .order_by(cls.location)\ - .paginate(page, per_page=ITEMS_PER_PAGE) - - @classmethod - def get_all(cls): - return db.session.query(cls)\ - .order_by(cls.location)\ - .all() - - @classmethod - def get_all_as_dict(cls): - countries = {} - for my_country in cls.get_all(): - countries[my_country.location] = my_country - return countries - - @classmethod - def get_by_id(cls, other_id): - return db.session.query(cls)\ - .filter(cls.id == other_id)\ - .one() - - @classmethod - def get_germany(cls): - return db.session.query(cls)\ - .filter(cls.location_code == 'DE')\ - .one_or_none() - - @classmethod - def find_by_location_code(cls, i_location_code: str): + def find_by_location_code(cls, location_code: str): return db.session.query(cls).filter( - cls.location_code == i_location_code + cls.location_code == location_code ).one_or_none() @classmethod - def get_by_location_code(cls, i_location_code: str): + def get_by_location_code(cls, location_code: str): return db.session.query(cls).filter( - cls.location_code == i_location_code + cls.location_code == location_code ).one() @classmethod - def find_by_location(cls, i_location: str): + def find_by_location(cls, location: str): return db.session.query(cls).filter( - cls.location == i_location + cls.location == location ).one_or_none() @classmethod - def get_by_location(cls, i_location: str): + def get_by_location(cls, location: str): return db.session.query(cls).filter( - cls.location == i_location + cls.location == location ).one() @classmethod - def get_locations_for_location_group(cls, location_group, page): + def find_by_location_group(cls, location_group, page: int): return db.session.query(cls).filter( cls.location_group == location_group ).order_by(cls.location).paginate(page, per_page=ITEMS_PER_PAGE) -class BlueprintFactTableTimeSeries(db.Model): +class BlueprintFactTableTimeSeries(BlueprintEntity): __tablename__ = 'blueprint_data_timeline' __table_args__ = ( db.UniqueConstraint('date_reported_id', name='uix_blueprint_data_timeline'), ) + + def __str__(self): + return self.date_reported.__str__() + 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) date_reported_id = db.Column(db.Integer, db.ForeignKey('blueprint_date_reported.id'), nullable=False) date_reported = db.relationship( 'BlueprintDateReported', lazy='joined', cascade='save-update', order_by='desc(BlueprintDateReported.datum)') - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - - @classmethod - def remove_all(cls): - num_rows_deleted = 0 - try: - num_rows_deleted = db.session.query(cls).delete() - db.session.commit() - except: - db.session.rollback() - return num_rows_deleted - - @classmethod - def get_all_as_page(cls, page): - return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod - def get_all(cls): - return db.session.query(cls).all() + def get_date_reported_list(cls): + date_reported_list = [] + for data in db.session.query(cls).options(subqueryload("date_reported").load_only("datum")): + datum = data.date_reported.datum.isoformat() + if not datum in date_reported_list: + date_reported_list.append(datum) + date_reported_list.sort() + return date_reported_list @classmethod - def get_by_id(cls, other_id): - return db.session.query(cls).filter(cls.id == other_id).one() + def get_joungest_datum(cls): + data = cls.get_date_reported_list() + if len(data) > 0: + return data.pop() + else: + return None @classmethod - def find_by_id(cls, other_id: int): - return db.session.query(cls).filter(cls.id == other_id).one_or_none() + def find_by_date_reported(cls, date_reported): + pass @classmethod - def get_datum_of_all_data(cls): - datum_of_all_who_data = [] - for data in db.session.query(cls).options(subqueryload("date_reported").load_only("datum")): - datum = data.date_reported.datum.isoformat() - if not datum in datum_of_all_who_data: - datum_of_all_who_data.append(datum) - datum_of_all_who_data.sort() - return datum_of_all_who_data + def get_by_date_reported(cls, date_reported, page: int): + pass @classmethod - def get_joungest_datum(cls): - return cls.get_datum_of_all_data().pop() + def delete_data_for_one_day(cls, date_reported): + pass -class BlueprintFactTable(db.Model): +class BlueprintFactTable(BlueprintFactTableTimeSeries): __tablename__ = 'blueprint_data' __table_args__ = ( db.UniqueConstraint('location_id', 'date_reported_id', name='uix_blueprint_data'), @@ -382,6 +312,8 @@ class BlueprintFactTable(db.Model): return self.date_reported.__str__() + " " + self.location.__str__() 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) date_reported_id = db.Column(db.Integer, db.ForeignKey('blueprint_date_reported.id'), nullable=False) date_reported = db.relationship( 'BlueprintDateReported', @@ -394,45 +326,3 @@ class BlueprintFactTable(db.Model): lazy='joined', cascade='save-update', order_by='asc(BlueprintLocation.location)') - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - - @classmethod - def remove_all(cls): - num_rows_deleted = 0 - try: - num_rows_deleted = db.session.query(cls).delete() - db.session.commit() - except: - db.session.rollback() - return num_rows_deleted - - @classmethod - def get_all_as_page(cls, page): - return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) - - @classmethod - def get_all(cls): - return db.session.query(cls).all() - - @classmethod - def get_by_id(cls, other_id): - return db.session.query(cls).filter(cls.id == other_id).one() - - @classmethod - def find_by_id(cls, other_id: int): - return db.session.query(cls).filter(cls.id == other_id).one_or_none() - - @classmethod - def get_datum_of_all_data(cls): - datum_of_all_who_data = [] - for data in db.session.query(cls).options(subqueryload("date_reported").load_only("datum")): - datum = data.date_reported.datum.isoformat() - if not datum in datum_of_all_who_data: - datum_of_all_who_data.append(datum) - datum_of_all_who_data.sort() - return datum_of_all_who_data - - @classmethod - def get_joungest_datum(cls): - return cls.get_datum_of_all_data().pop() diff --git a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py index 37843414b6aedfbd9a59db32ee759c2e1d9ffe8f..0f7d1f30fe46b9fa01d78ae02aaba08f30a588ba 100644 --- a/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py +++ b/src/flask_covid19/blueprints/data_ecdc/ecdc_model.py @@ -83,11 +83,7 @@ class EcdcCountry(BlueprintLocation): pop_data_2019 = db.Column(db.String(255), nullable=False) geo_id = db.Column(db.String(255), nullable=False) - @classmethod - def find_by_id(cls, other_id: int): - return db.session.query(cls)\ - .filter(cls.id == other_id)\ - .one_or_none() + @classmethod def get_by(cls, location: str = '', geo_id: str = '', location_code: str = ''): diff --git a/src/flask_covid19/blueprints/data_owid/owid_model.py b/src/flask_covid19/blueprints/data_owid/owid_model.py index 847e8dd16ef3513105722d97b9360fc1c266506b..743d5279e49a914b934429b1ae0046ebbf767ba5 100644 --- a/src/flask_covid19/blueprints/data_owid/owid_model.py +++ b/src/flask_covid19/blueprints/data_owid/owid_model.py @@ -53,10 +53,6 @@ class OwidContinent(BlueprintLocationGroup): processed_update = db.Column(db.Boolean, nullable=False) processed_full_update = db.Column(db.Boolean, nullable=False) - @classmethod - def get_last_continent(cls): - return db.session.query(cls).all().pop() - class OwidCountry(BlueprintLocation): __tablename__ = 'owid_country' @@ -211,9 +207,9 @@ class OwidData(BlueprintFactTable): stringency_index = db.Column(db.String(255), nullable=False) @classmethod - def delete_all_data_for_country(cls, owid_country_one): + def delete_by_location(cls, location: OwidCountry): db.session.query(cls).filter( - cls.country == owid_country_one + cls.location_id == location.id ).populate_existing().options( joinedload(cls.country), joinedload(cls.date_reported), @@ -222,115 +218,75 @@ class OwidData(BlueprintFactTable): return None @classmethod - def get_all_data_for_country(cls, owid_country_one): + def find_by_location(cls, location: OwidCountry): return db.session.query(cls).filter( - cls.country == owid_country_one + cls.location_id == location.id ).populate_existing().options( joinedload(cls.country), joinedload(cls.date_reported), ).all() @classmethod - def get_data_for_country(cls, owid_country_one, page): + def gest_by_location(cls, location: OwidCountry, page: int): return db.session.query(cls).filter( - cls.country == owid_country_one + cls.location_id == location.id ).populate_existing().options( - joinedload(cls.country), + joinedload(cls.location), joinedload(cls.date_reported), + ).order_by( + cls.date_reported.desc() ).paginate(page, per_page=ITEMS_PER_PAGE) @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() - return num_rows_deleted - - @classmethod - def get_all_as_page(cls, page): - return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) - - @classmethod - def get_all(cls): - return db.session.query(cls).all() - - @classmethod - def get_by_id(cls, other_id): - return db.session.query(cls).filter(cls.id == other_id).one() + 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( + cls.new_deaths_per_million.desc(), + cls.new_cases_per_million.desc(), + cls.new_deaths.desc(), + cls.new_cases.desc(), + ).all() @classmethod - def get_data_for_day(cls, date_reported, page): + 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( + cls.new_deaths_per_million.desc(), + cls.new_cases_per_million.desc(), cls.new_deaths.desc(), cls.new_cases.desc(), - cls.new_deaths_per_million.desc(), - cls.new_cases_per_million.desc() ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod - def get_data_for_day_order_by_deaths_new(cls, date_reported, page): + def find_by_date_reported_order_by_deaths_new(cls, date_reported: OwidDateReported, page: int): # TODO pass @classmethod - def get_data_for_day_order_by_deaths_cumulative(cls, date_reported, page): + def find_by_date_reported_order_by_deaths_cumulative(cls, date_reported: OwidDateReported, page: int): # TODO pass @classmethod - def get_data_for_day_order_by_cases_cumulative(cls, date_reported, page): + def find_by_date_reported_order_by_cases_new(cls, date_reported: OwidDateReported, page: int): # TODO pass @classmethod - def get_data_for_day_order_by_cases_new(cls, date_reported, page): + def find_by_date_reported_order_by_cases_cumulative(cls, date_reported: OwidDateReported, page: int): # TODO pass @classmethod - def get_data_for_one_day(cls, date_reported): - return db.session.query(cls).filter( - cls.date_reported_id == date_reported.id - ).populate_existing().options( - joinedload(cls.country).joinedload(OwidCountry.continent), - joinedload(cls.date_reported) - ).order_by( - cls.new_deaths.desc(), - cls.new_cases.desc(), - cls.new_deaths_per_million.desc(), - cls.new_cases_per_million.desc() - ).all() - - @classmethod - def get_datum_of_all_data(cls): - datum_of_all_who_data = [] - for data in db.session.query(cls).options( - subqueryload("date_reported").load_only("date_reported_import_str") - ): - datum = data.date_reported.date_reported_import_str - if not datum in datum_of_all_who_data: - datum_of_all_who_data.append(datum) - datum_of_all_who_data.sort() - return datum_of_all_who_data - - @classmethod - def get_joungest_datum(cls): - data = cls.get_datum_of_all_data() - if len(data) > 0: - return data.pop() - else: - return None - - @classmethod - def delete_data_for_one_day(cls, date_reported): + def delete_data_for_one_day(cls, date_reported: OwidDateReported): for data in cls.get_data_for_one_day(date_reported): db.session.delete(data) db.session.delete(date_reported) diff --git a/src/flask_covid19/blueprints/data_rki/rki_model.py b/src/flask_covid19/blueprints/data_rki/rki_model.py index 143966756ca59663f73771b0218e8225a15aa536..7384ae31198232d2fd5d1d13dc677be0722e5413 100644 --- a/src/flask_covid19/blueprints/data_rki/rki_model.py +++ b/src/flask_covid19/blueprints/data_rki/rki_model.py @@ -64,7 +64,8 @@ class RkiLandkreis(BlueprintLocation): return " " + str(self.location_group) + " : " + self.location + " ( " + self.id_landkreis + " ) " id = db.Column(db.Integer, primary_key=True) - id_landkreis = db.Column(db.String(255), nullable=False) + 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) location_group = db.relationship( @@ -72,43 +73,7 @@ class RkiLandkreis(BlueprintLocation): lazy='joined', cascade='save-update', order_by='RkiBundesland.location_group') - processed_update = db.Column(db.Boolean, nullable=False) - processed_full_update = db.Column(db.Boolean, nullable=False) - - @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() - return num_rows_deleted - - @classmethod - def get_all_as_page(cls, page): - return db.session.query(cls) \ - .order_by(cls.location.asc()) \ - .paginate(page, per_page=ITEMS_PER_PAGE) - - @classmethod - def get_all(cls): - return db.session.query(cls)\ - .order_by(cls.location.asc())\ - .all() - - @classmethod - def get_all_as_dict(cls): - locations = {} - for my_location in cls.get_all(): - locations[my_location.location] = my_location - return locations - - @classmethod - def get_by_id(cls, other_id): - return db.session.query(cls)\ - .filter(cls.id == other_id)\ - .one() + id_landkreis = db.Column(db.String(255), nullable=False) @classmethod def get_bochum(cls): @@ -117,44 +82,16 @@ class RkiLandkreis(BlueprintLocation): .one() @classmethod - def find_by_country_code_and_country_and_who_region_id(cls, my_id_landkreis, i_location_group, my_location_group): + def find_by_location_group(cls, location_group: RkiBundesland, page: int): return db.session.query(cls).filter( - and_( - cls.id_landkreis == my_id_landkreis, - cls.location_group == i_location_group, - cls.location_group_id == my_location_group.id - ) - ).one_or_none() + cls.location_group == location_group + ).order_by(cls.location).all() @classmethod - def find_by_id_landkreis(cls, my_id_landkreis): + def get_by_location_group(cls, location_group: RkiBundesland, page: int): return db.session.query(cls).filter( - cls.id_landkreis == my_id_landkreis - ).one_or_none() - - @classmethod - def get_by_id_landkreis(cls, my_id_landkreis): - return db.session.query(cls).filter( - cls.id_landkreis == my_id_landkreis - ).one() - - @classmethod - def find_by_landkreis(cls, i_landkreis): - return db.session.query(cls).filter( - cls.landkreis == i_landkreis - ).one_or_none() - - @classmethod - def get_by_landkreis(cls, i_landkreis): - return db.session.query(cls).filter( - cls.landkreis == i_landkreis - ).one() - - @classmethod - def get_landkreise_for_bundesland(cls, bundesland, page): - return db.session.query(cls).filter( - cls.location_group == bundesland - ).order_by(cls.country).paginate(page, per_page=ITEMS_PER_PAGE) + cls.location_group == location_group + ).order_by(cls.location).paginate(page, per_page=ITEMS_PER_PAGE) class RkiData(BlueprintFactTable): @@ -192,26 +129,3 @@ class RkiData(BlueprintFactTable): 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 remove_all(cls): - for one in cls.get_all(): - db.session.delete(one) - db.session.commit() - return None - - @classmethod - def get_all_as_page(cls, page): - return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) - - @classmethod - def get_all(cls): - return db.session.query(cls).all() - - @classmethod - def get_by_id(cls, other_id): - return db.session.query(cls).filter(cls.id == other_id).one() - - @classmethod - def find_by_id(cls, other_id): - return db.session.query(cls).filter(cls.id == other_id).one_or_none() diff --git a/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py b/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py index 32aaff55d2086ddfb45f8d9c6310f5d6777e6eb9..2e7229d53c846dd00d294e5c09c3e98a272eb1bf 100644 --- a/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py +++ b/src/flask_covid19/blueprints/data_vaccination/vaccination_model.py @@ -73,7 +73,7 @@ class VaccinationData(BlueprintFactTableTimeSeries): @classmethod - def find_by_datum(cls, datum: VaccinationDateReported): + def find_by_date_reported(cls, date_reported: VaccinationDateReported): return db.session.query(cls) \ - .filter(cls.date_reported_id == datum.id) \ + .filter(cls.date_reported_id == date_reported.id) \ .one_or_none()