Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 14 additions & 47 deletions local/rest_api_gcbm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,25 +602,7 @@ def gcbm_disturbances():

# Get the title from the payload
title = request.form.get("title") or "simulation"

# Check for project directory else create one
input_dir = f"{os.getcwd()}/input/{title}"
if not os.path.exists(f"{input_dir}"):
os.makedirs(f"{input_dir}")
logging.debug(os.getcwd())

# input files follow a strict structure
if not os.path.exists(f"{input_dir}/disturbances"):
os.makedirs(f"{input_dir}/disturbances")

# store disturbances file in a new folder
if "disturbances" in request.files:
for file in request.files.getlist("disturbances"):
file.save(f"{input_dir}/disturbances/{file.filename}")
else:
return {"error": "Missing disturbances file"}, 400

return {"data": "Disturbances file uploaded succesfully. Proceed to the next step."}
return upload_files("disturbances", title)


@app.route("/gcbm/upload/classifiers", methods=["POST"])
Expand All @@ -643,25 +625,7 @@ def gcbm_classifiers():

# Get the title from the payload
title = request.form.get("title") or "simulation"

# Check for project directory else create one
input_dir = f"{os.getcwd()}/input/{title}"
if not os.path.exists(f"{input_dir}"):
os.makedirs(f"{input_dir}")
logging.debug(os.getcwd())

# input files follow a strict structure
if not os.path.exists(f"{input_dir}/classifiers"):
os.makedirs(f"{input_dir}/classifiers")

# store disturbances file in a new folder
if "classifiers" in request.files:
for file in request.files.getlist("classifiers"):
file.save(f"{input_dir}/classifiers/{file.filename}")
else:
return {"error": "Missing classifiers file"}, 400

return {"data": "Classifiers file uploaded succesfully. Proceed to the next step."}
return upload_files("classifiers", title)


@app.route("/gcbm/upload/miscellaneous", methods=["POST"])
Expand All @@ -684,26 +648,29 @@ def gcbm_miscellaneous():

# Get the title from the payload
title = request.form.get("title") or "simulation"

return upload_files("miscellaneous", title)


def upload_files(type:str, title:str):
# Check for project directory else create one
input_dir = f"{os.getcwd()}/input/{title}"
if not os.path.exists(f"{input_dir}"):
os.makedirs(f"{input_dir}")
logging.debug(os.getcwd())

# input files follow a strict structure
if not os.path.exists(f"{input_dir}/miscellaneous"):
os.makedirs(f"{input_dir}/miscellaneous")
if not os.path.exists(f"{input_dir}/{type}"):
os.makedirs(f"{input_dir}/{type}")

# store miscellaneous file in a new folder
if "miscellaneous" in request.files:
for file in request.files.getlist("miscellaneous"):
file.save(f"{input_dir}/miscellaneous/{file.filename}")
# store file in a new folder
if type in request.files:
for file in request.files.getlist(type):
file.save(f"{input_dir}/{type}/{file.filename}")
else:
return {"error": "Missing miscellaneous file"}, 400
return {"error": f"Missing {type} file"}, 400

return {
"data": "Miscellaneous file uploaded succesfully. Proceed to the next step."
"data": f"{type.capitalize()} file uploaded succesfully. Proceed to the next step."
}


Expand Down