Skip to content
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

auto-detect json from response #1346

Closed
wants to merge 6 commits into from
Closed

Conversation

7malikk
Copy link
Collaborator

@7malikk 7malikk commented Feb 5, 2023

Fixes #1343

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with grunt test
  • code is in a uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updates
  • @mention the original creator of the issue in a comment below for help or for a review

UI changes:

When there are multiple JSON files in URL response
loadJSON-t2

When there is just one JSON file in URL response
loadJSON-t1

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 5, 2023

Hello @jywarren, in trying to address the solution using the method in #1343, I came across a small disparity.

IA returns JSON files like so:
someWork
With this, I could not verify if the JSON file contains images or not.

So I pivoted to construct the URL and pass it to the reconstructMapFromURL() function here

What are your thoughts?

@jywarren
Copy link
Member

jywarren commented Feb 5, 2023

Ah I see, that makes sense, we don't see the contents. We could try two things:

  1. Download and test each JSON file (could be a lot of requests but probably won't be, people don't store a lot of JSON files in IA!)
  2. Have a consistent name for the JSON file, kind of like package.json or something. We could call it mapknitter.json?

What do you prefer? We could also have it search for mapknitter.json first but if it doesn't find it, try all other JSON files?

@jywarren
Copy link
Member

jywarren commented Feb 5, 2023

Or we could let people choose one from a list, but that's a lot of extra UI to design! 😅

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 5, 2023

  1. Download and test each JSON file (could be a lot of requests but probably won't be, people don't store a lot of JSON files in IA!)

By download, do you mean we should load it on the tile layer? I'm not sure I understand.

  1. Have a consistent name for the JSON file, kind of like package.json or something. We could call it mapknitter.json?

Alright, I understand this

What do you prefer? We could also have it search for mapknitter.json first but if it doesn't find it, try all other JSON files?

Okay, so do you mean if there's no Json file named mapknitter.json it should load whatever Json file is available?

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 5, 2023

Or we could let people choose one from a list, but that's a lot of extra UI to design! 😅

😅😅
That's right.

So what's your final say, I'm still trying to wrap my head around the previous comment

@jywarren
Copy link
Member

jywarren commented Feb 5, 2023 via email

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 5, 2023

I'm not sure! Maybe the easiest way for now is to standardize the name.
Then we can add full auto detection later?

Sounds good to me.
What of cases of multiple files?

Also should standardization remove the need to prompt the user for a file name?

And I believe this will affect the download button too, so the naming should be standardized for now

@jywarren
Copy link
Member

jywarren commented Feb 5, 2023 via email

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 5, 2023

What if it just has to start with "mapknitter" but could also contain later
characters like date, a more specific label. So mapknitter-______.json. And
we just use the first one we find, for now.

Okay, I think that makes sense

So the first match for the search of "mapknitter" should be loaded.

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 5, 2023

@jywarren I made the changes to have a standardized name of mapknitter with a unique ID generated from the time it was downloaded resulting in a filename of: mapknitter-1293929493 like so:

newDownload

I also updated the JSON filter to check for files that start with "mapknitter" and are in JSON format and prompt the user. If the user confirms to load it, it is then loaded on the map like so:

loadNewJSON

@jywarren
Copy link
Member

jywarren commented Feb 5, 2023

This sounds great. What if the random number is a timestamp? Or a date time formatted string like 20:00-01-04-2023 or something?

Testing your code out now!


function showImages(getUrl) {
const url = getUrl.replace('details', 'metadata');

axios.get(url)
.then((response) => {
.then((response) => {
loadJSONfromResponse(response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, but I'm seeing this error when entering the url https://archive.org/details/sanborn-1885

DistortableCollection.js:226 err TypeError: Cannot read properties of undefined (reading 'length')

The JSON in this is mapknitter.json and the contents are:

[{"id":1504,"src":"https://archive.org/download/sanborn-1885/sanborn-1885.jpg",
"width":7573,
"height":6396,
"image_file_name":"sanborn-1885.jpg",
"nodes":[
{"lat":39.32869582897733,"lon":-120.187548995018},
{"lat":39.32982863334289,"lon":-120.18338084220888},
{"lat":39.3270941035765,"lon":-120.182141661644},
{"lat":39.32596125491416,"lon":-120.18630981445314}
],"cm_per_pixel":10.875006010132818}]

What do you think is happening? Ah, look:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'avg_cm_per_pixel') at reconstructMapFromJson (archive.js:254:53)

Maybe we have to check for that first, in case it doesn't exist?

Great work so far!!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh alright, I'll add that check

Although I have an idea, I'd explore it and get back to you

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 6, 2023

@jywarren I've added the check for the avg_cm_per_pixel though it looks a tad hacky, what do you think?

@jywarren
Copy link
Member

jywarren commented Feb 6, 2023

Hmm, can't we still reconstruct without this value? Where are we depending on it?

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 6, 2023

Hmm, can't we still reconstruct without this value? Where are we depending on it?

I wondered the same thing we do make use of it here, but I am yet to answer the question if the reconstruction from JSON is dependent on that value

@jywarren
Copy link
Member

jywarren commented Feb 6, 2023

I want to say we are providing it optionally. Instead of rejecting if we don't have the value, shall we make the change in the following area to only include that value in the output if it exists, otherwise we don't set that property on line 215?

avg_cm_per_pixel: response.data.avg_cm_per_pixel,

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 7, 2023

I want to say we are providing it optionally. Instead of rejecting if we don't have the value, shall we make the change in the following area to only include that value in the output if it exists, otherwise we don't set that property on line 215?

Alright, I will give it a shot @jywarren

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 7, 2023

I want to say we are providing it optionally. Instead of rejecting if we don't have the value, shall we make the change in the following area to only include that value in the output if it exists, otherwise we don't set that property on line 215?

While attempting to do this, I noticed that the format which the JSON file I saved is integral to how it would be reconstructed based on the setup here:

if (response.data.images.length > 1) {
response.data.images.forEach((data) => {

I propose we stick to a single format of saving JSON files, our choices are :

{"avg_cm_per_pixel":7.291666666666667,
"images":[{image1}, {image2}]
}

or

[{image1}, {image2}]

What do you think @jywarren?

@segun-codes
Copy link
Collaborator

I want to say we are providing it optionally. Instead of rejecting if we don't have the value, shall we make the change in the following area to only include that value in the output if it exists, otherwise we don't set that property on line 215?

While attempting to do this, I noticed that the format which the JSON file I saved is integral to how it would be reconstructed based on the setup here:

if (response.data.images.length > 1) {
response.data.images.forEach((data) => {

I propose we stick to a single format of saving JSON files, our choices are :

{"avg_cm_per_pixel":7.291666666666667,
"images":[{image1}, {image2}]
}

or

[{image1}, {image2}]

What do you think @jywarren?

Oh! @7malikk, good observation. Your question is similar to what we are discussing here #1345

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 7, 2023

Oh! @7malikk, good observation. Your question is similar to what we are discussing here #1345

Really? @segun-codes, let me go give it a read through

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 9, 2023

Hello, @jywarren I've made avg_cm_per_pixel an optional property in reconstructing the map from JSON URL.
I took into consideration changes from #1345 which upon final works, this PR would be ready for merge after some conflict resolutions

@jywarren
Copy link
Member

jywarren commented Feb 9, 2023 via email

@7malikk
Copy link
Collaborator Author

7malikk commented Feb 13, 2023

@jywarren this PR is refactored at #1351, I'll be closing this one

@7malikk 7malikk closed this Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prompt user of saved map state
3 participants