Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: GCBM Refactor Idea Draft #206

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bddce12
Enrich the CML Action using Jupytext (#176)
radistoubalidis Sep 7, 2022
65135c8
chore: moved get_config_templates, get_modules_cbm_config, get_pr… (#…
khanjasir90 Sep 10, 2022
9545161
feat: added Furo theme, GCBM dev docs and Restructured deployments do…
SanjaySinghRajpoot Sep 16, 2022
2a803b6
feat: autoapi implemented to document APIs (#173)
SanjaySinghRajpoot Sep 16, 2022
e4d2e62
docs: Add responses to the GCBM docs (#184)
Crystalsage Sep 17, 2022
7ecf76a
feat: added endpoint to return .json for the input .tiff file (#185)
khanjasir90 Oct 2, 2022
61a459b
Updated curl cmds for the GCBM dynamic endpoints (#194)
SanjaySinghRajpoot Oct 8, 2022
bcf0c3f
chore:removed /rothc endpoint description from swagger documentation …
temitayopelumi Oct 15, 2022
420d80a
Improved Documentation for GCBM REST API (#144)
Saurabh-Suchak Oct 16, 2022
6f843c6
GCBM Refactor idea Draft
Freeman-kuch Oct 27, 2022
8c24f84
GCBM Refactor idea Draft
Freeman-kuch Oct 27, 2022
9a9a9a1
GCBM Refactor idea Draft
Freeman-kuch Oct 27, 2022
bbdab43
fix: add a check to see if simulation output exists (#199)
temitayopelumi Oct 18, 2022
1a6da28
docs: document the `/gcbm/getConfig` endpoint (#201)
clintonMF Oct 23, 2022
cce284d
GCBM Refactor idea Draft
Freeman-kuch Oct 27, 2022
b93e518
GCBM Refactor idea Draft
Freeman-kuch Oct 27, 2022
0c6092c
GCBM Refactor idea Draft
Freeman-kuch Oct 27, 2022
0f6000c
GCBM Refactor idea Draft
Freeman-kuch Oct 27, 2022
674b919
GCBM Refactor idea Draft
Freeman-kuch Oct 27, 2022
3354a5c
GCBM Refactor idea Draft
Freeman-kuch Oct 27, 2022
64e8704
Merge branch 'master' into feat/Refactor_idea_Draft
Freeman-kuch Oct 28, 2022
7a561fe
added MVC architecture
Freeman-kuch Nov 27, 2022
0e83e9d
Merge branch 'master' into feat/Refactor_idea_Draft
Freeman-kuch Nov 27, 2022
e94616b
Merge branch 'master' into feat/Refactor_idea_Draft
Freeman-kuch Nov 27, 2022
bd6f0fa
Merge branch 'feat/Refactor_idea_Draft' of https://github.com/Freeman…
Freeman-kuch Nov 27, 2022
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
Empty file.
155 changes: 155 additions & 0 deletions local/rest_api_skeleton/Endpoints/gcbm_endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
from flask_restful import Resource
import os
from threading import Thread
from Helpers.preprocess import (
DisturbanceConfig,
launch_run,
ClassifierConfig,
MiscellaneousConfig,
)
from Helpers.for_requests import (
title_query,
miscellaneous_query,
disturbance_query,
classifier_query,
)


class disturbance(Resource):
def post(self):
title = title_query().get("title") or "simulation"
input_dir = f"{os.getcwd()}/input/{title}"
if not os.path.exists(f"{input_dir}"):
os.makedirs(f"{input_dir}")
if not os.path.exists(f"{input_dir}/disturbances"):
os.makedirs(f"{input_dir}/disturbances")

# store disturbances file in a new folder
disturbances = disturbance_query()
if not disturbances:
return {"error": "Missing disturbances file"}, 400
for file in disturbances.get("disturbances"):
file.save(f"{input_dir}/disturbances/{file.filename}")
try:
disturb = DisturbanceConfig(
input_dir, file.filename, disturbances.get("attributes")
)
disturb()
except Exception as e:
return e
disturb.flatten_directory("disturbances")
return {
"data": "Disturbances file uploaded succesfully. Proceed to the next step."
}


class classifier(Resource):
def post(self):
# Get the title from the payload
title = title_query().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}")

# 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
classifiers = classifier_query()
if not classifiers:
return {"error": "Missing classifiers file"}, 400

for file in classifiers.get("classifiers"):
file.save(f"{input_dir}/classifiers/{file.filename}")
try:
classify = ClassifierConfig(
input_dir, file.filename, classifiers.get("attributes")
)
classify()
except Exception as e:
return e
classify.flatten_directory("classifiers")
return {
"data": "Classifiers file uploaded succesfully. Proceed to the next step."
}


class Database(Resource):
def post(self):
pass


class miscellaneous(Resource):
def post(self):
# Get the title from the payload
title = title_query().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}")

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

# store miscellaneous file in a new folder
mis = miscellaneous_query()
if not mis:
return {"error": "Missing classifiers file"}, 400

for file in mis.get("miscellaneous"):
file.save(f"{input_dir}/miscellaneous/{file.filename}")
try:
miscel = MiscellaneousConfig(
input_dir, file.filename, mis.get("attributes")
)
miscel()
except Exception as e:
return e
miscel.flatten_directory("miscellaneous")
return {
"data": "Classifiers file uploaded succesfully. Proceed to the next step."
}


class title(Resource):
def post(self):
# Default title = simulation
title = title_query().get("title") or "simulation"
# Sanitize title
title = "".join(c for c in title if c.isalnum())
# input_dir = f"{title}"
input_dir = f"{os.getcwd()}/input/{title}"
if not os.path.exists(f"{input_dir}"):
os.makedirs(f"{input_dir}")
message = "New simulation started. Please move on to the next stage for uploading files at /gcbm/upload."
else:
message = "Simulation already exists. Please check the list of simulations present before proceeding with a new simulation at gcbm/list. You may also download the input and output files for this simulation at gcbm/download sending parameter title in the body."

return {"data": message}, 200


class Run(Resource):
"""THIS ENDPOINT WILL BE ABLE TO RUN A SIMULATION
GOAL IS TO EQUIP IT TO BE ABLE TO RUN MORE THAN ONE SIMULATIONS AT A TIME"""

def post(self):
title = title_query().get("title") or "simulation"

# Sanitize title
title = "".join(c for c in title if c.isalnum())
input_dir = f"{os.getcwd()}/input/{title}"

if not os.path.exists(f"{input_dir}"):
os.makedirs(f"{input_dir}")

thread = Thread(
target=launch_run, kwargs={"title": title, "input_dir": input_dir}
)
thread.start()

return {"status": "Run started"}, 200
Empty file.
47 changes: 47 additions & 0 deletions local/rest_api_skeleton/Helpers/for_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from flask_restful import reqparse
from werkzeug.datastructures import FileStorage


def title_query():
query = reqparse.RequestParser()
query.add_argument("title", required=True, location="form")
return query.parse_args()


def classifier_query():
query = reqparse.RequestParser()
query.add_argument(
"classifiers",
type=FileStorage,
required=True,
action="append",
location="files",
)
query.add_argument("attributes", location="form")
return query.parse_args()


def disturbance_query():
query = reqparse.RequestParser()
query.add_argument(
"disturbances",
type=FileStorage,
required=True,
action="append",
location="files",
)
query.add_argument("attributes", location="form")
return query.parse_args()


def miscellaneous_query():
query = reqparse.RequestParser()
query.add_argument(
"miscellaneous",
type=FileStorage,
required=True,
action="append",
location="files",
)
query.add_argument("attributes", location="form")
return query.parse_args()
Loading