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

dev_course
jingquan huang 6 years ago
commit 6ce1a46d33

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

@ -1023,7 +1023,7 @@ class ExercisesController < ApplicationController
if @t_user_exercise_status == 3
get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id)
end
get_user_answer_status(@exercise_questions,@exercise_current_user_id)
get_user_answer_status(@exercise_questions,@exercise_current_user_id,@exercise,@t_user_exercise_status)
rescue Exception => e
uid_logger_error(e.message)
@ -1117,7 +1117,7 @@ class ExercisesController < ApplicationController
@student_status = 0
else
@student_status = 1
get_user_answer_status(@exercise_questions,@exercise_current_user_id)
get_user_answer_status(@exercise_questions,@exercise_current_user_id,@exercise,get_exercise_status)
end
end
end
@ -1685,11 +1685,17 @@ class ExercisesController < ApplicationController
end
end
def get_user_answer_status(exercise_questions,user_id)
def get_user_answer_status(exercise_questions,user_id,exercise,exercise_user_status)
@question_status = []
@exercise_all_questions = []
ex_question_random = exercise.question_random
question_answered = 0
exercise_questions.each_with_index do |q,index|
if ex_question_random && exercise_user_status != 3
ques_number = index + 1
else
ques_number = q.question_number
end
if q.question_type != 5
ques_vote = q.exercise_answers.search_exercise_answer("user_id",user_id)
else
@ -1725,12 +1731,12 @@ class ExercisesController < ApplicationController
end
question_status = {
:ques_id => q.id,
:ques_number => index+1, #仅问题的显示位置变化但是问题的question_number 不会变化与之相关的choice/standard_answer/answer不会变化
:ques_number => ques_number, #仅问题的显示位置变化但是问题的question_number 不会变化与之相关的choice/standard_answer/answer不会变化
:ques_status => ques_status,
}
question_options = {
:question => q,
:ques_number => index+1,
:ques_number => ques_number,
}
@question_status = @question_status.push(question_status).sort_by {|k| k[:ques_number]}
@exercise_all_questions = @exercise_all_questions.push(question_options).sort_by {|k| k[:ques_number]}

@ -71,7 +71,7 @@ class GraduationTasksController < ApplicationController
@work_list = @task.graduation_works.where(user_id: user_ids).includes(user: [:user_extension])
@all_work_count = @work_list.count
@teachers = @course.teachers
@teachers = @course.teachers.where.not(user_id: current_user.id)
# 教师评阅搜索 0: 未评, 1 已评
unless params[:teacher_comment].blank?
graduation_work_ids = GraduationWorkScore.where(graduation_work_id: @work_list.map(&:id)).pluck(:graduation_work_id)
@ -98,7 +98,7 @@ class GraduationTasksController < ApplicationController
unless params[:cross_comment].blank?
graduation_work_id = @task.graduation_work_comment_assignations.where(:user_id =>current_user.id)
.pluck(:graduation_work_id).uniq if @task.graduation_work_comment_assignations
@work_list = @work_list.where(id: graduation_work_id)
@work_list = @task.graduation_works.where(id: graduation_work_id)
end
# 输入姓名和学号搜索

@ -89,15 +89,9 @@ class HomeworkCommonsController < ApplicationController
@homework_commons = @homework_commons.page(page).per(15)
if @homework_type == 4
if @user_course_identity == Course::STUDENT
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns,
student_works: [myshixun: [:games]])
else
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works)
end
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns)
else
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group,
:student_works)
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group)
end
end

@ -17,17 +17,25 @@ class MessagesController < ApplicationController
@page = params[:page] || 1
@page_size = params[:page_size] || 15
sort = params[:sort] || 0
sort = params[:sort].to_i == 1 ? 'asc' : 'desc'
sort_type = params[:sort_type] || 'time'
sort = sort.to_i
sort_type = sort_type.strip
@messages = @board.messages.root_nodes.by_keywords(params[:search]).includes(:praise_treads, :author, :children)
@messages = @messages.ordered(sort: sort, sort_type: sort_type)
@messages = sort_by_all_replies(sort, sort_type, @messages)
messages = @board.messages.root_nodes.by_keywords(params[:search])
@messages = sort_by_sticky(@messages)
@messages = Kaminari.paginate_array(@messages).page(@page).per(@page_size)
messages = messages.reorder('(sticky = 1) DESC') # 置顶
messages =
case sort_type
when 'time' then messages.order("created_on #{sort}")
when 'hot' then messages.order("descendants_count #{sort}")
else messages.order("created_on #{sort}")
end
messages = messages.includes(:author)
@messages = Kaminari.paginate_array(messages).page(@page).per(@page_size)
ids = @messages.map(&:id)
@praises_count_map = Message.where(root_id: ids).group(:root_id).sum(:praises_count)
end
def reply_list
@ -43,33 +51,17 @@ class MessagesController < ApplicationController
def reply
return normal_status(2, "回复内容不能为空") if params[:content].blank?
begin
@reply = Message.create!(board: @message.board,
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: {
content: params[:content]
}
)
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
})
end
def sticky_top
return normal_status(403, "您没有权限进行该操作") unless current_user.teacher_of_course?(@message.board.course)
ActiveRecord::Base.transaction do
begin
@message.update_attributes(:sticky => @message.sticky == 1 ? 0 : 1)
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
end
def bulk_delete

@ -44,7 +44,7 @@ class StudentWorksController < ApplicationController
# 统一设置的作业取所有学生,否则取已发布的分班学生
students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id))
unless params[:search].blank?
@members = students.joins(user: :user_extensions).where("user_id != #{current_user.id} and (concat(users.lastname, users.firstname)
@members = students.joins(user: :user_extension).where("course_members.user_id != #{current_user.id} and (concat(users.lastname, users.firstname)
like ? or user_extensions.student_id like ?)", "%#{params[:search]}%", "%#{params[:search]}%")
else

@ -4,6 +4,10 @@ class Users::ShixunsController < Users::BaseController
@count = shixuns.count
@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
private

@ -1,8 +1,4 @@
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
I18n.t("shixun.status.#{status}")
end

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

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

@ -352,7 +352,7 @@ module ExercisesHelper
score2 = 0.0 #填空题
score5 = 0.0 #实训题
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|
if q.question_type != 5
answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案
@ -360,6 +360,7 @@ module ExercisesHelper
answers_content = q.exercise_shixun_answers.search_shixun_answers("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) #学生答案的位置
@ -368,29 +369,33 @@ module ExercisesHelper
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的分数均摊。
q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时每个answer的分数均摊。
else
multi_each_score = 0.0
q_score_1 = 0.0
end
answers_content.update_all(:score => multi_each_score)
answers_content.update_all(:score => q_score_1)
score1 = score1 + q.question_score
end
else
score1 += 0.0
end
elsif q.question_type == 3 #填空题
if answers_content.present?
null_standard_answer = q.exercise_standard_answers
standard_answer_array = null_standard_answer.select(:exercise_choice_id,: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 #存在标准答案时才有分数
each_standard_score = (q.question_score.to_f / standard_answer_count).round(1) #每一空的得分
q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分
else
each_standard_score = 0.0
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_attribute("score",each_standard_score)
score2 = score2 + each_standard_score
u.update_column('score',q_score_2)
score2 = score2 + q_score_2
end
end
else
@ -398,24 +403,29 @@ module ExercisesHelper
answers_content.each do |u|
u_answer_text = u.answer_text.downcase
if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分
u.update_attribute("score",each_standard_score)
score2 = score2 + each_standard_score
u.update_column("score",q_score_2)
score2 = score2 + q_score_2
st_answer_text.delete(u_answer_text)
end
end
end
else
score2 += 0.0
end
elsif q.question_type == 5 #实训题时,主观题这里不评分
if answers_content.present?
q.exercise_shixun_challenges.each do |exercise_cha|
game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡
if game.present?
exercise_cha_score = 0
exercise_cha_score = 0.0
answer_status = 0
cha_path = challenge_path exercise_cha.challenge.path
if game.status == 2 && game.final_score >= 0
exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分
exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 1
end
if exercise_cha.exercise_shixun_answers.search_shixun_answers("user_id",user.id).blank? #把关卡的答案存入试卷的实训里
ex_shixun_answer_content = answers_content.where(exercise_shixun_challenge_id: exercise_cha.id)
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
game_challenge = game.game_codes.search_challenge_path(cha_path).first
if game_challenge.present?
game_code = game_challenge
@ -432,12 +442,17 @@ module ExercisesHelper
:status => answer_status
}
ExerciseShixunAnswer.create(sx_option)
else
ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
end
score5 += exercise_cha_score
end
end
else
score5 += 0.0
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
stand_answer = 1
else

@ -131,4 +131,20 @@ module GraduationTasksHelper
end
end
end
# 阶段剩余时间
def task_left_time task
if task.publish_time && task.publish_time < Time.now
if task.end_time > Time.now
status = "剩余提交时间"
time = "#{how_much_time(task.end_time)}"
else
if task.allow_late && task.late_time && task.late_time >= Time.now
status = "剩余补交时间"
time = "#{how_much_time(task.late_time)}"
end
end
end
{status: status, time: time}
end
end

@ -165,7 +165,7 @@ class Course < ApplicationRecord
all_course_module_types.each do |type|
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?
end
end
@ -174,8 +174,9 @@ class Course < ApplicationRecord
%w[activity shixun_homework common_homework group_homework graduation exercise poll attachment board course_group]
end
def get_course_module_by_type(type, course_id)
CourseModule.where(course_id: course_id, module_type: type).first
def get_course_module_by_type(type)
#CourseModule.where(course_id: course_id, module_type: type).first
self.course_modules.where(module_type: type).first
end
# 创建课程讨论区

@ -168,6 +168,8 @@ class GraduationTask < ApplicationRecord
end
end
# 是否具有分组
def have_grouping?
self.task_type == 2

@ -170,7 +170,7 @@ class HomeworkCommon < ApplicationRecord
#删除时更新题库中的引用数
def update_homework_bank_quotes
old_banks = HomeworkBank.where(homework_common_id: self.id)
old_banks = self.homework_bank
unless old_banks.blank?
old_banks.each do |bank|
bank.update_attributes(quotes: (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0, homework_common_id: nil)
@ -243,10 +243,15 @@ class HomeworkCommon < ApplicationRecord
end
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
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

@ -4,6 +4,8 @@ class Message < ApplicationRecord
belongs_to :board, counter_cache: true
belongs_to :author, class_name: "User", foreign_key: 'author_id'
belongs_to :parent, class_name: "Message", foreign_key: "parent_id", counter_cache: :replies_count, optional: true
belongs_to :root, class_name: 'Message', foreign_key: :root_id, counter_cache: :descendants_count, optional: true
has_one :message_detail, dependent: :destroy
accepts_nested_attributes_for :message_detail, update_only: true
@ -12,6 +14,7 @@ class Message < ApplicationRecord
has_many :tidings, as: :container, dependent: :destroy
has_many :attachments, as: :container, dependent: :destroy
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy # 课程动态
has_many :descendants, class_name: 'Message', foreign_key: :root_id, dependent: :destroy
scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子
scope :reply_nodes, -> { where("parent_id IS NOT NULL") }
@ -70,24 +73,16 @@ class Message < ApplicationRecord
# 包含二级回复的总点赞数
def total_praises_count
praises_count + children.includes(:children).reduce(0) { |count, filed|
sub_sum_count = filed.children.reduce(0) { |sub_count, sub_filed| sub_count += sub_filed.praises_count }
count += filed.praises_count
sub_sum_count += count
}
descendants.sum(:praises_count)
end
# 包含二级回复数的总回复数
def total_replies_count
replies_count + children.includes(:children).reduce(0) { |count, child|
sub_sum_count = child.children.reduce(0) { |sub_count, sub_child| sub_count += sub_child.replies_count }
count += child.replies_count
sub_sum_count += count
}
descendants_count
end
def has_replies
children.present?
children.exists?
end
#

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

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

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

@ -5,7 +5,7 @@ class ExercisePublishTask
def publish
Rails.logger.info("log--------------------------------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|
exercise.update_column('exercise_status', 2)
course = exercise.course
@ -67,21 +67,21 @@ class ExercisePublishTask
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|
course = exercise.course
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|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
# exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
if exercise_user.commit_status == 0 && exercise_user.start_at.present?
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
if ex_type.include?(4) #是否包含主观题
subjective_score = exercise_user.subjective_score
else
subjective_score = -1.0
end
# subjective_score = exercise_user.subjective_score
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score
commit_option = {
@ -93,21 +93,23 @@ class ExercisePublishTask
:subjective_score => subjective_score
}
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
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(",") + ")"
ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}")
ex_group_settings.each do |exercise_setting|
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
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|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
@ -117,7 +119,6 @@ class ExercisePublishTask
subjective_score = -1.0
end
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 = s_score + total_score_subjective_score
commit_option = {
@ -129,17 +130,11 @@ class ExercisePublishTask
:subjective_score => subjective_score
}
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
Rails.logger.info("log--------------------------------exercise_end completed")
Rails.logger.info("log--------------------------------exercise_end end")
puts "--------------------------------exercise_end end"
end
end

@ -1,5 +1,6 @@
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_type question.question_type
json.question_score question.question_score.round(1).to_s

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

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

@ -62,7 +62,8 @@ json.exercise_questions do
shixun_challenges: q.exercise_shixun_challenges,
exercise_type: ex_type,
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
json.question_comments do
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,
shixun_challenges: q.exercise_shixun_challenges,
exercise_type:2,
user_answer:[]
user_answer:[],
ques_position:nil
end
end

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

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

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

@ -12,10 +12,11 @@ json.tasks @tasks.each do |task|
json.name task.name
json.private_icon !task.is_public
json.task_status task.status #6.12 -hs
json.status task_curr_status(task, @course)[:status]
json.status_time task_curr_status(task, @course)[:time]
task_curr_status = task_curr_status(task, @course)
json.status task_curr_status[:status]
json.status_time task_curr_status[:time]
unless task_curr_status(task, @course)[:status].include?("未发布")
unless task_curr_status[:status].include?("未发布")
json.commit_count grduationwork_count task, 1
json.uncommit_count grduationwork_count task, 0
end

@ -1,6 +1,7 @@
json.partial! "public_navigation", locals: {graduation: @task, course: @course}
json.user_course_identity @user_course_identity
json.course_group_count @course.course_groups_count
json.cross_comment @task.cross_comment
# 课程发布才有数据
if @task.published? || @user_course_identity < Course::STUDENT
# 老师身份才有的分类信息
@ -25,8 +26,14 @@ if @task.published? || @user_course_identity < Course::STUDENT
# 是否具有分组
json.have_grouping @task.have_grouping?
if @user_course_identity == Course::STUDENT
json.commit_count grduationwork_count @task, 1
json.uncommit_count grduationwork_count @task, 0
json.left_time task_left_time @task
else
json.work_count @work_count
json.all_work_count @all_work_count
end
# 学生数据
json.work_lists do
json.array! @work_list do |work|

@ -3,8 +3,9 @@ json.course_name course.name
json.is_end course.is_end
json.category homework.category_info
member = course.course_members.find_by(user_id: user.id, is_active: 1)
json.homework_status homework_curr_status(homework, user.course_identity(course), course, member, member&.teacher_course_groups)[:status]
json.time_status homework_curr_status(homework, user.course_identity(course), course, member, member&.teacher_course_groups)[:time_status]
curr_status = homework_curr_status(homework, user.course_identity(course), course, member, member&.teacher_course_groups)
json.homework_status curr_status[:status]
json.time_status curr_status[:time_status]
json.homework_name homework.name
json.homework_id homework.id
json.homework_type homework.homework_type

@ -13,15 +13,16 @@ json.category_name @category.try(:name)
json.homeworks @homework_commons.each do |homework|
# homework_private = (@user_course_identity > Course::STUDENT) && !homework.is_public
curr_status = homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)
json.homework_id homework.id
json.name homework.name
json.private_icon !homework.is_public
json.status homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:status]
json.status_time homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:time]
json.time_status homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:time_status]
json.status curr_status[:status]
json.status_time curr_status[:time]
json.time_status curr_status[:time_status]
json.allow_late homework.allow_late
unless homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:status].include?("未发布")
unless curr_status[:status].include?("未发布")
json.commit_count studentwork_count homework, 1, @user.id
json.uncommit_count studentwork_count homework, 0, @user.id
end

@ -29,8 +29,9 @@ elsif @user_course_identity == Course::STUDENT
json.left_time left_time @homework, @current_user.id
if @homework.homework_type == "practice"
json.(@work, :id, :work_status, :update_time, :late_penalty, :ultimate_score)
json.(@work, :id, :work_status, :update_time, :ultimate_score)
json.late_penalty @work.late_penalty if @homework.allow_late
json.cost_time @work.myshixun.try(:total_cost_time)
json.work_score work_score_format(@work.work_score, true, @homework.score_open)
json.final_score work_score_format(@work.final_score, true, @homework.score_open)
@ -38,7 +39,7 @@ elsif @user_course_identity == Course::STUDENT
json.eff_score work_score_format(@work.eff_score, true, @homework.score_open)
json.complete_count @work.myshixun.try(:passed_count)
else
json.(@work, :id, :work_status, :update_time, :late_penalty, :absence_penalty, :appeal_penalty, :ultimate_score)
json.(@work, :id, :work_status, :update_time, :ultimate_score)
json.work_score work_score_format(@work.work_score, true, @homework.score_open)
json.final_score work_score_format(@work.final_score, true, @homework.score_open)
@ -48,13 +49,17 @@ elsif @user_course_identity == Course::STUDENT
json.ta_comment_count @work.ta_comment_count
json.late_penalty @work.late_penalty if @homework.allow_late
if @homework.anonymous_comment
json.student_comment_count @work.student_comment_num
json.absence_penalty @work.absence_penalty
end
if @homework.anonymous_appeal
json.appeal_all_count @work.appeal_all_count
json.appeal_deal_count @work.appeal_deal_count
json.appeal_penalty @work.appeal_penalty
end
if @homework.homework_type == "group"
@ -76,8 +81,9 @@ if @homework.homework_type == "practice"
json.work_efficiency @homework.work_efficiency
json.student_works @student_works.each do |work|
json.(work, :id, :work_status, :update_time, :late_penalty, :ultimate_score)
json.(work, :id, :work_status, :update_time, :ultimate_score)
json.late_penalty work.late_penalty if @homework.allow_late
json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open)
json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open)
json.efficiency work_score_format(work.efficiency, @current_user == work.user, @homework.score_open)
@ -103,8 +109,9 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
# json.student_comment_count anon_comments(@current_user, work.id).count
else
json.(work, :id, :work_status, :update_time, :work_score, :final_score, :teacher_score, :student_score,
:teaching_asistant_score, :late_penalty, :absence_penalty, :appeal_penalty, :ultimate_score)
:teaching_asistant_score, :ultimate_score)
json.late_penalty work.late_penalty if @homework.allow_late
json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open)
json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open)
json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @homework.score_open)
@ -117,6 +124,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
# 作品匿评条数
if @homework.anonymous_comment
json.student_comment_count @homework_detail_manual.comment_status > 2 ? work.student_comment_num : 0
json.absence_penalty work.absence_penalty
end
json.student_id work.user.try(:student_id)
@ -133,6 +141,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
if @homework.anonymous_appeal
json.appeal_all_count work.appeal_all_count
json.appeal_deal_count work.appeal_deal_count
json.appeal_penalty work.appeal_penalty
end
json.user_login @is_evaluation ? "--" : work.user.try(:login)

@ -6,6 +6,11 @@ json.data do
json.total_count @messages.total_count
json.messages do
json.array! @messages do |message|
json.extract! message, :id, :parent_id, :subject, :created_on, :total_replies_count,
:praises_count, :visits, :sticky, :is_hidden, :is_public
json.total_praises_count @praises_count_map.fetch(message.id, 0)
json.partial! "messages/message", message: message
json.author do
json.partial! "users/user_simple", user: message.author

@ -1,6 +1,6 @@
# json.partial! 'shixuns/right', locals: { shixun: @shixun }
json.partial! 'shixuns/right', locals: { shixun: @shixun }
#json.follow follow?(@shixun.owner, User.current)
#json.fans_count @fans_count
#json.followed_count @followed_count
json.follow follow?(@shixun.owner, User.current)
json.fans_count @fans_count
json.followed_count @followed_count
json.user_shixuns_count @user_own_shixuns

@ -6,4 +6,4 @@ json.name shixun.name
json.status shixun.status
json.human_status shixun.human_status
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)

@ -0,0 +1,5 @@
class AddDescendantsCountToMessages < ActiveRecord::Migration[5.2]
def change
add_column :messages, :descendants_count, :integer, default: 0
end
end

@ -20,6 +20,23 @@ namespace :course_board do
end
end
desc 'transfer root id && statistic descendants count'
task messages_descendants_count_transfer: :environment do
Message.root_nodes.find_each do |root|
logger("Current transfer root id: #{root.id} ~")
children_ids = root.children.pluck(:id)
next if children_ids.blank?
second_children_ids = Message.where(parent_id: children_ids).pluck(:id)
ids = children_ids.concat(second_children_ids).uniq
Message.where(id: ids).update_all(root_id: root.id)
Message.reset_counters(root.id, :descendants)
logger("transfer success ~")
end
end
def logger(msg)
puts msg
end

@ -6,7 +6,7 @@ namespace :poll_publish do
task :publish => :environment do
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|
poll.update_attributes(:polls_status => 2)
course = poll.course
@ -71,7 +71,7 @@ namespace :poll_publish do
task :nearly_end => :environment do
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|
if poll.tidings.where(:parent_container_type => "NearlyEnd").count == 0
course = poll.course
@ -111,7 +111,7 @@ namespace :poll_publish do
end
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|
poll.update_attributes(:polls_status => 3)
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|
poll = poll_setting.poll
poll.update_column('polls_status',3)
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))

Loading…
Cancel
Save