From a6096533003042237118ffc48cd8e5ef2bbe4566 Mon Sep 17 00:00:00 2001 From: Antonio Cavalcante Date: Mon, 18 Nov 2019 14:09:09 +1100 Subject: [PATCH] Fixing file extension and lower case problem. --- mustache/static/js/home/home.js | 23 +++++++---------------- mustache/tasks/tasks.py | 11 ++++++++--- mustache/views/api.py | 8 ++++---- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/mustache/static/js/home/home.js b/mustache/static/js/home/home.js index b3e8aa3..4b93ec2 100644 --- a/mustache/static/js/home/home.js +++ b/mustache/static/js/home/home.js @@ -315,16 +315,16 @@ function startStep() { function nextStep() { - var filename = $("#file-dataset")[0].files[0].name.split(".")[0] + // GETS THE FILE NAME FROM THE FILE JUST READ. + var filename = $("#file-dataset")[0].files[0].name - $("input[name='datasetName']").val(filename[0].toUpperCase() + filename.substring(1)); + // INITIALIZES THE NAME AND NUMBER OF POINTS FIELDS WITH THE NAME OF THE FILE. + $("input[name='datasetName']").val(filename); $("input[name='datasetPoints']").val(checkSum[0]); - if (checkSum[0] < 100) { - $("input[name='datasetMaxMpts']").attr("value", checkSum[0]); - } else { - $("input[name='datasetMaxMpts']").attr("value", 100); - } + $("input[name='datasetMaxMpts']").attr("value", Math.min(checkSum[0], 100)); + + // FORCES MAXMPTS TO BE AT LEAST ONE AND AT MOST THE NUMBER OF POINTS IN THE DATASET. $("input[name='datasetMaxMpts']").attr("data-validation-allowing", "range[" + 1 + ";" + (checkSum[0] - 1) + "]") $("input[name='datasetMaxMpts']").on("input", function () { @@ -335,7 +335,6 @@ function nextStep() { $("input[name='datasetMaxMpts']").attr("data-validation-allowing", "range[" + $(this).val() + ";" + (checkSum[0] - 1) + "]") }) - $.validate({ form: '#submitDataForm', modules: 'logic,toggleDisabled', @@ -362,7 +361,6 @@ function nextStep() { } }) - $("#next1").attr("disabled", true); } @@ -380,7 +378,6 @@ var modal = $('#addDataModal').modalSteps({ $("#next1").attr("disabled", true); - function check(selection) { var labels = selection[0].files[0] Papa.parse(labels, { @@ -406,12 +403,6 @@ function check(selection) { $('.dropify-wrapper').has("#" + id).toggleClass("has-error") } - // if (errors.length > 0) { - // resetFile(id); - // console.log(errors); - // return false; - // } - if (checkSum.length == 2) { if (checkSum[0] != checkSum[1]) { alert("Label Index Error: number of labels does not match number of dataset. ") diff --git a/mustache/tasks/tasks.py b/mustache/tasks/tasks.py index 16c9724..1fe9ba1 100644 --- a/mustache/tasks/tasks.py +++ b/mustache/tasks/tasks.py @@ -20,10 +20,15 @@ def createDatasetPath(workspace, directory): @celery.task(bind=True) def process(self, workspace, root, files, settings): + task_id = self.request.id.__str__() - print("task {} queued!".format(task_id)) - settings['date_added'] = str(dt.datetime.now().timestamp()) + + settings['date-added'] = str(dt.datetime.now().timestamp()) + + settings['labels-file'] = str() + path = createDatasetPath(workspace, task_id) + if path: for file in files: f = open(os.path.join(path, file['name']), 'wb') @@ -48,7 +53,7 @@ def process(self, workspace, root, files, settings): outp = True distance = str(settings['datasetDistance']) com = False - + subprocess.check_call([sh, in_file, mpts, minCluster, rng, str(outp), distance, str(com), path], cwd=os.path.join(root, 'resources')) else: diff --git a/mustache/views/api.py b/mustache/views/api.py index 4b94711..b2ee32c 100644 --- a/mustache/views/api.py +++ b/mustache/views/api.py @@ -70,7 +70,7 @@ def rng(): @api.route("/submit", methods=['GET', 'POST']) def submit(): if request.method == 'POST': - result = request.form.to_dict() + form = request.form.to_dict() files = request.files data = [] @@ -78,16 +78,16 @@ def submit(): data.append({"name": files['file-dataset'].filename, "data": files['file-dataset'].read()}) except Exception as e: - print("file datatset error!", e) + print("Error reading dataset file:", e) try: data.append({"name": files['file-labels'].filename, "data": files['file-labels'].read()}) except Exception as e: - print("file labels error!", e) + print("Error reading labels file:", e) process.apply_async( - args=[app.config['WORKSPACE'], base, data, result]) + args=[app.config['WORKSPACE'], base, data, form]) time.sleep(1)