Addded export feature in Survey_b, By Spen

This commit is contained in:
rulingcom 2013-10-11 11:45:52 +08:00
parent 6230bc3d36
commit 852166dabb
8 changed files with 365 additions and 1 deletions

View File

@ -5,3 +5,5 @@
# Mime::Type.register_alias "text/html", :iphone # Mime::Type.register_alias "text/html", :iphone
Mime::Type.register_alias "text/html", :mobile Mime::Type.register_alias "text/html", :mobile
Mime::Type.register 'application/vnd.ms-excel',:xls

View File

@ -89,4 +89,64 @@ class Panel::SurveyB::BackEnd::SurveyBController < OrbitBackendController
end end
end end
def export
if params[:period] && @period = SurveyBPeriod.find(params[:period])
@answers = ::SurveyBAnswer.where(:created_at.gte => @period.start_date, :created_at.lte => @period.end_date)
@comment_question = ::SurveyBAnswer.where(:created_at.gte => @period.start_date, :created_at.lte => @period.end_date, :comment_question.nin => [''])
else
@answers = ::SurveyBAnswer.all
@comment_question = ::SurveyBAnswer.where(:comment_question.nin => [''])
end
@results = Hash[(t('survey_b.institutions').keys + [ 'all' ]).map do |i_key|
[i_key, Hash[(t('survey_b.questions').keys + ['count', 'sum', 'sum7'] ).map{|q_key| [q_key, 0] }].merge({ 'count' => 0, 'sum' => 0, 'sum7' => 0 })]
end]
[:good_institutions, :bad_institutions].each do |item|
@results[item] = Hash[t('survey_b.institutions').map{|k, i| [k, 0] }]
end
[:person_question, :rate_question, :quality_question].each do |item|
@results[item] = t("survey_b.#{item}_options").map{|o| 0 }
end
@answers.each do |answer|
t('survey_b.institutions').each do |i_key, institution|
if answer[i_key.to_s]
@results[i_key]['count'] += 1
t('survey_b.questions').keys.each do |q_key|
point = 10 - ( answer[i_key.to_s][q_key.to_s].to_i * 2 )
@results[i_key][q_key] += point
@results[i_key]['sum'] += point
if q_key != :question6
@results[i_key]['sum7'] += point
end
end
end
end
[:good_institutions, :bad_institutions].each do |item|
if answer[item.to_s]
answer[item.to_s].each do |institution|
@results[item][institution] += 1
end
end
end
[:person_question, :rate_question, :quality_question].each do |item|
if answer[item.to_s]
@results[item][answer[item.to_s].to_i] += 1
end
end
end
t('survey_b.institutions').each do |i_key, institution|
(t('survey_b.questions').keys + ['count', 'sum', 'sum7'] ).each do |q_key|
@results['all'][q_key] += @results[i_key][q_key]
end
end
@setting = SurveyBSetting.first
headers['Content-Type'] = "application/vnd.ms-excel"
headers['Content-Disposition'] = "attachment; filename=#{@period.title}.xls"
headers['Cache-Control'] = ''
render :layout => false
end
end end

View File

@ -14,6 +14,7 @@
<li><%= link_to t(:list_), panel_survey_b_back_end_survey_b_index_path(:period => period, :page => params[:page]) %></li> <li><%= link_to t(:list_), panel_survey_b_back_end_survey_b_index_path(:period => period, :page => params[:page]) %></li>
<li><%= link_to t('edit'), edit_panel_survey_b_back_end_period_path(period, :page => params[:page]) %></li> <li><%= link_to t('edit'), edit_panel_survey_b_back_end_period_path(period, :page => params[:page]) %></li>
<li><%= link_to t(:delete_), panel_survey_b_back_end_period_path(period), :confirm => t('sure?'), :method => :delete %></li> <li><%= link_to t(:delete_), panel_survey_b_back_end_period_path(period), :confirm => t('sure?'), :method => :delete %></li>
<li><%= link_to t('survey_b.export'), export_panel_survey_b_back_end_survey_b_index_path(:period => period, :page => params[:page]) %></li>
</ul> </ul>
</div> </div>
</td> </td>

View File

@ -0,0 +1,257 @@
<table border="1">
<tr>
<td>標題</td>
<td><%= @period.title rescue '' %></td>
</tr>
<tr>
<td>問卷前言</td>
<td><%= @setting.description rescue '' %></td>
</tr>
<tr>
<td>填答人數</td>
<td><%= @answers.count rescue '' %></td>
</tr>
</table>
<br /><br />
一 、 顧客滿意填表人身分分析
<table border="1">
<tr>
<td>身份</td>
<% @results[:person_question].each_with_index do |count, option| %>
<td><%= t("survey_b.person_question_options")[option] %></td>
<% end %>
</tr>
<tr>
<td>填答人數</td>
<% @results[:person_question].each_with_index do |count, option| %>
<td><%= count %></td>
<% end %>
</tr>
<tr>
<td>比例</td>
<% @results[:person_question].each_with_index do |count, option| %>
<% @pcount = count.to_f / @answers.count %>
<td><%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%</td>
<% end %>
</tr>
</table>
<br /><br />
二、 整體行政品質表現比較分析
<br /><br />
對於總務處這一、二年之行政品質表現,您感覺是
<table border="1">
<tr>
<td>行政品質表現</td>
<% @results[:quality_question].each_with_index do |count, option| %>
<td><%= t("survey_b.quality_question_options")[option] %></td>
<% end %>
<td></td>
</tr>
<tr>
<td>填答人數</td>
<% @qcount = 0 %>
<% @results[:quality_question].each_with_index do |count, option| %>
<td><%= count %></td>
<% @qcount = @qcount + count %>
<% end %>
<td><%= @qcount %></td>
</tr>
<tr>
<td>比例</td>
<% @tqcount = 0 %>
<% @results[:quality_question].each_with_index do |count, option| %>
<% @pcount = count.to_f / @qcount %>
<td><%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%</td>
<% @tqcount = @tqcount + @pcount %>
<% end %>
<td><%= @tqcount %></td>
</tr>
</table>
<br />
對本處整體行政品質表現給予評鑑分數
<table border="1">
<tr>
<td>行政品質表現</td>
<% @results[:rate_question].each_with_index do |count, option| %>
<td><%= t("survey_b.rate_question_options")[option] %></td>
<% end %>
<td></td>
</tr>
<tr>
<td>填答人數</td>
<% @rcount = 0 %>
<% @results[:rate_question].each_with_index do |count, option| %>
<td><%= count %></td>
<% @rcount = @rcount + count %>
<% end %>
<td><%= @rcount %></td>
</tr>
<tr>
<td>比例</td>
<% @tqcount = 0 %>
<% @results[:rate_question].each_with_index do |count, option| %>
<% @pcount = count.to_f / @rcount %>
<td><%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%</td>
<% @tqcount = @tqcount + @pcount %>
<% end %>
<td><%= @tqcount %></td>
</tr>
</table>
<br />
以您與總務處各單位接觸之經驗,您覺得以下哪一組的服務品質較優。 (可複選)
<table border="1">
<tr>
<td>組別</td>
<% @results[:good_institutions].each do |institution, count| %>
<td><%= t("survey_b.institutions.#{institution}") %></td>
<% end %>
<td></td>
</tr>
<tr>
<td>人數</td>
<% @gcount = 0 %>
<% @results[:good_institutions].each do |institution, count| %>
<td><%= count %></td>
<% @gcount = @gcount + count %>
<% end %>
<td><%= @gcount %></td>
</tr>
<tr>
<td>比例</td>
<% @tqcount = 0 %>
<% @results[:good_institutions].each do |institution, count| %>
<% @pcount = count.to_f / @gcount %>
<td><%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%</td>
<% @tqcount = @tqcount + @pcount %>
<% end %>
<td><%= @tqcount %></td>
</tr>
</table>
<br />
以您與總務處各單位接觸之經驗,您覺得以下哪一組的服務品質尚待改進。 (可複選)
<table border="1">
<tr>
<td>組別</td>
<% @results[:bad_institutions].each do |institution, count| %>
<td><%= t("survey_b.institutions.#{institution}") %></td>
<% end %>
<td></td>
</tr>
<tr>
<td>人數</td>
<% @bcount = 0 %>
<% @results[:bad_institutions].each do |institution, count| %>
<td><%= count %></td>
<% @bcount = @bcount + count %>
<% end %>
<td><%= @bcount %></td>
</tr>
<tr>
<td>比例</td>
<% @tqcount = 0 %>
<% @results[:bad_institutions].each do |institution, count| %>
<% @pcount = count.to_f / @bcount %>
<td><%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%</td>
<% @tqcount = @tqcount + @pcount %>
<% end %>
<td><%= @tqcount %></td>
</tr>
</table>
<br /><br />
三、 各單位顧客滿意度調查分析
<table border="1">
<tr>
<td>組別</td>
<% @results[:bad_institutions].each do |institution, count| %>
<td><%= t("survey_b.institutions.#{institution}") %></td>
<% end %>
<td></td>
</tr>
<tr>
<% @tcount = 0 %>
<td><%= t('survey_b.answered_sum') %></td>
<% t('survey_b.institutions').each do |i_key, institution| %>
<% if @results[i_key]['count'] == 0 %>
<td><%= t('survey_b.no_data') %></td>
<% @tcount = @tcount + @results[i_key]['count'] %>
<% else %>
<td><%= ( ( @results[i_key]['sum'].to_f / t('survey_b.questions').count.to_f ) / @results[i_key]['count'].to_f ).round(2) %></td>
<% @tcount = @tcount + (( @results[i_key]['sum'].to_f / t('survey_b.questions').count.to_f ) / @results[i_key]['count'].to_f ) %>
<% end %>
<% end %>
<td><%= @tcount %></td>
</tr>
<tr>
<% @tcount = 0 %>
<td><%= t('survey_b.answered_sum7') %></td>
<% t('survey_b.institutions').each do |i_key, institution| %>
<% if @results[i_key]['count'] == 0 %>
<td><%= t('survey_b.no_data') %></td>
<% @tcount = @tcount + @results[i_key]['count'] %>
<% else %>
<td><%= ( ( @results[i_key]['sum7'].to_f / 7.0 ) / @results[i_key]['count'].to_f ).round(2) %></td>
<% @tcount = @tcount + ( ( @results[i_key]['sum7'].to_f / 7.0 ) / @results[i_key]['count'].to_f ) %>
<% end %>
<% end %>
<td><%= @tcount %></td>
</tr>
<tr>
<% @tcount = 0 %>
<td><%= t('survey_b.answered_count') %></td>
<% t('survey_b.institutions').each do |i_key, institution| %>
<td><%= @results[i_key]['count'] %></td>
<% @tcount = @tcount + @results[i_key]['count'] %>
<% end %>
<td><%= @tcount %></td>
</tr>
<% t('survey_b.questions').each do |q_key, question| %>
<% @tcount = 0 %>
<tr>
<td><%= question.sub /\d\./, '' %></td>
<% t('survey_b.institutions').each do |i_key, institution| %>
<% if @results[i_key]['count'] == 0 %>
<td><%= t('survey_b.no_data') %></td>
<% @tcount = @tcount + @results[i_key]['count'] %>
<% else %>
<td><%= ( @results[i_key][q_key].to_f / @results[i_key]['count'].to_f ).round(2) %></td>
<% @tcount = @tcount + ( @results[i_key][q_key].to_f / @results[i_key]['count'].to_f ) %>
<% end %>
<% end %>
<td><%= @tcount %></td>
</tr>
<% end %>
</table>
<br /><br />
您覺得本處之行政品質有那些地方尚待改進嗎?
<table border="1">
<tr>
<td>填答人數</td>
<td><%= @comment_question.count %></td>
</tr>
</table>
<br /><br />
<table border="0">
<tr>
<td>發佈日期</td>
<td><%= display_date_time @period.start_date %></td>
</tr>
<tr>
<td>截止日期</td>
<td><%= display_date_time @period.end_date %></td>
</tr>
</table>

View File

@ -56,36 +56,77 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<ul> <ul>
<% [:good_institutions, :bad_institutions, :person_question, :rate_question, :quality_question].each do |item| %> <% [:good_institutions, :bad_institutions, :person_question, :rate_question, :quality_question].each do |item| %>
<li> <li>
<div id="<%= item.to_s %>_chart" style="width: 700px; height: 300px;"></div> <table>
<tr>
<td><div id="<%= item.to_s %>_chart" style="width: 600px; height: 300px;"></div>
</td>
<td><div id="<%= item.to_s %>_bar_chart" style="width: 600px; height: 300px;"></div>
</td>
</tr>
</table>
</li> </li>
<% end %> <% end %>
</ul> </ul>
<script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript"> <script type="text/javascript">
window.google.load("visualization", "1", {packages: ["columnchart"]});
window.google.load("visualization", "1", {packages:["corechart"]}); window.google.load("visualization", "1", {packages:["corechart"]});
window.google.setOnLoadCallback(function(){ window.google.setOnLoadCallback(function(){
<% [:good_institutions, :bad_institutions].each do |item| %> <% [:good_institutions, :bad_institutions].each do |item| %>
<% @tcount = 0 %>
var data_<%= item %> = google.visualization.arrayToDataTable([ var data_<%= item %> = google.visualization.arrayToDataTable([
['<%= t("survey_b.#{item}_label") %>', ''], ['<%= t("survey_b.#{item}_label") %>', ''],
<% @results[item].each do |institution, count| %> <% @results[item].each do |institution, count| %>
['<%= t("survey_b.institutions.#{institution}") %>', <%= count %>], ['<%= t("survey_b.institutions.#{institution}") %>', <%= count %>],
<% @tcount = @tcount + count %>
<% end %> <% end %>
]); ]);
var chart_<%= item %> = new google.visualization.PieChart(document.getElementById('<%= item.to_s %>_chart')); var chart_<%= item %> = new google.visualization.PieChart(document.getElementById('<%= item.to_s %>_chart'));
chart_<%= item %>.draw(data_<%= item %>, {title: '<%= t("survey_b.#{item}_label") %>'}); chart_<%= item %>.draw(data_<%= item %>, {title: '<%= t("survey_b.#{item}_label") %>'});
//bar
var data_bar_<%= item %> = google.visualization.arrayToDataTable([
['<%= t("survey_b.#{item}_label") %>', '%'],
<% @results[item].each do |institution, count| %>
['<%= t("survey_b.institutions.#{institution}") %>', <%= count == 0 ? "0" : sprintf("%.2f", (count.to_f / @tcount ) * 100 ) %>],
<% end %> <% end %>
]);
var bar_chart_<%= item %> = new google.visualization.ColumnChart(document.getElementById("<%= item.to_s %>_bar_chart"));
bar_chart_<%= item %>.draw(data_bar_<%= item %>, {title: '<%= t("survey_b.#{item}_label") %>'});
<% end %>
<% [:person_question, :rate_question, :quality_question].each do |item| %> <% [:person_question, :rate_question, :quality_question].each do |item| %>
<% @tcount = 0 %>
var data_<%= item %> = google.visualization.arrayToDataTable([ var data_<%= item %> = google.visualization.arrayToDataTable([
['<%= t("survey_b.#{item}_label") %>', ''], ['<%= t("survey_b.#{item}_label") %>', ''],
<% @results[item].each_with_index do |count, option| %> <% @results[item].each_with_index do |count, option| %>
['<%= t("survey_b.#{item}_options")[option] %>', <%= count %>], ['<%= t("survey_b.#{item}_options")[option] %>', <%= count %>],
<% @tcount = @tcount + count %>
<% end %> <% end %>
]); ]);
var chart_<%= item %> = new google.visualization.PieChart(document.getElementById('<%= item.to_s %>_chart')); var chart_<%= item %> = new google.visualization.PieChart(document.getElementById('<%= item.to_s %>_chart'));
chart_<%= item %>.draw(data_<%= item %>, {title: '<%= t("survey_b.#{item}_label") %>'}); chart_<%= item %>.draw(data_<%= item %>, {title: '<%= t("survey_b.#{item}_label") %>'});
//bar
var data_bar_<%= item %> = google.visualization.arrayToDataTable([
['<%= t("survey_b.#{item}_label") %>', '%'],
<% @results[item].each_with_index do |count, option| %>
['<%= t("survey_b.#{item}_options")[option] %>', <%= count == 0 ? "0" : sprintf("%.2f", (count.to_f / @tcount ) * 100 ) %>],
<% end %>
]);
var bar_chart_<%= item %> = new google.visualization.ColumnChart(document.getElementById("<%= item.to_s %>_bar_chart"));
bar_chart_<%= item %>.draw(data_bar_<%= item %>, {title: '<%= t("survey_b.#{item}_label") %>'});
<% end %> <% end %>
}); });
</script> </script>

View File

@ -3,6 +3,7 @@ en:
survey_b: survey_b:
survey_b: 滿意度調查 survey_b: 滿意度調查
result: 結果 result: 結果
export: 匯出
setting: 設定 setting: 設定
description: 前言 description: 前言

View File

@ -3,6 +3,7 @@ zh_tw:
survey_b: survey_b:
survey_b: 滿意度調查 survey_b: 滿意度調查
result: 結果 result: 結果
export: 匯出
setting: 設定 setting: 設定
description: 前言 description: 前言

View File

@ -7,6 +7,7 @@ Rails.application.routes.draw do
collection do collection do
get 'result' get 'result'
get 'delete' get 'delete'
get 'export'
end end
end end
resources :periods resources :periods