diff --git a/controllers/analytics_controller.rb b/controllers/analytics_controller.rb new file mode 100644 index 00000000..b6c2207c --- /dev/null +++ b/controllers/analytics_controller.rb @@ -0,0 +1,44 @@ +require 'csv' +class AnalyticsController < ApplicationController + + ## + # get all ontology analytics for a given year/month combination + # TODO use a namespace analytics after migration the old OntologyAnalyticsController + namespace "/data/analytics" do + + get 'ontologies' do + expires 86400, :public + year = year_param(params) + error 400, "The year you supplied is invalid. Valid years start with 2 and contain 4 digits." if params["year"] && !year + month = month_param(params) + error 400, "The month you supplied is invalid. Valid months are 1-12." if params["month"] && !month + acronyms = restricted_ontologies_to_acronyms(params) + analytics = Ontology.analytics(year, month, acronyms) + + reply analytics + end + + + get 'users' do + expires 86400, :public + year = year_param(params) + error 400, "The year you supplied is invalid. Valid years start with 2 and contain 4 digits." if params["year"] && !year + month = month_param(params) + error 400, "The month you supplied is invalid. Valid months are 1-12." if params["month"] && !month + analytics = User.analytics(year, month) + reply analytics['all_users'] + end + + get 'page_visits' do + expires 86400, :public + year = year_param(params) + error 400, "The year you supplied is invalid. Valid years start with 2 and contain 4 digits." if params["year"] && !year + month = month_param(params) + error 400, "The month you supplied is invalid. Valid months are 1-12." if params["month"] && !month + analytics = User.page_visits_analytics + reply analytics['all_pages'] + end + + end + +end diff --git a/helpers/application_helper.rb b/helpers/application_helper.rb index d90630a3..24893eef 100644 --- a/helpers/application_helper.rb +++ b/helpers/application_helper.rb @@ -276,7 +276,7 @@ def month_param(params=nil) if params["month"] month = params["month"].strip if %r{(?^(0[1-9]|[1-9]|1[0-2])$)}x === month - month.to_i + month.to_i.to_s end end end @@ -287,7 +287,7 @@ def year_param(params=nil) if params["year"] year = params["year"].strip if %r{(?^([1-2]\d{3})$)}x === year - year.to_i + year.to_i.to_s end end end