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.
@@ -1,91 +1,92 @@
1
- import pandas as pd
2
- from sqlalchemy import text
3
-
4
- from scripts.base import my_eng
5
- from .net_helper import *
6
- from .net_manager_queries import (DELETE_DATASET, INSERT_DATASET,
7
- SELECT_ALL_DATASET_NAMES)
8
-
9
-
10
- class DataSet:
11
- def __init__(self, name: str, path: str, engine=None):
12
- """
13
- Initialize a DataSet object.
14
-
15
- :param name: The name of the dataset.
16
- :type name: str
17
- :param path: The file path of the dataset CSV file.
18
- :type path: str
19
- """
20
- self.name = name
21
- self.path = path
22
- self.engine = engine if engine is not None else my_eng
23
-
24
- def validate(self):
25
- """
26
- Validate name and path attributes.
27
-
28
- :raises TypeError: If name or path is not a string.
29
- """
30
- if not isinstance(self.name, str):
31
- raise TypeError("name argument must be a string")
32
-
33
- if not isinstance(self.path, str):
34
- raise TypeError("path argument must be a string")
35
-
36
- def upload_dataset(self, NodeId=-1):
37
- """
38
- Upload the dataset to the database.
39
-
40
- :param NodeId: The NodeId associated with the dataset.
41
- :type NodeId: int
42
-
43
- Notes:
44
- - Assumes the file at self.path is a valid CSV file.
45
- - The dataset is uploaded to the 'DataSets' table in the database.
46
- """
47
-
48
- data_df = pd.read_csv(self.path)
49
- nodeId = NodeId
50
- columns = data_df.columns.tolist()
51
-
52
-
53
- data_df = process_eicu(data_df)
54
- for index, row in data_df.iterrows():
55
- query_1 = "INSERT INTO DataSets(DataSetName,nodeId," + "".join(
56
- f"{x}," for x in columns
57
- )
58
- query_2 = f" VALUES ('{self.name}',{nodeId}, " + "".join(
59
- f"{is_str(data_df, row, x)}," for x in columns
60
- )
61
- query = query_1[:-1] + ")" + query_2[:-1] + ")"
62
-
63
- self.engine.execute(text(query))
64
-
65
- def delete_dataset(self):
66
- """
67
- Delete the dataset from the database.
68
-
69
- Notes:
70
- - Assumes the dataset name is unique in the 'DataSets' table.
71
- """
72
- self.engine.execute(text(DELETE_DATASET), {"name": self.name})
73
-
74
- def update_data(self):
75
- """
76
- Update the data in the dataset.
77
-
78
- Not implemented yet.
79
- """
80
- pass
81
-
82
- @staticmethod
83
- def list_alldatasets(engine):
84
- """
85
- List all dataset names from the 'DataSets' table.
86
-
87
- :returns: A DataFrame containing the names of all datasets in the 'DataSets' table.
88
- :rtype: pd.DataFrame
89
- """
90
- res = pd.read_sql(text(SELECT_ALL_DATASET_NAMES), engine)
91
- 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