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

chore: add time limit to geographic author report #1676

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/tasks/stash_engine_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,23 @@ namespace :identifiers do

desc 'Generate a report of Dryad authors and their countries'
task geographic_authors_report: :environment do
# Get the year-month specified in YEAR_MONTH environment variable.
# If none, default to the previously completed month.
if ENV['YEAR_MONTH'].blank?
p 'No month specified, assuming last month.'
year_month = 1.month.ago.strftime('%Y-%m')
else
year_month = ENV['YEAR_MONTH']
end

p "Writing Geographic Authors Report for #{year_month} to file..."
CSV.open('geographic_authors_report.csv', 'w') do |csv|
csv << ['Dataset DOI', 'Author First', 'Author Last', 'Institution', 'Country']
StashEngine::Identifier.publicly_viewable.find_each do |i|
# Limit the query to datasets that existed at the time of the target report,
# and have been updated the within the month of the target.
limit_date = Date.parse("#{year_month}-01")
limit_date_filter = "updated_at > '#{limit_date - 1.day}' AND created_at < '#{limit_date + 1.month}' "
StashEngine::Identifier.publicly_viewable.where(limit_date_filter).find_each do |i|
res = i.latest_viewable_resource
res&.authors&.each do |a|
affil = a.affiliation
Expand Down
Loading