|
|
@ -186,6 +186,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
@work_count = @student_works.size
|
|
|
|
@work_count = @student_works.size
|
|
|
|
@work_excel = @student_works
|
|
|
|
@work_excel = @student_works
|
|
|
|
|
|
|
|
@students = @course.students
|
|
|
|
|
|
|
|
|
|
|
|
# 分页参数
|
|
|
|
# 分页参数
|
|
|
|
page = params[:page] || 1
|
|
|
|
page = params[:page] || 1
|
|
|
@ -236,94 +237,51 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update_score
|
|
|
|
def update_score
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
if @homework.unified_setting
|
|
|
|
student_works = @homework.student_works
|
|
|
|
student_works = @homework.student_works
|
|
|
|
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: @course.students.pluck(:user_id))
|
|
|
|
user_ids = @course.students.pluck(:user_id)
|
|
|
|
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id).
|
|
|
|
else
|
|
|
|
joins("join course_members on myshixuns.user_id=course_members.user_id").where(course_members: {course_id: @course.id, role: 4}).includes(:games)
|
|
|
|
user_ids = @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)).pluck(:user_id)
|
|
|
|
myshixuns.find_each(batch_size: 100) do |myshixun|
|
|
|
|
student_works = @homework.student_works.where(user_id: user_ids)
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
work.update_time = Time.now
|
|
|
|
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)})
|
|
|
|
work.final_score = final_score
|
|
|
|
challenge_settings = @homework.homework_challenge_settings
|
|
|
|
score = work.final_score + work.eff_score - work.late_penalty
|
|
|
|
myshixuns.find_each(batch_size: 100) do |myshixun|
|
|
|
|
work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score
|
|
|
|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
|
|
|
|
#logger.info("#############work_score: #{score}")
|
|
|
|
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
|
|
|
|
work.save!
|
|
|
|
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
|
|
|
|
|
|
|
|
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update_student_score
|
|
|
|
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)
|
|
|
|
myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id)
|
|
|
|
if work && myshixun
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
# 判断作品是否关联过myshixun
|
|
|
|
begin
|
|
|
|
if work.myshixun_id.nil?
|
|
|
|
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
|
|
|
|
work.myshixun_id = myshixun.id
|
|
|
|
challenge_settings = @homework.homework_challenge_settings
|
|
|
|
work.update_time = myshixun.updated_at
|
|
|
|
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
|
|
|
|
setting_time = @homework.homework_group_setting myshixun.user_id
|
|
|
|
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
|
|
|
|
games = myshixun.games.where(:challenge_id => @homework.homework_challenge_settings.pluck(:challenge_id))
|
|
|
|
normal_status("更新成功")
|
|
|
|
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
|
|
|
|
else
|
|
|
|
compelete_status = 1
|
|
|
|
normal_status("已是最新成绩")
|
|
|
|
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
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
|
|
uid_logger(e.message)
|
|
|
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -1036,7 +994,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
if homework.course_acts.size == 0
|
|
|
|
if homework.course_acts.size == 0
|
|
|
|
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
|
|
|
|
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# 发消息
|
|
|
|
HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids)
|
|
|
|
HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
create_homework_group_settings(homework)
|
|
|
|
create_homework_group_settings(homework)
|
|
|
@ -1057,6 +1015,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
homework.save!
|
|
|
|
homework.save!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 更新学生状态及成绩
|
|
|
|
HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id)
|
|
|
|
HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
normal_status(0, "发布成功")
|
|
|
|
normal_status(0, "发布成功")
|
|
|
|