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

dev_course
cxt 6 years ago
commit 29b8279db6

@ -349,12 +349,6 @@ class ApplicationController < ActionController::Base
end end
end end
#实训题的关卡url初始化
def challenge_path(path)
cha_path = path.present? ? path.split("") : []
cha_path.reject(&:blank?)[0].try(:strip)
end
# 适用与已经用url_safe编码后回调字符串形式 # 适用与已经用url_safe编码后回调字符串形式
def tran_base64_decode64(str) def tran_base64_decode64(str)
s_size = str.size % 4 s_size = str.size % 4

@ -49,4 +49,10 @@ module GitHelper
GitService.fork_repository(repo_path: original_rep_path, fork_repository_path: (new_repo_name + ".git")) GitService.fork_repository(repo_path: original_rep_path, fork_repository_path: (new_repo_name + ".git"))
container.update_attributes!(:repo_name => new_repo_name) container.update_attributes!(:repo_name => new_repo_name)
end end
#实训题的关卡url初始化
def challenge_path(path)
cha_path = path.present? ? path.split("") : []
cha_path.reject(&:blank?)[0].try(:strip)
end
end end

@ -22,13 +22,13 @@ class MessagesController < ApplicationController
messages = @board.messages.root_nodes.by_keywords(params[:search]) messages = @board.messages.root_nodes.by_keywords(params[:search])
messages = messages.order('(sticky = 1) DESC') # 置顶 messages = messages.reorder('(sticky = 1) DESC') # 置顶
messages = messages =
case sort_type case sort_type
when 'time' then messages.reorder("created_on #{sort}") when 'time' then messages.order("created_on #{sort}")
when 'hot' then messages.reorder("descendants_count #{sort}") when 'hot' then messages.order("descendants_count #{sort}")
else messages.reorder("created_on #{sort}") else messages.order("created_on #{sort}")
end end
messages = messages.includes(:author) messages = messages.includes(:author)
@ -51,7 +51,8 @@ class MessagesController < ApplicationController
def reply def reply
return normal_status(2, "回复内容不能为空") if params[:content].blank? return normal_status(2, "回复内容不能为空") if params[:content].blank?
@reply = Message.create!(board: @message.board, root: @message.root, author: current_user, parent: @message, @reply = Message.create!(board: @message.board, root_id: @message.root_id || @message.id,
author: current_user, parent: @message,
message_detail_attributes: { message_detail_attributes: {
content: params[:content] content: params[:content]
}) })

@ -4,6 +4,10 @@ class Users::ShixunsController < Users::BaseController
@count = shixuns.count @count = shixuns.count
@shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: true) @shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: true)
ids = @shixuns.map(&:id)
@finished_challenges_count_map = Game.joins(:myshixun).where(user_id: observed_user.id, status: 2)
.where(myshixuns: { shixun_id: ids }).group('myshixuns.shixun_id').count
end end
private private

@ -1,8 +1,4 @@
module ShixunDecorator module ShixunDecorator
def finished_challenges_count(user)
Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count
end
def human_status def human_status
I18n.t("shixun.status.#{status}") I18n.t("shixun.status.#{status}")
end end

@ -39,19 +39,19 @@ module UserDecorator
apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization') apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization')
apply && !apply.status.zero? apply.present? && !apply.status.zero?
end end
# 是否已经签到 # 是否已经签到
def attendance_signed? def attendance_signed?
attendance = Attendance.find_by(user_id: id) attendance = Attendance.find_by(user_id: id)
attendance && Util.days_between(Time.zone.now, attendance.created_at).zero? attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero?
end end
# 明日签到金币 # 明日签到金币
def tomorrow_attendance_gold def tomorrow_attendance_gold
Attendance.find_by(user_id: id)&.next_gold Attendance.find_by(user_id: id)&.next_gold || 50
end end
# ----------- 账号管理 ------------- # ----------- 账号管理 -------------

@ -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)
@ -353,7 +352,7 @@ module ExercisesHelper
score2 = 0.0 #填空题 score2 = 0.0 #填空题
score5 = 0.0 #实训题 score5 = 0.0 #实训题
ques_stand = [] #问题是否正确 ques_stand = [] #问题是否正确
exercise_questions = exercise.exercise_questions 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 if q.question_type != 5
answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案
@ -361,84 +360,99 @@ module ExercisesHelper
answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案
end end
if q.question_type <= 2 #为选择题或判断题时 if q.question_type <= 2 #为选择题或判断题时
answer_choice_array = [] if answers_content.present? #学生有回答时
answers_content.each do |a| answer_choice_array = []
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 answers_content.each do |a|
end answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
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
multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时每个answer的分数均摊。
else
multi_each_score = 0.0
end end
answers_content.update_all(:score => multi_each_score) user_answer_content = answer_choice_array.sort
score1 = score1 + q.question_score standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
end if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
elsif q.question_type == 3 #填空题 if standard_answer.count > 0
null_standard_answer = q.exercise_standard_answers q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时每个answer的分数均摊。
standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) else
standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 q_score_1 = 0.0
standard_answer_count = standard_answer_ids.count
if standard_answer_count > 0 #存在标准答案时才有分数
each_standard_score = (q.question_score.to_f / standard_answer_count).round(1) #每一空的得分
else
each_standard_score = 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_attribute("score",each_standard_score)
score2 = score2 + each_standard_score
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_attribute("score",each_standard_score) null_standard_answer = q.exercise_standard_answers
score2 = score2 + each_standard_score 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
elsif q.question_type == 5 #实训题时,主观题这里不评分 elsif q.question_type == 5 #实训题时,主观题这里不评分
q.exercise_shixun_challenges.each do |exercise_cha| if answers_content.present?
game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡 q.exercise_shixun_challenges.each do |exercise_cha|
if game.present? game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡
exercise_cha_score = 0 if game.present?
answer_status = 0 exercise_cha_score = 0.0
cha_path = challenge_path exercise_cha.challenge.path answer_status = 0
if game.status == 2 && game.final_score >= 0 cha_path = challenge_path exercise_cha.challenge.path
exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分 if game.status == 2 && game.final_score >= 0
answer_status = 1 exercise_cha_score = exercise_cha.question_score #每一关卡的得分
end answer_status = 1
if exercise_cha.exercise_shixun_answers.search_shixun_answers("user_id",user.id).blank? #把关卡的答案存入试卷的实训里 end
game_challenge = game.game_codes.search_challenge_path(cha_path).first ex_shixun_answer_content = answers_content.where(exercise_shixun_challenge_id: exercise_cha.id)
if game_challenge.present? if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
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?
game_code = game_challenge
code = game_code.try(:new_code)
else
code = git_fle_content(exercise_cha.shixun.repo_path,cha_path)
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)
end end
score5 += exercise_cha_score
end end
else
score5 += 0.0
end end
end end
user_scores = answers_content.score_reviewed.pluck(:score).sum user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0
if user_scores > 0 if user_scores > 0
stand_answer = 1 stand_answer = 1
else else

@ -165,7 +165,7 @@ class Course < ApplicationRecord
all_course_module_types.each do |type| all_course_module_types.each do |type|
hidden_value = course_module_types.include?(type) ? 0 : 1 hidden_value = course_module_types.include?(type) ? 0 : 1
course_module = get_course_module_by_type(type, self.id) course_module = course_modules.where(module_type: type).first
course_module.update_attribute(:hidden, hidden_value) if course_module.present? course_module.update_attribute(:hidden, hidden_value) if course_module.present?
end end
end end
@ -174,8 +174,9 @@ class Course < ApplicationRecord
%w[activity shixun_homework common_homework group_homework graduation exercise poll attachment board course_group] %w[activity shixun_homework common_homework group_homework graduation exercise poll attachment board course_group]
end end
def get_course_module_by_type(type, course_id) def get_course_module_by_type(type)
CourseModule.where(course_id: course_id, module_type: type).first #CourseModule.where(course_id: course_id, module_type: type).first
self.course_modules.where(module_type: type).first
end end
# 创建课程讨论区 # 创建课程讨论区

@ -170,7 +170,7 @@ class HomeworkCommon < ApplicationRecord
#删除时更新题库中的引用数 #删除时更新题库中的引用数
def update_homework_bank_quotes def update_homework_bank_quotes
old_banks = HomeworkBank.where(homework_common_id: self.id) old_banks = self.homework_bank
unless old_banks.blank? unless old_banks.blank?
old_banks.each do |bank| old_banks.each do |bank|
bank.update_attributes(quotes: (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0, homework_common_id: nil) bank.update_attributes(quotes: (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0, homework_common_id: nil)
@ -243,10 +243,15 @@ class HomeworkCommon < ApplicationRecord
end end
def min_group_publish_time def min_group_publish_time
HomeworkGroupSetting.where("homework_common_id = #{self.id} and publish_time is not null").pluck(:publish_time).min #HomeworkGroupSetting.where("homework_common_id = #{self.id} and publish_time is not null").pluck(:publish_time).min
# 可以使用includes
self.homework_group_settings.where("publish_time is not null").pluck(:publish_time).min
end end
def max_group_end_time def max_group_end_time
HomeworkGroupSetting.where("homework_common_id = #{self.id} and end_time is not null").pluck(:end_time).max #HomeworkGroupSetting.where("homework_common_id = #{self.id} and end_time is not null").pluck(:end_time).max
# 可以使用includes
self.homework_group_settings.where("end_time is not null").pluck(:end_time).max
end end
end end

@ -233,4 +233,8 @@ class Shixun < ApplicationRecord
shixun_members.where(role: [1, 2]).exists?(user_id: user.id) shixun_members.where(role: [1, 2]).exists?(user_id: user.id)
end end
def finished_challenges_count(user)
Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count
end
end end

@ -58,7 +58,7 @@ class Users::ShixunService
when 'passed' then 1 when 'passed' then 1
when 'processing' then 0 when 'processing' then 0
end end
relations.where(myshixuns: { status: status }) if status relations = relations.where(myshixuns: { status: status }) if status
relations relations
end end

@ -65,7 +65,7 @@ class Users::SubjectService
when 'finished' then subjects.having('finished = 1').map(&:id) when 'finished' then subjects.having('finished = 1').map(&:id)
end end
relations.where(id: subject_ids) if subject_ids.present? relations = relations.where(id: subject_ids) if subject_ids.present?
relations relations
end end
@ -75,7 +75,7 @@ class Users::SubjectService
when 'applying' then 1 when 'applying' then 1
when 'published' then 2 when 'published' then 2
end end
relations.where(status: status) if status relations = relations.where(status: status) if status
relations relations
end end

@ -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 + 900)
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.present?
# 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,23 @@ 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 + 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
exercise.update_column('exercise_status', 3)
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.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 +119,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 +130,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

@ -1,5 +1,6 @@
json.question_id question.id json.question_id question.id
json.question_number question.question_number # json.question_number question.question_number
json.q_position ques_position.present? ? ques_position : question.question_number
json.question_title question.question_title json.question_title question.question_title
json.question_type question.question_type json.question_type question.question_type
json.question_score question.question_score.round(1).to_s json.question_score question.question_score.round(1).to_s

@ -5,4 +5,5 @@ json.partial! "exercise_questions/exercise_questions",
choices:@exercise_choices, choices:@exercise_choices,
shixun_challenges: @exercise_question_shixun, shixun_challenges: @exercise_question_shixun,
exercise_type:1, exercise_type:1,
user_answer:[] user_answer:[],
ques_position:nil

@ -5,4 +5,5 @@ json.partial! "exercise_questions/exercise_questions",
choices:@exercise_choices, choices:@exercise_choices,
shixun_challenges: @exercise_question_shixun, shixun_challenges: @exercise_question_shixun,
exercise_type:1, exercise_type:1,
user_answer:[] user_answer:[],
ques_position:nil

@ -62,7 +62,8 @@ json.exercise_questions do
shixun_challenges: q.exercise_shixun_challenges, shixun_challenges: q.exercise_shixun_challenges,
exercise_type: ex_type, exercise_type: ex_type,
user_answer: user_ques_answers[:answered_content], user_answer: user_ques_answers[:answered_content],
shixun_type: user_ques_answers[:shixun_type] shixun_type: user_ques_answers[:shixun_type],
ques_position:nil
if user_ques_comments.count > 0 if user_ques_comments.count > 0
json.question_comments do json.question_comments do
json.partial! "exercises/exercise_comments", question_comment:user_ques_answers[:question_comment].first json.partial! "exercises/exercise_comments", question_comment:user_ques_answers[:question_comment].first

@ -11,7 +11,8 @@ json.exercise_questions do
choices:q.exercise_choices, choices:q.exercise_choices,
shixun_challenges: q.exercise_shixun_challenges, shixun_challenges: q.exercise_shixun_challenges,
exercise_type:2, exercise_type:2,
user_answer:[] user_answer:[],
ques_position:nil
end end
end end

@ -15,7 +15,8 @@ json.exercise_questions do
shixun_challenges: q.exercise_shixun_challenges, shixun_challenges: q.exercise_shixun_challenges,
exercise_type:1, exercise_type:1,
user_answer:[], user_answer:[],
shixun_type:0 shixun_type:0,
ques_position:nil
end end
end end

@ -18,7 +18,8 @@ json.exercise_questions do
shixun_challenges: q.exercise_shixun_challenges, shixun_challenges: q.exercise_shixun_challenges,
exercise_type:1, exercise_type:1,
user_answer:[], user_answer:[],
shixun_type:0 shixun_type:0,
ques_position:nil
end end
end end

@ -36,9 +36,9 @@ json.partial! "exercises/exercise_scores"
json.exercise_questions do json.exercise_questions do
json.array! @exercise_all_questions do |q| json.array! @exercise_all_questions do |q|
question = q[:question] question = q[:question]
ques_position = q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 # ques_position = q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号
question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id) question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id)
json.q_position ques_position # json.q_position q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号
if @t_user_exercise_status == 3 if @t_user_exercise_status == 3
this_answer_status = "0.0" this_answer_status = "0.0"
user_score = "0.0" user_score = "0.0"
@ -58,6 +58,7 @@ json.exercise_questions do
user_answer: question_info[:answered_content], user_answer: question_info[:answered_content],
choices:question.exercise_choices, choices:question.exercise_choices,
exercise_type:3, exercise_type:3,
shixun_type:question_info[:shixun_type] shixun_type:question_info[:shixun_type],
ques_position: q[:ques_number]
end end
end end

@ -6,4 +6,4 @@ json.name shixun.name
json.status shixun.status json.status shixun.status
json.human_status shixun.human_status json.human_status shixun.human_status
json.challenges_count shixun.challenges_count json.challenges_count shixun.challenges_count
json.finished_challenges_count shixun.finished_challenges_count(user) json.finished_challenges_count @finished_challenges_count_map&.fetch(shixun.id, 0) || shixun.finished_challenges_count(user)

@ -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