-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generateExportJson follow-ups #270
Comments
@jywarren for point 3, not sure how to proceed. Is the indicator of progress that the image has been added to the |
I think you can just console.log the contents of status.json for now, and it doesn't have to be correlated to anything yet! |
But, the steps of progress will be:
So, we can treat those each as 1/5 (or 1/(5+x)) of completion, depending on the num of images. |
@jywarren so this part will be in rails (aka mapknitter repo)? |
This'll be running in one of our new exporter systems, like: http://export.mapknitter.org/export?url=https://mapknitter.org/maps/ceres--2/warpables.json&scale=30 (now operational!) But it'll be displaying in MapKnitter eventually, yeah. But actually since we don't /require/ any back-end now (using this cloud system) we can start by just showing status in the console (later using a Bootstrap progress bar) and doing everything client-side. Let's just ensure we have callbacks in place to save the |
So it'll be:
How does that sound? |
@jywarren Ok first I can make an example of calling that link above specifically, grabbing the data from it (the status.json url), using that to make another request, and console.log the output of Sorry if i'm not understanding correctly |
So does @icarito need to set this there first? Or is there a way to get around this? This is what my request looks like:
|
OK, got CORS for the storage bucket. The ID generated is usable to fetch the status.json, jpg, and tif files, and we'll add the others too. We can document later. But until i get CORS enabled for the Kubernetes cluster app, this can be a workaround: https://storage.googleapis.com/mapknitter-exports-warps/1559178763/status.json so then it'd be: https://storage.googleapis.com/mapknitter-exports-warps/1559178763/1559178763.jpg https://storage.googleapis.com/mapknitter-exports-warps/1559178763/1559178763.tif |
Just noting current progress bar code! https://github.com/publiclab/mapknitter/blob/6c79669983a5707a622f1cd90b3cc1d5d562eb84/app/views/maps/_sidebar_exports.html.erb#L144-L193 |
You should be able to POST the .json of the collected corner coordinates (for each image) to this route: https://github.com/publiclab/mapknitter-exporter-sinatra/blob/34b13d674f9500599b5aa34ee3d0b7350af53e97/app.rb#L64-L66 Which should be, i think: http://export.mapknitter.org/export (with $.post(
'http://export.mapknitter.org/export',
{
collections: distortableCollection.generateExportJson(),
scale: 30
}
);
|
alt: $.ajax({
url: "https://storage.googleapis.com/mapknitter-exports-warps/1559178763/status.json",
crossDomain: true,
method: 'post'
}) |
kubernetes CORS access info! https://discuss.kubernetes.io/t/how-to-enable-google-cloud-kubernetes-cors/3053 |
OK! Adding CORS to our sinatra app... or trying... publiclab/mapknitter-exporter-sinatra#44 |
OK, we'll resolve CORS and SSL for the sinatra app... in the meantime, you can work from 2 test files that mock the exporter responses with static files. File 1 would be the initial request (like
(although the ID number would change... it's just a timestamp) Once you load that file, the idea is to use the returned URL to fetch the status file itself, which will be updated periodicaly. The status file will return something in this format, though it'll change as the map processes: {"status_url":"https://mapknitter-exports-warps.storage.googleapis.com/1559243723/status.json","status":"warping 1 of 9","tms":false,"geotiff":false,"zip":false,"jpg":false,"export_id":1559243723,"user_id":null,"size":null,"width":null,"height":null,"start_time":null,"run_time":null,"gem_version":"1.0.7","cm_per_pixel":null} |
I'm imagining something like... but you know React better than I! |
OK! Progress! CORS is now enabled on exporter.mapknitter.org, and this works -- although ONLY from HTTP and not HTTPS: $.get("http://export.mapknitter.org/export?url=https://mapknitter.org/maps/pvdtest/warpables.json&scale=30", {
crossDomain: true
}).done(function(response){
// now fetch the actual status
getStatus("http://export.mapknitter.org" + response, console.log);
});
function getStatus(url, callback) {
$.get(url, {
crossDomain: true
}).done(function(response){
callback(response);
})
} |
Next i'll work with sebastian on SSL/HTTPS, but you can run this locally already! |
@jywarren ok I updated locally to the above function you gave in #286 (its a little messier but I will clean it up just concerned about functionality right now), but I am pretty confused because it doesn't include from it I get the output: AJAX request 1: /id/1559692778/status.json AJAX request 2 (using data from 1):{"status_url":null,"status":"starting","tms":false,"geotiff":false,"zip":false,"jpg":false,"export_id":1559692778,"user_id":null,"size":null,"width":null,"height":null,"start_time":"2019-06-04 23:59:38 +0000","run_time":null,"gem_version":"1.0.7","cm_per_pixel":null} Is this what we want right now? Lmk and I will clean up the function! |
Yes this is almost it! Basically there are multiple forms of submitting the
Json. My example used a URL, but yours will supply it in a post request as
the "collection" parameter (if I remember correctly, it's documented at the
mapknitter-exporter-sinatra readme) but the response should be the same. So
you run generateExportJson and assign it's output to "collection" in your
request. Make sense?
…On Tue, Jun 4, 2019, 8:05 PM Sasha Boginsky ***@***.***> wrote:
@jywarren <https://github.com/jywarren> ok I updated locally to the above
function you gave in #286
<#286> (its a
little messier but I will clean it up just concerned about functionality
right now), but I am pretty confused because it doesn't include
_generateExportJson, and the 2nd part is just making a get request.
from it I get the output:
AJAX request 1: /id/1559692778/status.json
AJAX request 2 (using data from
1):{"status_url":null,"status":"starting","tms":false,"geotiff":false,"zip":false,"jpg":false,"export_id":1559692778,"user_id":null,"size":null,"width":null,"height":null,"start_time":"2019-06-04
23:59:38 +0000","run_time":null,"gem_version":"1.0.7","cm_per_pixel":null}
Is this what we want right now?
Lmk and I will clean up the function!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#270?email_source=notifications&email_token=AAAF6J6C7OU6TZ773PFPMBDPY37J3A5CNFSM4HOGSC4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODW6GYFQ#issuecomment-498887702>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAF6J6766SLXLQBKK6P5KTPY37J3ANCNFSM4HOGSC4A>
.
|
@jywarren I tried a bunch of different combinations and I couldn't get it to work. Would you be available tomorrow afternoon to go through it with me and get it working? Sorry for the delay! |
I'm actually taking a couple days off, but I'll see if I can write an Ajax
request that works. Did the example here not work?
https://github.com/publiclab/mapknitter-exporter-sinatra/blob/main/README.md#usage
…On Thu, Jun 6, 2019, 12:24 AM Sasha Boginsky ***@***.***> wrote:
@jywarren <https://github.com/jywarren> I tried a bunch of different
combinations and I couldn't get it to work. Would you be available tomorrow
afternoon to go through it with me and get it working? Sorry for the delay!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#270?email_source=notifications&email_token=AAAF6J6BR6EHZYQGIJ4HVETPZC3P3A5CNFSM4HOGSC4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXB7AQY#issuecomment-499380291>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAF6J3XFFXQJIAZ65JU54DPZC3P3ANCNFSM4HOGSC4A>
.
|
OK we'll look at this now! |
Running this locally, at a non-SSL (http, not HTTPS) site, in the console, i see this succeed, code coming straight from your PR:
Maybe you saw an SSL error by running it from an HTTPS site? |
So, running this on MapKnitter, I see:
|
Sorry! OK, i tried this: collection = [{"cm_per_pixel":24.771,"created_at":"2019-04-30T20:40:21Z","deleted":false,"height":166,"history":"","id":312455,"image_content_type":"image/png","image_file_name":"test.png","image_file_size":103148,"locked":false,"map_id":13238,"nodes":[{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629578,"lat":"41.8200720823","lon":"-71.4033919887","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0},{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629579,"lat":"41.8199361572","lon":"-71.4029521064","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0},{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629580,"lat":"41.8197102811","lon":"-71.4030567126","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0},{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629581,"lat":"41.8198082274","lon":"-71.4035100059","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0}],"parent_id":null,"thumbnail":null,"updated_at":"2019-04-30T20:40:36Z","width":214,"src":"https://s3.amazonaws.com/grassrootsmapping/warpables/312455/test.png","srcmedium":"https://s3.amazonaws.com/grassrootsmapping/warpables/312455/test_medium.png"},{"cm_per_pixel":0.0,"created_at":"2019-04-30T20:40:25Z","deleted":false,"height":166,"history":"","id":312456,"image_content_type":"image/png","image_file_name":"test.png","image_file_size":103148,"locked":false,"map_id":13238,"nodes":[],"parent_id":null,"thumbnail":null,"updated_at":"2019-04-30T20:40:25Z","width":214,"src":"https://s3.amazonaws.com/grassrootsmapping/warpables/312456/test.png","srcmedium":"https://s3.amazonaws.com/grassrootsmapping/warpables/312456/test_medium.png"}];
$.ajax({
url:
"http://export.mapknitter.org/export",
crossDomain: true,
success: function _startExport(data) {
console.log(data);
$.ajax("http://export.mapknitter.org" + data, {
type: "POST",
data: {
collections: collection,
scale: 30
},
crossDomain: true
}).done(function(data) {
console.log(data);
});
},
}); And this DID see a CORS error. Looking... |
But the error is for so I think it's because it errored, and we got CORS blocked on the error! |
Realizing that we want the collection = [{"cm_per_pixel":24.771,"created_at":"2019-04-30T20:40:21Z","deleted":false,"height":166,"history":"","id":312455,"image_content_type":"image/png","image_file_name":"test.png","image_file_size":103148,"locked":false,"map_id":13238,"nodes":[{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629578,"lat":"41.8200720823","lon":"-71.4033919887","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0},{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629579,"lat":"41.8199361572","lon":"-71.4029521064","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0},{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629580,"lat":"41.8197102811","lon":"-71.4030567126","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0},{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629581,"lat":"41.8198082274","lon":"-71.4035100059","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0}],"parent_id":null,"thumbnail":null,"updated_at":"2019-04-30T20:40:36Z","width":214,"src":"https://s3.amazonaws.com/grassrootsmapping/warpables/312455/test.png","srcmedium":"https://s3.amazonaws.com/grassrootsmapping/warpables/312455/test_medium.png"},{"cm_per_pixel":0.0,"created_at":"2019-04-30T20:40:25Z","deleted":false,"height":166,"history":"","id":312456,"image_content_type":"image/png","image_file_name":"test.png","image_file_size":103148,"locked":false,"map_id":13238,"nodes":[],"parent_id":null,"thumbnail":null,"updated_at":"2019-04-30T20:40:25Z","width":214,"src":"https://s3.amazonaws.com/grassrootsmapping/warpables/312456/test.png","srcmedium":"https://s3.amazonaws.com/grassrootsmapping/warpables/312456/test_medium.png"}];
$.ajax({
url:
"http://export.mapknitter.org/export",
crossDomain: true,
type: "POST",
data: {
collection: collection,
scale: 30
},
success: function _startExport(data) {
console.log(data);
$.ajax("http://export.mapknitter.org" + data, {
type: "POST",
crossDomain: true
}).done(function(data) {
console.log(data);
});
},
}); But it doesn't... looking now.... |
https://github.com/publiclab/mapknitter-exporter-sinatra/blob/019548fbe21ba8f01ad7d219516af4d2c8c805de/app.rb#L71-L85 is where this should be receiving, but we got a 500 error... checking logs... |
Ha! Found the error:
|
On |
Aha! We needed to |
Got it!!! OK, here: collection = [{"cm_per_pixel":24.771,"created_at":"2019-04-30T20:40:21Z","deleted":false,"height":166,"history":"","id":312455,"image_content_type":"image/png","image_file_name":"test.png","image_file_size":103148,"locked":false,"map_id":13238,"nodes":[{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629578,"lat":"41.8200720823","lon":"-71.4033919887","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0},{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629579,"lat":"41.8199361572","lon":"-71.4029521064","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0},{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629580,"lat":"41.8197102811","lon":"-71.4030567126","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0},{"author":"warren","body":null,"color":"black","created_at":"2019-04-30T20:40:36Z","description":"","id":2629581,"lat":"41.8198082274","lon":"-71.4035100059","map_id":0,"name":"","order":0,"updated_at":"2019-04-30T20:40:36Z","way_id":0,"way_order":0}],"parent_id":null,"thumbnail":null,"updated_at":"2019-04-30T20:40:36Z","width":214,"src":"https://s3.amazonaws.com/grassrootsmapping/warpables/312455/test.png","srcmedium":"https://s3.amazonaws.com/grassrootsmapping/warpables/312455/test_medium.png"},{"cm_per_pixel":0.0,"created_at":"2019-04-30T20:40:25Z","deleted":false,"height":166,"history":"","id":312456,"image_content_type":"image/png","image_file_name":"test.png","image_file_size":103148,"locked":false,"map_id":13238,"nodes":[],"parent_id":null,"thumbnail":null,"updated_at":"2019-04-30T20:40:25Z","width":214,"src":"https://s3.amazonaws.com/grassrootsmapping/warpables/312456/test.png","srcmedium":"https://s3.amazonaws.com/grassrootsmapping/warpables/312456/test_medium.png"}];
$.ajax({
url:
"http://export.mapknitter.org/export",
crossDomain: true,
type: "POST",
data: {
collection: JSON.stringify(collection),
scale: 30
},
success: function _startExport(data) {
console.log(data);
$.ajax("http://export.mapknitter.org" + data, {
type: "GET",
crossDomain: true
}).done(function(data) {
console.log(data);
});
},
}); This works properly!!! |
And if you keep running this, it'll keep updating the status: data = "/id/1560202769/status.json"
$.ajax("http://export.mapknitter.org" + data, {
type: "GET",
crossDomain: true
}).done(function(data) {
console.log(data);
}); |
Hooray! This just returned:
And http://export.mapknitter.org/public/warps/1560202769/1560202769.jpg redirects to https://mapknitter-exports-warps.storage.googleapis.com/1560202769/1560202769.jpg, which shows: |
@jywarren I still get a 500 internal server error for the POST request and then a message saying I am blocked by CORS. You were able to run this on my PR from LDI? |
Hm, I was able to run it from any page that's http, not https -- you ran the entire snippet at #270 (comment) ? The 500 could be something malformed or erroring; the error pages themselves are not cors permitted, which makes it hard to debug. |
Post request payload: collection: {"images":[{"id":77,"src":"http://sasha.mapknitter.org/examples/example.png","nodes":[{"lat":51.51,"lng":-0.16},{"lat":51.51,"lng":-0.2},{"lat":51.49,"lng":-0.17},{"lat":51.49,"lng":-0.21}],"cm_per_pixel":18.28125},{"id":79,"src":"http://sasha.mapknitter.org/examples/example.png","nodes":[{"lat":51.5,"lng":-0.09},{"lat":51.5,"lng":-0.13},{"lat":51.48,"lng":-0.1},{"lat":51.48,"lng":-0.14}],"cm_per_pixel":18.28125},{"id":81,"src":"http://sasha.mapknitter.org/examples/example.png","nodes":[{"lat":51.51,"lng":-0.03},{"lat":51.51,"lng":-0.07},{"lat":51.49,"lng":-0.04},{"lat":51.49,"lng":-0.08}],"cm_per_pixel":18.28125}],"avg_cm_per_pixel":18.28125} |
Strangely, when I run this, I get:
But Sasha gets something different! So strange! |
local working implementation _runExport: function() {
var collection = this._generateExportJson();
$.ajax({
url: "http://export.mapknitter.org/export",
crossDomain: true,
type: "POST",
data: {
collection: JSON.stringify(collection.images),
scale: 30
},
success: function _getStatusJson(data) {
console.log(data);
$.ajax("http://export.mapknitter.org" + data, {
type: "GET",
crossDomain: true
}).done(function(data) {
console.log(data);
});
}
}); Output:
mirroring @jywarren's ajax call to show my different reply:
permanently getting |
Even stranger, when I go directly through the Google Cloud Storage interface, i get a
|
Maybe we were getting a locally browser cached
|
@jywarren is my next step here to open a PR to: the last PR really just grabbed that file finally, no cb to keep calling it |
yes, exactly. You'll store the returned status.json URL as a variable, and
then start a setInterval to run a periodic check on that URL, running a
callback function on the response each time.
What'll be great is to make it possible to set the callback function (maybe
onStatusUpdate(statusJson)?) as an overridable option. That way we can add
extra things when we integrate with MapKnitter, for example, saving the
status string to the database or something.
…On Fri, Jun 14, 2019 at 4:49 PM Sasha Boginsky ***@***.***> wrote:
@jywarren <https://github.com/jywarren> is my next step here to open a PR
to: distortableCollection.startExport(callbackFn) with basic console.log
callback function to show progress every X seconds
the last PR really just grabbed that file finally, no cb to keep calling it
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#270?email_source=notifications&email_token=AAAF6J5X3KZZHCTQXXDKB5LP2P7ZVA5CNFSM4HOGSC4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXX5UJQ#issuecomment-502258214>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAF6J3TTUIJYZFSDAAZH6DP2P7ZVANCNFSM4HOGSC4A>
.
|
I updated the checklist!!! |
follow-ups to #254 :
distortableCollection.avg_cm_per_pixel
generateExportJson
pulls fromdistortableCollection.avg_cm_per_pixel
status.json
file_getStatusJson
separated from outer ajax call_runExport
distortableCollection.startExport(callbackFn)
with basicconsole.log
callback function to show progress every X secondsThe text was updated successfully, but these errors were encountered: