소스 검색

decoding, decoding

kora 1 년 전
부모
커밋
3afc6ffab6
2개의 변경된 파일82개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 2
      test_suite/tests_kora_misc/Query_speed/decoding/vettSpec.csv
  2. 81 1
      test_suite/tests_kora_misc/Query_speed/queries_2.py

+ 1 - 2
test_suite/tests_kora_misc/Query_speed/decoding/vettSpec.csv

@@ -1037,8 +1037,7 @@ intcode,unicode
 30001,AA
 30002,BA
 30003,194
-30004,"195
-195"
+30004,195
 30005,196
 30006,19B
 30007,1A2

+ 81 - 1
test_suite/tests_kora_misc/Query_speed/queries_2.py

@@ -4,7 +4,7 @@ import sqlite3
 import pandas as pd
 import time
 
-from decoding.decoding import getVettSpec, db_results_decode_pandas, db_results_decode, db_results_decode_nodict, db_encode
+from decoding.decoding import getVettSpec, db_results_decode_pandas, db_results_decode, db_results_decode_nodict, db_encode, isColumnToDecode
 
 # Rifattorizzazione della routine 'findtext', per recuperare i contesti dal DB di Gatto4.
 # Per semplificare, la ricerca principale è limitata alla prima table di occorrenze -- Occ00001
@@ -170,3 +170,83 @@ cond2 = ((listatesti['mappa'] - listatesti[f'mappa_{cod}']) != 0) & ((listatesti
 # %%
 listatesti = listatesti[cond1 & cond2]
 # %%
+# %%
+# Better decoding?
+vettSpec
+# %%
+print('The first one:', chr(int(vettSpec[0]['unicode'], 16)) )
+print('... is a newline')
+
+for index, entry in enumerate(vettSpec):
+    try:
+        print(index+1, chr(int(entry['intcode'])), chr(int(entry['unicode'], 16)))
+    except Exception as err:
+        print(index+1, err)
+        if(index>0):
+            break
+
+print('Total:', len(vettSpec))
+
+# %%
+timestamp0 = time.time()
+vettDictDec = {}
+vettDictEnc = {}
+for index, entry in enumerate(vettSpec):
+    try:
+        vettDictDec[chr(int(entry['intcode']))] = chr(int(entry['unicode'], 16))
+        vettDictEnc[chr(int(entry['unicode'], 16))] = chr(int(entry['intcode']))
+    except Exception as err:
+        print(index+1, err)
+        if(index>0):
+            break
+
+timestamp1 = time.time()
+print(timestamp1 - timestamp0)
+# %%
+timestamp0 = time.time()
+str0 = 'c%'
+strEnc0 = db_encode(vettSpec, str0)
+
+queryString0 = firstQueryL(strEnc0)
+
+with sqlite3.connect(f"file:{dbFile}?mode=ro", uri=True) as connection:
+    connection.row_factory = dict_factory
+    queryReponse = connection.cursor().execute(queryString0)
+    lemsNoPandas0 = queryReponse.fetchall()
+db_results_decode(lemsNoPandas0, vettSpec)
+
+timestamp1 = time.time()
+print(timestamp1 - timestamp0)
+# %%
+def db_decodeB(string):
+    return ''.join([vettDictDec[char] for char in string])
+
+def db_results_decodeB(result):
+    keysToTest = [key for key in result[0].keys() if isColumnToDecode(key)]
+    for row in result:
+        for key in keysToTest:
+            row[key] = db_decodeB(row[key])
+    return result
+# %%
+lemsNoPandas0[0:1]
+db_results_decodeB(lemsNoPandas0[0:1])
+lemsNoPandas0[0:1]
+# %%
+# %%
+timestamp0 = time.time()
+str0 = 'c%'
+strEnc0 = db_encode(vettSpec, str0)
+
+queryString0 = firstQueryL(strEnc0)
+
+with sqlite3.connect(f"file:{dbFile}?mode=ro", uri=True) as connection:
+    connection.row_factory = dict_factory
+    queryReponse = connection.cursor().execute(queryString0)
+    lemsNoPandas0 = queryReponse.fetchall()
+
+db_results_decodeB(lemsNoPandas0)
+
+timestamp1 = time.time()
+print(timestamp1 - timestamp0)
+# IT WORKZ!
+# %%