|
|
|
@ -186,6 +186,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
@work_count = @student_works.size
|
|
|
|
|
@work_excel = @student_works
|
|
|
|
|
@students = @course.students
|
|
|
|
|
|
|
|
|
|
# 分页参数
|
|
|
|
|
page = params[:page] || 1
|
|
|
|
@ -236,94 +237,51 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
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)
|
|
|
|
|
begin
|
|
|
|
|
if @homework.unified_setting
|
|
|
|
|
student_works = @homework.student_works
|
|
|
|
|
user_ids = @course.students.pluck(:user_id)
|
|
|
|
|
else
|
|
|
|
|
user_ids = @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)).pluck(:user_id)
|
|
|
|
|
student_works = @homework.student_works.where(user_id: user_ids)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 如果作业的最大效率值有变更则更新所有作品的效率分
|
|
|
|
|
if homework.work_efficiency && homework.max_efficiency < work.efficiency
|
|
|
|
|
homework.update_column("max_efficiency", work.efficiency)
|
|
|
|
|
end
|
|
|
|
|
myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids).
|
|
|
|
|
includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)})
|
|
|
|
|
challenge_settings = @homework.homework_challenge_settings
|
|
|
|
|
myshixuns.find_each(batch_size: 100) do |myshixun|
|
|
|
|
|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
|
|
|
|
|
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
|
|
|
|
|
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
|
|
|
|
|
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
|
|
|
|
|
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 ||
|
|
|
|
|
|
|
|
|
|
@homework.update_attribute('calculation_time', Time.now)
|
|
|
|
|
normal_status("更新成功")
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger(e.message)
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_student_score
|
|
|
|
|
work = @homework.students_works.find_by(user_id: current_user.id)
|
|
|
|
|
work = @homework.student_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
|
|
|
|
|
games.each do |game|
|
|
|
|
|
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
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
|
|
|
|
|
challenge_settings = @homework.homework_challenge_settings
|
|
|
|
|
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
|
|
|
|
|
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
|
|
|
|
|
normal_status("更新成功")
|
|
|
|
|
else
|
|
|
|
|
normal_status("已是最新成绩")
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger(e.message)
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -1036,7 +994,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
if homework.course_acts.size == 0
|
|
|
|
|
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 发消息
|
|
|
|
|
HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids)
|
|
|
|
|
else
|
|
|
|
|
create_homework_group_settings(homework)
|
|
|
|
@ -1057,6 +1015,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
homework.save!
|
|
|
|
|
|
|
|
|
|
# 更新学生状态及成绩
|
|
|
|
|
HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id)
|
|
|
|
|
end
|
|
|
|
|
normal_status(0, "发布成功")
|
|
|
|
|