-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename QueryService to Statistics::QueryService
This better reflects it's scope as specifically for statistics. We may want to repurpose a general Hyrax::QueryService for the Valkyrie integration.
- Loading branch information
Showing
7 changed files
with
71 additions
and
60 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Hyrax | ||
module Statistics | ||
class QueryService | ||
# query to find works created during the time range | ||
# @param [DateTime] start_datetime starting date time for range query | ||
# @param [DateTime] end_datetime ending date time for range query | ||
def find_by_date_created(start_datetime, end_datetime = nil) | ||
return [] if start_datetime.blank? # no date just return nothing | ||
relation.where(build_date_query(start_datetime, end_datetime)) | ||
end | ||
|
||
def find_registered_in_date_range(start_datetime, end_datetime = nil) | ||
find_by_date_created(start_datetime, end_datetime).merge(where_registered) | ||
end | ||
|
||
def find_public_in_date_range(start_datetime, end_datetime = nil) | ||
find_by_date_created(start_datetime, end_datetime).merge(where_public) | ||
end | ||
|
||
def where_public | ||
where_access_is 'public' | ||
end | ||
|
||
def where_registered | ||
where_access_is 'registered' | ||
end | ||
|
||
def build_date_query(start_datetime, end_datetime) | ||
start_date_str = start_datetime.utc.strftime(date_format) | ||
end_date_str = if end_datetime.blank? | ||
"*" | ||
else | ||
end_datetime.utc.strftime(date_format) | ||
end | ||
"system_create_dtsi:[#{start_date_str} TO #{end_date_str}]" | ||
end | ||
|
||
delegate :count, to: :relation | ||
|
||
def relation | ||
Hyrax::WorkRelation.new | ||
end | ||
|
||
private | ||
|
||
def where_access_is(access_level) | ||
relation.where Hydra.config.permissions.read.group => access_level | ||
end | ||
|
||
def date_format | ||
"%Y-%m-%dT%H:%M:%SZ" | ||
end | ||
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
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