From d8f9bdf1c2830a00836ed14e19b0107a7758b29e Mon Sep 17 00:00:00 2001
From: kshitijrajsharma
Date: Thu, 26 Sep 2024 12:16:37 +0200
Subject: [PATCH 1/5] fix(userinfo): adds user info in prediction that lets
user know about the user
---
backend/core/models.py | 3 +++
backend/core/views.py | 1 +
2 files changed, 4 insertions(+)
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..7a95fc88 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
existing_approved_feature = ApprovedPredictions.objects.filter(
training=training_id, geom=geom
From 7f8526b7913ed8da0e1f63750a63e2154b17d0ee Mon Sep 17 00:00:00 2001
From: kshitijrajsharma
Date: Thu, 26 Sep 2024 13:32:24 +0200
Subject: [PATCH 2/5] feat(acceptedFeature): allows user to accept feature and
send back to API
---
.../Start/Prediction/EditableGeoJSON.js | 41 ++++++++++++++++++-
.../Layout/Start/Prediction/Prediction.js | 8 ++--
2 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js b/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js
index bc696287..2f2f8344 100644
--- a/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js
+++ b/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js
@@ -95,7 +95,7 @@ const EditableGeoJSON = ({
modelId,
trainingId,
sourceImagery,
- refestchFeeedback,
+ refetchFeedback,
onAcceptFeature,
}) => {
const onPMCreate = (event) => {
@@ -165,13 +165,49 @@ 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 {
}
};
const { mutate: mutateSubmitFeedback } = useMutation(submitFeedback);
+ const { mutate: mutatesubmitAcceptedPrediction } = useMutation(
+ submitAcceptedPrediction
+ );
+
+ 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 onEachFeature = (feature, layer) => {
// layer.on({
@@ -263,6 +299,7 @@ const EditableGeoJSON = ({
console.log("popup layer ", layer);
// handle submitting feedback
mutateSubmitFeedback(layer);
+ mutatesubmitAcceptedPrediction(layer);
popup.close();
});
diff --git a/frontend/src/components/Layout/Start/Prediction/Prediction.js b/frontend/src/components/Layout/Start/Prediction/Prediction.js
index 9ee65547..643590be 100644
--- a/frontend/src/components/Layout/Start/Prediction/Prediction.js
+++ b/frontend/src/components/Layout/Start/Prediction/Prediction.js
@@ -240,16 +240,16 @@ const Prediction = () => {
if (acceptedFeatures.length === 0) {
return;
}
-
+
const content = JSON.stringify(acceptedFeatures);
const blob = new Blob([content], { type: "application/json" });
const url = URL.createObjectURL(blob);
-
+
const link = document.createElement("a");
link.href = url;
link.download = "accepted_predictions.geojson";
link.click();
-
+
URL.revokeObjectURL(url);
};
@@ -584,7 +584,7 @@ const Prediction = () => {
// setModifiedCount={setModifiedCount}
// setDeletedCount={setDeletedCount}
tileBoundaryLayer={tileBoundaryLayer}
- refestchFeeedback={() => {
+ refetchFeedback={() => {
refetchFeedback();
}}
onAcceptFeature={handleAcceptFeature}
From 6a50743bb22fe7609de54330f2795264129f2311 Mon Sep 17 00:00:00 2001
From: kshitijrajsharma
Date: Thu, 26 Sep 2024 13:49:56 +0200
Subject: [PATCH 3/5] do not mutate accepted predictions
---
.../components/Layout/Start/Prediction/EditableGeoJSON.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js b/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js
index 2f2f8344..6eee938b 100644
--- a/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js
+++ b/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js
@@ -172,9 +172,9 @@ const EditableGeoJSON = ({
}
};
const { mutate: mutateSubmitFeedback } = useMutation(submitFeedback);
- const { mutate: mutatesubmitAcceptedPrediction } = useMutation(
- submitAcceptedPrediction
- );
+ // const { mutate: mutatesubmitAcceptedPrediction } = useMutation(
+ // submitAcceptedPrediction
+ // );
const submitAcceptedPrediction = async (layer) => {
const newAOI = {
From eb2942b746c6611a6048988104d419821ef65a4a Mon Sep 17 00:00:00 2001
From: kshitijrajsharma
Date: Thu, 26 Sep 2024 14:38:38 +0200
Subject: [PATCH 4/5] distinguish feedback and accepted features
---
.../Start/Prediction/EditableGeoJSON.js | 21 ++++++++++---------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js b/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js
index 6eee938b..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";
@@ -172,9 +172,6 @@ const EditableGeoJSON = ({
}
};
const { mutate: mutateSubmitFeedback } = useMutation(submitFeedback);
- // const { mutate: mutatesubmitAcceptedPrediction } = useMutation(
- // submitAcceptedPrediction
- // );
const submitAcceptedPrediction = async (layer) => {
const newAOI = {
@@ -208,6 +205,9 @@ const EditableGeoJSON = ({
} finally {
}
};
+ const { mutate: mutatesubmitAcceptedPrediction } = useMutation(
+ submitAcceptedPrediction
+ );
const onEachFeature = (feature, layer) => {
// layer.on({
@@ -282,8 +282,8 @@ const EditableGeoJSON = ({
Comments:
-
-
+
+
`;
const popup = L.popup()
@@ -292,24 +292,25 @@ const EditableGeoJSON = ({
.openOn(e.target._map);
const popupElement = popup.getElement();
popupElement
- .querySelector("#rightButton")
+ .querySelector("#submitFeedback")
.addEventListener("click", () => {
- feature.properties.action = "ACCEPT";
+ feature.properties.action = "FEEDBACK";
onAcceptFeature(feature);
console.log("popup layer ", layer);
// handle submitting feedback
mutateSubmitFeedback(layer);
- mutatesubmitAcceptedPrediction(layer);
+
popup.close();
});
popupElement
- .querySelector("#josmButton")
+ .querySelector("#acceptFeedback")
.addEventListener("click", () => {
feature.properties.action = "JOSM";
// console.log("popup layer ", layer);
// handle submitting feedback
// mutateSubmitFeedback(layer);
+ mutatesubmitAcceptedPrediction(layer);
setRender(Math.random());
popup.close();
});
From c2d2260bbe8c753f35d0a9e454e9cc2207ef7f54 Mon Sep 17 00:00:00 2001
From: kshitijrajsharma
Date: Thu, 26 Sep 2024 13:26:22 +0000
Subject: [PATCH 5/5] Add osmid specifically to the approved predictions
---
backend/core/views.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/backend/core/views.py b/backend/core/views.py
index 7a95fc88..d0bd9634 100644
--- a/backend/core/views.py
+++ b/backend/core/views.py
@@ -307,7 +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
+ request.data["approved_by"] = self.request.user.osm_id
existing_approved_feature = ApprovedPredictions.objects.filter(
training=training_id, geom=geom