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

dev_forum
SylorHuang 5 years ago
commit feb9d3dde7

@ -89,7 +89,7 @@ class ExercisesController < ApplicationController
@page = params[:page] || 1
@limit = params[:limit] || 15
@exercises = @exercises.page(@page).per(@limit)
@exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings)
@exercises = @exercises&.includes(:published_settings)
else
@exercises = []
end
@ -1183,12 +1183,12 @@ class ExercisesController < ApplicationController
ex_common_ids = @exercise.common_published_ids(current_user.id)
@exercise_course_groups = @course.get_ex_published_course(ex_common_ids)
@exercise_users_list = @exercise.all_exercise_users(current_user.id) #当前老师所在班级的全部学生
get_exercise_answers(@exercise_users_list)
get_exercise_answers(@exercise_users_list, @exercise_status)
end
elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交)
@ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间
@exercise_all_users = @exercise.get_stu_exercise_users
get_exercise_answers(@exercise_all_users) # 未答和已答的
get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的
exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做)
if exercise_current_user.present?
@exercise_current_user_status = 1 #当前用户的状态,为学生
@ -1202,7 +1202,7 @@ class ExercisesController < ApplicationController
end
else
@exercise_all_users = @exercise.get_stu_exercise_users
get_exercise_answers(@exercise_all_users) # 未答和已答的
get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的
@exercise_current_user_status = 2 #当前用户非课堂成员
@exercise_users_list = []
end

@ -77,7 +77,7 @@ class GamesController < ApplicationController
# 区分选择题和编程题st0编程题
if @st == 0
has_answer = game_challenge.challenge_answers.size == 0 ? false : true
has_answer = game_challenge.challenge_answers.size != 0
game_challenge.answer = nil
mirror_name = @shixun.mirror_name
@ -87,7 +87,7 @@ class GamesController < ApplicationController
rescue
uid_logger("实训平台繁忙繁忙等级81")
end
tpm_cases_modified = (game_challenge.modify_time != @game.modify_time ? true : false) # modify_time 决定TPM测试集是否有更新
tpm_cases_modified = (game_challenge.modify_time != @game.modify_time) # modify_time 决定TPM测试集是否有更新
@task_result = {tpm_modified: tpm_modified, tpm_cases_modified: tpm_cases_modified, mirror_name: mirror_name, has_answer: has_answer}
@ -311,7 +311,7 @@ class GamesController < ApplicationController
# 扣除总分计算
@game.update_attributes!(:answer_open => 1, :answer_deduction => 100)
end
@challenge_answers = @challenge.challenge_chooses
@challenge_chooses = @challenge.challenge_chooses
rescue Exception => e
uid_logger_error("#######金币扣除异常: #{e.message}")
raise ActiveRecord::Rollback
@ -629,7 +629,7 @@ class GamesController < ApplicationController
# user_answer虽然是传的数组,但是可能存在多选择提的情况.
user_answer_tran = user_answer[index].size > 1 ? user_answer[index].split("").sort.join("") : user_answer[index]
standard_answer_tran = choose.standard_answer.size > 1 ? choose.standard_answer.split("").sort.join("") : choose.standard_answer
correct = (user_answer_tran == standard_answer_tran) ? true : false
correct = (user_answer_tran == standard_answer_tran)
if str.present?
str += ","
end
@ -903,7 +903,7 @@ class GamesController < ApplicationController
end
# actual_output为空表示暂时没有评测答题不允许查看
actual_output = output.try(:actual_output).try(:strip)
has_answer << choose.answer if choose.answer.present?
#has_answer << choose.answer if choose.answer.present?
# 标准答案处理,错误的不让用户查看,用-1替代
standard_answer = (actual_output.blank? || !output.try(:result)) ? -1 : choose.standard_answer
result = output.try(:result)
@ -914,7 +914,7 @@ class GamesController < ApplicationController
@chooses << sin_choose
test_sets << sin_test_set
end
@has_answer = has_answer.present?
@has_answer = true # 选择题永远都有答案
@choose_test_cases = {:had_submmit => had_submmit, :challenge_chooses_count => challenge_chooses_count,
:choose_correct_num => choose_correct_num, :test_sets => test_sets}
end

@ -250,12 +250,12 @@ class HomeworkCommonsController < ApplicationController
student_works = @homework.student_works.where(user_id: user_ids)
end
myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids).
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: user_ids).
includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)})
challenge_settings = @homework.homework_challenge_settings
myshixuns.find_each(batch_size: 100) do |myshixun|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max)
if work && myshixun
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
end
@ -276,13 +276,13 @@ class HomeworkCommonsController < ApplicationController
myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id)
ActiveRecord::Base.transaction do
begin
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max)
if work && myshixun
challenge_settings = @homework.homework_challenge_settings
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
normal_status("更新成功")
else
normal_status("已是最新成绩")
normal_status("还开启挑战,暂不能更新成绩")
end
rescue Exception => e
uid_logger(e.message)

@ -33,7 +33,7 @@ class MyshixunsController < ApplicationController
uid_logger_error("版本库删除异常,详情:#{e.message}")
end
StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => nil, :work_status => 0)
StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => 0, :work_status => 0)
rescue Exception => e
uid_logger_error("myshixun reset failed #{e}")
@ -278,7 +278,6 @@ class MyshixunsController < ApplicationController
end
end
if game.status == 2
@resubmit = Time.now.to_i
end

@ -250,10 +250,15 @@ module ExercisesHelper
end
#获取试卷的已答/未答人数
def get_exercise_answers(ex_users)
@exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户
course_all_members_count = ex_users.size
@exercise_unanswers = (course_all_members_count - @exercise_answers)
def get_exercise_answers(ex_users, status)
if status == 1
@exercise_answers = 0
@exercise_unanswers = 0
else
@exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户
course_all_members_count = ex_users.size
@exercise_unanswers = (course_all_members_count - @exercise_answers)
end
end
def exercise_index_show(exercise,course,is_teacher_or,user)
@ -281,8 +286,8 @@ module ExercisesHelper
if is_teacher_or == 1
exercise_users_list = exercise.all_exercise_users(user.id) #当前老师所在班级的全部学生
unreview_count = exercise_users_list.exercise_unreview.size
get_exercise_answers(exercise_users_list)
unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size
get_exercise_answers(exercise_users_list, exercise_status)
ex_pb_time = exercise.get_exercise_times(user.id,true)
exercise_publish_time = ex_pb_time[:publish_time]
exercise_end_time = ex_pb_time[:end_time]
@ -295,8 +300,8 @@ module ExercisesHelper
end
elsif is_teacher_or == 2
exercise_users_list = exercise.get_stu_exercise_users
get_exercise_answers(exercise_users_list) # 未答和已答的
unreview_count = exercise_users_list.exercise_unreview.size
get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的
unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size
ex_pb_time = exercise.get_exercise_times(user.id,false)
exercise_publish_time = ex_pb_time[:publish_time]
exercise_end_time = ex_pb_time[:end_time]
@ -307,7 +312,7 @@ module ExercisesHelper
end
else
exercise_users_list = exercise.get_stu_exercise_users
get_exercise_answers(exercise_users_list) # 未答和已答的
get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的
exercise_publish_time = exercise.publish_time
exercise_end_time = exercise.end_time
unreview_count = nil

@ -308,12 +308,12 @@ class Course < ApplicationRecord
teacher_power_courses = []
if course_groups.present?
common_ids.each do |i|
student_count = students.where(course_group_id:i).count
if i == 0
student_count = students.where(course_group_id:i).count
teacher_power_courses << {course_name:"未分班",course_id:0,student_count:student_count}
else
course_group_name = course_groups.find_by(id:i)
teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:student_count}
teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:course_group_name&.course_members_count}
end
end
end

@ -7,6 +7,8 @@ class Exercise < ApplicationRecord
has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser"
has_many :exercise_questions, :dependent => :delete_all
has_many :exercise_group_settings, :dependent => :delete_all
has_many :published_settings, -> { exercise_group_published }, class_name: "ExerciseGroupSetting"
has_many :tidings, as: :container
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all
@ -41,8 +43,8 @@ class Exercise < ApplicationRecord
exercise_users
else
ex_group_setting_ids = exercise_group_settings.exercise_group_published.pluck(:course_group_id)
course_user_ids = course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id)
exercise_users.where(user_id:course_user_ids)
exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
where(course_members: {course_group_id: ex_group_setting_ids})
end
end
@ -55,22 +57,45 @@ class Exercise < ApplicationRecord
end
end
#统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
def all_exercise_users(user_id)
ex_users = exercise_users
group_ids = common_published_ids(user_id)
if group_ids.present?
ex_users = ex_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id))
# 根据是否统一发布获取作业的作品列表
def all_works
exercise_users = self.unified_setting ? self.exercise_users :
self.exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)})
end
# 分班权限的老师可见的作品列表
def all_exercise_users user_id
# member = course.course_member(user_id)
teacher_course_groups = course.teacher_course_groups.where(user_id: user_id)
ex_users = self.all_works
# 有分班权限的统计管理的分班且已发布的学生情况
if teacher_course_groups.exists?
group_ids = teacher_course_groups.pluck(:course_group_id)
ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
where(course_members: {course_group_id: group_ids})
end
ex_users
end
# #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
# def all_exercise_users(user_id)
# ex_users = exercise_users
# group_ids = common_published_ids(user_id)
# if group_ids.present?
# ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
# where(course_members: {course_group_id: group_ids})
# end
# ex_users
# end
#当前用户已发布的班级id和试卷分组已发布的班级id的交集
def common_published_ids(user_id)
current_user_groups = course.teacher_course_ids(user_id)
if unified_setting
un_group_ids = (course.none_group_count > 0) ? [0] : []
published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时为当前用户的分班id及未分班
# un_group_ids = (course.none_group_count > 0) ? [0] : []
# published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时为当前用户的分班id及未分班
published_group_ids = current_user_groups
else
ex_group_setting = exercise_group_settings.select(:course_group_id).pluck("course_group_id").uniq
common_all_ids = ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时为当前用户有权限的且已发布分班的id

@ -79,7 +79,8 @@ class HomeworkCommon < ApplicationRecord
# 根据是否统一发布获取作业的作品列表
def all_works
student_works = self.unified_setting ? self.student_works :
self.student_works.joins("join course_members on student_works.user_id=course_members.user_id").where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)})
self.student_works.joins("join course_members on student_works.user_id=course_members.user_id").
where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)})
end
# 分班权限的老师可见的作品列表
@ -88,7 +89,7 @@ class HomeworkCommon < ApplicationRecord
teacher_course_groups = member.try(:teacher_course_groups)
all_student_works = self.all_works
# 有分班权限的统计管理的分班且已发布的学生情况
if member.present? && teacher_course_groups.size > 0
if member.present? && teacher_course_groups.exists?
group_ids = teacher_course_groups.pluck(:course_group_id)
all_student_works = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id").
where(course_members: {course_group_id: group_ids})

@ -0,0 +1,5 @@
class AddIndexForRunCodeMessage < ActiveRecord::Migration[5.2]
def change
add_index :run_code_messages, :game_id
end
end
Loading…
Cancel
Save