diff --git a/app/controllers/admin/journal_papers_controller.rb b/app/controllers/admin/journal_papers_controller.rb index 5a45371..f528a9a 100644 --- a/app/controllers/admin/journal_papers_controller.rb +++ b/app/controllers/admin/journal_papers_controller.rb @@ -23,6 +23,20 @@ class Admin::JournalPapersController < OrbitMemberController end end + def analysis + end + + def analysis_report + role = params[:role_id] + year_start = params[:year_start].to_i + year_end = params[:year_end].to_i + graph_by = params[:graph_by] + + @data = get_chart_data(year_start,year_end,role,params[:graph_by]) + + render :layout => false + end + def create if !journal_paper_params['member_profile_id'].blank? @@ -140,6 +154,7 @@ class Admin::JournalPapersController < OrbitMemberController def setting end + def frontend_setting @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @intro = JournalPaperIntro.find_by(:member_profile_id=>@member.id) rescue nil diff --git a/app/helpers/admin/journal_papers_helper.rb b/app/helpers/admin/journal_papers_helper.rb index bbb2135..0858313 100644 --- a/app/helpers/admin/journal_papers_helper.rb +++ b/app/helpers/admin/journal_papers_helper.rb @@ -115,6 +115,54 @@ module Admin::JournalPapersHelper jp.member_profile = mp jp.save end + + def get_chart_data(year_start,year_end,role,type) + case type + when "paper_type" + jls = JournalPaperType.all + when "level_type" + jls = JournalLevel.all + when "author_type" + jls = JournalPaperAuthorType.all + end + + finaldata = [] + role = Role.find(role) rescue nil + mps = [] + if !role.nil? + mps = role.member_profile_ids + end + jls.each do |jl| + data = {} + data["name"] = jl.title + data["data"] = {} + (year_start..year_end).each do |year| + d1 = DateTime.new(year,1,1,0,0) + d2 = DateTime.new(year,12,31,23,59) + t = jl.journal_papers.where(:created_at.gte => d1, :created_at.lte => d2, :member_profile_id.in => mps).count rescue 0 + data["data"][year.to_s] = t + end + finaldata << data + end + data = {"name" => "N/A", "data" => {}} + (year_start..year_end).each do |year| + d1 = DateTime.new(year,1,1,0,0) + d2 = DateTime.new(year,12,31,23,59) + case type + when "paper_type" + t = JournalPaper.where(:created_at.gte => d1, :created_at.lte => d2, :member_profile_id.in => mps, :journal_paper_type_id => nil).count rescue 0 + when "level_type" + t = JournalPaper.where(:created_at.gte => d1, :created_at.lte => d2, :member_profile_id.in => mps, :journal_level_ids => nil).count rescue 0 + when "author_type" + t = JournalPaper.where(:created_at.gte => d1, :created_at.lte => d2, :member_profile_id.in => mps, :journal_paper_author_type_ids => nil).count rescue 0 + end + + data["data"][year.to_s] = t + end + finaldata << data + finaldata + end + end diff --git a/app/views/admin/journal_papers/analysis.html.erb b/app/views/admin/journal_papers/analysis.html.erb new file mode 100644 index 0000000..5c30677 --- /dev/null +++ b/app/views/admin/journal_papers/analysis.html.erb @@ -0,0 +1,110 @@ +<% # encoding: utf-8 %> +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/main-form-col2" %> + +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "//www.google.com/jsapi", "chartkick"%> + <%= javascript_include_tag "justgage.1.0.1.min" %> + <%= javascript_include_tag "raphael.2.1.0.min" %> + <%= javascript_include_tag "validator" %> +<% end %> +