-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2760 from projecthydra/guard_nil
Guard for nil GA profile in FileDownloadStat
- Loading branch information
Showing
17 changed files
with
219 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Called by the stats controller, it finds cached file pageview data, | ||
# and prepares it for visualization in /app/views/stats/file.html.erb | ||
module Sufia | ||
class FileUsage < StatsUsagePresenter | ||
def initialize(id) | ||
self.model = ::FileSet.find(id) | ||
end | ||
|
||
alias file model | ||
|
||
def total_downloads | ||
downloads.reduce(0) { |total, result| total + result[1].to_i } | ||
end | ||
|
||
def total_pageviews | ||
pageviews.reduce(0) { |total, result| total + result[1].to_i } | ||
end | ||
|
||
# Package data for visualization using JQuery Flot | ||
def to_flot | ||
[ | ||
{ label: "Pageviews", data: pageviews }, | ||
{ label: "Downloads", data: downloads } | ||
] | ||
end | ||
|
||
private | ||
|
||
def downloads | ||
to_flots(FileDownloadStat.statistics(model, created, user_id)) | ||
end | ||
|
||
def pageviews | ||
to_flots(FileViewStat.statistics(model, created, user_id)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Sufia | ||
# Methods used by both WorkUsage and FileUsage | ||
class StatsUsagePresenter | ||
attr_accessor :id, :model | ||
|
||
def created | ||
@created ||= date_for_analytics | ||
end | ||
|
||
private | ||
|
||
def user_id | ||
@user_id ||= begin | ||
user = Hydra::Ability.user_class.find_by_user_key(model.depositor) | ||
user ? user.id : nil | ||
end | ||
end | ||
|
||
# TODO: make this a lazy enumerator | ||
def to_flots(stats) | ||
stats.map(&:to_flot) | ||
end | ||
|
||
# model.date_uploaded reflects the date the object was uploaded by the user | ||
# and therefore (if available) the date that we want to use for the stats | ||
# model.create_date reflects the date the file was added to Fedora. On data | ||
# migrated from one repository to another the created_date can be later | ||
# than the date the file was uploaded. | ||
def date_for_analytics | ||
earliest = Sufia.config.analytic_start_date | ||
date_uploaded = string_to_date(model.date_uploaded) | ||
date_analytics = date_uploaded ? date_uploaded : model.create_date | ||
return date_analytics if earliest.blank? | ||
earliest > date_analytics ? earliest : date_analytics | ||
end | ||
|
||
def string_to_date(date_str) | ||
Time.zone.parse(date_str) | ||
rescue ArgumentError, TypeError | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# class WorkUsage follows the model established by FileUsage | ||
# Called by the stats controller, it finds cached work pageview data, | ||
# and prepares it for visualization in /app/views/stats/work.html.erb | ||
module Sufia | ||
class WorkUsage < StatsUsagePresenter | ||
def initialize(id) | ||
self.model = CurationConcerns::WorkRelation.new.find(id) | ||
end | ||
|
||
alias work model | ||
delegate :to_s, to: :model | ||
|
||
def total_pageviews | ||
pageviews.reduce(0) { |total, result| total + result[1].to_i } | ||
end | ||
|
||
# Package data for visualization using JQuery Flot | ||
def to_flot | ||
[ | ||
{ label: "Pageviews", data: pageviews } | ||
] | ||
end | ||
|
||
private | ||
|
||
def pageviews | ||
to_flots WorkViewStat.statistics(model, created, user_id) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.