Skip to content

Commit f409623

Browse files
committed
feat: unique directories for each launch
1 parent d237399 commit f409623

7 files changed

Lines changed: 88 additions & 63602 deletions

File tree

backend/config/paths.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
import os
22

3+
4+
def get_process_filepath(uid, filepath):
5+
base_prefix = TMP_FILE_DIR + "/"
6+
new_prefix = f"{TMP_FILE_DIR}/{uid}_"
7+
return filepath.replace(base_prefix, new_prefix)
8+
9+
10+
DOCKER_DIR = os.getcwd() + "/docker"
311
BASE_DIR = os.getcwd() + "/backend"
12+
TMP_FILE_DIR = BASE_DIR + "/tmp"
413

514
RESOURCES_DIR = os.path.join(BASE_DIR, "resources")
6-
UPLOAD_DIR = os.path.join(BASE_DIR, "uploads")
7-
RESULTS_DIR = os.path.join(BASE_DIR, "results")
15+
UPLOAD_DIR = os.path.join(TMP_FILE_DIR, "uploads")
16+
RESULTS_DIR = os.path.join(TMP_FILE_DIR, "results")
817

918
DATASET_FILE = os.path.join(RESOURCES_DIR, "dataset.json")
1019
LAUNCH_INFO_FILE = os.path.join(UPLOAD_DIR, "launch_info.csv")
1120
MODEL_ONNX_FILE = os.path.join(UPLOAD_DIR, "model.onnx")
1221
METHODS_TS_FILE = os.path.join(
1322
BASE_DIR, "../frontend/src/components/components/Methods.ts"
1423
)
24+
COMPSTRAT_RESULTS_DIR = os.path.join(RESULTS_DIR, "compstrat_results")
25+
ARTIFACTS_AI_CSV_FILE = os.path.join(RESULTS_DIR, "artifacts_run_ai/AI.csv")
26+
ARTIFACTS_BASELINE_CSV_FILE = os.path.join(
27+
RESULTS_DIR, "artifacts_run_baseline/ExecutionTreeContributedCoverage.csv"
28+
)

backend/main.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
from fastapi import FastAPI, UploadFile, File, Form
22
from fastapi.middleware.cors import CORSMiddleware
3+
import shortuuid
34

5+
from backend.file_utils.files import reset_dir
46
from backend.utils.docker_runner import run_pipeline
57
from backend.utils.data_uploader import handle_upload
68
from backend.utils.methods_handler import Methods
79
from backend.utils.results_sender import send_folder_by_email
8-
from backend.config.paths import RESULTS_DIR, DATASET_FILE, METHODS_TS_FILE
10+
from backend.config.paths import (
11+
RESULTS_DIR,
12+
DATASET_FILE,
13+
METHODS_TS_FILE,
14+
get_process_filepath, BASE_DIR,
15+
)
916

1017
dataset_methods = Methods(data_filepath=DATASET_FILE, output_filepath=METHODS_TS_FILE)
1118

@@ -20,23 +27,26 @@
2027

2128

2229
@app.post("/api/upload")
23-
async def upload_file(
24-
file: UploadFile = File(...),
25-
email: str = Form(...),
26-
methods: str = Form(...),
27-
experiment: str = Form(...),
30+
async def handle_submit(
31+
file: UploadFile = File(...),
32+
email: str = Form(...),
33+
methods: str = Form(...),
34+
experiment: str = Form(...),
2835
):
29-
handle_upload(file, methods, dataset_methods)
36+
task_uid = str(shortuuid.uuid())
37+
38+
handle_upload(task_uid, file, methods, dataset_methods)
3039

31-
run_pipeline()
40+
run_pipeline(task_uid)
3241

3342
send_folder_by_email(
3443
email,
35-
RESULTS_DIR,
44+
get_process_filepath(task_uid, RESULTS_DIR),
3645
experiment,
3746
file.filename,
3847
)
3948

49+
reset_dir(BASE_DIR)
4050
return {
4151
"experiment": experiment,
4252
"filename": file.filename,

0 commit comments

Comments
 (0)