MEDfl 0.1.7__py3-none-any.whl → 0.1.16__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 -150
- Medfl/LearningManager/dynamicModal.py +287 -287
- Medfl/LearningManager/federated_dataset.py +60 -57
- Medfl/LearningManager/flpipeline.py +192 -189
- Medfl/LearningManager/model.py +223 -223
- Medfl/LearningManager/params.yaml +14 -0
- Medfl/LearningManager/params_optimiser.py +442 -442
- Medfl/LearningManager/plot.py +229 -229
- Medfl/LearningManager/server.py +179 -179
- Medfl/LearningManager/strategy.py +82 -82
- Medfl/LearningManager/utils.py +311 -233
- Medfl/NetManager/__init__.py +9 -9
- Medfl/NetManager/database_connector.py +50 -0
- Medfl/NetManager/dataset.py +92 -91
- Medfl/NetManager/flsetup.py +320 -304
- Medfl/NetManager/net_helper.py +264 -243
- Medfl/NetManager/net_manager_queries.py +137 -137
- Medfl/NetManager/network.py +168 -160
- Medfl/NetManager/node.py +187 -181
- Medfl/__init__.py +1 -1
- {Medfl-0.1.7.data → Medfl-0.1.16.data}/scripts/setup_mysql.sh +22 -22
- {Medfl-0.1.7.dist-info → Medfl-0.1.16.dist-info}/METADATA +127 -127
- Medfl-0.1.16.dist-info/RECORD +32 -0
- alembic/env.py +61 -61
- scripts/base.py +29 -29
- scripts/config.ini +5 -5
- scripts/create_db.py +131 -113
- Medfl-0.1.7.dist-info/RECORD +0 -31
- {Medfl-0.1.7.dist-info → Medfl-0.1.16.dist-info}/WHEEL +0 -0
- {Medfl-0.1.7.dist-info → Medfl-0.1.16.dist-info}/top_level.txt +0 -0
Medfl/NetManager/dataset.py
CHANGED
@@ -1,91 +1,92 @@
|
|
1
|
-
import pandas as pd
|
2
|
-
from sqlalchemy import text
|
3
|
-
|
4
|
-
from
|
5
|
-
from .
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
|
19
|
-
|
20
|
-
self.
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
:
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|