dev_forum
cxt 5 years ago
parent 6f2b416852
commit 2a50253d39

@ -235,6 +235,96 @@ class HomeworkCommonsController < ApplicationController
end end
end end
def update_score
student_works = @homework.student_works
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: @course.students.pluck(:user_id))
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id).
joins("join course_members on myshixuns.user_id=course_members.user_id").where(course_members: {course_id: @course.id, role: 4}).includes(:games)
myshixuns.find_each(batch_size: 100) do |myshixun|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
setting_time = @homework.homework_group_setting work.user_id
if setting_time.end_time.present? && (setting_time.end_time > Time.now || (@homework.allow_late && @homework.late_time && @homework.late_time > Time.now))
#logger.info("#############setting_time: #{setting_time.end_time}")
user_total_score = 0
pass_consume_time = 0
final_score = 0
homework.homework_challenge_settings.each do |setting|
game = myshixun.games.where(:challenge_id => setting.challenge_id, :status => 2).first
unless game.nil?
pass_consume_time += (game.cost_time / 60.0).to_f
user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i
adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last
final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0))
end
end
if work.work_status == 0
is_complete = myshixun.is_complete? && (myshixun.done_time < setting_time.end_time)
work.work_status = setting_time.end_time > Time.now ? 1 : (is_complete ? 1 : 2)
work.late_penalty = setting_time.end_time > Time.now ? 0 : (is_complete ? 0 : homework.late_penalty)
work.commit_time = myshixun.created_at > setting_time.publish_time ? setting_time.publish_time : myshixun.created_at
work.myshixun_id = myshixun.id
end
games = myshixun.games.where(:challenge_id => homework.homework_challenge_settings.map(&:challenge_id))
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil
if myshixun_endtime.present?
min_efficiency_changed = min_efficiency_changed.present? ? min_efficiency_changed : false
work.compelete_status = 1
work.cost_time = myshixun_endtime.to_i - setting_time.publish_time.to_i
efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0))
work.efficiency = format("%.2f", efficiency)
# 如果作业的最大效率值有变更则更新所有作品的效率分
if homework.work_efficiency && homework.max_efficiency < work.efficiency
homework.update_column("max_efficiency", work.efficiency)
end
end
work.update_time = Time.now
work.final_score = final_score
score = work.final_score + work.eff_score - work.late_penalty
work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score
#logger.info("#############work_score: #{score}")
work.save!
end
end
@homework.student_works.each do ||
end
end
def update_student_score
work = @homework.students_works.find_by(user_id: current_user.id)
myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id)
if work && myshixun
# 判断作品是否关联过myshixun
if work.myshixun_id.nil?
work.myshixun_id = myshixun.id
work.update_time = myshixun.updated_at
setting_time = @homework.homework_group_setting myshixun.user_id
games = myshixun.games.where(:challenge_id => @homework.homework_challenge_settings.pluck(:challenge_id))
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil
compelete_status = 0
if myshixun_endtime.present? && myshixun_endtime < setting_time.end_time
if myshixun_endtime < setting_time.publish_time
compelete_status = 2
else
compelete_status = 1
end
end
if setting_time.end_time > Time.now
work.update_attributes(:work_status => 1, :late_penalty => 0, :commit_time => myshixun.updated_at, :update_time => myshixun.updated_at, :myshixun_id => myshixun.id, :compelete_status => compelete_status)
else
work.update_attributes(:work_status => ((myshixun.is_complete? && (myshixun.done_time < setting_time.end_time)) ? 1 : 2), :late_penalty => (myshixun.is_complete? && (myshixun.done_time < setting_time.end_time) ? 0 : homework.late_penalty), :commit_time => myshixun.updated_at, :update_time => myshixun.updated_at, :myshixun_id => myshixun.id, :compelete_status => compelete_status)
end
end
end
end
def alter_name def alter_name
tip_exception("作业名称不能为空") if params[:name].blank? tip_exception("作业名称不能为空") if params[:name].blank?
@homework.update_attributes(name: params[:name].strip) @homework.update_attributes(name: params[:name].strip)
@ -620,7 +710,7 @@ class HomeworkCommonsController < ApplicationController
if @homework_detail_manual.comment_status < 4 if @homework_detail_manual.comment_status < 4
tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank? tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank?
tip_exception("匿评截止时间必须晚于匿评开启时间") if @homework.anonymous_comment && tip_exception("匿评截止时间必须晚于匿评开启时间") if @homework.anonymous_comment &&
params[:evaluation_end] <= params[:evaluation_start] params[:evaluation_end] <= strf_time(@homework_detail_manual.evaluation_start)
tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment && tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment &&
@course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day) @course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day)

@ -231,9 +231,13 @@ class HomeworkCommon < ApplicationRecord
# 作业的分班设置时间 # 作业的分班设置时间
def homework_group_setting user_id def homework_group_setting user_id
member = course.course_member(user_id) if unified_setting
group_setting = self.homework_group_settings.find_by_course_group_id(member.try(:course_group_id)) homework_setting = self
homework_setting = group_setting.present? ? group_setting : self else
member = course.course_member(user_id)
group_setting = self.homework_group_settings.find_by_course_group_id(member.try(:course_group_id))
homework_setting = group_setting.present? ? group_setting : self
end
homework_setting homework_setting
end end

Loading…
Cancel
Save