Skip to content

Commit

Permalink
Merge branch 'development' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Dec 27, 2023
2 parents d20e944 + e341c63 commit 328b9be
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
45 changes: 45 additions & 0 deletions controllers/analytics_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'csv'

class OntologyAnalyticsController < 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
4 changes: 2 additions & 2 deletions helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def month_param(params=nil)
if params["month"]
month = params["month"].strip
if %r{(?<month>^(0[1-9]|[1-9]|1[0-2])$)}x === month
month.to_i
month.to_i.to_s
end
end
end
Expand All @@ -287,7 +287,7 @@ def year_param(params=nil)
if params["year"]
year = params["year"].strip
if %r{(?<year>^([1-2]\d{3})$)}x === year
year.to_i
year.to_i.to_s
end
end
end
Expand Down

0 comments on commit 328b9be

Please sign in to comment.