添加作业时增加教师评分所占比例设置

This commit is contained in:
sw 2014-07-01 11:53:55 +08:00
parent 12b6525cc6
commit 4470f0dd73
7 changed files with 33 additions and 9 deletions

View File

@ -498,10 +498,10 @@ class BidsController < ApplicationController
#增加作业按评分排序,
#@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
@homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{@bid.courses.first.teacher.id}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id <> #{@bid.courses.first.teacher.id}) AS s_score
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{@bid.author_id}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id <> #{@bid.author_id}) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY
(CASE WHEN t_score IS NULL THEN 0 ELSE t_score * 0.6 END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * 0.4 END) DESC,created_at ASC")
(CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{@bid.proportion * 1.0 / 100} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - @bid.proportion * 1.0 / 100} END) DESC,created_at ASC")
if params[:student_id].present?
@temp = []
@homework_list.each do |pro|
@ -788,6 +788,7 @@ class BidsController < ApplicationController
@bid.name = params[:bid][:name]
@bid.description = params[:bid][:description]
@bid.is_evaluation = params[:bid][:is_evaluation]
@bid.proportion = params[:bid][:proportion]
@bid.reward_type = 3
# @bid.budget = params[:bid][:budget]
@bid.deadline = params[:bid][:deadline]

View File

@ -490,6 +490,7 @@ class CoursesController < ApplicationController
# 新建作业
def new_homework
@homework = Bid.new
@homework.proportion
@homework.safe_attributes = params[:bid]
if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] ))
render :layout => 'base_courses'

View File

@ -83,6 +83,19 @@ module CoursesHelper
type << option2
end
def proportion_option
type = []
i = 0
while i <= 100
option = []
option << i.to_s + "%"
option << i
type << option
i = i + 10
end
type
end
alias teacherCountOrigin teacherCount
def teacherCount project
@ -308,7 +321,7 @@ module CoursesHelper
#最终评分 = 学生评分的平均分 * 0.4 +教师评分 * 0.6
def score_for_homework homework
if homework.bid.is_evaluation == 1 || homework.bid.is_evaluation == nil
return format("%.2f",(teacher_score_for_homework(homework).to_f * 0.6 + student_score_for_homework(homework).to_f * 0.4))
return format("%.2f",(homework.bid.proportion * 1.0 / 100) * (teacher_score_for_homework(homework).to_f) + (1 - homework.bid.proportion * 1.0 / 100) * (student_score_for_homework(homework).to_f))
else
return teacher_score_for_homework homework
end

View File

@ -34,6 +34,8 @@
</p>
<p><%= f.select :is_evaluation, is_evaluation_option %>
</p>
<p><%= f.select :proportion, proportion_option %>
</p>
<p><%= hidden_field_tag 'course_id', @course.id %>
</p>
<fieldset><legend><%= l(:label_attachment_plural) %></legend>

View File

@ -1573,6 +1573,7 @@ zh:
field_budget: 奖励
field_deadline: 截止日期
field_is_evaluation: 是否启动互评
field_proportion: 教师评分比例
label_tags_selected: 已选标签
label_tags_related: 相关标签
button_project_tags_add: 增加

View File

@ -0,0 +1,5 @@
class AddProportionToBid < ActiveRecord::Migration
def change
add_column :bids, :proportion, :integer, default: 60
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140626012511) do
ActiveRecord::Schema.define(:version => 20140701031909) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -106,6 +106,7 @@ ActiveRecord::Schema.define(:version => 20140626012511) do
t.integer "parent_id"
t.string "password"
t.integer "is_evaluation"
t.integer "proportion", :default => 60
end
create_table "boards", :force => true do |t|
@ -793,7 +794,7 @@ ActiveRecord::Schema.define(:version => 20140626012511) do
end
create_table "relative_memos", :force => true do |t|
t.integer "osp_id"
t.integer "osp_id", :null => false
t.integer "parent_id"
t.string "subject", :null => false
t.text "content", :null => false