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

Fix broken visualizations of single articles #24

Merged
merged 2 commits into from
Sep 5, 2014
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion lib/alm_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ def self.get_data_for_one_article(report_dois)
results = article["sources"].inject({}) do | result, source |
key = source["name"].to_sym
result[key] = {}
result[key][:histories] = source["histories"]
result[key][:total] = source["metrics"]["total"].to_i
result
end
Expand Down
36 changes: 20 additions & 16 deletions lib/chart_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def self.generate_data_for_subject_area_chart(report)
subject_area_data = {}

report.report_dois.each do | report_doi |
# get the subject area
# get the subject area
if !report_doi.solr["subject"].nil?
# collect the second level subject areas
# we are looking for unique list of second level subject areas
Expand Down Expand Up @@ -69,7 +69,7 @@ def self.generate_data_for_subject_area_chart(report)
return article_usage_citation_subject_area_data
end


# Generates tooltip text for markers on the article locations chart,
# based on the author affiliations. Returns a tuple of the first
# and second lines of the tooltip. (Unfortunately, it seems impossible
Expand All @@ -92,11 +92,11 @@ def self.generate_location_tooltip(address, author_count, institutions)
end
return [line1, line2]
end
# Generate data for author location geo graph

# Generate data for author location geo graph
def self.generate_data_for_articles_by_location_chart(report)
total_authors_data = 0

# Map from address to author count and list of author institutions, parsed
# from the author affiliate data.
address_to_count_and_inst = Hash.new{|h, k| h[k] = [0, []]}
Expand Down Expand Up @@ -147,7 +147,7 @@ def self.generate_data_for_articles_by_location_chart(report)
# a linear scale, the large markers tend to take over the map. So after
# playing around a while I settled on the following concave function.
size = Math.atan(Math.log2(count + 1))

# There's an undocumented feature of the GeoChart where you can specify
# the first line of tooltip text as an element right after the lat/lng.
# Otherwise, the first line will be lat/lng. The final element is the
Expand All @@ -166,7 +166,7 @@ def self.generate_data_for_articles_by_location_chart(report)
institutions = fields[1]
size = Math.atan(Math.log2(count + 1))
tooltip = generate_location_tooltip(address, count, institutions)

# When we're not in lat/lng mode, the first line of the tooltip must
# be the address.
article_locations_data << [address, size, size, tooltip[1]]
Expand All @@ -176,7 +176,7 @@ def self.generate_data_for_articles_by_location_chart(report)
end


# Generate data for single article usage chart
# Generate data for single article usage chart
def self.generate_data_for_usage_chart(report)

# get counter and pmc usage stat data
Expand All @@ -202,8 +202,8 @@ def self.generate_data_for_usage_chart(report)

month_index = 0

# process the usage data in order
# ignore gaps
# process the usage data in order
# ignore gaps
sorted_keys.each do | key |
counter_month_data = counter_data[key]
pmc_month_data = pmc_data[key]
Expand All @@ -229,8 +229,8 @@ def self.generate_data_for_citation_chart(report)

article_citation_data = []

if (report.report_dois[0].alm[:crossref][:total] == 0 &&
report.report_dois[0].alm[:pubmed][:total] == 0 &&
if (report.report_dois[0].alm[:crossref][:total] == 0 &&
report.report_dois[0].alm[:pubmed][:total] == 0 &&
report.report_dois[0].alm[:scopus][:total] == 0)

return article_citation_data
Expand All @@ -240,6 +240,9 @@ def self.generate_data_for_citation_chart(report)
pubmed_history_data = process_history_data(report.report_dois[0].alm[:pubmed][:histories])
scopus_history_data = process_history_data(report.report_dois[0].alm[:scopus][:histories])

# check that we have history data
return [] if crossref_history_data.empty? && pubmed_history_data.empty? && scopus_history_data.empty?

# starting date is the publication date
data_date = Date.parse(report.report_dois[0].alm[:publication_date])
current_date = DateTime.now.to_date
Expand Down Expand Up @@ -324,7 +327,7 @@ def self.generate_data_for_social_data_chart(report)
index = 1
column = {}

social_data.each do | data |
social_data.each do | data |
if (!data[:data].empty?)
# collect the sources that will be used for the graph (ones with data)
column_header << data[:column_name]
Expand Down Expand Up @@ -361,7 +364,7 @@ def self.generate_data_for_social_data_chart(report)
social_scatter << row
end
end

month_index = month_index + 1
data_date = data_date >> 1
end
Expand Down Expand Up @@ -406,6 +409,7 @@ def self.generate_data_for_mendeley_reader_chart(report)


def self.process_history_data(history_data)
return {} unless history_data.is_a?(Array)

monthly_historical_data = {}

Expand All @@ -422,7 +426,7 @@ def self.process_history_data(history_data)

current_date = data_date

# loop through the historical data and pick out one data point per month
# loop through the historical data and pick out one data point per month
# want to grab the first data retrieval event
# alm usually retrieves data more than once a month
history_data.each do | data |
Expand All @@ -447,4 +451,4 @@ def self.process_history_data(history_data)
end


end
end
Loading