MEDfl 0.1.31__py3-none-any.whl → 0.1.33__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 (56) hide show
  1. {MEDfl-0.1.31.dist-info → MEDfl-0.1.33.dist-info}/METADATA +127 -128
  2. MEDfl-0.1.33.dist-info/RECORD +34 -0
  3. {MEDfl-0.1.31.dist-info → MEDfl-0.1.33.dist-info}/WHEEL +1 -1
  4. {MEDfl-0.1.31.dist-info → MEDfl-0.1.33.dist-info}/top_level.txt +0 -1
  5. Medfl/LearningManager/__init__.py +13 -13
  6. Medfl/LearningManager/client.py +150 -150
  7. Medfl/LearningManager/dynamicModal.py +287 -287
  8. Medfl/LearningManager/federated_dataset.py +60 -60
  9. Medfl/LearningManager/flpipeline.py +192 -192
  10. Medfl/LearningManager/model.py +223 -223
  11. Medfl/LearningManager/params.yaml +14 -14
  12. Medfl/LearningManager/params_optimiser.py +442 -442
  13. Medfl/LearningManager/plot.py +229 -229
  14. Medfl/LearningManager/server.py +181 -181
  15. Medfl/LearningManager/strategy.py +82 -82
  16. Medfl/LearningManager/utils.py +331 -308
  17. Medfl/NetManager/__init__.py +10 -9
  18. Medfl/NetManager/database_connector.py +43 -48
  19. Medfl/NetManager/dataset.py +92 -92
  20. Medfl/NetManager/flsetup.py +320 -320
  21. Medfl/NetManager/net_helper.py +254 -248
  22. Medfl/NetManager/net_manager_queries.py +142 -137
  23. Medfl/NetManager/network.py +194 -174
  24. Medfl/NetManager/node.py +184 -178
  25. Medfl/__init__.py +3 -2
  26. Medfl/scripts/__init__.py +2 -0
  27. Medfl/scripts/base.py +30 -0
  28. Medfl/scripts/create_db.py +126 -0
  29. alembic/env.py +61 -61
  30. scripts/base.py +29 -29
  31. scripts/config.ini +5 -5
  32. scripts/create_db.py +133 -133
  33. MEDfl/LearningManager/__init__.py +0 -13
  34. MEDfl/LearningManager/client.py +0 -150
  35. MEDfl/LearningManager/dynamicModal.py +0 -287
  36. MEDfl/LearningManager/federated_dataset.py +0 -60
  37. MEDfl/LearningManager/flpipeline.py +0 -192
  38. MEDfl/LearningManager/model.py +0 -223
  39. MEDfl/LearningManager/params.yaml +0 -14
  40. MEDfl/LearningManager/params_optimiser.py +0 -442
  41. MEDfl/LearningManager/plot.py +0 -229
  42. MEDfl/LearningManager/server.py +0 -181
  43. MEDfl/LearningManager/strategy.py +0 -82
  44. MEDfl/LearningManager/utils.py +0 -333
  45. MEDfl/NetManager/__init__.py +0 -9
  46. MEDfl/NetManager/database_connector.py +0 -48
  47. MEDfl/NetManager/dataset.py +0 -92
  48. MEDfl/NetManager/flsetup.py +0 -320
  49. MEDfl/NetManager/net_helper.py +0 -248
  50. MEDfl/NetManager/net_manager_queries.py +0 -137
  51. MEDfl/NetManager/network.py +0 -174
  52. MEDfl/NetManager/node.py +0 -178
  53. MEDfl/__init__.py +0 -2
  54. MEDfl-0.1.31.data/scripts/setup_mysql.sh +0 -22
  55. MEDfl-0.1.31.dist-info/RECORD +0 -54
  56. scripts/db_config.ini +0 -6
@@ -1,9 +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 *
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 *
@@ -1,48 +1,43 @@
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
+ 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()
@@ -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