Skip to content

Commit 7ed271c

Browse files
authored
Merge pull request #434 from MEDomics-UdeS/scalability
V1.4.0 merge
2 parents bf787d4 + 95977f6 commit 7ed271c

File tree

7 files changed

+586
-2
lines changed

7 files changed

+586
-2
lines changed

go_server/blueprints/input/input.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package input
22

33
import (
4+
"fmt"
45
Utils "go_module/src"
56
"log"
67
)
@@ -26,6 +27,8 @@ func AddHandleFunc() {
2627
Utils.CreateHandleFunc(prePath+"/get_subset_data/", handleGetSubsetData)
2728
Utils.CreateHandleFunc(prePath+"/create_new_collection/", handleCreateNewCollection)
2829
Utils.CreateHandleFunc(prePath+"/overwrite_collection/", handleOverwriteCollection)
30+
Utils.CreateHandleFunc(prePath+"/overwrite_encoded_data", handleOverwriteEncodedData)
31+
Utils.CreateHandleFunc(prePath+"/append_encoded_data", handleAppendEncodedData)
2932
Utils.CreateHandleFunc(prePath+"/create_group_DB/", handleCreateGroupDB)
3033
}
3134

@@ -234,6 +237,40 @@ func handleOverwriteCollection(jsonConfig string, id string) (string, error) {
234237
return response, nil
235238
}
236239

240+
func handleOverwriteEncodedData(jsonConfig string, id string) (string, error) {
241+
242+
response, err := Utils.StartPythonScripts(jsonConfig, "../pythonCode/modules/input/overwrite_encoded_data.py", id)
243+
if err != nil {
244+
log.Println("Error executing Python script:", err)
245+
return "", err
246+
}
247+
248+
// Log to verify response
249+
log.Println("Python script response:", response)
250+
251+
if response == "" {
252+
return "", fmt.Errorf("empty response from Python script")
253+
}
254+
255+
return response, nil
256+
}
257+
258+
func handleAppendEncodedData(jsonConfig string, id string) (string, error) {
259+
response, err := Utils.StartPythonScripts(jsonConfig, "../pythonCode/modules/input/append_encoded_data.py", id)
260+
if err != nil {
261+
log.Println("Error executing Python script:", err)
262+
return "", err
263+
}
264+
265+
log.Println("Python script response:", response)
266+
267+
if response == "" {
268+
return "", fmt.Errorf("empty response from Python script")
269+
}
270+
271+
return response, nil
272+
}
273+
237274
// handleCreateGroupDB handles the request to create the group for the DB
238275
// It returns the response from the python script
239276
func handleCreateGroupDB(jsonConfig string, id string) (string, error) {

go_server/main

7.43 MB
Binary file not shown.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import json
2+
import os
3+
import sys
4+
from pathlib import Path
5+
6+
sys.path.append(
7+
str(Path(os.path.dirname(os.path.abspath(__file__))).parent.parent))
8+
from med_libs.GoExecutionScript import GoExecutionScript, parse_arguments
9+
from med_libs.server_utils import go_print
10+
from med_libs.mongodb_utils import connect_to_mongo
11+
12+
# Parse arguments
13+
json_params_dict, id_ = parse_arguments()
14+
go_print("running script.py:" + id_)
15+
16+
17+
class GoExecScriptAppend(GoExecutionScript):
18+
"""
19+
This class overwrites an existing MongoDB collection while keeping existing columns.
20+
21+
Args:
22+
json_params: Input JSON parameters
23+
_id: Request ID (optional)
24+
"""
25+
26+
def __init__(self, json_params: dict, _id: str = None):
27+
super().__init__(json_params, _id)
28+
self.results = {"status": "error", "message": "Process not completed."} # Default response
29+
30+
def _custom_process(self, json_config: dict) -> dict:
31+
"""
32+
Overwrites the specified collection with new data while preserving existing columns.
33+
"""
34+
try:
35+
36+
if "collectionName" not in json_config or "data" not in json_config:
37+
raise ValueError("Invalid JSON format: 'collectionName' or 'data' missing.")
38+
39+
# Set local variables
40+
collection_name = json_config["collectionName"]
41+
new_data = json_config["data"]
42+
43+
44+
# Connect to MongoDB
45+
db = connect_to_mongo()
46+
collection = db[collection_name]
47+
48+
49+
existing_doc = collection.find_one({}, {"_id": 0})
50+
51+
52+
if existing_doc:
53+
all_keys = set(existing_doc.keys())
54+
else:
55+
all_keys = set()
56+
57+
58+
# Append new Data
59+
for doc in new_data:
60+
all_keys.update(doc.keys())
61+
62+
63+
temp_doc = {key: None for key in all_keys}
64+
temp_id = collection.insert_one(temp_doc).inserted_id
65+
66+
67+
collection.delete_many({"_id": {"$ne": temp_id}})
68+
collection.insert_many(new_data)
69+
collection.delete_one({"_id": temp_id})
70+
71+
# Return success
72+
self.results = {
73+
"status": "success",
74+
"message": "Data overwritten successfully while keeping existing schema."
75+
}
76+
77+
# Handle exceptions
78+
except Exception as e:
79+
self.results = {"status": "error", "message": str(e)}
80+
go_print(f"Error: {str(e)}")
81+
82+
return self.results
83+
84+
85+
86+
if __name__ == "__main__":
87+
script = GoExecScriptAppend(json_params_dict, id_)
88+
script.start() # Start the process and execute `_custom_process`
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import json
2+
import os
3+
import sys
4+
from pathlib import Path
5+
6+
sys.path.append(
7+
str(Path(os.path.dirname(os.path.abspath(__file__))).parent.parent))
8+
from med_libs.GoExecutionScript import GoExecutionScript, parse_arguments
9+
from med_libs.mongodb_utils import connect_to_mongo
10+
from med_libs.server_utils import go_print
11+
12+
json_params_dict, id_ = parse_arguments()
13+
go_print("running script.py:" + id_)
14+
15+
16+
17+
18+
class GoExecScriptOverwrite(GoExecutionScript):
19+
"""
20+
This class overwrites data in a MongoDB collection.
21+
22+
Args:
23+
json_params: Input JSON parameters
24+
_id: Request ID (optional)
25+
"""
26+
27+
def __init__(self, json_params: dict, _id: str = None):
28+
super().__init__(json_params, _id)
29+
self.results = None # Initially set to None
30+
31+
def _custom_process(self, json_config: dict) -> dict:
32+
"""
33+
Overwrites the specified collection with new data.
34+
35+
Args:
36+
json_config: Input JSON parameters
37+
"""
38+
try:
39+
# Set local variables
40+
collection_name = json_config["collectionName"]
41+
new_data = json_config["data"]
42+
43+
# Connect to MongoDB
44+
db = connect_to_mongo()
45+
collection = db[collection_name]
46+
47+
# Overwrite the data
48+
go_print(f"Overwriting data in collection: {collection_name}")
49+
collection.drop()
50+
collection.insert_many(new_data)
51+
52+
# Return success
53+
self.results = {"status": "success", "message": "Data overwritten successfully."}
54+
except Exception as e:
55+
# Handle exceptions
56+
self.results = {"status": "error", "message": str(e)}
57+
go_print(f"Error: {str(e)}")
58+
59+
return self.results
60+
61+
62+
# Start the script
63+
script = GoExecScriptOverwrite(json_params_dict, id_)
64+
script.start()

renderer/components/dbComponents/InputToolsComponent.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DataContext } from "../workspace/dataContext"
88
import BasicToolsDB from "./inputToolsDB/basicToolsDB"
99
import DropDuplicatesToolsDB from "./inputToolsDB/dropDuplicatesToolsDB"
1010
import FeatureReductionToolsDB from "./inputToolsDB/featureReductionToolsDB/featureReductionToolsDB"
11+
import ConvertCategoricalColumnIntoNumericDB from "./inputToolsDB/convertCategoricalColumnIntoNumericDB"
1112
import GroupingTaggingToolsDB from "./inputToolsDB/groupingTaggingToolsDB"
1213
import HoldoutSetCreationToolsDB from "./inputToolsDB/holdoutSetCreationToolsDB"
1314
import MergeToolsDB from "./inputToolsDB/mergeToolsDB"
@@ -95,6 +96,9 @@ const InputToolsComponent = ({ exportOptions }) => {
9596
<Panel header="Basic Tools" toggleable collapsed={true}>
9697
<BasicToolsDB collectionSize={collectionSize} currentCollection={!collectionId ? null : collectionId} />
9798
</Panel>
99+
<Panel header="Convert Categorical Column Into Numeric" toggleable collapsed={true}>
100+
<ConvertCategoricalColumnIntoNumericDB exportOptions={exportOptions} currentCollection={!collectionId ? null : collectionId} />
101+
</Panel>
98102
<Panel header="Drop Duplicates Tools" toggleable collapsed={true}>
99103
<DropDuplicatesToolsDB exportOptions={exportOptions} currentCollection={!collectionId ? null : collectionId} />
100104
</Panel>

renderer/components/dbComponents/dataTableFromDB.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ const DataTableFromDB = ({ data, tablePropsData, tablePropsColumn, isReadOnly })
770770
// Loop through each tag to find the group names for the current rowData
771771
rowTags.forEach(tag => {
772772
tag.data.forEach(item => {
773-
if (item._id.toString() === rowData._id.toString()) {
773+
if (item?._id.toString() === rowData?._id.toString()) {
774774
item.groupNames.forEach(groupName => groupNames.add(groupName));
775775
}
776776
});
@@ -844,7 +844,6 @@ const DataTableFromDB = ({ data, tablePropsData, tablePropsColumn, isReadOnly })
844844

845845
return (
846846
<>
847-
{console.log("TESDTY", rowTags[0])}
848847
<Dialog visible={viewMode} header="Preview changes" style={{ width: "80%", height: "80%" }} modal={true} onHide={() => onCancelChanges()}>
849848
<DataTable
850849
className="p-datatable-striped p-datatable-gridlines"

0 commit comments

Comments
 (0)