Skip to content

Commit

Permalink
calculate number of draft dois in export. #676
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Nov 27, 2020
1 parent 37ea092 commit 656e35b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 23 additions & 2 deletions app/controllers/exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,24 @@ def repositories
}
end

draft_response =
DataciteDoi.query(
nil,
state: "draft",
page: { size: 0, number: 1 },
totals_agg: "client_export",
)

draft_client_totals = {}
draft_totals_buckets = draft_response.aggregations.clients_totals.buckets
draft_totals_buckets.each do |totals|
draft_client_totals[totals["key"]] = {
"count" => totals["doc_count"],
"this_year" => totals.this_year.buckets[0]["doc_count"],
"last_year" => totals.last_year.buckets[0]["doc_count"],
}
end

headers = [
"Repository Name",
"Repository ID",
Expand All @@ -389,14 +407,15 @@ def repositories
"doisCurrentYear",
"doisPreviousYear",
"doisTotal",
"doisDraftTotal",
"doisDbTotal",
"doisMissing"
]

csv = headers.to_csv

# get doi counts from database
dois_by_client = DataciteDoi.where.not(aasm_state: "draft").group(:datacentre).count
dois_by_client = DataciteDoi.group(:datacentre).count

clients.each do |client|
# Limit for salesforce default of max 80 chars
Expand All @@ -407,6 +426,7 @@ def repositories

db_total = dois_by_client[client.id.to_i].to_i
es_total = client_totals[client.uid] ? client_totals[client.uid]["count"] : 0
es_draft_total = draft_client_totals[client.uid] ? draft_client_totals[client.uid]["count"] : 0

row = {
accountName: name,
Expand Down Expand Up @@ -444,8 +464,9 @@ def repositories
0
end,
doisCountTotal: es_total,
doisCountDraftTotal: es_draft_total,
doisDbTotal: db_total,
doisMissing: db_total - es_total,
doisMissing: db_total - (es_total + es_draft_total),
}.values

csv += CSV.generate_line row
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/exports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
)
dois_total = csv[1].strip.split(",")[15].to_i
expect(dois_total).to eq(3)
dois_missing = csv[1].strip.split(",")[17].to_i
dois_missing = csv[1].strip.split(",")[18].to_i
expect(dois_missing).to eq(0)
end

Expand All @@ -113,7 +113,7 @@
)
dois_total = csv[1].strip.split(",")[15].to_i
expect(dois_total).to eq(3)
dois_missing = csv[1].strip.split(",")[17].to_i
dois_missing = csv[1].strip.split(",")[18].to_i
expect(dois_missing).to eq(0)
end
end
Expand Down

0 comments on commit 656e35b

Please sign in to comment.