From 05a441e19b9f065050074cf0da2363f936aa5d78 Mon Sep 17 00:00:00 2001
From: thomaswoehlke <thomas.woehlke@gmail.com>
Date: Mon, 8 Feb 2021 22:02:37 +0100
Subject: [PATCH] start DEV 0.0.15

---
 .../blueprints/rki/rki_model_import.py        | 42 +++++++-------
 .../vaccination/vaccination_model_import.py   | 30 ++++++----
 .../blueprints/who/who_model_import.py        | 57 ++++++++++++-------
 3 files changed, 78 insertions(+), 51 deletions(-)

diff --git a/src/covid19/blueprints/rki/rki_model_import.py b/src/covid19/blueprints/rki/rki_model_import.py
index 280ea122..08f39842 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 17d80dc8..7818212b 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 a7924118..35dbe0b0 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):
-- 
GitLab