MEDfl 0.2.1__py3-none-any.whl → 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- MEDfl/LearningManager/__init__.py +13 -13
- MEDfl/LearningManager/client.py +150 -181
- MEDfl/LearningManager/dynamicModal.py +287 -287
- MEDfl/LearningManager/federated_dataset.py +60 -60
- MEDfl/LearningManager/flpipeline.py +192 -192
- MEDfl/LearningManager/model.py +223 -223
- MEDfl/LearningManager/params.yaml +14 -14
- MEDfl/LearningManager/params_optimiser.py +442 -442
- MEDfl/LearningManager/plot.py +229 -229
- MEDfl/LearningManager/server.py +181 -189
- MEDfl/LearningManager/strategy.py +82 -138
- MEDfl/LearningManager/utils.py +331 -331
- MEDfl/NetManager/__init__.py +10 -10
- MEDfl/NetManager/database_connector.py +43 -43
- MEDfl/NetManager/dataset.py +92 -92
- MEDfl/NetManager/flsetup.py +320 -320
- MEDfl/NetManager/net_helper.py +254 -254
- MEDfl/NetManager/net_manager_queries.py +142 -142
- MEDfl/NetManager/network.py +194 -194
- MEDfl/NetManager/node.py +184 -184
- MEDfl/__init__.py +2 -2
- MEDfl/scripts/__init__.py +1 -1
- MEDfl/scripts/base.py +29 -29
- MEDfl/scripts/create_db.py +126 -126
- Medfl/LearningManager/__init__.py +13 -0
- Medfl/LearningManager/client.py +150 -0
- Medfl/LearningManager/dynamicModal.py +287 -0
- Medfl/LearningManager/federated_dataset.py +60 -0
- Medfl/LearningManager/flpipeline.py +192 -0
- Medfl/LearningManager/model.py +223 -0
- Medfl/LearningManager/params.yaml +14 -0
- Medfl/LearningManager/params_optimiser.py +442 -0
- Medfl/LearningManager/plot.py +229 -0
- Medfl/LearningManager/server.py +181 -0
- Medfl/LearningManager/strategy.py +82 -0
- Medfl/LearningManager/utils.py +331 -0
- Medfl/NetManager/__init__.py +10 -0
- Medfl/NetManager/database_connector.py +43 -0
- Medfl/NetManager/dataset.py +92 -0
- Medfl/NetManager/flsetup.py +320 -0
- Medfl/NetManager/net_helper.py +254 -0
- Medfl/NetManager/net_manager_queries.py +142 -0
- Medfl/NetManager/network.py +194 -0
- Medfl/NetManager/node.py +184 -0
- Medfl/__init__.py +3 -0
- Medfl/scripts/__init__.py +2 -0
- Medfl/scripts/base.py +30 -0
- Medfl/scripts/create_db.py +126 -0
- alembic/env.py +61 -61
- {MEDfl-0.2.1.dist-info → medfl-2.0.0.dist-info}/METADATA +120 -108
- medfl-2.0.0.dist-info/RECORD +55 -0
- {MEDfl-0.2.1.dist-info → medfl-2.0.0.dist-info}/WHEEL +1 -1
- {MEDfl-0.2.1.dist-info → medfl-2.0.0.dist-info/licenses}/LICENSE +674 -674
- MEDfl-0.2.1.dist-info/RECORD +0 -31
- {MEDfl-0.2.1.dist-info → medfl-2.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,331 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
|
3
|
+
import pkg_resources
|
4
|
+
import torch
|
5
|
+
import yaml
|
6
|
+
from sklearn.metrics import *
|
7
|
+
from yaml.loader import SafeLoader
|
8
|
+
|
9
|
+
|
10
|
+
from MEDfl.NetManager.database_connector import DatabaseManager
|
11
|
+
|
12
|
+
# from scripts.base import *
|
13
|
+
import json
|
14
|
+
|
15
|
+
|
16
|
+
import pandas as pd
|
17
|
+
import numpy as np
|
18
|
+
|
19
|
+
import os
|
20
|
+
import configparser
|
21
|
+
|
22
|
+
import subprocess
|
23
|
+
import ast
|
24
|
+
|
25
|
+
from sqlalchemy import text
|
26
|
+
|
27
|
+
|
28
|
+
# Get the directory of the current script
|
29
|
+
current_directory = os.path.dirname(os.path.abspath(__file__))
|
30
|
+
|
31
|
+
# Load configuration from the config file
|
32
|
+
yaml_path = os.path.join(current_directory, 'params.yaml')
|
33
|
+
|
34
|
+
with open(yaml_path) as g:
|
35
|
+
params = yaml.load(g, Loader=SafeLoader)
|
36
|
+
|
37
|
+
# global_yaml_path = pkg_resources.resource_filename(__name__, "../../global_params.yaml")
|
38
|
+
# with open(global_yaml_path) as g:
|
39
|
+
# global_params = yaml.load(g, Loader=SafeLoader)
|
40
|
+
|
41
|
+
|
42
|
+
# Default path for the config file
|
43
|
+
DEFAULT_CONFIG_PATH = 'db_config.ini'
|
44
|
+
|
45
|
+
|
46
|
+
def load_db_config_dep():
|
47
|
+
config = os.environ.get('MEDfl_DB_CONFIG')
|
48
|
+
|
49
|
+
if config:
|
50
|
+
return ast.literal_eval(config)
|
51
|
+
else:
|
52
|
+
raise ValueError(f"MEDfl db config not found")
|
53
|
+
|
54
|
+
# Function to allow users to set config path programmatically
|
55
|
+
|
56
|
+
|
57
|
+
def set_db_config_dep(config_path):
|
58
|
+
config = configparser.ConfigParser()
|
59
|
+
config.read(config_path)
|
60
|
+
if (config['sqllite']):
|
61
|
+
os.environ['MEDfl_DB_CONFIG'] = str(dict(config['sqllite']))
|
62
|
+
else:
|
63
|
+
raise ValueError(f"mysql key not found in file '{config_path}'")
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
def load_db_config():
|
68
|
+
"""Read a dictionary from an environment variable."""
|
69
|
+
obj_str = os.getenv("MEDfl_DB_CONFIG")
|
70
|
+
if obj_str is not None:
|
71
|
+
return ast.literal_eval(obj_str)
|
72
|
+
else:
|
73
|
+
raise ValueError(f"Environment variable MEDfl_DB_CONFIG not found")
|
74
|
+
|
75
|
+
# Function to allow users to set config path programmatically
|
76
|
+
|
77
|
+
|
78
|
+
def set_db_config(config_path):
|
79
|
+
obj = {"database" : config_path}
|
80
|
+
|
81
|
+
"""Store a dictionary as a string in an environment variable."""
|
82
|
+
obj_str = str(obj)
|
83
|
+
os.environ['MEDfl_DB_CONFIG'] = obj_str
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
# Create databas
|
91
|
+
|
92
|
+
|
93
|
+
def create_MEDfl_db():
|
94
|
+
script_path = os.path.join(os.path.dirname(
|
95
|
+
__file__), 'scripts', 'create_db.sh')
|
96
|
+
subprocess.run(['sh', script_path], check=True)
|
97
|
+
|
98
|
+
|
99
|
+
def custom_classification_report(y_true, y_pred_prob):
|
100
|
+
"""
|
101
|
+
Compute custom classification report metrics including accuracy, sensitivity, specificity, precision, NPV,
|
102
|
+
F1-score, false positive rate, and true positive rate.
|
103
|
+
|
104
|
+
Args:
|
105
|
+
y_true (array-like): True labels.
|
106
|
+
y_pred (array-like): Predicted labels.
|
107
|
+
|
108
|
+
Returns:
|
109
|
+
dict: A dictionary containing custom classification report metrics.
|
110
|
+
"""
|
111
|
+
y_pred = (y_pred_prob).round(
|
112
|
+
) # Round absolute values of predicted probabilities to the nearest integer
|
113
|
+
|
114
|
+
auc = roc_auc_score(y_true, y_pred_prob) # Calculate AUC
|
115
|
+
|
116
|
+
tn, fp, fn, tp = confusion_matrix(y_true, y_pred).ravel()
|
117
|
+
|
118
|
+
# Accuracy
|
119
|
+
denominator_acc = tp + tn + fp + fn
|
120
|
+
acc = (tp + tn) / denominator_acc if denominator_acc != 0 else 0.0
|
121
|
+
|
122
|
+
# Sensitivity/Recall
|
123
|
+
denominator_sen = tp + fn
|
124
|
+
sen = tp / denominator_sen if denominator_sen != 0 else 0.0
|
125
|
+
|
126
|
+
# Specificity
|
127
|
+
denominator_sp = tn + fp
|
128
|
+
sp = tn / denominator_sp if denominator_sp != 0 else 0.0
|
129
|
+
|
130
|
+
# PPV/Precision
|
131
|
+
denominator_ppv = tp + fp
|
132
|
+
ppv = tp / denominator_ppv if denominator_ppv != 0 else 0.0
|
133
|
+
|
134
|
+
# NPV
|
135
|
+
denominator_npv = tn + fn
|
136
|
+
npv = tn / denominator_npv if denominator_npv != 0 else 0.0
|
137
|
+
|
138
|
+
# F1 Score
|
139
|
+
denominator_f1 = sen + ppv
|
140
|
+
f1 = 2 * (sen * ppv) / denominator_f1 if denominator_f1 != 0 else 0.0
|
141
|
+
|
142
|
+
# False Positive Rate
|
143
|
+
denominator_fpr = fp + tn
|
144
|
+
fpr = fp / denominator_fpr if denominator_fpr != 0 else 0.0
|
145
|
+
|
146
|
+
# True Positive Rate
|
147
|
+
denominator_tpr = tp + fn
|
148
|
+
tpr = tp / denominator_tpr if denominator_tpr != 0 else 0.0
|
149
|
+
|
150
|
+
return {
|
151
|
+
"confusion matrix": {"TP": tp, "FP": fp, "FN": fn, "TN": tn},
|
152
|
+
"Accuracy": round(acc, 3),
|
153
|
+
"Sensitivity/Recall": round(sen, 3),
|
154
|
+
"Specificity": round(sp, 3),
|
155
|
+
"PPV/Precision": round(ppv, 3),
|
156
|
+
"NPV": round(npv, 3),
|
157
|
+
"F1-score": round(f1, 3),
|
158
|
+
"False positive rate": round(fpr, 3),
|
159
|
+
"True positive rate": round(tpr, 3),
|
160
|
+
"auc": auc
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
def test(model, test_loader, device=torch.device("cpu")):
|
165
|
+
"""
|
166
|
+
Evaluate a model using a test loader and return a custom classification report.
|
167
|
+
|
168
|
+
Args:
|
169
|
+
model (torch.nn.Module): PyTorch model to evaluate.
|
170
|
+
test_loader (torch.utils.data.DataLoader): DataLoader for the test dataset.
|
171
|
+
device (torch.device, optional): Device for model evaluation. Default is "cpu".
|
172
|
+
|
173
|
+
Returns:
|
174
|
+
dict: A dictionary containing custom classification report metrics.
|
175
|
+
"""
|
176
|
+
|
177
|
+
model.eval()
|
178
|
+
with torch.no_grad():
|
179
|
+
X_test, y_test = test_loader.dataset[:][0].to(
|
180
|
+
device), test_loader.dataset[:][1].to(device)
|
181
|
+
y_hat_prob = torch.squeeze(model(X_test), 1).cpu()
|
182
|
+
|
183
|
+
return custom_classification_report(y_test.cpu().numpy(), y_hat_prob.cpu().numpy())
|
184
|
+
|
185
|
+
|
186
|
+
column_map = {"object": "VARCHAR(255)", "int64": "INT", "float64": "FLOAT"}
|
187
|
+
|
188
|
+
|
189
|
+
def empty_db():
|
190
|
+
"""
|
191
|
+
Empty the database by deleting records from multiple tables and resetting auto-increment counters.
|
192
|
+
|
193
|
+
Returns:
|
194
|
+
None
|
195
|
+
"""
|
196
|
+
db_manager = DatabaseManager()
|
197
|
+
db_manager.connect()
|
198
|
+
my_eng = db_manager.get_connection()
|
199
|
+
|
200
|
+
# my_eng.execute(text(f"DELETE FROM {'DataSets'}"))
|
201
|
+
my_eng.execute(text(f"DELETE FROM {'Nodes'}"))
|
202
|
+
my_eng.execute(text(f"DELETE FROM {'FedDatasets'}"))
|
203
|
+
my_eng.execute(text(f"DELETE FROM {'Networks'}"))
|
204
|
+
my_eng.execute(text(f"DELETE FROM {'FLsetup'}"))
|
205
|
+
|
206
|
+
my_eng.execute(text(f"DELETE FROM {'FLpipeline'}"))
|
207
|
+
my_eng.execute(text(f"ALTER TABLE {'Nodes'} AUTO_INCREMENT = 1"))
|
208
|
+
my_eng.execute(text(f"ALTER TABLE {'Networks'} AUTO_INCREMENT = 1"))
|
209
|
+
my_eng.execute(text(f"ALTER TABLE {'FedDatasets'} AUTO_INCREMENT = 1"))
|
210
|
+
my_eng.execute(text(f"ALTER TABLE {'FLsetup'} AUTO_INCREMENT = 1"))
|
211
|
+
my_eng.execute(text(f"ALTER TABLE {'FLpipeline'} AUTO_INCREMENT = 1"))
|
212
|
+
my_eng.execute(text(f"DELETE FROM {'testResults'}"))
|
213
|
+
my_eng.execute(text(f"DROP TABLE IF EXISTS {'MasterDataset'}"))
|
214
|
+
my_eng.execute(text(f"DROP TABLE IF EXISTS {'DataSets'}"))
|
215
|
+
|
216
|
+
|
217
|
+
def get_pipeline_from_name(name):
|
218
|
+
"""
|
219
|
+
Get the pipeline ID from its name in the database.
|
220
|
+
|
221
|
+
Args:
|
222
|
+
name (str): Name of the pipeline.
|
223
|
+
|
224
|
+
Returns:
|
225
|
+
int: ID of the pipeline.
|
226
|
+
"""
|
227
|
+
db_manager = DatabaseManager()
|
228
|
+
db_manager.connect()
|
229
|
+
my_eng = db_manager.get_connection()
|
230
|
+
|
231
|
+
NodeId = int(
|
232
|
+
pd.read_sql(
|
233
|
+
text(f"SELECT id FROM FLpipeline WHERE name = '{name}'"), my_eng
|
234
|
+
).iloc[0, 0]
|
235
|
+
)
|
236
|
+
return NodeId
|
237
|
+
|
238
|
+
|
239
|
+
def get_pipeline_confusion_matrix(pipeline_id):
|
240
|
+
"""
|
241
|
+
Get the global confusion matrix for a pipeline based on test results.
|
242
|
+
|
243
|
+
Args:
|
244
|
+
pipeline_id (int): ID of the pipeline.
|
245
|
+
|
246
|
+
Returns:
|
247
|
+
dict: A dictionary representing the global confusion matrix.
|
248
|
+
"""
|
249
|
+
db_manager = DatabaseManager()
|
250
|
+
db_manager.connect()
|
251
|
+
my_eng = db_manager.get_connection()
|
252
|
+
|
253
|
+
data = pd.read_sql(
|
254
|
+
text(
|
255
|
+
f"SELECT confusionmatrix FROM testResults WHERE pipelineid = '{pipeline_id}'"), my_eng
|
256
|
+
)
|
257
|
+
|
258
|
+
# Convert the column of strings into a list of dictionaries representing confusion matrices
|
259
|
+
confusion_matrices = [
|
260
|
+
json.loads(matrix.replace("'", "\"")) for matrix in data['confusionmatrix']
|
261
|
+
]
|
262
|
+
|
263
|
+
# Initialize variables for global confusion matrix
|
264
|
+
global_TP = global_FP = global_FN = global_TN = 0
|
265
|
+
|
266
|
+
# Iterate through each dictionary and sum the corresponding values for each category
|
267
|
+
for matrix in confusion_matrices:
|
268
|
+
global_TP += matrix['TP']
|
269
|
+
global_FP += matrix['FP']
|
270
|
+
global_FN += matrix['FN']
|
271
|
+
global_TN += matrix['TN']
|
272
|
+
|
273
|
+
# Create a global confusion matrix as a dictionary
|
274
|
+
global_confusion_matrix = {
|
275
|
+
'TP': global_TP,
|
276
|
+
'FP': global_FP,
|
277
|
+
'FN': global_FN,
|
278
|
+
'TN': global_TN
|
279
|
+
}
|
280
|
+
# Return the list of dictionaries representing confusion matrices
|
281
|
+
return global_confusion_matrix
|
282
|
+
|
283
|
+
|
284
|
+
def get_node_confusion_matrix(pipeline_id, node_name):
|
285
|
+
"""
|
286
|
+
Get the confusion matrix for a specific node in a pipeline based on test results.
|
287
|
+
|
288
|
+
Args:
|
289
|
+
pipeline_id (int): ID of the pipeline.
|
290
|
+
node_name (str): Name of the node.
|
291
|
+
|
292
|
+
Returns:
|
293
|
+
dict: A dictionary representing the confusion matrix for the specified node.
|
294
|
+
"""
|
295
|
+
db_manager = DatabaseManager()
|
296
|
+
db_manager.connect()
|
297
|
+
my_eng = db_manager.get_connection()
|
298
|
+
|
299
|
+
data = pd.read_sql(
|
300
|
+
text(
|
301
|
+
f"SELECT confusionmatrix FROM testResults WHERE pipelineid = '{pipeline_id}' AND nodename = '{node_name}'"), my_eng
|
302
|
+
)
|
303
|
+
|
304
|
+
# Convert the column of strings into a list of dictionaries representing confusion matrices
|
305
|
+
confusion_matrices = [
|
306
|
+
json.loads(matrix.replace("'", "\"")) for matrix in data['confusionmatrix']
|
307
|
+
]
|
308
|
+
|
309
|
+
# Return the list of dictionaries representing confusion matrices
|
310
|
+
return confusion_matrices[0]
|
311
|
+
|
312
|
+
|
313
|
+
def get_pipeline_result(pipeline_id):
|
314
|
+
"""
|
315
|
+
Get the test results for a pipeline.
|
316
|
+
|
317
|
+
Args:
|
318
|
+
pipeline_id (int): ID of the pipeline.
|
319
|
+
|
320
|
+
Returns:
|
321
|
+
pandas.DataFrame: DataFrame containing test results for the specified pipeline.
|
322
|
+
"""
|
323
|
+
db_manager = DatabaseManager()
|
324
|
+
db_manager.connect()
|
325
|
+
my_eng = db_manager.get_connection()
|
326
|
+
|
327
|
+
data = pd.read_sql(
|
328
|
+
text(
|
329
|
+
f"SELECT * FROM testResults WHERE pipelineid = '{pipeline_id}'"), my_eng
|
330
|
+
)
|
331
|
+
return data
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# # MEDfl/NetworkManager/__init__.py
|
2
|
+
|
3
|
+
# # Import modules from this package
|
4
|
+
# from .dataset import *
|
5
|
+
# from .flsetup import *
|
6
|
+
# from .net_helper import *
|
7
|
+
# from .net_manager_queries import *
|
8
|
+
# from .network import *
|
9
|
+
# from .node import *
|
10
|
+
# from .database_connector import *
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import os
|
2
|
+
import subprocess
|
3
|
+
from sqlalchemy import create_engine
|
4
|
+
from configparser import ConfigParser
|
5
|
+
|
6
|
+
class DatabaseManager:
|
7
|
+
def __init__(self):
|
8
|
+
from MEDfl.LearningManager.utils import load_db_config
|
9
|
+
db_config = load_db_config()
|
10
|
+
if db_config:
|
11
|
+
self.config = db_config
|
12
|
+
else:
|
13
|
+
self.config = None
|
14
|
+
self.engine = None
|
15
|
+
|
16
|
+
def connect(self):
|
17
|
+
if not self.config:
|
18
|
+
raise ValueError("Database configuration not loaded. Use load_db_config() or set_config_path() first.")
|
19
|
+
# Assuming the SQLite database file path is provided in the config with the key 'database'
|
20
|
+
database_path = self.config['database']
|
21
|
+
connection_string = f"sqlite:///{database_path}"
|
22
|
+
self.engine = create_engine(connection_string, pool_pre_ping=True)
|
23
|
+
|
24
|
+
def get_connection(self):
|
25
|
+
if not self.engine:
|
26
|
+
self.connect()
|
27
|
+
return self.engine.connect()
|
28
|
+
|
29
|
+
def create_MEDfl_db(self, path_to_csv):
|
30
|
+
# Get the directory of the current script
|
31
|
+
current_directory = os.path.dirname(__file__)
|
32
|
+
|
33
|
+
# Define the path to the create_db.py script
|
34
|
+
create_db_script_path = os.path.join(current_directory, '..', 'scripts', 'create_db.py')
|
35
|
+
|
36
|
+
# Execute the create_db.py script
|
37
|
+
subprocess.run(['python', create_db_script_path, path_to_csv], check=True)
|
38
|
+
|
39
|
+
return
|
40
|
+
|
41
|
+
def close(self):
|
42
|
+
if self.engine:
|
43
|
+
self.engine.dispose()
|
@@ -0,0 +1,92 @@
|
|
1
|
+
import pandas as pd
|
2
|
+
from sqlalchemy import text
|
3
|
+
|
4
|
+
from .net_helper import *
|
5
|
+
from .net_manager_queries import (DELETE_DATASET, INSERT_DATASET,
|
6
|
+
SELECT_ALL_DATASET_NAMES)
|
7
|
+
from MEDfl.NetManager.database_connector import DatabaseManager
|
8
|
+
|
9
|
+
class DataSet:
|
10
|
+
def __init__(self, name: str, path: str, engine=None):
|
11
|
+
"""
|
12
|
+
Initialize a DataSet object.
|
13
|
+
|
14
|
+
:param name: The name of the dataset.
|
15
|
+
:type name: str
|
16
|
+
:param path: The file path of the dataset CSV file.
|
17
|
+
:type path: str
|
18
|
+
"""
|
19
|
+
self.name = name
|
20
|
+
self.path = path
|
21
|
+
db_manager = DatabaseManager()
|
22
|
+
db_manager.connect()
|
23
|
+
self.engine = db_manager.get_connection()
|
24
|
+
|
25
|
+
def validate(self):
|
26
|
+
"""
|
27
|
+
Validate name and path attributes.
|
28
|
+
|
29
|
+
:raises TypeError: If name or path is not a string.
|
30
|
+
"""
|
31
|
+
if not isinstance(self.name, str):
|
32
|
+
raise TypeError("name argument must be a string")
|
33
|
+
|
34
|
+
if not isinstance(self.path, str):
|
35
|
+
raise TypeError("path argument must be a string")
|
36
|
+
|
37
|
+
def upload_dataset(self, NodeId=-1):
|
38
|
+
"""
|
39
|
+
Upload the dataset to the database.
|
40
|
+
|
41
|
+
:param NodeId: The NodeId associated with the dataset.
|
42
|
+
:type NodeId: int
|
43
|
+
|
44
|
+
Notes:
|
45
|
+
- Assumes the file at self.path is a valid CSV file.
|
46
|
+
- The dataset is uploaded to the 'DataSets' table in the database.
|
47
|
+
"""
|
48
|
+
|
49
|
+
data_df = pd.read_csv(self.path)
|
50
|
+
nodeId = NodeId
|
51
|
+
columns = data_df.columns.tolist()
|
52
|
+
|
53
|
+
|
54
|
+
data_df = process_eicu(data_df)
|
55
|
+
for index, row in data_df.iterrows():
|
56
|
+
query_1 = "INSERT INTO DataSets(DataSetName,nodeId," + "".join(
|
57
|
+
f"{x}," for x in columns
|
58
|
+
)
|
59
|
+
query_2 = f" VALUES ('{self.name}',{nodeId}, " + "".join(
|
60
|
+
f"{is_str(data_df, row, x)}," for x in columns
|
61
|
+
)
|
62
|
+
query = query_1[:-1] + ")" + query_2[:-1] + ")"
|
63
|
+
|
64
|
+
self.engine.execute(text(query))
|
65
|
+
|
66
|
+
def delete_dataset(self):
|
67
|
+
"""
|
68
|
+
Delete the dataset from the database.
|
69
|
+
|
70
|
+
Notes:
|
71
|
+
- Assumes the dataset name is unique in the 'DataSets' table.
|
72
|
+
"""
|
73
|
+
self.engine.execute(text(DELETE_DATASET), {"name": self.name})
|
74
|
+
|
75
|
+
def update_data(self):
|
76
|
+
"""
|
77
|
+
Update the data in the dataset.
|
78
|
+
|
79
|
+
Not implemented yet.
|
80
|
+
"""
|
81
|
+
pass
|
82
|
+
|
83
|
+
@staticmethod
|
84
|
+
def list_alldatasets(engine):
|
85
|
+
"""
|
86
|
+
List all dataset names from the 'DataSets' table.
|
87
|
+
|
88
|
+
:returns: A DataFrame containing the names of all datasets in the 'DataSets' table.
|
89
|
+
:rtype: pd.DataFrame
|
90
|
+
"""
|
91
|
+
res = pd.read_sql(text(SELECT_ALL_DATASET_NAMES), engine)
|
92
|
+
return res
|