-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_initialisation.py
46 lines (37 loc) · 1.22 KB
/
db_initialisation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#-------------------save to data base-----------------
import sqlite3
import json
import numpy as np
def init_table():
conn = sqlite3.connect("data/test_data.db")
cursor = conn.cursor()
# Activer les clés étrangères
cursor.execute('''PRAGMA foreign_keys = ON;''')
cursor.execute(f"DROP TABLE IF EXISTS test_data;")
# Créer la table test_data
query = """ CREATE TABLE test_data (
matrice_id TEXT,
data TEXT,
label TEXT,
PRIMARY KEY (matrice_id)
)"""
cursor.execute(query)
# Valider les changements
conn.commit()
cursor.close()
conn.close()
def load_data():
conn = sqlite3.connect("data/test_data.db")
cursor = conn.cursor()
query = """SELECT data,label FROM test_data"""
cursor.execute(query)
data_label_pairs= cursor.fetchall()
# Fermer la connexion à la base de données
cursor.close()
conn.close()
# Convertir les données JSON en ndarray
X_test = np.array([np.array(json.loads(data)) for data, label in data_label_pairs])
y_test = np.array([np.array(json.loads(label)) for data, label in data_label_pairs])
return X_test,y_test
X_test,y_test=load_data()
print(X_test[0]," label est ", y_test[0])