added analysis for journal papers

This commit is contained in:
Harry Bomrah 2016-06-01 16:04:19 +08:00
parent 97e0406b9d
commit 4bb1e2ac02
8 changed files with 179 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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" %>
<style>
.graph-type {
margin-right: 10px !important;
}
.analysis-show-area{
margin-top: 25px;
}
.role {
margin: 15px auto;
width: 90%;
height: 400px;
}
.role h3{
border-bottom: 1px solid #000;
}
.role .graph-area{
text-align: center;
}
.role .graph-area .loader {
margin-top: 170px;
}
</style>
<% 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 %>
<div id="analysis-area">
<div class="analysis-form">
<form id="analysis-form" action="/admin/journal_papers/analysis_report" class="form-horizontal main-forms">
<div class="input-area">
<div class="control-group input-title">
<label class="control-label muted"><%= t("personal_journal.year") %> : </label>
<div class="controls">
<%= select_year(DateTime.now.year - 5, {:start_year => DateTime.now.year, :end_year => 1950}, {:name => 'start_year', :class => "span1"} ) %>
-
<%= select_year(DateTime.now.year, {:start_year => DateTime.now.year, :end_year => 1950}, {:name => 'end_year', :class => "span1"} ) %>
</div>
</div>
<div class="control-group input-title">
<label class="control-label muted"><%= t("personal_journal.graph_by") %> : </label>
<div class="controls">
<%= t("personal_journal.paper_type") %> <input type="radio" name="graph_by" class="graph-type" value="paper_type">
<%= t("personal_journal.level_type") %> <input type="radio" name="graph_by" class="graph-type" value="level_type">
<%= t("personal_journal.author_type") %> <input data-fv-validation="required;" data-fv-messages="Please select atleast one.;" type="radio" name="graph_by" class="graph-type" value="author_type">
</div>
</div>
</div>
<div class="form-actions">
<button id="generate_graph" class="btn btn-info">Graphs</button>
<button class="btn btn-primary">Export</button>
</div>
</form>
</div>
<div class="analysis-show-area hide in">
<% Role.where(:disabled => false, :title.ne => "", :title.ne => nil).each do |role| %>
<div class="role muted" data-role-id="<%= role.id.to_s %>">
<h3><%= role.title %></h3>
<div class="graph-area">
<img class="loader" src="/assets/preloader.gif" alt="loading" width="70" height="70">
</div>
</div>
<% end %>
</div>
</div>
<script type="text/javascript">
var form = new FormValidator($("#analysis-form")),
roleArea = $("#analysis-area .analysis-show-area"),
totalRoles = roleArea.find(".role").length;
form.form.on("submit",function(){return false;})
$("#generate_graph").on("click",function(){
if(form.isFormValidated()){
generateCharts(0);
roleArea.removeClass("hide");
}
return false;
})
var generateCharts = function(index){
var role = roleArea.find(".role").eq(index);
$.ajax({
url : "/admin/journal_papers/analysis_report",
data : {"role_id" : role.data("role-id"), "year_start" : form.form.find("select[name=start_year]").val(), "year_end" : form.form.find("select[name=end_year]").val(), "graph_by" : form.form.find("input[name=graph_by]:checked").val()},
type : "get",
dataType : "html"
}).done(function(html){
role.find(".graph-area").html(html);
if(index < totalRoles){
generateCharts(index + 1);
}
}).error(function(){
role.find(".graph-area").html("There was an error loading this graph.");
if(index < totalRoles){
generateCharts(index + 1);
}
})
}
</script>

View File

@ -0,0 +1 @@
<%= column_chart @data, :id => params[:role_id], :height => "350px", :xtitle => "Year", :ytitle => "Total number" %>

View File

@ -31,6 +31,7 @@ en:
author_type : "Author Type"
from : "From"
to : "To"
graph_by : "Graph by"
file : "File"
file_name : "File name"
description : "File Description"

View File

@ -30,6 +30,7 @@ zh_tw:
paper_type: "論文類型"
from : "起"
to : "迄"
graph_by : "Graph by"
file : "檔案"
file_name : "檔案名稱"
description : "描述"

View File

@ -9,6 +9,8 @@ Rails.application.routes.draw do
resources :journal_papers do
collection do
get 'toggle_hide' => 'journal_papers#toggle_hide'
get 'analysis' => 'journal_papers#analysis'
get 'analysis_report' => 'journal_papers#analysis_report'
end
end

View File

@ -4,7 +4,7 @@ module PersonalJournal
OrbitApp.registration "PersonalJournal",:type=> 'ModuleApp' do
module_label 'module_name.journal_paper'
base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true, :sort_number => '5', :app_name=>"JournalPaper", :intro_app_name=>"JournalPaperlIntro",:path=>"/plugin/personal_journal/profile",:front_path=>"/profile",:admin_path=>"/admin/journal_papers/",:i18n=>'module_name.journal_paper', :module_app_name=>'PersonalJournal', :one_line_title => true, :field_modifiable => true
personal_plugin :enable => true, :sort_number => '5', :app_name=>"JournalPaper", :intro_app_name=>"JournalPaperlIntro",:path=>"/plugin/personal_journal/profile",:front_path=>"/profile",:admin_path=>"/admin/journal_papers/",:i18n=>'module_name.journal_paper', :module_app_name=>'PersonalJournal', :one_line_title => true, :field_modifiable => true, :analysis => true, :analysis_path => "/admin/journal_papers/analysis"
version "0.1"
desktop_enabled true