From b63b4974ebb58fbbf28f19051f63a837ec1a6075 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 14 Jan 2015 16:36:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 4 +- app/views/poll/_choice_show.html.erb | 24 +++ app/views/poll/statistics_result.html.erb | 185 +--------------------- db/schema.rb | 52 +++++- 4 files changed, 83 insertions(+), 182 deletions(-) create mode 100644 app/views/poll/_choice_show.html.erb diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 9177e044b..f9a07b134 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -76,11 +76,12 @@ class PollController < ApplicationController end def statistics_result + @poll_questions = PollQuestion.all respond_to do |format| format.html{render :layout => 'base_courses'} end end - + #添加单选题 def add_mc @@ -114,4 +115,5 @@ class PollController < ApplicationController def is_course_teacher render_403 unless(@course && User.current.allowed_to?(:as_teacher,@course)) end + end \ No newline at end of file diff --git a/app/views/poll/_choice_show.html.erb b/app/views/poll/_choice_show.html.erb new file mode 100644 index 000000000..a37ca148a --- /dev/null +++ b/app/views/poll/_choice_show.html.erb @@ -0,0 +1,24 @@ +
+ + + + + + + + <% poll_question.poll_answers.each do |poll_answer| %> + + + + + + <% end %> + + + + + + +
选项 小计 比例
<%= poll_answer.answer_text %> 24
75%
本题有效填写人次 26 
+
+ diff --git a/app/views/poll/statistics_result.html.erb b/app/views/poll/statistics_result.html.erb index 164020cde..f0f992c90 100644 --- a/app/views/poll/statistics_result.html.erb +++ b/app/views/poll/statistics_result.html.erb @@ -12,190 +12,17 @@

某问卷统计

- +<% @poll_questions.each do |poll_question| %>
  1. - 第1题:问题描述问题描述 [单选题] + 第1题:问题描述问题描述<%= poll_question.question_title %> [单选题]<% poll_question.poll_answers %>
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  2. -
  3. -
    - 第1题:问题描述问题描述 [单选题] -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  4. -
  5. -
    - 第1题:问题描述问题描述 [单选题] -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  6. -
  7. -
    - 第1题:问题描述问题描述 [单选题] -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  8. -
  9. -
    - 第1题:问题描述问题描述 [单选题] -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  10. + <%= render :partial =>'choice_show', :locals =>{ :poll_question => poll_question } %> +
+ <% end %>
@@ -205,8 +32,6 @@
- -
diff --git a/db/schema.rb b/db/schema.rb index 9c6f4eac3..627529a57 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150112024820) do +ActiveRecord::Schema.define(:version => 20150112090810) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -23,6 +23,18 @@ ActiveRecord::Schema.define(:version => 20150112024820) do add_index "activities", ["user_id", "act_type"], :name => "index_activities_on_user_id_and_act_type" add_index "activities", ["user_id"], :name => "index_activities_on_user_id" + create_table "api_keys", :force => true do |t| + t.string "access_token" + t.datetime "expires_at" + t.integer "user_id" + t.boolean "active", :default => true + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "api_keys", ["access_token"], :name => "index_api_keys_on_access_token" + add_index "api_keys", ["user_id"], :name => "index_api_keys_on_user_id" + create_table "applied_projects", :force => true do |t| t.integer "project_id", :null => false t.integer "user_id", :null => false @@ -1055,6 +1067,14 @@ ActiveRecord::Schema.define(:version => 20150112024820) do t.string "description" end + create_table "social_groups", :force => true do |t| + t.string "name" + t.text "description" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "softapplications", :force => true do |t| t.string "name" t.text "description" @@ -1270,6 +1290,36 @@ ActiveRecord::Schema.define(:version => 20150112024820) do add_index "versions", ["project_id"], :name => "versions_project_id" add_index "versions", ["sharing"], :name => "index_versions_on_sharing" + create_table "voting_choices", :force => true do |t| + t.integer "poll_id", :null => false + t.string "text", :null => false + t.datetime "created_on", :null => false + t.integer "position", :default => 1 + end + + add_index "voting_choices", ["poll_id"], :name => "choices_poll_id" + + create_table "voting_polls", :force => true do |t| + t.integer "project_id", :null => false + t.string "question", :null => false + t.datetime "created_on", :null => false + t.boolean "revote" + end + + add_index "voting_polls", ["project_id"], :name => "polls_project_id" + + create_table "voting_votes", :force => true do |t| + t.integer "user_id", :null => false + t.integer "poll_id", :null => false + t.integer "choice_id", :null => false + t.datetime "created_on", :null => false + end + + add_index "voting_votes", ["choice_id"], :name => "votes_choice_id" + add_index "voting_votes", ["poll_id"], :name => "votes_poll_id" + add_index "voting_votes", ["user_id", "poll_id"], :name => "votes_user_poll_unique", :unique => true + add_index "voting_votes", ["user_id"], :name => "votes_user_id" + create_table "watchers", :force => true do |t| t.string "watchable_type", :default => "", :null => false t.integer "watchable_id", :default => 0, :null => false From 34b8ffeb5bbde39d7a5d666904775ad4a4f7708a Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 16 Jan 2015 10:51:08 +0800 Subject: [PATCH 2/4] tongji --- app/controllers/poll_controller.rb | 16 ++++++++++++++-- app/controllers/projects_controller.rb | 4 ++-- app/views/poll/_choice_show.html.erb | 5 +++-- app/views/poll/statistics_result.html.erb | 8 +++++--- db/schema.rb | 2 +- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 084c43545..774923404 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -78,12 +78,24 @@ class PollController < ApplicationController end def statistics_result - @poll_questions = PollQuestion.all + @poll = Poll.find(params[:id]) + @offset, @limit = api_offset_and_limit({:limit => 10}) + @poll_questions = @poll.poll_questions + @poll_questions_count = @poll_questions.count + @poll_questions_pages = Paginator.new @poll_questions_count, @limit, params['page'] respond_to do |format| format.html{render :layout => 'base_courses'} end end + def get_poll_totalcount poll_question + @total_questions_count = poll_question.poll_votes.count + end + + def get_poll_everycount poll_answer + @every_answer_count = poll_answer.poll_votes.count + end + #添加单选题 def create_poll_question question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title] @@ -111,7 +123,7 @@ class PollController < ApplicationController end end - private + private def find_poll_and_course @poll = Poll.find params[:id] @course = Course.find @poll.polls_group_id diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5d43a4e20..5ff9a3f17 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -116,8 +116,8 @@ class ProjectsController < ApplicationController joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id").joins("LEFT JOIN #{ProjectScore.table_name} ON #{Project.table_name}.id = #{ProjectScore.table_name}.project_id"). where("#{Project.table_name}.project_type = ? ", Project::ProjectType_project) - @project_count = @projects_all.count - @project_pages = Paginator.new @project_count, per_page_option, params['page'] + @poll_questions_count = @projects_all.count + @poll_questions_pages = Paginator.new @project_count, per_page_option, params['page'] #gcm activity count diff --git a/app/views/poll/_choice_show.html.erb b/app/views/poll/_choice_show.html.erb index a37ca148a..aa425e748 100644 --- a/app/views/poll/_choice_show.html.erb +++ b/app/views/poll/_choice_show.html.erb @@ -1,3 +1,4 @@ +
@@ -9,13 +10,13 @@ <% poll_question.poll_answers.each do |poll_answer| %> - + <% end %> - + diff --git a/app/views/poll/statistics_result.html.erb b/app/views/poll/statistics_result.html.erb index f0f992c90..1bdbb0ff1 100644 --- a/app/views/poll/statistics_result.html.erb +++ b/app/views/poll/statistics_result.html.erb @@ -17,19 +17,21 @@
  1. - 第1题:问题描述问题描述<%= poll_question.question_title %> [单选题]<% poll_question.poll_answers %> + 第<%= poll_question.question_number %>题:<%= poll_question.question_title %> [单选题]<% poll_question.poll_answers %>
    <%= render :partial =>'choice_show', :locals =>{ :poll_question => poll_question } %>
+ <% end %>
-
答题已完成 0%
- +
答题已完成 0%
diff --git a/db/schema.rb b/db/schema.rb index 6c2a9f58a..f9ea40ae9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150112090810) do +ActiveRecord::Schema.define(:version => 20150114022710) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false From 7177303eeb4899010db5af9c831b85504813970b Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 16 Jan 2015 15:49:22 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=9C=80=E7=BB=88=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 2 +- app/helpers/poll_helper.rb | 18 ++++++++- app/views/poll/_choice_show.html.erb | 49 ++++++++++++----------- app/views/poll/statistics_result.html.erb | 10 ++--- config/locales/zh.yml | 5 +++ 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 3de4e8339..3b4bf3694 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -86,7 +86,7 @@ class PollController < ApplicationController def statistics_result @poll = Poll.find(params[:id]) poll_questions = @poll.poll_questions - @poll_questions = paginateHelper poll_questions,3 #分页 + @poll_questions = paginateHelper poll_questions, 5 respond_to do |format| format.html{render :layout => 'base_courses'} end diff --git a/app/helpers/poll_helper.rb b/app/helpers/poll_helper.rb index 7816d8e37..1a8fabae3 100644 --- a/app/helpers/poll_helper.rb +++ b/app/helpers/poll_helper.rb @@ -27,7 +27,7 @@ module PollHelper false end end - + #获取文本题答案 def get_anwser_vote_text(question_id,user_id) pv = PollVote.find_by_poll_question_id_and_user_id(question_id,user_id) @@ -47,4 +47,20 @@ module PollHelper true end end + + #统计答题百分比 + def statistics_result_percentage(e, t) + return e*100/t + end + + def options_show p + case p + when 1 + "单选题" + when 2 + "多选题" + else + "问答题" + end + end end \ No newline at end of file diff --git a/app/views/poll/_choice_show.html.erb b/app/views/poll/_choice_show.html.erb index aa425e748..16971d5ad 100644 --- a/app/views/poll/_choice_show.html.erb +++ b/app/views/poll/_choice_show.html.erb @@ -1,25 +1,28 @@ -
-
<%= poll_answer.answer_text %> 24 <% poll_answer.poll_votes.count %>
75%
本题有效填写人次 26<%= poll_question.poll_votes.count %>  
- - - - - - - <% poll_question.poll_answers.each do |poll_answer| %> - - - - - - <% end %> - - - - - - -
选项 小计 比例
<%= poll_answer.answer_text %> <% poll_answer.poll_votes.count %>
75%
本题有效填写人次 <%= poll_question.poll_votes.count %> 
-
+ + + + + + + + <% poll_question.poll_answers.each do |poll_answer| %> + + + + + + <% end %> + + + + + + +
<%= l(:label_poll_options) %> <%= l(:label_poll_subtotal) %> <%= l(:label_poll_proportion) %>
<%= poll_answer.answer_text %> <%= poll_answer.poll_votes.count %> +
+ +
+ <%= statistics_result_percentage(poll_answer.poll_votes.count, @poll.users.count) %>%
<%= l(:label_poll_valid_commit) %> <%= poll_question.poll_votes.count %> 
+ diff --git a/app/views/poll/statistics_result.html.erb b/app/views/poll/statistics_result.html.erb index d6181fb1a..dea18f8d8 100644 --- a/app/views/poll/statistics_result.html.erb +++ b/app/views/poll/statistics_result.html.erb @@ -2,14 +2,14 @@ - 问卷调查_问卷结果 + <%= l(:label_poll_result) %> <%= stylesheet_link_tag 'polls', :media => 'all' %>
-

某问卷统计

+

<%= @poll.polls_name %> <%= l(:label_poll) %>

<% @poll_questions.each do |poll_question| %> @@ -17,7 +17,8 @@
  1. - 第<%= poll_question.question_number %>题:<%= poll_question.question_title %> [单选题]<% poll_question.poll_answers %> + 第<%= poll_question.question_number %>题:<%= poll_question.question_title %> + [<%= options_show(poll_question.question_type) %>]
    <%= render :partial =>'choice_show', :locals =>{ :poll_question => poll_question } %>
  2. @@ -28,11 +29,8 @@
    - -
    -
    答题已完成 0%
diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 95ab07d5d..5c2925b90 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2253,5 +2253,10 @@ zh: label_new_answer: 新建选项 label_poll_title: 问卷标题 label_poll_description: 问卷描述 + label_poll_options: 选项 + label_poll_subtotal: 小计 + label_poll_proportion: 比例 + label_poll_valid_commit: 本题有效填写人次 + label_poll_result: 问卷调查_问卷统计 From dd42c89ee6972d08237fe549dffe51503c4f279a Mon Sep 17 00:00:00 2001 From: z9hang Date: Fri, 16 Jan 2015 15:51:26 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=99=BE=E5=88=86=E6=AF=94=E9=99=A4?= =?UTF-8?q?=E6=95=B0=E4=B8=BA0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index d77f7c872..221c482c7 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -178,20 +178,26 @@ class PollController < ApplicationController #单选题 pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id) if pv.nil? + #尚未答该题,添加答案 pv = PollVote.new pv.user_id = User.current.id pv.poll_question_id = params[:poll_question_id] end + #修改该题对应答案 pv.poll_answer_id = params[:poll_answer_id] if pv.save + #保存成功返回成功信息及当前以答题百分比 @percent = get_percent(@poll,User.current) render :json => {:text => "ok" ,:percent => format("%.2f" ,@percent)} else + #返回失败信息 render :json => {:text => "failure"} end elsif pq.question_type == 2 + #多选题 pv = PollVote.find_by_poll_answer_id_and_user_id(params[:poll_answer_id],User.current.id) if pv.nil? + #尚未答该题,添加答案 pv = PollVote.new pv.user_id = User.current.id pv.poll_question_id = params[:poll_question_id] @@ -203,6 +209,7 @@ class PollController < ApplicationController render :json => {:text => "failure"} end else + #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案 if pv.delete @percent = get_percent(@poll,User.current) render :json => {:text => "false" ,:percent => format("%.2f" ,@percent)} @@ -211,12 +218,16 @@ class PollController < ApplicationController end end elsif pq.question_type == 3 || pq.question_type == 4 + #单行文本,多行文本题 pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id) if pv.nil? + #pv为空之前尚未答题,添加答案 if params[:vote_text].nil? || params[:vote_text].blank? + #用户提交空答案,视作不作答 @percent = get_percent(@poll,User.current) render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)} else + #添加答案 pv = PollVote.new pv.user_id = User.current.id pv.poll_question_id = params[:poll_question_id] @@ -229,7 +240,9 @@ class PollController < ApplicationController end end else + #pv不为空说明用户之前已作答 if params[:vote_text].nil? || params[:vote_text].blank? + #用户提交空答案,视为删除答案 if pv.delete @percent = get_percent(@poll,User.current) render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)} @@ -237,6 +250,7 @@ class PollController < ApplicationController render :json => {:text => "failure"} end else + #用户修改答案 pv.vote_text = params[:vote_text] if pv.save @percent = get_percent(@poll,User.current) @@ -335,7 +349,11 @@ class PollController < ApplicationController def get_percent poll,user complete_count = get_complete_question(poll,user).count - (complete_count.to_f / poll.poll_questions.count.to_f)*100 + if poll.poll_questions.count == 0 + return 0 + else + return (complete_count.to_f / poll.poll_questions.count.to_f)*100 + end end #PollUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个