better csv parsing with errors

This commit is contained in:
ori agranat
2020-01-23 20:53:31 +02:00
parent 526733aeb4
commit 198009df0d
2 changed files with 67 additions and 22 deletions

View File

@@ -17,10 +17,14 @@
<mini-map class="miniMapClass" :targets="targets" :horizontal-f-o-v="horizontalFOV"/> <mini-map class="miniMapClass" :targets="targets" :horizontal-f-o-v="horizontalFOV"/>
</v-col> </v-col>
<v-col> <v-col>
<v-select v-model="selectedModel" :items="FRCtargets" item-text="name" item-value="data" dark color="#4baf62" item-color="green"/> <v-select v-model="selectedModel" :items="FRCtargets" item-text="name" item-value="data" dark
color="#4baf62" item-color="green"/>
<v-btn small v-if="selectedModel !== null" @click="uploadPremade">Upload Premade</v-btn> <v-btn small v-if="selectedModel !== null" @click="uploadPremade">Upload Premade</v-btn>
</v-col> </v-col>
</v-row> </v-row>
<v-snackbar v-model="snack" top :color="snackbar.color">
<span>{{snackbar.text}}</span>
</v-snackbar>
</div> </div>
</template> </template>
@@ -41,7 +45,12 @@
return { return {
is3D: false, is3D: false,
selectedModel: null, selectedModel: null,
FRCtargets: null FRCtargets: null,
snackbar: {
color: "success",
text: ""
},
snack: false
} }
}, },
methods: { methods: {
@@ -57,17 +66,50 @@
}); });
}, },
onParse(result) { onParse(result) {
let data = result.data.map(item => { if (result.data.length > 0) {
Object.keys(item).forEach(k => item[k] = isNaN(item[k])? item[k] : Number(item[k]));
return item;
}); let data = [];
this.uploadModel(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() { uploadPremade() {
this.uploadModel(this.selectedModel); this.uploadModel(this.selectedModel);
}, },
uploadModel(model) { 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: { computed: {

View File

@@ -187,20 +187,23 @@ public class RequestHandler {
public static void onPnpModel(Context ctx) throws JsonProcessingException { public static void onPnpModel(Context ctx) throws JsonProcessingException {
//noinspection unchecked //noinspection unchecked
List<List<Number>> points = kObjectMapper.readValue(ctx.body(), List.class); List<List<Number>> points = kObjectMapper.readValue(ctx.body(), List.class);
try {
// each entry should be an xy pair // each entry should be an xy pair
var pointsList = new ArrayList<Point3>(); var pointsList = new ArrayList<Point3>();
for (List<Number> point : points) { for (List<Number> point : points) {
double x, y; double x, y;
x = point.get(0).doubleValue(); x = point.get(0).doubleValue();
y = point.get(1).doubleValue(); y = point.get(1).doubleValue();
var pointToAdd = new Point3(x, y, 0.0); var pointToAdd = new Point3(x, y, 0.0);
pointsList.add(pointToAdd); pointsList.add(pointToAdd);
} }
System.out.println(pointsList.toString()); System.out.println(pointsList.toString());
if (VisionManager.getCurrentUIVisionProcess().pipelineManager.getCurrentPipeline().settings instanceof StandardCVPipelineSettings) { if (VisionManager.getCurrentUIVisionProcess().pipelineManager.getCurrentPipeline().settings instanceof StandardCVPipelineSettings) {
var settings = (StandardCVPipelineSettings) VisionManager.getCurrentUIVisionProcess().pipelineManager.getCurrentPipeline().settings; var settings = (StandardCVPipelineSettings) VisionManager.getCurrentUIVisionProcess().pipelineManager.getCurrentPipeline().settings;
settings.targetCornerMat.fromList(pointsList); settings.targetCornerMat.fromList(pointsList);
}
} catch (Exception e){
ctx.status(500);
} }
} }
} }