kora 1 year ago
parent
commit
cb674a82e7
2 changed files with 9 additions and 14 deletions
  1. 0 1
      .~lock.Techman 4.doc#
  2. 9 13
      test_suite/tests_kora_misc/Query_speed/queries.py

+ 0 - 1
.~lock.Techman 4.doc#

@@ -1 +0,0 @@
-,DESKTOP-2CBLQ8B/Kora,,18.05.2023 17:12,file:///C:/Users/Kora/AppData/Roaming/OfficeDocOpener/4;

+ 9 - 13
test_suite/tests_kora_misc/Query_speed/queries.py

@@ -102,9 +102,9 @@ db_results_decode_pandas(results2, vettSpec)
 print(time.time() - timestamp0)
 # %%
 # Dump dei risultati
-with open('DeResult.json', 'w') as file1:
-    results2Dict = json.loads(results2.to_json(orient='records'))
-    json.dump(results2Dict, file1, indent=2)
+#with open('DeResult.json', 'w') as file1:
+#    results2Dict = json.loads(results2.to_json(orient='records'))
+#    json.dump(results2Dict, file1, indent=2)
 # %%
 # Still 30 seconds!
 timestamp0 = time.time()
@@ -142,10 +142,8 @@ with sqlite3.connect(f"file:{dbFile}?mode=ro", uri=True) as connection:
     cur = connection.cursor()
     for index, row in results2Simp2.iterrows():
         ntx = row['ntx']
-        indlem = row['indlem']
         prevMappa = row['mappa'] - 15
-        nextMappa = row['mappa'] + 15
-        cur.execute(f'SELECT prev_tab.pitxt AS piniz FROM Occ00001 AS prev_tab, periodi WHERE prev_tab.ntx = {ntx} AND prev_tab.indlem = {indlem} AND prev_tab.mappa = {prevMappa}')
+        cur.execute(f'SELECT prev_tab.pitxt AS piniz FROM Occ00001 AS prev_tab WHERE prev_tab.ntx = {ntx} AND prev_tab.mappa = {prevMappa}')
         res = cur.fetchone()
         piniz.append(res[0] if res is not None else None)
 
@@ -154,14 +152,12 @@ print(time.time() - timestamp0)
 timestamp0 = time.time()
 with sqlite3.connect(f"file:{dbFile}?mode=ro", uri=True) as connection:
     tmpQuery = theQuerySimp2(','.join(codesStr), ','.join(formCodesStr))
+    querr = 'CREATE TEMPORARY TABLE stuff AS ' + tmpQuery
+    connection.execute(querr)
+    riQuery = "SELECT * FROM stuff LEFT JOIN Occ00001 AS prev_tab ON prev_tab.ntx = stuff.ntx AND prev_tab.mappa = stuff.mappa - 15"
     results2Simp2 = pd.read_sql(tmpQuery, connection)
-    piniz = []
-    strList = []
-    for index, row in results2Simp2.iterrows():
-        ntx = row['ntx']
-        prevMappa = row['mappa'] - 15
-        strList.append( f'(prev_tab.ntx = {ntx} AND prev_tab.mappa = {prevMappa})' )
-    pazzi = '(' + ' OR '.join(strList) + ')'
+
+print(time.time() - timestamp0)
 # %%
 with sqlite3.connect(f"file:{dbFile}?mode=ro", uri=True) as connection:
     cur = connection.cursor()