Skip to content

Commit

Permalink
Merge pull request #171 from crosscite/bug_cmetrics_variables_refacto…
Browse files Browse the repository at this point in the history
…r_fix

Bug metrics variables refactor fix
  • Loading branch information
kjgarza authored Mar 19, 2020
2 parents ff93a9a + a7925b7 commit 9ec6bf0
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 503 deletions.
6 changes: 3 additions & 3 deletions lib/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_works(params = {})
year: params.fetch('year', nil),
registered: params.fetch('registered', nil),
include: 'client',
'fields[dois]' => 'doi,creators,titles,descriptions,publisher,publicationYear,types,rightsList',
'fields[dois]' => 'doi,creators,titles,descriptions,publisher,publicationYear,types,rightsList,citationCount,viewCount,downloadCount',
'resource-type-id' => params.fetch('resource-type-id', nil),
'client-id' => params.fetch('data-center-id', nil),
'provider-id' => params.fetch('member-id', nil),
Expand All @@ -31,8 +31,8 @@ def get_works(params = {})

url = "#{ENV['API_URL']}/dois?" + URI.encode_www_form(params)
end
response = Maremma.get(url, headers: { "Content-Type" => "application/json;charset=UTF-8" }, timeout: TIMEOUT)
response = Maremma.get(url, headers: { "Content-Type" => "application/json;charset=UTF-8", "Accept-Encoding"=> "gzip" }, timeout: TIMEOUT)

{ data: response.body.fetch("data", []),
included: response.body.fetch("included", []),
errors: Array(response.body.fetch("errors", [])),
Expand Down
5 changes: 2 additions & 3 deletions spec/features/works/citation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
it 'show summary information' do
visit '/works/10.91819/71718'

expect(page).not_to have_css("#citations-tab")
expect(page).to have_css("#citations-tab")
# expect(page).to have_css("#summary-citations", text: "4 citations")
# expect(page).to have_css("#summary-views", text: "No usage information was reported.")
end

it 'show citation chart' do
visit '/works/10.91819/71718'

visit '/works/10.1007/978-1-4757-9930-9_8'
expect(page).not_to have_css("#citations-tab")
# expect(page).to have_css("#citations-tab", text: "4 Citations")
# expect(page).to have_css("small", text: "4 citations reported since publication in 2011.")
Expand Down
488 changes: 26 additions & 462 deletions spec/fixtures/vcr_cassettes/citation/show_citation_chart.yml

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions views/works/item.haml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
- attributes = item.fetch("attributes", {})
- puts attributes
- type = attributes.fetch("resource-type-id", nil)
- includes = @works.present? ? @works[:included] : @work[:included]
- work_types = Array.wrap(includes).select { |item| item["type"] == "work-types" }
- new_params = params[:model] == "works" && params["id"] == attributes.fetch("doi", nil) ? params.merge(external_link: true) : params
- title = Array.wrap(attributes["titles"]).first.to_h.fetch("title", nil).to_s.gsub(/"/, '\"')
- if @work.present? && attributes["views-over-time"].present?
- gon.chart_views = attributes["views-over-time"].map { |d| { "id" => d["yearMonth"], "title" => Date.strptime(d["yearMonth"], '%Y-%m').strftime('%B %Y'), "sum" => d["total"] } }
- if @work.present? && attributes["viewsOverTime"].present?
- gon.chart_views = attributes["viewsOverTime"].map { |d| { "id" => d["yearMonth"], "title" => Date.strptime(d["yearMonth"], '%Y-%m').strftime('%B %Y'), "sum" => d["total"] } }
- gon.yop = attributes.fetch("published", "").to_i
- if @work.present? && attributes["downloads-over-time"].present?
- gon.chart_downloads = attributes["downloads-over-time"].map { |d| { "id" => d["yearMonth"], "title" => Date.strptime(d["yearMonth"], '%Y-%m').strftime('%B %Y'), "sum" => d["total"] } }
- if @work.present? && attributes["downloadsOverTime"].present?
- gon.chart_downloads = attributes["downloadsOverTime"].map { |d| { "id" => d["yearMonth"], "title" => Date.strptime(d["yearMonth"], '%Y-%m').strftime('%B %Y'), "sum" => d["total"] } }
- gon.yop = attributes.fetch("published", "").to_i
- if @work.present? && attributes["citations-over-time"].present?
- gon.chart_citations = attributes["citations-over-time"].map { |d| { "id" => d["year"], "title" => d["year"], "sum" => d["total"] } }
- if @work.present? && attributes["citationsOverTime"].present?
- gon.chart_citations = attributes["citationsOverTime"].map { |d| { "id" => d["year"], "title" => d["year"], "sum" => d["total"] } }
- gon.yop = attributes.fetch("published", nil).to_i
-# - citation_events = includes.select { |e| e.dig("relationships", "doiForTarget", "data", "id") == attributes["doi"] }
-# - reference_events = includes.select { |e| e.dig("relationships", "doiForSource", "data", "id") == attributes["doi"] }
Expand All @@ -35,26 +36,26 @@
= license_img(attributes["license"])
.panel-footer
- if (attributes["citation-count"].to_i + attributes["view-count"].to_i + attributes["download-count"].to_i).zero?
- if (attributes["citationCount"].to_i + attributes["viewCount"].to_i + attributes["downloadCount"].to_i).zero?
%span.metrics{id: "summary-citations"}
.fa.fa-info-circle
No citations were reported. No usage information was reported.
- else
- if attributes["citation-count"].to_i.positive?
- if attributes["citationCount"].to_i.positive?
%span.metrics{id: "summary-citations"}
.fa.fa-quote-left
= pluralize(attributes["citation-count"].to_i, "citation")
= pluralize(attributes["citationCount"].to_i, "citation")
- else
%span.metrics
.fa.fa-info-circle
No citations were reported.
- if (attributes["view-count"].to_i + attributes["download-count"].to_i).positive?
- if (attributes["viewCount"].to_i + attributes["download-count"].to_i).positive?
%span.metrics{id: "summary-views"}
.fa.fa-eye
= pluralize(attributes["view-count"].to_i, "view")
= pluralize(attributes["viewCount"].to_i, "view")
%span.metrics{id: "summary-downloads"}
.fa.fa-download
= pluralize(attributes["download-count"].to_i, "download")
= pluralize(attributes["downloadCount"].to_i, "download")
- else
%span.metrics{id: "summary-views"}
.fa.fa-info-circle
Expand All @@ -76,13 +77,13 @@
- if user_signed_in? && is_person?
= haml :'works/claim', locals: { item: item }

- if @work.present? && (attributes["citation-count"].to_i + attributes["view-count"].to_i + attributes["download-count"].to_i).positive?
= haml :'works/visualisation', locals: { attributes: attributes, views: attributes["views-over-time"], downloads: attributes["downloads-over-time"], citations: attributes["citations-over-time"] }
- if @work.present? && (attributes["citationCount"].to_i + attributes["viewCount"].to_i + attributes["downloadCount"].to_i).positive?
= haml :'works/visualisation', locals: { attributes: attributes, views: attributes["viewsOverTime"], downloads: attributes["downloadsOverTime"], citations: attributes["citationsOverTime"] }
- if @work.present?
- data_center = @work[:included].find { |i| i.fetch("type", nil) == "clients" }
- client_name = data_center.fetch("attributes", {}).fetch("name", nil)
-# = haml :'works/citations', locals: { attributes: attributes, client_name: client_name }
- if @work.present? && (attributes["view-count"].to_i + attributes["download-count"].to_i).zero?
- if @work.present? && (attributes["viewCount"].to_i + attributes["downloadCount"].to_i).zero?
.panel-body.alert.alert-simple-info
= "This data repository is not currently reporting usage information. For information on how your repository can submit usage information, please see"
%a{href: 'https://support.datacite.org/docs/views-and-downloads'}
Expand Down
40 changes: 20 additions & 20 deletions views/works/visualisation.haml
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
%ul.nav.nav-tabs.usage{:role => "tablist"}
- if attributes["citation-count"].to_i > 0
- if attributes["citationCount"].to_i > 0
%li.nav-item.active
%a#citations-tab.nav-link.active{"aria-controls" => "citations", "aria-selected" => "true", "data-toggle" => "tab", :href => "#citations", :role => "tab"} #{pluralize(attributes["citation-count"], "Citation")}
%a#citations-tab.nav-link.active{"aria-controls" => "citations", "aria-selected" => "true", "data-toggle" => "tab", :href => "#citations", :role => "tab"} #{pluralize(attributes["citationCount"], "Citation")}

- if attributes["view-count"].to_i > 0 && attributes["citation-count"].to_i > 0
- if attributes["viewCount"].to_i > 0 && attributes["citationCount"].to_i > 0
%li.nav-item.usage
%a#views-tab.nav-link{"aria-controls" => "views", "aria-selected" => "false", "data-toggle" => "tab", :href => "#views", :role => "tab"} #{pluralize(attributes["view-count"], "View")}
- elsif attributes["view-count"].to_i > 0
%a#views-tab.nav-link{"aria-controls" => "views", "aria-selected" => "false", "data-toggle" => "tab", :href => "#views", :role => "tab"} #{pluralize(attributes["viewCount"], "View")}
- elsif attributes["viewCount"].to_i > 0
%li.nav-item.usage.active
%a#views-tab.nav-link.active{"aria-controls" => "views", "aria-selected" => "true", "data-toggle" => "tab", :href => "#views", :role => "tab"} #{pluralize(attributes["view-count"], "View")}
%a#views-tab.nav-link.active{"aria-controls" => "views", "aria-selected" => "true", "data-toggle" => "tab", :href => "#views", :role => "tab"} #{pluralize(attributes["viewCount"], "View")}

- if attributes["download-count"].to_i > 0 && attributes["view-count"].to_i > 0
- if attributes["downloadCount"].to_i > 0 && attributes["viewCount"].to_i > 0
%li.nav-item.usage
%a#downloads-tab.nav-link{"aria-controls" => "downloads", "aria-selected" => "false", "data-toggle" => "tab", :href => "#downloads", :role => "tab"} #{pluralize(attributes["download-count"], "Download")}
- elsif attributes["download-count"].to_i > 0
%a#downloads-tab.nav-link{"aria-controls" => "downloads", "aria-selected" => "false", "data-toggle" => "tab", :href => "#downloads", :role => "tab"} #{pluralize(attributes["downloadCount"], "Download")}
- elsif attributes["downloadCount"].to_i > 0
%li.nav-item.usage.active
%a#downloads-tab.nav-link.active{"aria-controls" => "downloads", "aria-selected" => "true", "data-toggle" => "tab", :href => "#downloads", :role => "tab"} #{pluralize(attributes["download-count"], "Download")}
%a#downloads-tab.nav-link.active{"aria-controls" => "downloads", "aria-selected" => "true", "data-toggle" => "tab", :href => "#downloads", :role => "tab"} #{pluralize(attributes["downloadCount"], "Download")}

.panel.panel-default
.panel-body.usage-charts
%div#myTabContent.tab-content
- if attributes["citation-count"].to_i > 0
- if attributes["citationCount"].to_i > 0
.row#citations.tab-pane.active{"aria-labelledby" => "citations-tab", :role => "tabpanel", :style => "position: relative;"}
.col-lg-12
.row
.p{:style => "padding-left:20px;"}
= "<small>#{pluralize(attributes["citation-count"], "citation")} reported since publication in #{attributes.fetch("published", "")}.</small>"
= "<small>#{pluralize(attributes["citationCount"], "citation")} reported since publication in #{attributes.fetch("published", "")}.</small>"
.row#citations-chart{:style => "padding-left:10px;"}
- if attributes["view-count"].to_i > 0 && attributes["citation-count"].to_i > 0
- if attributes["viewCount"].to_i > 0 && attributes["citationCount"].to_i > 0
.row#views.tab-pane.fade{"aria-labelledby" => "views-tab", :role => "tabpanel",:style => "position: relative;"}
.col-lg-12
.row
.p{:style => "padding-left:20px;"}
= "<small>#{pluralize(attributes["view-count"], "view") } reported since publication in #{attributes.fetch("published", "")}.</small>"
= "<small>#{pluralize(attributes["viewCount"], "view") } reported since publication in #{attributes.fetch("published", "")}.</small>"
.row#views-chart{:style => "padding-left:10px;"}
%br
.row{:style => "position: relative;"}
Expand All @@ -44,12 +44,12 @@
= "meaning that Internet robots and repeats within a certain time frame are excluded.</br> "
%a{href: 'https://support.datacite.org/docs/usage-stats'}
What does this mean?
- elsif attributes["view-count"].to_i > 0
- elsif attributes["viewCount"].to_i > 0
.row#views.tab-pane.active{"aria-labelledby" => "views-tab", :role => "tabpanel",:style => "position: relative;"}
.col-lg-12
.row
.p{:style => "padding-left:20px;"}
= "<small>#{pluralize(attributes["view-count"].to_i, "view") } reported since publication in #{attributes.fetch("published", "")}.</small>"
= "<small>#{pluralize(attributes["viewCount"].to_i, "view") } reported since publication in #{attributes.fetch("published", "")}.</small>"
.row#views-chart{:style => "padding-left:10px;"}
%br
.row{:style => "position: relative;"}
Expand All @@ -62,12 +62,12 @@
%a{href: 'https://support.datacite.org/docs/usage-stats'}
What does this mean?

- if attributes["download-count"].to_i > 0 && attributes["view-count"].to_i > 0
- if attributes["downloadCount"].to_i > 0 && attributes["viewCount"].to_i > 0
.row#downloads.tab-pane.fade{"aria-labelledby" => "downloads-tab", :role => "tabpanel", :style => "position: relative;"}
.col-lg-12
.row
.p{:style => "padding-left:20px;"}
= "<small>#{pluralize(attributes["download-count"], "download") } reported since publication in #{attributes.fetch("published", "")}.</small>"
= "<small>#{pluralize(attributes["downloadCount"], "download") } reported since publication in #{attributes.fetch("published", "")}.</small>"
.row#downloads-chart{:style => "padding-left:10px;"}
%br
.row
Expand All @@ -79,12 +79,12 @@
= "meaning that Internet robots and repeats within a certain time frame are excluded.</br> "
%a{href: 'https://support.datacite.org/docs/usage-stats'}
What does this mean?
- elsif attributes["download-count"].to_i > 0
- elsif attributes["downloadCount"].to_i > 0
.row#downloads.tab-pane.active{"aria-labelledby" => "downloads-tab", :role => "tabpanel", :style => "position: relative;"}
.col-lg-12
.row
.p{:style => "padding-left:20px;"}
= "<small>#{pluralize(attributes["download-count"], "download") } reported since publication in #{attributes.fetch("published", "")}.</small>"
= "<small>#{pluralize(attributes["downloadCount"], "download") } reported since publication in #{attributes.fetch("published", "")}.</small>"
.row#downloads-chart{:style => "padding-left:10px;"}
%br
.row
Expand Down

0 comments on commit 9ec6bf0

Please sign in to comment.