From 8e1f13fcc5aefa92a809f5511f9940dd17eafcd0 Mon Sep 17 00:00:00 2001
From: Pierre-Gilles Levallois <pierregilles.levallois@gmail.com>
Date: Wed, 29 Mar 2023 16:57:37 +0200
Subject: [PATCH] Bugfixes on getProcess' conversions

---
 Dockerfiles/python/scripts/main.py  | 4 ++--
 Dockerfiles/python/scripts/utils.py | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Dockerfiles/python/scripts/main.py b/Dockerfiles/python/scripts/main.py
index 8e3febb..d22d078 100644
--- a/Dockerfiles/python/scripts/main.py
+++ b/Dockerfiles/python/scripts/main.py
@@ -652,8 +652,8 @@ def computeFactors(inseeCode=None):
 
         # queryFactorAndInsee = "SELECT count(*) FROM base.tiles_factors tf INNER JOIN base.tiles t ON tf.id_tile = t.id AND t.insee = '{}' WHERE id_factor = {};".format(inseeCode, currFactorID)
         # currTFDataFAI = getDatafromDB(DB_params, queryFactorAndInsee)
-        currTFDataFAI = getProgress(cur, DB_schema, inseeCode, currFactorID)
-        currTFDataCount = json.loads(currTFDataFAI)[0]['count']
+        currTFDataCount = getProgress(cur, DB_schema, inseeCode, currFactorID)
+        # currTFDataCount = json.loads(currTFDataFAI)[0]['count']
 
         # if inseeCode:
         #     # Check TILES_FACTORS existing data (with insee)
diff --git a/Dockerfiles/python/scripts/utils.py b/Dockerfiles/python/scripts/utils.py
index bf86588..242f264 100644
--- a/Dockerfiles/python/scripts/utils.py
+++ b/Dockerfiles/python/scripts/utils.py
@@ -827,8 +827,8 @@ def setProgress(DBcursor, DBSchema, codeInsee, id_factor=None):
         qryFilter = ' and id_factor = ' + id_factor
         insertComplement = ', ' + id_factor
     # Ensure there is only one occurence for the township
-    DBcursor.execute('DELETE FROM ' + DBSchema + '.' + stage + '_progress WHERE codeInsee = ' + codeInsee + qryFilter)
-    insertDataInDB(DBcursor,'INSERT INTO ' + stage + '_progress VALUES (' + codeInsee + insertComplement + ')')
+    DBcursor.execute('DELETE FROM ' + DBSchema + '.' + stage + '_progress WHERE insee = ' + codeInsee + qryFilter)
+    insertDataInDB(DBcursor,'INSERT INTO ' + DBSchema + '.' + stage + '_progress VALUES (' + codeInsee + insertComplement + ')')
 
 def getProgress(DBcursor, DBSchema, codeInsee, id_factor=None):
     stage = 'tiles'
@@ -837,5 +837,5 @@ def getProgress(DBcursor, DBSchema, codeInsee, id_factor=None):
         stage = 'factors'
         qryFilter = ' and id_factor = ' + id_factor
     DBcursor.execute('SELECT count(1) FROM '+ DBSchema + '.'  + stage + '_progress WHERE insee = ' + codeInsee + qryFilter)
-    dataValues = json.dumps(DBcursor.fetchall(), indent=2, default=dateConverter)
+    dataValues = json.loads(json.dumps(DBcursor.fetchall(), indent=2, default=dateConverter))[0][0]
     return dataValues
-- 
GitLab