Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_course
cxt 6 years ago
commit cf583826ea

@ -25,51 +25,49 @@ class AttachmentsController < ApplicationController
# 2. 上传到云 # 2. 上传到云
upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称 upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}") uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
if upload_file raise "未上传文件" unless upload_file
folder = edu_setting('attachment_folder')
raise "存储目录未定义" unless folder.present?
month_folder = current_month_folder folder = edu_setting('attachment_folder')
save_path = File.join(folder, month_folder) raise "存储目录未定义" unless folder.present?
ext = file_ext(upload_file.original_filename) month_folder = current_month_folder
save_path = File.join(folder, month_folder)
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) ext = file_ext(upload_file.original_filename)
content_type = upload_file.content_type.presence || 'application/octet-stream' local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) content_type = upload_file.content_type.presence || 'application/octet-stream'
logger.info "local_path: #{local_path}" remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
logger.info "remote_path: #{remote_path}"
logger.info "local_path: #{local_path}"
logger.info "remote_path: #{remote_path}"
disk_filename = local_path[save_path.size + 1, local_path.size]
#存数据库
#
@attachment = Attachment.where(disk_filename: disk_filename,
author_id: current_user.id,
cloud_url: remote_path).first
unless @attachment.present? disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment = Attachment.new #存数据库
@attachment.filename = upload_file.original_filename #
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size] @attachment = Attachment.where(disk_filename: disk_filename,
@attachment.filesize = upload_file.tempfile.size author_id: current_user.id,
@attachment.content_type = content_type cloud_url: remote_path).first
@attachment.digest = digest
@attachment.author_id = current_user.id
@attachment.disk_directory = month_folder
@attachment.cloud_url = remote_path
@attachment.save!
else
logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}"
end
render_json if @attachment.blank?
@attachment = Attachment.new
@attachment.filename = upload_file.original_filename
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment.filesize = upload_file.tempfile.size
@attachment.content_type = content_type
@attachment.digest = digest
@attachment.author_id = current_user.id
@attachment.disk_directory = month_folder
@attachment.cloud_url = remote_path
@attachment.save!
else else
raise "未上传文件" logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}"
end end
render_json
end end
def destroy def destroy

@ -9,46 +9,39 @@ class BoardsController < ApplicationController
end end
def show def show
end
def new
end end
def create def create
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin board = @course.course_board
board = @course.course_board new_board = Board.new(board_params)
new_board = Board.new(board_params) new_board.course_id = @course.id
new_board.course_id = @course.id new_board.project_id = -1
new_board.project_id = -1 new_board.parent_id = board.try(:id)
new_board.parent_id = board.try(:id) new_board.position = board.children.count + 1
new_board.position = board.children.count + 1 new_board.save!
new_board.save!
normal_status(0, "添加成功")
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end end
normal_status(0, "添加成功")
end end
# 子目录的拖动 # 子目录的拖动
def move_category def move_category
tip_exception("移动失败") if params[:position].blank? tip_exception("移动失败") if params[:position].blank?
unless params[:position].to_i == @board.position return normal_status(-1, "位置没有变化") if params[:position].to_i == @board.position
course_board = @course.course_board
course_board = @course.course_board
ActiveRecord::Base.transaction do
if params[:position].to_i < @board.position if params[:position].to_i < @board.position
course_board.children.where("position < #{@board.position} and position >= ?", params[:position]).update_all("position = position + 1") course_board.children.where("position < ? and position >= ?", @board.position, params[:position])
.update_all("position = position + 1")
else else
course_board.children.where("position > #{@board.position} and position <= ?", params[:position]).update_all("position = position - 1") course_board.children.where("position > ? and position <= ?", @board.position, params[:position])
.update_all("position = position - 1")
end end
@board.update_attributes(position: params[:position]) @board.update_attributes(position: params[:position])
normal_status(0, "移动成功")
else
normal_status(-1, "位置没有变化")
end end
normal_status(0, "移动成功")
end end
def destroy def destroy

@ -12,10 +12,10 @@ class ExercisesController < ApplicationController
before_action :get_exercise_question_counts,only: [:show,:edit,:start_answer,:review_exercise,:blank_exercise,:export_exercise] before_action :get_exercise_question_counts,only: [:show,:edit,:start_answer,:review_exercise,:blank_exercise,:export_exercise]
before_action :validate_publish_time,only: [:commit_setting] #提交设置时,需判断时间是否符合 before_action :validate_publish_time,only: [:commit_setting] #提交设置时,需判断时间是否符合
before_action :check_course_public,only: [:set_public] before_action :check_course_public,only: [:set_public]
before_action :check_user_on_answer,only: [:show,:start_answer,:commit_exercise,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限 before_action :check_user_on_answer,only: [:show,:start_answer,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限
before_action :only_student_in,only: [:start_answer] before_action :only_student_in,only: [:start_answer]
before_action :check_user_id_start_answer,only: [:start_answer,:review_exercise] before_action :check_user_id_start_answer,only: [:start_answer,:review_exercise]
before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #判断试卷时间到用户是否提交 # before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #已有定时的任务
before_action :check_exercise_time,only: [:commit_exercise] #提交试卷时,判断时间是否超过 before_action :check_exercise_time,only: [:commit_exercise] #提交试卷时,判断时间是否超过
before_action :check_exercise_status,only: [:redo_modal,:redo_exercise] before_action :check_exercise_status,only: [:redo_modal,:redo_exercise]
before_action :check_exercise_is_end, only: [:review_exercise] before_action :check_exercise_is_end, only: [:review_exercise]
@ -1006,6 +1006,7 @@ class ExercisesController < ApplicationController
def start_answer def start_answer
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first
if @exercise_user_current.blank? if @exercise_user_current.blank?
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候不创建exercise_user表理论上老师是不能进入答题的 if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候不创建exercise_user表理论上老师是不能进入答题的
exercise_user_params = { exercise_user_params = {
@ -1640,38 +1641,38 @@ class ExercisesController < ApplicationController
end end
def check_exercise_time def check_exercise_time
@answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first
if @answer_committed_user.blank? if @answer_committed_user.blank?
normal_status(404,"答题用户不存在") normal_status(404,"答题用户不存在")
elsif @exercise.get_exercise_status(current_user.id) != 2 || @answer_committed_user.commit_status == 1 # # elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交
normal_status(-1,"提交错误,试卷已截止/用户已提交!") # normal_status(-1,"提交错误,试卷用户已提交!")
end end
end end
def commit_user_exercise # def commit_user_exercise
@exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id).first #查找当前用户是否有过答题 # @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题
if @user_course_identity == Course::STUDENT # if @user_course_identity == Course::STUDENT
if @exercise_user_current.present? # if @exercise_user_current.present?
if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && # if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) &&
((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) # ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)
#当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 # #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
objective_score = calculate_student_score(@exercise,current_user)[:total_score] # objective_score = calculate_student_score(@exercise,current_user)[:total_score]
subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score # subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score
total_score = objective_score + subjective_score # total_score = objective_score + subjective_score
commit_option = { # commit_option = {
:status => 1, # :status => 1,
:commit_status => 1, # :commit_status => 1,
:end_at => Time.now, # :end_at => Time.now,
:objective_score => objective_score, # :objective_score => objective_score,
:score => total_score, # :score => total_score,
:subjective_score => subjective_score # :subjective_score => subjective_score
} # }
@exercise_user_current.update_attributes(commit_option) # @exercise_user_current.update_attributes(commit_option)
normal_status(0,"已交卷成功!") # normal_status(0,"已交卷成功!")
end # end
end # end
end # end
end # end
#打回重做时的初步判断 #打回重做时的初步判断
def check_exercise_status def check_exercise_status

@ -43,9 +43,15 @@ class MessagesController < ApplicationController
@page_size = params[:page_size] || 10 @page_size = params[:page_size] || 10
@current_user = current_user || nil @current_user = current_user || nil
@messages = @message.children.preload_messages @messages = @message.children.preload_messages.includes(:message_detail, :praise_treads)
@messages = @messages.ordered(sort: 1) unless @message.parent_id.nil? @messages = @messages.ordered(sort: 1) unless @message.parent_id.nil?
@user_course_identity = current_user.course_identity(@message.board.course)
case @user_course_identity
when 5, 6, 7
@messages = @messages.visible
end
@messages = @messages.page(@page).per(@page_size) @messages = @messages.page(@page).per(@page_size)
end end

@ -353,117 +353,123 @@ module ExercisesHelper
score5 = 0.0 #实训题 score5 = 0.0 #实训题
ques_stand = [] #问题是否正确 ques_stand = [] #问题是否正确
exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges)
exercise_questions.each do |q| exercise_questions&.each do |q|
if q.question_type != 5 begin
answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 if q.question_type != 5
else answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案
answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案
end
if q.question_type <= 2 #为选择题或判断题时
if answers_content.present? #学生有回答时
answer_choice_array = []
answers_content.each do |a|
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
end
user_answer_content = answer_choice_array.sort
standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
if standard_answer.count > 0
q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时每个answer的分数均摊。
else
q_score_1 = 0.0
end
answers_content.update_all(:score => q_score_1)
score1 = score1 + q.question_score
end
else else
score1 += 0.0 answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案
end end
elsif q.question_type == 3 #填空题 if q.question_type <= 2 #为选择题或判断题时
if answers_content.present? if answers_content.present? #学生有回答时
null_standard_answer = q.exercise_standard_answers answer_choice_array = []
standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) answers_content.each do |a|
standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
standard_answer_count = standard_answer_ids.count end
if standard_answer_count > 0 #存在标准答案时才有分数 user_answer_content = answer_choice_array.sort
q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分 standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
else if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
q_score_2 = 0.0 if standard_answer.count > 0
end q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时每个answer的分数均摊。
if q.is_ordered else
answers_content.each do |u| q_score_1 = 0.0
i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案
if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数
u.update_column('score',q_score_2)
score2 = score2 + q_score_2
end end
answers_content.update_all(:score => q_score_1)
score1 = score1 + q.question_score
end end
else else
st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) score1 += 0.0
answers_content.each do |u| end
u_answer_text = u.answer_text.downcase elsif q.question_type == 3 #填空题
if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 if answers_content.present?
u.update_column("score",q_score_2) null_standard_answer = q.exercise_standard_answers
score2 = score2 + q_score_2 standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text)
st_answer_text.delete(u_answer_text) standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组
standard_answer_count = standard_answer_ids.count
if standard_answer_count > 0 #存在标准答案时才有分数
q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分
else
q_score_2 = 0.0
end
if q.is_ordered
answers_content.each do |u|
i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案
if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数
u.update_column('score',q_score_2)
score2 = score2 + q_score_2
end
end
else
st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase)
answers_content.each do |u|
u_answer_text = u.answer_text.downcase
if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分
u.update_column("score",q_score_2)
score2 = score2 + q_score_2
st_answer_text.delete(u_answer_text)
end
end end
end end
else
score2 += 0.0
end end
else elsif q.question_type == 5 #实训题时,主观题这里不评分
score2 += 0.0 q.exercise_shixun_challenges&.each do |exercise_cha|
end game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
elsif q.question_type == 5 #实训题时,主观题这里不评分 if game.present?
q.exercise_shixun_challenges.each do |exercise_cha| exercise_cha_score = 0.0
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡 answer_status = 0
if game.present? if game.status == 2 && game.final_score >= 0
exercise_cha_score = 0.0 exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 0 answer_status = 1
if game.status == 2 && game.final_score >= 0 end
exercise_cha_score = exercise_cha.question_score #每一关卡的得分 ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
answer_status = 1 if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
end cha_path = challenge_path(exercise_cha.challenge&.path)
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) game_challenge = game.game_codes.search_challenge_path(cha_path)&.first
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 if game_challenge.present?
cha_path = challenge_path(exercise_cha.challenge&.path) game_code = game_challenge
game_challenge = game.game_codes.search_challenge_path(cha_path)&.first code = game_code.try(:new_code)
if game_challenge.present? else
game_code = game_challenge code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path)
code = game_code.try(:new_code) end
sx_option = {
:exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id,
:score => exercise_cha_score,
:answer_text => code,
:status => answer_status
}
ExerciseShixunAnswer.create(sx_option)
else else
code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
end end
sx_option = { score5 += exercise_cha_score
:exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id,
:score => exercise_cha_score,
:answer_text => code,
:status => answer_status
}
ExerciseShixunAnswer.create(sx_option)
else else
ex_shixun_answer_content.first.update_column('score',exercise_cha_score) score5 += 0.0
end end
score5 += exercise_cha_score
else
score5 += 0.0
end end
end end
user_scores = answers_content.blank? ? 0.0 : answers_content.score_reviewed.pluck(:score).sum
if user_scores > 0.0
stand_answer = 1
else
stand_answer = 0
end
ques_option = {
"q_id":q.id, #该问题的id
"q_type":q.question_type,
"q_position":q.question_number, #该问题的位置
"stand_status":stand_answer, #该问题是否正确,1为正确0为错误
"user_score":user_scores.round(1) #每个问题的总得分
}
ques_stand.push(ques_option)
rescue Exception => e
Rails.logger.info("calcuclate_score_have_error____________________________#{e}")
next
end end
user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0
if user_scores > 0.0
stand_answer = 1
else
stand_answer = 0
end
ques_option = {
"q_id":q.id, #该问题的id
"q_type":q.question_type,
"q_position":q.question_number, #该问题的位置
"stand_status":stand_answer, #该问题是否正确,1为正确0为错误
"user_score":user_scores.round(1) #每个问题的总得分
}
ques_stand.push(ques_option)
end end
total_score = score1 + score2 + score5 total_score = score1 + score2 + score5
{ {

@ -18,7 +18,7 @@ class Message < ApplicationRecord
scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子 scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子
scope :reply_nodes, -> { where("parent_id IS NOT NULL") } scope :reply_nodes, -> { where("parent_id IS NOT NULL") }
scope :visible, -> { where(is_hidden: false)} scope :visible, -> { where(is_hidden: false) }
scope :by_user, ->(user) { visible if user.nil? || !user.admin? } scope :by_user, ->(user) { visible if user.nil? || !user.admin? }
scope :preload_messages, -> { includes(:author, :message_detail) } scope :preload_messages, -> { includes(:author, :message_detail) }
scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) } scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) }

@ -6,7 +6,7 @@ class ExercisePublishTask
Rails.logger.info("log--------------------------------exercise_publish start") Rails.logger.info("log--------------------------------exercise_publish start")
puts "--------------------------------exercise_publish start" puts "--------------------------------exercise_publish start"
exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
exercises.each do |exercise| exercises&.each do |exercise|
exercise.update_column('exercise_status', 2) exercise.update_column('exercise_status', 2)
course = exercise.course course = exercise.course
tid_str = "" tid_str = ""
@ -45,7 +45,7 @@ class ExercisePublishTask
# 分组设置发布时间的测验 # 分组设置发布时间的测验
exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 900, Time.now - 900) exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 900, Time.now - 900)
exercise_group_settings.each do |exercise_group| exercise_group_settings&.each do |exercise_group|
exercise = exercise_group.exercise exercise = exercise_group.exercise
if exercise.present? if exercise.present?
course = exercise.course course = exercise.course
@ -71,29 +71,35 @@ class ExercisePublishTask
puts "--------------------------------exercise_end start" puts "--------------------------------exercise_end start"
# 1。统一设置的试卷 # 1。统一设置的试卷
exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900)
exercises.each do |exercise| exercises&.each do |exercise|
ex_type = exercise.exercise_questions.pluck(:question_type).uniq ex_type = exercise.exercise_questions.pluck(:question_type).uniq
exercise.update_column('exercise_status', 3) exercise.update_column('exercise_status', 3)
exercise.exercise_users.each do |exercise_user| exercise.exercise_users&.each do |exercise_user|
if exercise_user&.commit_status == 0 && exercise_user&.start_at.present? begin
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] if (exercise_user&.commit_status == 0) && (exercise_user&.start_at.present?)
if ex_type.include?(4) #是否包含主观题 s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
subjective_score = exercise_user.subjective_score if ex_type.include?(4) #是否包含主观题
else subjective_score = exercise_user.subjective_score
subjective_score = -1.0 else
subjective_score = -1.0
end
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score
}
exercise_user.update_attributes(commit_option)
end end
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score rescue Exception => e
total_score = s_score + total_score_subjective_score Rails.logger.info("rescue errors ___________________________#{e}")
commit_option = { next
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score
}
exercise_user.update_attributes(commit_option)
end end
end end
end end
@ -101,36 +107,41 @@ class ExercisePublishTask
all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900)
exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")"
ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}")
ex_group_settings.each do |exercise_setting| ex_group_settings&.each do |exercise_setting|
exercise = exercise_setting.exercise exercise = exercise_setting.exercise
if exercise&.end_time <= Time.now if exercise.end_time <= Time.now
exercise.update_column('exercise_status', 3) exercise.update_column('exercise_status', 3)
end end
ex_types = exercise.exercise_questions.pluck(:question_type).uniq ex_types = exercise.exercise_questions.pluck(:question_type).uniq
users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id)
exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id)) exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id))
exercise_users&.each do |exercise_user|
exercise_users.each do |exercise_user| begin
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
if ex_types.include?(4) #是否包含主观题 if ex_types.include?(4) #是否包含主观题
subjective_score = exercise_user.subjective_score subjective_score = exercise_user.subjective_score
else else
subjective_score = -1.0 subjective_score = -1.0
end
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score
}
exercise_user.update_attributes(commit_option)
end end
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] rescue Exception => e
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score Rails.logger.info("unified_setting_false_rescue errors ___________________________#{e}")
total_score = s_score + total_score_subjective_score next
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score
}
exercise_user.update_attributes(commit_option)
end end
end end
end end
Rails.logger.info("log--------------------------------exercise_end end") Rails.logger.info("log--------------------------------exercise_end end")

@ -1,6 +1,6 @@
json.partial! "commons/success" json.partial! "commons/success"
json.data do json.data do
json.user_course_identity @current_user.course_identity(@message.board.course) json.user_course_identity @user_course_identity
json.id @message.id json.id @message.id
json.total_count @messages.total_count json.total_count @messages.total_count
json.total_replies_count @message.total_replies_count json.total_replies_count @message.total_replies_count

Loading…
Cancel
Save