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

Backfill original_filename #2577

Closed
3 tasks done
JoeCohen opened this issue Dec 13, 2024 · 2 comments
Closed
3 tasks done

Backfill original_filename #2577

JoeCohen opened this issue Dec 13, 2024 · 2 comments
Assignees
Labels
iNat interaction with iNat

Comments

@JoeCohen
Copy link
Member

JoeCohen commented Dec 13, 2024

Fix original_filename of Images of Observations imported from iNat prior to Fri Dec 13 15:03:37 2024 -0800
They are blank, and should be updated to look like this:

"iNat photo_id: 443196391, uuid: 9da79bb3-efc4-4ecd-8893-400b4d31c339"

I'll need to write script which:

  • finds those Observations (601 of them);
  • Uses the iNat API to get the iNat photos;
  • Matches them with MO images (I think this is possible by looking at the order of the photos and of the images);
  • Updates the image original_filename

Tasks

  • Copy script from PR to webserver
  • Run script once on webserver
  • Delete script from webserver
@JoeCohen JoeCohen added the bug label Dec 13, 2024
@JoeCohen JoeCohen reopened this Dec 17, 2024
@JoeCohen
Copy link
Member Author

The image.notes which need correction have aoriginal_name blank &&
notes in this form: "Imported from iNat 2024-09-24 14:59:20 +0000"

Last bad image:

irb(main):052>Image.where(Image[:notes] =~ /Imported from iNat/).where(original_name: "").order(created_at: :asc).last.id
  Image Load (1651.9ms)  SELECT `images`.* FROM `images` WHERE (`images`.`notes` REGEXP 'Imported from iNat') AND (`images`.`original_name` = '') ORDER BY `images`.`created_at` DESC LIMIT 1
=> 1730052

Last bad Obs

Observation.joins(:images).where(images: [foo]).pluck(:id)
  Observation Pluck (292.8ms)  SELECT `observations`.`id` FROM `observations` INNER JOIN `observation_images` ON `observation_images`.`observation_id` = `observations`.`id` INNER JOIN `images` ON `images`.`id` = `observation_images`.`image_id` WHERE `images`.`id` = 1730052
=> [567978]
bads = Observation.where(Observation[:id].lteq(567978)).where(source: "mo_inat_import")
...
irb(main):061> bads.size
...
=> 596

@JoeCohen
Copy link
Member Author

JoeCohen commented Dec 17, 2024

Now it gets a little complicated.
For each bad, wait 1 second, hit the iNat API for bad.inat_id,
For each photo where photo notes are blank.
set photo notes == something in this form: iNat photo_id: 446732921, uuid: c8327b74-36c2-4600-8a90-3e45a8cb3f51

@JoeCohen JoeCohen added iNat interaction with iNat and removed bug labels Dec 28, 2024
@JoeCohen JoeCohen linked a pull request Dec 28, 2024 that will close this issue
@JoeCohen JoeCohen self-assigned this Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iNat interaction with iNat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant