MEDfl 0.1.26__py3-none-any.whl → 0.1.27__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.
Files changed (52) hide show
  1. MEDfl/LearningManager/__init__.py +13 -0
  2. MEDfl/LearningManager/client.py +150 -0
  3. MEDfl/LearningManager/dynamicModal.py +287 -0
  4. MEDfl/LearningManager/federated_dataset.py +60 -0
  5. MEDfl/LearningManager/flpipeline.py +192 -0
  6. MEDfl/LearningManager/model.py +223 -0
  7. MEDfl/LearningManager/params.yaml +14 -0
  8. MEDfl/LearningManager/params_optimiser.py +442 -0
  9. MEDfl/LearningManager/plot.py +229 -0
  10. MEDfl/LearningManager/server.py +181 -0
  11. MEDfl/LearningManager/strategy.py +82 -0
  12. MEDfl/LearningManager/utils.py +308 -0
  13. MEDfl/NetManager/__init__.py +9 -0
  14. MEDfl/NetManager/database_connector.py +48 -0
  15. MEDfl/NetManager/dataset.py +92 -0
  16. MEDfl/NetManager/flsetup.py +320 -0
  17. MEDfl/NetManager/net_helper.py +248 -0
  18. MEDfl/NetManager/net_manager_queries.py +137 -0
  19. MEDfl/NetManager/network.py +174 -0
  20. MEDfl/NetManager/node.py +178 -0
  21. MEDfl/__init__.py +2 -0
  22. {MEDfl-0.1.26.data → MEDfl-0.1.27.data}/scripts/setup_mysql.sh +22 -22
  23. {MEDfl-0.1.26.dist-info → MEDfl-0.1.27.dist-info}/METADATA +127 -127
  24. MEDfl-0.1.27.dist-info/RECORD +53 -0
  25. {MEDfl-0.1.26.dist-info → MEDfl-0.1.27.dist-info}/WHEEL +1 -1
  26. Medfl/LearningManager/__init__.py +13 -13
  27. Medfl/LearningManager/client.py +150 -150
  28. Medfl/LearningManager/dynamicModal.py +287 -287
  29. Medfl/LearningManager/federated_dataset.py +60 -60
  30. Medfl/LearningManager/flpipeline.py +192 -192
  31. Medfl/LearningManager/model.py +223 -223
  32. Medfl/LearningManager/params.yaml +14 -14
  33. Medfl/LearningManager/params_optimiser.py +442 -442
  34. Medfl/LearningManager/plot.py +229 -229
  35. Medfl/LearningManager/server.py +181 -181
  36. Medfl/LearningManager/strategy.py +82 -82
  37. Medfl/LearningManager/utils.py +308 -308
  38. Medfl/NetManager/__init__.py +9 -9
  39. Medfl/NetManager/database_connector.py +48 -48
  40. Medfl/NetManager/dataset.py +92 -92
  41. Medfl/NetManager/flsetup.py +320 -320
  42. Medfl/NetManager/net_helper.py +248 -248
  43. Medfl/NetManager/net_manager_queries.py +137 -137
  44. Medfl/NetManager/network.py +174 -174
  45. Medfl/NetManager/node.py +178 -178
  46. Medfl/__init__.py +1 -1
  47. alembic/env.py +61 -61
  48. scripts/base.py +29 -29
  49. scripts/config.ini +5 -5
  50. scripts/create_db.py +133 -133
  51. MEDfl-0.1.26.dist-info/RECORD +0 -32
  52. {MEDfl-0.1.26.dist-info → MEDfl-0.1.27.dist-info}/top_level.txt +0 -0
@@ -1,48 +1,48 @@
1
- import os
2
- from sqlalchemy import create_engine
3
- from configparser import ConfigParser
4
-
5
- import subprocess
6
-
7
- class DatabaseManager:
8
- def __init__(self):
9
-
10
- from MEDfl.LearningManager.utils import load_db_config
11
- db_config = load_db_config()
12
- if db_config:
13
- self.config = db_config
14
- else:
15
- self.config = None
16
- self.engine = None
17
-
18
- def connect(self):
19
- if not self.config:
20
- raise ValueError("Database configuration not loaded. Use load_db_config() or set_config_path() first.")
21
- connection_string = (
22
- f"mysql+mysqlconnector://{self.config['user']}:{self.config['password']}@"
23
- f"{self.config['host']}:{self.config['port']}/{self.config['database']}"
24
- )
25
- self.engine = create_engine(connection_string, pool_pre_ping=True)
26
-
27
- def get_connection(self):
28
- if not self.engine:
29
- self.connect()
30
- return self.engine.connect()
31
-
32
- def create_MEDfl_db(self , path_to_csv):
33
- # Get the directory of the current script
34
- current_directory = os.path.dirname(__file__)
35
-
36
- # Define the path to the create_db.py script
37
- create_db_script_path = os.path.join(current_directory, '..', 'scripts', 'create_db.py')
38
-
39
- # Execute the create_db.py script
40
- subprocess.run(['python', create_db_script_path, path_to_csv], check=True)
41
-
42
- return
43
-
44
- def close(self):
45
- if self.engine:
46
- self.engine.dispose()
47
-
48
-
1
+ import os
2
+ from sqlalchemy import create_engine
3
+ from configparser import ConfigParser
4
+
5
+ import subprocess
6
+
7
+ class DatabaseManager:
8
+ def __init__(self):
9
+
10
+ from MEDfl.LearningManager.utils import load_db_config
11
+ db_config = load_db_config()
12
+ if db_config:
13
+ self.config = db_config
14
+ else:
15
+ self.config = None
16
+ self.engine = None
17
+
18
+ def connect(self):
19
+ if not self.config:
20
+ raise ValueError("Database configuration not loaded. Use load_db_config() or set_config_path() first.")
21
+ connection_string = (
22
+ f"mysql+mysqlconnector://{self.config['user']}:{self.config['password']}@"
23
+ f"{self.config['host']}:{self.config['port']}/{self.config['database']}"
24
+ )
25
+ self.engine = create_engine(connection_string, pool_pre_ping=True)
26
+
27
+ def get_connection(self):
28
+ if not self.engine:
29
+ self.connect()
30
+ return self.engine.connect()
31
+
32
+ def create_MEDfl_db(self , path_to_csv):
33
+ # Get the directory of the current script
34
+ current_directory = os.path.dirname(__file__)
35
+
36
+ # Define the path to the create_db.py script
37
+ create_db_script_path = os.path.join(current_directory, '..', 'scripts', 'create_db.py')
38
+
39
+ # Execute the create_db.py script
40
+ subprocess.run(['python', create_db_script_path, path_to_csv], check=True)
41
+
42
+ return
43
+
44
+ def close(self):
45
+ if self.engine:
46
+ self.engine.dispose()
47
+
48
+
@@ -1,92 +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
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