diff --git a/backend/core/models.py b/backend/core/models.py index ba5cf22c..7ad9afd6 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -145,3 +145,6 @@ class ApprovedPredictions(models.Model): srid=4326 ) ## Making this geometry field to support point/line prediction later on approved_at = models.DateTimeField(auto_now_add=True) + approved_by = models.ForeignKey( + OsmUser, to_field="osm_id", on_delete=models.CASCADE + ) diff --git a/backend/core/views.py b/backend/core/views.py index 5ee2217d..d0bd9634 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -307,6 +307,7 @@ class ApprovedPredictionsViewSet(viewsets.ModelViewSet): def create(self, request, *args, **kwargs): training_id = request.data.get("training") geom = request.data.get("geom") + request.data["approved_by"] = self.request.user.osm_id existing_approved_feature = ApprovedPredictions.objects.filter( training=training_id, geom=geom diff --git a/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js b/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js index bc696287..8303aae2 100644 --- a/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js +++ b/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js @@ -67,7 +67,7 @@ function tile2boundingbox(xtile, ytile, zoom) { function getFeatureStyle(feature) { let color = ""; - if (feature.properties.action === "ACCEPT") { + if (feature.properties.action === "FEEDBACK") { color = "blue"; } else if (feature.properties.action === "INITIAL") { color = "red"; @@ -95,7 +95,7 @@ const EditableGeoJSON = ({ modelId, trainingId, sourceImagery, - refestchFeeedback, + refetchFeedback, onAcceptFeature, }) => { const onPMCreate = (event) => { @@ -165,7 +165,7 @@ const EditableGeoJSON = ({ }; const res = await axios.post(`/feedback/`, body, { headers }); console.log("res ", res); - refestchFeeedback(); + refetchFeedback(); } catch (error) { console.log("Error in submitting feedback", error); } finally { @@ -173,6 +173,42 @@ const EditableGeoJSON = ({ }; const { mutate: mutateSubmitFeedback } = useMutation(submitFeedback); + const submitAcceptedPrediction = async (layer) => { + const newAOI = { + id: Math.random(), + latlngs: layer.getLatLngs()[0], + }; + const points = JSON.stringify( + converToGeoPolygon([newAOI])[0][0].reduce( + (p, c, i) => p + c[1] + " " + c[0] + ",", + "" + ) + ).slice(1, -2); + + const polygon = "SRID=4326;POLYGON((" + points + "))"; + try { + const body = { + config: {}, + geom: polygon, + training: trainingId, + }; + + const headers = { + "access-token": accessToken, + }; + + const res = await axios.post(`/approved-prediction/`, body, { headers }); + console.log("res ", res); + refetchFeedback(); + } catch (error) { + console.log("Error in submitting accepted prediction", error); + } finally { + } + }; + const { mutate: mutatesubmitAcceptedPrediction } = useMutation( + submitAcceptedPrediction + ); + const onEachFeature = (feature, layer) => { // layer.on({ // "pm:update": (event) => { @@ -246,8 +282,8 @@ const EditableGeoJSON = ({
Comments: