diff --git a/src/covid19/blueprints/rki/rki_model_import.py b/src/covid19/blueprints/rki/rki_model_import.py index 280ea1228cc70e9b10ce11e639ccb2fb4857d719..08f3984234fd525c1d1887821e68ea6698b9fa99 100644 --- a/src/covid19/blueprints/rki/rki_model_import.py +++ b/src/covid19/blueprints/rki/rki_model_import.py @@ -105,28 +105,32 @@ class RkiLandkreiseImport(db.Model): def get_new_dates_as_array(cls): # TODO: #129 change to ORM ClassHierarchy in: RkiLandkreiseImport.get_new_dates_as_array sql_query = """ - select - date_reported - from - rki_landkreise_import - where - date_reported - not in ( select distinct - common_date_reported.date_reported + rki_landkreise_import.date_reported from - rki_landkreise - left join - rki_date_reported - on - rki_landkreise.date_reported_id=common_date_reported.id - and - common_date_reported.type='rki_date_reported' - ) - group by - rki_landkreise_import.date_reported - order by date_reported desc + rki_landkreise_import + where + date_reported + not in ( + select + distinct + rki_date_reported.date_reported + from + rki_landkreise + left join + rki_date_reported + on + rki_landkreise.date_reported_id=rki_date_reported.id + group by + rki_date_reported.datum + order by + rki_date_reported.datum desc + ) + group by + rki_landkreise_import.date_reported + order by + rki_landkreise_import.date_reported desc """ new_dates = [] for item in db.session.execute(sql_query): diff --git a/src/covid19/blueprints/vaccination/vaccination_model_import.py b/src/covid19/blueprints/vaccination/vaccination_model_import.py index 17d80dc820c9f08016eb003eef5288d898a4d1e5..7818212b2a92a3bc8ba8181af9e42f8cc571e38f 100644 --- a/src/covid19/blueprints/vaccination/vaccination_model_import.py +++ b/src/covid19/blueprints/vaccination/vaccination_model_import.py @@ -92,13 +92,14 @@ class VaccinationImport(db.Model): @classmethod def get_daterep_missing_in_vaccination_data(cls): sql_query = """ - select - datum - from - vaccination_import - where - datum - not in ( + select + distinct + vaccination_import.datum + from + vaccination_import + where + datum + not in ( select distinct vaccination_import.datum @@ -108,11 +109,16 @@ class VaccinationImport(db.Model): vaccination_date_reported on vaccination_data.date_reported_id=vaccination_date_reported.id - ) - group by - vaccination_import.datum - order by datum desc - """ + group by + vaccination_import.datum + order by + vaccination_import.datum desc + ) + group by + vaccination_import.datum + order by + vaccination_import.datum desc + """ new_dates = [] for item, in db.session.execute(sql_query): new_dates.append(item) diff --git a/src/covid19/blueprints/who/who_model_import.py b/src/covid19/blueprints/who/who_model_import.py index a7924118f1a1f9532447becbcab44c9ee1621a9c..35dbe0b05e40e63d09c7b21e2b08ee3a0282f4bf 100644 --- a/src/covid19/blueprints/who/who_model_import.py +++ b/src/covid19/blueprints/who/who_model_import.py @@ -47,13 +47,13 @@ class WhoImport(db.Model): def get_regions(cls): return db.session.query(cls.who_region)\ .order_by(cls.who_region)\ - .distinct() + .distinct().all() @classmethod def get_dates_reported(cls): return db.session.query(cls.date_reported)\ .order_by(cls.date_reported.desc())\ - .distinct() + .distinct().all() @classmethod def get_for_one_day(cls, day): @@ -62,31 +62,48 @@ class WhoImport(db.Model): .order_by(cls.country.asc())\ .all() + @classmethod + def get_dates_reported_as_array(cls): + myresultarray = [] + myresultset = db.session.query(cls.date_reported)\ + .order_by(cls.date_reported.desc())\ + .group_by(cls.date_reported)\ + .distinct() + for item, in myresultset: + pass + return myresultarray + @classmethod def get_new_dates_as_array(cls): # TODO: #82 BUG: change to ORM ClassHierarchy # TODO: #83 SQLalchemy instead of SQL in WhoImport.get_new_dates_as_array sql_query = """ select - date_reported - from - who_import - where - date_reported - not in ( - select - distinct - who_date_reported.date_reported + distinct + who_import.date_reported from - who_data - left join - who_date_reported - on - who_data.date_reported_id=who_date_reported.id - ) - group by - who_import.date_reported - order by date_reported desc + who_import + where + date_reported + not in ( + select + distinct + who_date_reported.date_reported + from + who_data + left join + who_date_reported + on + who_data.date_reported_id=who_date_reported.id + group by + who_date_reported.date_reported + order by + who_date_reported.date_reported desc + ) + group by + who_import.date_reported + order by + who_import.date_reported desc """ new_dates = [] for item in db.session.execute(sql_query):