From 198009df0de229e8f78d47a2e5ab528e5a7928fa Mon Sep 17 00:00:00 2001 From: ori agranat Date: Thu, 23 Jan 2020 20:53:31 +0200 Subject: [PATCH] better csv parsing with errors --- .../src/views/CameraViewes/3D.vue | 58 ++++++++++++++++--- .../chameleonvision/web/RequestHandler.java | 31 +++++----- 2 files changed, 67 insertions(+), 22 deletions(-) diff --git a/chameleon-client/src/views/CameraViewes/3D.vue b/chameleon-client/src/views/CameraViewes/3D.vue index b30c57673..339c7dc2c 100644 --- a/chameleon-client/src/views/CameraViewes/3D.vue +++ b/chameleon-client/src/views/CameraViewes/3D.vue @@ -17,10 +17,14 @@ - + Upload Premade + + {{snackbar.text}} + @@ -41,7 +45,12 @@ return { is3D: false, selectedModel: null, - FRCtargets: null + FRCtargets: null, + snackbar: { + color: "success", + text: "" + }, + snack: false } }, methods: { @@ -57,17 +66,50 @@ }); }, onParse(result) { - let data = result.data.map(item => { - Object.keys(item).forEach(k => item[k] = isNaN(item[k])? item[k] : Number(item[k])); - return item; - }); - this.uploadModel(data); + if (result.data.length > 0) { + + + let data = []; + for (let item of result.data) { + let tmp = []; + tmp.push(Number(item[0])); + tmp.push(Number(item[1])); + if (isNaN(tmp[0]) || isNaN(tmp[1])) { + this.snackbar = { + color: "error", + text: "Error: cvs did parse correctly" + }; + this.snack = true; + return; + } + data.push(tmp); + } + this.uploadModel(data); + } else { + this.snackbar = { + color: "error", + text: "Error: cvs did not contain any data" + }; + this.snack = true; + } }, uploadPremade() { this.uploadModel(this.selectedModel); }, uploadModel(model) { - this.axios.post("http://" + this.$address + "/api/vision/pnpModel", model); + this.axios.post("http://" + this.$address + "/api/vision/pnpModel", model).then((response) => { + this.snackbar = { + color: "success", + text: "File uploaded successfully" + }; + this.snack = true; + }).catch((error) => { + this.snackbar = { + color: "error", + text: "An error occurred" + }; + this.snack = true; + }) } }, computed: { diff --git a/chameleon-server/src/main/java/com/chameleonvision/web/RequestHandler.java b/chameleon-server/src/main/java/com/chameleonvision/web/RequestHandler.java index 29dc62484..e7ed11ed0 100644 --- a/chameleon-server/src/main/java/com/chameleonvision/web/RequestHandler.java +++ b/chameleon-server/src/main/java/com/chameleonvision/web/RequestHandler.java @@ -187,20 +187,23 @@ public class RequestHandler { public static void onPnpModel(Context ctx) throws JsonProcessingException { //noinspection unchecked List> points = kObjectMapper.readValue(ctx.body(), List.class); - - // each entry should be an xy pair - var pointsList = new ArrayList(); - for (List point : points) { - double x, y; - x = point.get(0).doubleValue(); - y = point.get(1).doubleValue(); - var pointToAdd = new Point3(x, y, 0.0); - pointsList.add(pointToAdd); - } - System.out.println(pointsList.toString()); - if (VisionManager.getCurrentUIVisionProcess().pipelineManager.getCurrentPipeline().settings instanceof StandardCVPipelineSettings) { - var settings = (StandardCVPipelineSettings) VisionManager.getCurrentUIVisionProcess().pipelineManager.getCurrentPipeline().settings; - settings.targetCornerMat.fromList(pointsList); + try { + // each entry should be an xy pair + var pointsList = new ArrayList(); + for (List point : points) { + double x, y; + x = point.get(0).doubleValue(); + y = point.get(1).doubleValue(); + var pointToAdd = new Point3(x, y, 0.0); + pointsList.add(pointToAdd); + } + System.out.println(pointsList.toString()); + if (VisionManager.getCurrentUIVisionProcess().pipelineManager.getCurrentPipeline().settings instanceof StandardCVPipelineSettings) { + var settings = (StandardCVPipelineSettings) VisionManager.getCurrentUIVisionProcess().pipelineManager.getCurrentPipeline().settings; + settings.targetCornerMat.fromList(pointsList); + } + } catch (Exception e){ + ctx.status(500); } } }