Skip to content

Instantly share code, notes, and snippets.

@dshorthouse
Created September 9, 2023 17:31
Show Gist options
  • Save dshorthouse/56a33c070f149a16e81320dfb4c948ac to your computer and use it in GitHub Desktop.
Save dshorthouse/56a33c070f149a16e81320dfb4c948ac to your computer and use it in GitHub Desktop.
Bionomia scratchpad to explore wikidata expeditions
# Q1312945 Expedition
qids = ["Q108669", "Q63760", "Q62747", "Q104839", "Q96384", "Q96384", "Q85444", "Q101823", "Q347529", "Q43881351", "Q95248572"]
user_ids = qids.map do |q|
u = User.find_by_identifier(q) rescue nil
u.id if !u.nil?
end.compact
start_date = "31 July 1898"
end_date = "1 May 1899"
CSV.open("Q1312945.csv", 'w') do |csv|
csv << Occurrence.column_names
Occurrence.joins(:user_occurrences)
.where(user_occurrences: { user_id: user_ids })
.where(user_occurrences: { visible: true })
.where("user_occurrences.action LIKE 'recorded'")
.where("eventDate_processed >= ?", Date.parse(start_date))
.where("eventDate_processed <= ?", Date.parse(end_date))
.find_each do |o|
csv << o.attributes.values
end
end
# Q4137287 Expedition
qids = ["Q67395", "Q109547"]
user_ids = qids.map do |q|
u = User.find_by_identifier(q) rescue nil
u.id if !u.nil?
end.compact
start_date = "1909-01-01" #Fudged here because only year is provided
end_date = "1913-12-31" #Fudged here because only year is provided
CSV.open("Q4137287.csv", 'w') do |csv|
csv << Occurrence.column_names
Occurrence.joins(:user_occurrences)
.where(user_occurrences: { user_id: user_ids })
.where(user_occurrences: { visible: true })
.where("user_occurrences.action LIKE 'recorded'")
.where("eventDate_processed >= ?", Date.parse(start_date))
.where("eventDate_processed <= ?", Date.parse(end_date))
.find_each do |o|
csv << o.attributes.values
end
end
# Q121786480 Expedition
qids = ["0000-0003-2661-2913", "0000-0001-5164-3186", "0000-0002-4989-3976"] #Missing some ORCIDs here
user_ids = qids.map do |q|
u = User.find_by_identifier(q) rescue nil
u.id if !u.nil?
end.compact
start_date = "5 September 1995"
end_date = "6 October 1995"
CSV.open("Q121786480.csv", 'w') do |csv|
csv << Occurrence.column_names
Occurrence.joins(:user_occurrences)
.where(user_occurrences: { user_id: user_ids })
.where(user_occurrences: { visible: true })
.where("user_occurrences.action LIKE 'recorded'")
.where("eventDate_processed >= ?", Date.parse(start_date))
.where("eventDate_processed <= ?", Date.parse(end_date))
.find_each do |o|
csv << o.attributes.values
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment