dev_course
SylorHuang 6 years ago
parent e269f32591
commit 471edd3607

@ -109,7 +109,7 @@ module ApplicationHelper
# 计算到结束还有多长时间 **天**小时**分 # 计算到结束还有多长时间 **天**小时**分
def how_much_time(time) def how_much_time(time)
if time.nil? if time.nil? || time < Time.now #6.21 -hs 增加小于time.now
'' ''
else else
result = ((time - Time.now.to_i).to_i / (24*60*60)).to_s + "" result = ((time - Time.now.to_i).to_i / (24*60*60)).to_s + ""

@ -323,7 +323,6 @@ module ExercisesHelper
else else
show_unreview_count = nil show_unreview_count = nil
end end
logger.info("##########__________exercise_end_time__________###############{exercise_end_time}")
if exercise_status == 2 && exercise_end_time.present? if exercise_status == 2 && exercise_end_time.present?
ex_left_time = how_much_time(exercise_end_time) ex_left_time = how_much_time(exercise_end_time)

@ -5,7 +5,7 @@ class ExercisePublishTask
def publish def publish
Rails.logger.info("log--------------------------------exercise_publish start") Rails.logger.info("log--------------------------------exercise_publish start")
puts "--------------------------------exercise_publish start" puts "--------------------------------exercise_publish start"
exercises = Exercise.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
@ -67,21 +67,21 @@ class ExercisePublishTask
end end
def end def end
exercises = Exercise.where("end_time <= ? and exercise_status = ?",Time.now,2) Rails.logger.info("log--------------------------------exercise_end start")
puts "--------------------------------exercise_end start"
# 1。统一设置的试卷
exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now)
exercises.each do |exercise| exercises.each do |exercise|
course = exercise.course
ex_type = exercise.exercise_questions.pluck(:question_type).uniq ex_type = exercise.exercise_questions.pluck(:question_type).uniq
exercise.update_attribute('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.nil? if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
# exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
if ex_type.include?(4) #是否包含主观题 if ex_type.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 end
# subjective_score = exercise_user.subjective_score
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score total_score = s_score + total_score_subjective_score
commit_option = { commit_option = {
@ -93,21 +93,20 @@ class ExercisePublishTask
:subjective_score => subjective_score :subjective_score => subjective_score
} }
exercise_user.update_attributes(commit_option) exercise_user.update_attributes(commit_option)
# if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
# exercise_user.update_attributes(:subjective_score => 0)
# end
end end
end end
end end
all_exercises = Exercise.where("end_time > ? and exercise_status = ?",Time.now,2) # 2.非统一的试卷
all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now)
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
exercise.update_column('exercise_status', 3)
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.map(&: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|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
@ -117,7 +116,6 @@ class ExercisePublishTask
subjective_score = -1.0 subjective_score = -1.0
end end
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
# subjective_score = exercise_user.subjective_score
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score total_score = s_score + total_score_subjective_score
commit_option = { commit_option = {
@ -129,17 +127,11 @@ class ExercisePublishTask
:subjective_score => subjective_score :subjective_score => subjective_score
} }
exercise_user.update_attributes(commit_option) exercise_user.update_attributes(commit_option)
# exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
# s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
# exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0)))
# if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
# exercise_user.update_attributes(:subjective_score => 0.0)
# end
end end
end end
end end
Rails.logger.info("log--------------------------------exercise_end completed") Rails.logger.info("log--------------------------------exercise_end end")
puts "--------------------------------exercise_end end"
end end
end end

@ -6,7 +6,7 @@ namespace :poll_publish do
task :publish => :environment do task :publish => :environment do
puts "--------------------------------poll_publish start" puts "--------------------------------poll_publish start"
# 统一设置发布时间的问卷 # 统一设置发布时间的问卷
polls = Poll.where("publish_time is not null and polls_status = 1 and publish_time <=?",Time.now) polls = Poll.includes(:poll_users).where("publish_time is not null and polls_status = 1 and publish_time <=?",Time.now)
polls.each do |poll| polls.each do |poll|
poll.update_attributes(:polls_status => 2) poll.update_attributes(:polls_status => 2)
course = poll.course course = poll.course
@ -71,7 +71,7 @@ namespace :poll_publish do
task :nearly_end => :environment do task :nearly_end => :environment do
puts "--------------------------------poll_nearly_end start" puts "--------------------------------poll_nearly_end start"
# 统一设置发布时间的问卷 # 统一设置发布时间的问卷
polls = Poll.where("polls_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) polls = Poll.includes(:poll_users).where("polls_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
polls.each do |poll| polls.each do |poll|
if poll.tidings.where(:parent_container_type => "NearlyEnd").count == 0 if poll.tidings.where(:parent_container_type => "NearlyEnd").count == 0
course = poll.course course = poll.course
@ -111,7 +111,7 @@ namespace :poll_publish do
end end
task :end => :environment do task :end => :environment do
polls = Poll.where("polls_status = 2 and unified_setting = 1 and end_time <=?",Time.now) polls = Poll.includes(:poll_users).where("polls_status = 2 and unified_setting = 1 and end_time <=?",Time.now)
polls.each do |poll| polls.each do |poll|
poll.update_attributes(:polls_status => 3) poll.update_attributes(:polls_status => 3)
poll.poll_users.each do |poll_user| poll.poll_users.each do |poll_user|
@ -123,6 +123,7 @@ namespace :poll_publish do
PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting| PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting|
poll = poll_setting.poll poll = poll_setting.poll
poll.update_column('polls_status',3)
users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id) users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id)
poll_users = poll.poll_users.where(:user_id => users.map(&:user_id)) poll_users = poll.poll_users.where(:user_id => users.map(&:user_id))

Loading…
Cancel
Save