Skip to content

Commit

Permalink
Now, in patch, we are launching the right command
Browse files Browse the repository at this point in the history
in geoattempt
  • Loading branch information
frasanz committed Sep 21, 2024
1 parent cbde2bd commit a42ae7e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
39 changes: 34 additions & 5 deletions frontend/templates/task2.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,42 @@ <h3>Lost at night</h3>

throw new Error("Invalid coordinate format");
}

function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
let iconCounter = 1; // Counter for numbering icons
let iconList = []; // List to store icon objects
let markerList = {}; // List to store marker objects
let iconMap = {}; // List to store the iconGroup objects
let isTurn = 'image'; // Variable to track the current turn
let group; // Variable to store the Fabric group object
let geoatempt_id; // Variable to store the geoattempt id
let image_name; // Variable to store the image name
const csrftoken = getCookie('csrftoken');
$.ajaxSetup({
headers: {
'X-CSRFToken': csrftoken
}
});
$.ajax({
url: 'http://127.0.0.1:8000/api/v1/geoattempt-pending/',
type: 'GET',
dataType: 'json',
success: function (response) {
image_name = response.image_name;
geoatempt_id = response.id;
// Initialize Fabric.js canvas
const canvas = new fabric.Canvas('canvas', {
fireRightClick: true, // Enable right-click events
Expand All @@ -197,14 +220,20 @@ <h3>Lost at night</h3>
return;
} else {
// Doing a post request to the backend
const data = {
"geoattempt_id": geoatempt_id,
"control_points": iconList,
"status": "TESTING"
}
$.ajax({
url: 'http://127.0.0.1:8000/api/v1/post-geoattempt/',
type: 'POST',
url: 'http://127.0.0.1:8000/api/v1/geoattempt-individual/'+geoatempt_id+'/',
type: 'PATCH',
dataType: 'json',
data: {
'image_name': image_name,
'iconList': JSON.stringify(iconList)
headers: {
'X-CSRFToken': csrftoken,
'Content-Type': 'application/json'
},
data: JSON.stringify(data),
})
}
});
Expand Down
1 change: 1 addition & 0 deletions georeferencing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GeoAttempt(models.Model):

STATUS_CHOICES = (
('PENDING', 'Pending'),
('TESTING', 'Testing'),
('DOING', 'Doing'),
('SUCCESS', 'Success'),
('FAILURE', 'Failure'),
Expand Down
17 changes: 14 additions & 3 deletions georeferencing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,21 @@ def get(self, request, pk=None):
operation_summary="Patch an image geo attempt")
def patch(self, request, pk=None):
geoattemp = get_object_or_404(GeoAttempt, pk=pk)
serializer = GeoAttemptSerializer(gegeoattemp, data=request.data, partial=True)
print(request.data)
serializer = GeoAttemptSerializer(geoattemp, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
if serializer.data['status'] == 'DOING':
#serializer.save()
if request.data['status'] == 'TESTING':
# let's start the testing process
# for the moment, just change the status
print('testing')
print('doing geoattemp')
command = 'gdal_translate -of GTiff'
for item in request.data['control_points']:
command += ' -gcp ' + str(item['actualPx']) + ' ' + str(item['actualPy']) + ' ' + str(item['lat']) + ' ' + str(item['lon'])
print(command)

elif serializer.data['status'] == 'DOING':
# let's start the georeferencing process
# for the moment, launch a batch script
print('doing georeferencing')
Expand Down

0 comments on commit a42ae7e

Please sign in to comment.