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

dev_forum
jingquan huang 6 years ago
commit 4e5c228581

@ -25,7 +25,8 @@ 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') folder = edu_setting('attachment_folder')
raise "存储目录未定义" unless folder.present? raise "存储目录未定义" unless folder.present?
@ -51,7 +52,7 @@ class AttachmentsController < ApplicationController
author_id: current_user.id, author_id: current_user.id,
cloud_url: remote_path).first cloud_url: remote_path).first
unless @attachment.present? if @attachment.blank?
@attachment = Attachment.new @attachment = Attachment.new
@attachment.filename = upload_file.original_filename @attachment.filename = upload_file.original_filename
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size] @attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
@ -67,9 +68,6 @@ class AttachmentsController < ApplicationController
end end
render_json render_json
else
raise "未上传文件"
end
end end
def destroy def destroy

@ -9,15 +9,10 @@ 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
@ -25,30 +20,28 @@ class BoardsController < ApplicationController
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

@ -127,7 +127,7 @@ class ExerciseQuestionsController < ApplicationController
shixun_scores = params[:question_scores] #试卷有多个的分值有多个分数表,所以为分数的数组 shixun_scores = params[:question_scores] #试卷有多个的分值有多个分数表,所以为分数的数组
shixun_name = params[:shixun_name] || shixun.name shixun_name = params[:shixun_name] || shixun.name
question_score = 0 question_score = 0
shixun.challenges.each_with_index do |challenge,index| shixun.challenges.try(:each_with_index) do |challenge,index|
shixun_option = { shixun_option = {
:challenge_id => challenge.id, :challenge_id => challenge.id,
:shixun_id => shixun.id, :shixun_id => shixun.id,
@ -384,24 +384,22 @@ class ExerciseQuestionsController < ApplicationController
begin begin
opr = params[:opr] opr = params[:opr]
current_q_p = @exercise_question.question_number.to_i #问题的当前位置 current_q_p = @exercise_question.question_number.to_i #问题的当前位置
# last_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p - 1)).first # 当前问题的前一个问题
# next_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p + 1)).first # 当前问题的后一个问题
last_q_p = @exercise.exercise_questions.last_exercise(current_q_p) # 当前问题的前一个问题
next_q_p = @exercise.exercise_questions.next_exercise(current_q_p) # 当前问题的后一个问题
if @exercise.exercise_status.to_i == 1 if @exercise.exercise_status.to_i == 1
if opr.present? if opr.present?
if opr.to_s == "up" if opr.to_s == "up"
last_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p - 1)) # 当前问题的前一个问题
if last_q_p.present? if last_q_p.present?
@exercise_question.update_attribute('question_number', (current_q_p - 1)) @exercise_question.update_attribute('question_number', (current_q_p - 1))
last_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i + 1)) # 重新获取当前问题的位置 last_q_p.update_attribute('question_number', current_q_p) # 重新获取当前问题的位置
normal_status(0, "问题上移成功!") normal_status(0, "问题上移成功!")
else else
normal_status(-1, "移动失败,已经是第一个问题了!") normal_status(-1, "移动失败,已经是第一个问题了!")
end end
elsif opr.to_s == "down" elsif opr.to_s == "down"
next_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p + 1)) # 当前问题的前一个问题
if next_q_p.present? if next_q_p.present?
@exercise_question.update_attribute('question_number', (current_q_p + 1)) @exercise_question.update_attribute('question_number', (current_q_p + 1))
next_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i - 1)) next_q_p.update_attribute('question_number', current_q_p)
normal_status(0, "问题下移成功!") normal_status(0, "问题下移成功!")
else else
normal_status(-1, "移动失败,已经是最后一个问题了!") normal_status(-1, "移动失败,已经是最后一个问题了!")

@ -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]
@ -32,13 +32,13 @@ class ExercisesController < ApplicationController
@exercises_all = @course.exercises @exercises_all = @course.exercises
member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷 member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷
@current_user_ = current_user @current_user_ = current_user
@exercises_count = @exercises_all.count # 全部页面,需返回 @exercises_count = @exercises_all.size # 全部页面,需返回
@exercises_unpublish_counts = @exercises_all.exercise_by_status(1).count #未发布的试卷数 @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数
@exercises_published_counts = @exercises_all.exercise_by_status([2,3]).count # 已发布的试卷数,包含已截止的 @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的
@exercises_ended_counts = @exercises_all.exercise_by_status(3).count #已截止的试卷数 @exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数
# 课堂的学生人数 # 课堂的学生人数
@course_all_members = @course.students #当前课堂的全部学生 @course_all_members = @course.students #当前课堂的全部学生
@course_all_members_count = @course_all_members.count #当前课堂的学生数 @course_all_members_count = @course_all_members.size #当前课堂的学生数
@current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生 @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生
# exercises的不同用户群体的显示 # exercises的不同用户群体的显示
@ -64,7 +64,7 @@ class ExercisesController < ApplicationController
@is_teacher_or = 0 @is_teacher_or = 0
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
end end
if @exercises.count > 0 if @exercises.size > 0
if params[:type].present? if params[:type].present?
choose_type = params[:type].to_i choose_type = params[:type].to_i
member_group_id = @current_student.first.try(:course_group_id).to_i member_group_id = @current_student.first.try(:course_group_id).to_i
@ -321,7 +321,7 @@ class ExercisesController < ApplicationController
begin begin
check_ids = Exercise.where(id: params[:check_ids]) check_ids = Exercise.where(id: params[:check_ids])
check_ids.each do |exercise| check_ids.each do |exercise|
current_ex_bank = current_user.exercise_banks.find_by_container(exercise.id,"Exercise").first current_ex_bank = current_user.exercise_banks.find_by_container(exercise.id,"Exercise")&.first
if current_ex_bank.present? #当前用户的选择试卷是否已加入习题库,存在则更新习题库和问题库,否则新建习题库和问题库 if current_ex_bank.present? #当前用户的选择试卷是否已加入习题库,存在则更新习题库和问题库,否则新建习题库和问题库
ex_params = { ex_params = {
:name => exercise.exercise_name, :name => exercise.exercise_name,
@ -402,7 +402,7 @@ class ExercisesController < ApplicationController
:position => c.position, :position => c.position,
:challenge_id => c.challenge_id, :challenge_id => c.challenge_id,
:shixun_id => q.shixun_id, :shixun_id => q.shixun_id,
:question_score => q.question_score :question_score => c.question_score
} }
shixun_challenge_bank = exercise_bank_question.exercise_bank_shixun_challenges.new challenge_option shixun_challenge_bank = exercise_bank_question.exercise_bank_shixun_challenges.new challenge_option
shixun_challenge_bank.save shixun_challenge_bank.save
@ -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

@ -64,7 +64,7 @@ class GamesController < ApplicationController
myshixun_manager: myshixun_manager} myshixun_manager: myshixun_manager}
if @shixun.vnc if @shixun.vnc
begin begin
shixun_tomcat = edu_setting('shixun_tomcat') shixun_tomcat = edu_setting('cloud_bridge')
service_host = edu_setting('vnc_url') service_host = edu_setting('vnc_url')
uri = "#{shixun_tomcat}/bridge/vnc/getvnc" uri = "#{shixun_tomcat}/bridge/vnc/getvnc"
params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"} params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"}
@ -72,8 +72,7 @@ class GamesController < ApplicationController
if res && res['code'].to_i != 0 if res && res['code'].to_i != 0
raise("实训云平台繁忙繁忙等级99") raise("实训云平台繁忙繁忙等级99")
end end
@url = "http://#{service_host}:#{res['port']}}/vnc_lite.html?password=headless" @vnc_url = "http://#{service_host}:#{res['port']}/vnc_lite.html?password=headless"
Rails.logger.info("66666666sssssss#{url}")
rescue Exception => e rescue Exception => e
Rails.logger.error(e.message) Rails.logger.error(e.message)
end end
@ -271,7 +270,8 @@ class GamesController < ApplicationController
if @game.status == 2 if @game.status == 2
@game.update_attributes!(:answer_open => @answer.level) @game.update_attributes!(:answer_open => @answer.level)
else else
@game.update_attributes!(:answer_open => @answer.level, :answer_deduction => deduct_score) answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score)
@game.update_attributes!(:answer_open => @answer.level, :answer_deduction => answer_deduction)
end end
rescue Exception => e rescue Exception => e
@ -613,13 +613,10 @@ class GamesController < ApplicationController
end end
# 批量插入评测结果 # 批量插入评测结果
uid_logger("choose_build") uid_logger("#------------chooice score: #{score}")
sql = "INSERT INTO outputs (game_id, test_set_position, actual_output, result, query_index, created_at, updated_at) VALUES" + str sql = "INSERT INTO outputs (game_id, test_set_position, actual_output, result, query_index, created_at, updated_at) VALUES" + str
ActiveRecord::Base.connection.execute sql ActiveRecord::Base.connection.execute sql
had_done = @game.had_done
@myshixun.update_attribute(:status, 1) if had_done == 1
# 没通关或者查看了答案通关的时候经验为0 # 没通关或者查看了答案通关的时候经验为0
# 通关但是查看了答案评测的时候金币显示0避免用户以为重复扣除但是在关卡列表中金币显示负数 # 通关但是查看了答案评测的时候金币显示0避免用户以为重复扣除但是在关卡列表中金币显示负数
experience = 0 experience = 0
@ -629,7 +626,8 @@ class GamesController < ApplicationController
if had_passed && !@game.had_passed? if had_passed && !@game.had_passed?
@game.update_attributes(:status => 2, :end_time => Time.now) @game.update_attributes(:status => 2, :end_time => Time.now)
# TPM实训已发布并且没有查看答案 # TPM实训已发布并且没有查看答案
if @shixun.is_published? && !@game.answer_open if @shixun.is_published? && @game.answer_open == 0
uid_logger("@@@@@@@@@@@@@@@@@chooice score: #{score}")
# 查看答案的时候处理final_scor和扣分记录 # 查看答案的时候处理final_scor和扣分记录
experience = score experience = score
reward_attrs = { container_id: @game.id, container_type: 'Game', score: score } reward_attrs = { container_id: @game.id, container_type: 'Game', score: score }
@ -638,6 +636,8 @@ class GamesController < ApplicationController
final_score = score final_score = score
RewardExperienceService.call(@myshixun.owner, reward_attrs) RewardExperienceService.call(@myshixun.owner, reward_attrs)
end end
had_done = @game.had_done
@myshixun.update_attribute(:status, 1) if had_done == 1
end end
grade = @myshixun.owner.try(:grade) grade = @myshixun.owner.try(:grade)

@ -24,8 +24,7 @@ class GraduationTopicsController < ApplicationController
end end
# 当前用户是否已经选过题 # 当前用户是否已经选过题
user_graduation_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]) #6.12 -hs @user_selected = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]).count > 0 #6.12 -hs
@user_selected = user_graduation_topics.size > 0
## 分页参数 ## 分页参数
page = params[:page] || 1 page = params[:page] || 1
limit = params[:limit] || 15 limit = params[:limit] || 15
@ -173,7 +172,7 @@ class GraduationTopicsController < ApplicationController
member = @course.course_members.where(:user_id => @graduation_topic.tea_id).first member = @course.course_members.where(:user_id => @graduation_topic.tea_id).first
tip_exception("分班名称不能为空") if params[:course_group_name].blank? tip_exception("分班名称不能为空") if params[:course_group_name].blank?
course_group = CourseGroup.create(:name => params[:course_group_name], :course_id => @course.id) course_group = CourseGroup.create(:name => params[:course_group_name], :course_id => @course.id)
teacher_group = TeacherCourseGroup.create(:course_id => @course.id, :member_id => member.try(:id), teacher_group = TeacherCourseGroup.create(:course_id => @course.id, :course_member_id => member.try(:id),
:user_id => @graduation_topic.tea_id, :user_id => @graduation_topic.tea_id,
:course_group_id => course_group.try(:id)) :course_group_id => course_group.try(:id))
end end
@ -195,7 +194,7 @@ class GraduationTopicsController < ApplicationController
user_unaccept_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]) user_unaccept_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1])
if user_unaccept_topics.size == 0 if user_unaccept_topics.size == 0
member_id = @course.course_members.find_by_user_id(current_user.id) member_id = @course.course_members.find_by_user_id(current_user.id)
StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, member_id: member_id, StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, course_member_id: member_id,
graduation_topic_id: @graduation_topic.id) graduation_topic_id: @graduation_topic.id)
@graduation_topic.update_attribute(:status, 1) @graduation_topic.update_attribute(:status, 1)
normal_status("选题成功") normal_status("选题成功")
@ -223,7 +222,7 @@ class GraduationTopicsController < ApplicationController
# 已加入的更新,未加入的新建 # 已加入的更新,未加入的新建
if topic_bank.present? if topic_bank.present?
topic_bank.update_attributes(name: topic, description: topic.description, topic_bank.update_attributes(name: topic.name, description: topic.description,
topic_source: topic.topic_source, topic_source: topic.topic_source,
topic_property_first: topic.topic_property_first, topic_property_first: topic.topic_property_first,
topic_property_second: topic.topic_property_second, topic_property_second: topic.topic_property_second,
@ -234,7 +233,7 @@ class GraduationTopicsController < ApplicationController
course_list_id: @course.course_list_id) course_list_id: @course.course_list_id)
topic_bank.attachments.destroy_all topic_bank.attachments.destroy_all
else else
topic_bank = GtopicBank.new(name: topic, description: topic.description, topic_bank = GtopicBank.new(name: topic.name, description: topic.description,
topic_source: topic.topic_source, topic_source: topic.topic_source,
topic_property_first: topic.topic_property_first, topic_property_first: topic.topic_property_first,
topic_property_second: topic.topic_property_second, topic_property_second: topic.topic_property_second,

@ -104,7 +104,7 @@ class HomeworkCommonsController < ApplicationController
@shixun = @homework.shixuns.take if @homework.homework_type == "practice" @shixun = @homework.shixuns.take if @homework.homework_type == "practice"
student_works = @homework.all_works student_works = @homework.all_works
@all_member_count = student_works.count @all_member_count = student_works.size
if @homework.publish_time.nil? || @homework.publish_time > Time.now if @homework.publish_time.nil? || @homework.publish_time > Time.now
@student_works = [] @student_works = []
respond_to do |format| respond_to do |format|
@ -134,15 +134,15 @@ class HomeworkCommonsController < ApplicationController
@student_works = [] @student_works = []
end end
elsif @user_course_identity < Course::STUDENT elsif @user_course_identity < Course::STUDENT
@student_works = @homework.teacher_works(@current_user.id) @student_works = @homework.teacher_works(@member)
@all_member_count = @student_works.count @all_member_count = @student_works.size
elsif @user_course_identity > Course::STUDENT && @homework.work_public elsif @user_course_identity > Course::STUDENT && @homework.work_public
@student_works = student_works @student_works = student_works
else else
@student_works = [] @student_works = []
end end
unless @student_works.size == 0 unless @student_works.blank?
# 教师评阅搜索 0: 未评, 1 已评 # 教师评阅搜索 0: 未评, 1 已评
unless params[:teacher_comment].blank? unless params[:teacher_comment].blank?
student_work_ids = StudentWorksScore.where(student_work_id: @student_works.map(&:id)).pluck(:student_work_id) student_work_ids = StudentWorksScore.where(student_work_id: @student_works.map(&:id)).pluck(:student_work_id)
@ -187,12 +187,13 @@ class HomeworkCommonsController < ApplicationController
# 分页参数 # 分页参数
page = params[:page] || 1 page = params[:page] || 1
limit = params[:limit] || 20 limit = params[:limit] || 20
@student_works = @student_works.page(page).per(limit).includes(:student_works_scores) @student_works = @student_works.page(page).per(limit)
if @homework.homework_type == "practice" if @homework.homework_type == "practice"
@student_works = @student_works.includes(user: :user_extension, myshixun: :games) @student_works = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games)
else else
@student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension) @student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension)
end end
# @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group)
end end
respond_to do |format| respond_to do |format|
format.json format.json
@ -203,6 +204,7 @@ class HomeworkCommonsController < ApplicationController
if @work_excel.present? if @work_excel.present?
student_work_to_xlsx(@work_excel,@homework) student_work_to_xlsx(@work_excel,@homework)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S')
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals:
{table_columns: @work_head_cells,task_users: @work_cells_column} {table_columns: @work_head_cells,task_users: @work_cells_column}
else else
@ -458,9 +460,9 @@ class HomeworkCommonsController < ApplicationController
tip_exception("发布时间不能为空") if setting[:publish_time].blank? tip_exception("发布时间不能为空") if setting[:publish_time].blank?
tip_exception("截止时间不能为空") if setting[:end_time].blank? tip_exception("截止时间不能为空") if setting[:end_time].blank?
# 如果该发布规则 没有已发布的分班则需判断发布时间 # 如果该发布规则 没有已发布的分班则需判断发布时间
tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0 tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0
tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now) tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now)
tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
tip_exception("截止时间不能早于课堂结束时间") if setting[:end_time] > strf_time(@course.end_date.end_of_day) tip_exception("截止时间不能早于课堂结束时间") if setting[:end_time] > strf_time(@course.end_date.end_of_day)
@ -585,9 +587,9 @@ class HomeworkCommonsController < ApplicationController
# anonymous_comment :true 是启用false 是不启用 # anonymous_comment :true 是启用false 是不启用
if params[:anonymous_comment] if params[:anonymous_comment]
tip_exception("匿评开启时间不能为空") if params[:evaluation_start].blank? tip_exception("匿评开启时间不能为空") if params[:evaluation_start].blank?
tip_exception("匿评开启时间不能早于截止时间") if params[:evaluation_start] <= strf_time(@homework.end_time) tip_exception("匿评开启时间不能早于截止时间") if params[:evaluation_start] < strf_time(@homework.end_time)
tip_exception("匿评结束时间不能为空") if params[:evaluation_end].blank? tip_exception("匿评结束时间不能为空") if params[:evaluation_end].blank?
tip_exception("匿评截止时间不能早于匿评开启时间") if params[:evaluation_end] <= params[:evaluation_start] tip_exception("匿评截止时间必须晚于匿评开启时间") if params[:evaluation_end] <= params[:evaluation_start]
tip_exception("匿评截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:evaluation_end] > tip_exception("匿评截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:evaluation_end] >
strf_time(@course.end_date.end_of_day) strf_time(@course.end_date.end_of_day)
tip_exception("匿评数必须为正整数") if params[:evaluation_num].blank? || params[:evaluation_num].to_i < 1 tip_exception("匿评数必须为正整数") if params[:evaluation_num].blank? || params[:evaluation_num].to_i < 1
@ -614,7 +616,7 @@ class HomeworkCommonsController < ApplicationController
# 匿评未截止时可以更新匿评结束时间 # 匿评未截止时可以更新匿评结束时间
if @homework_detail_manual.comment_status < 4 if @homework_detail_manual.comment_status < 4
tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank? tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank?
tip_exception("匿评截止时间不能早于匿评开启时间") if @homework.anonymous_comment && tip_exception("匿评截止时间必须晚于匿评开启时间") if @homework.anonymous_comment &&
params[:evaluation_end] <= params[:evaluation_start] params[:evaluation_end] <= params[:evaluation_start]
tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment && tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment &&
@course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day) @course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day)

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

@ -197,22 +197,23 @@ class PollQuestionsController < ApplicationController
begin begin
opr = params[:opr] opr = params[:opr]
current_q_p = @poll_question.question_number.to_i #问题的当前位置 current_q_p = @poll_question.question_number.to_i #问题的当前位置
last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题
next_q_p = @poll.poll_questions.next_poll(current_q_p) # 当前问题的后一个问题
if @poll.polls_status.to_i == 1 if @poll.polls_status.to_i == 1
if opr.present? if opr.present?
if opr.to_s == "up" if opr.to_s == "up"
last_q_p = @poll.poll_questions.find_by(question_number: (current_q_p-1)) #当前问题的前一个问题
if last_q_p.present? if last_q_p.present?
@poll_question.update_attribute(:question_number, (current_q_p - 1)) @poll_question.update_attribute("question_number", (current_q_p - 1))
last_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i + 1)) # 重新获取当前问题的位置 last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置
normal_status(0, "问题上移成功!") normal_status(0, "问题上移成功!")
else else
normal_status(-1, "移动失败,已经是第一个问题了!") normal_status(-1, "移动失败,已经是第一个问题了!")
end end
elsif opr.to_s == "down" elsif opr.to_s == "down"
next_q_p = @poll.poll_questions.find_by(question_number: (current_q_p+1)) #当前问题的后一个问题
if next_q_p.present? if next_q_p.present?
@poll_question.update_attribute(:question_number, (current_q_p + 1)) @poll_question.update_attribute("question_number", (current_q_p + 1))
next_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i - 1)) next_q_p.update_attribute("question_number", current_q_p)
normal_status(0, "问题下移成功!") normal_status(0, "问题下移成功!")
else else
normal_status(-1, "移动失败,已经是最后一个问题了!") normal_status(-1, "移动失败,已经是最后一个问题了!")

@ -123,7 +123,7 @@ class PollVotesController < ApplicationController
if @poll_question.blank? if @poll_question.blank?
normal_status(-1,"问卷试题不存在!") normal_status(-1,"问卷试题不存在!")
else else
@poll = @poll_question.poll.includes(:poll_users) @poll = @poll_question.poll
@course = @poll.course @course = @poll.course
if @poll.blank? if @poll.blank?
normal_status(-1,"问卷不存在!") normal_status(-1,"问卷不存在!")
@ -134,17 +134,11 @@ class PollVotesController < ApplicationController
end end
def check_answer_in_question def check_answer_in_question
# poll_answer_ids = @poll_question.poll_answers.pluck(:id)
# if @poll_question.question_type == 1 #单选题/多选题
# unless (params[:poll_answer_id].present? && poll_answer_ids.include?(params[:poll_answer_id].to_i)) || (params[:poll_answer_id].blank? && params[:vote_text].present?)
# normal_status(-1, "答案ID错误")
# end
# end
poll_user_status = @poll.get_poll_status(current_user.id) poll_user_status = @poll.get_poll_status(current_user.id)
poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户 poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户
question_type = @poll_question&.question_type question_type = @poll_question&.question_type
if [1,2].include?(question_type) && params[:poll_answer_id].blank? if (question_type == 1) && params[:poll_answer_id].blank?
normal_status(-1,"答案ID错误!") normal_status(-1,"答案ID错误!")
elsif question_type == 2 elsif question_type == 2
user_vote_count = params[:poll_answer_id].size user_vote_count = params[:poll_answer_id].size
@ -153,10 +147,10 @@ class PollVotesController < ApplicationController
else else
question_max_choices = 0 question_max_choices = 0
end end
if question_max_choices > 0 && user_vote_count > question_max_choices if question_max_choices > 0 && (user_vote_count > question_max_choices)
normal_status(-1,"多选题答案超过最大限制!") normal_status(-1,"多选题答案超过最大限制!")
end end
elsif (poll_user.present? && poll_user&.commit_status) || poll_user_status == 3 elsif (poll_user.present? && poll_user.commit_status == 1) || poll_user_status == 3
normal_status(-1,"已提交/已结束的问卷不允许修改!") normal_status(-1,"已提交/已结束的问卷不允许修改!")
end end
end end

@ -1184,7 +1184,7 @@ class PollsController < ApplicationController
def check_poll_commit_result def check_poll_commit_result
poll_status = @poll.get_poll_status(current_user.id) poll_status = @poll.get_poll_status(current_user.id)
commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的 commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的
unless @user_course_identity < Course::STUDENT || (@poll.show_result && poll_status == 3 && commit_poll_user.present?) unless (@user_course_identity < Course::STUDENT) || ((@poll.show_result == 1) && (poll_status == 3) && commit_poll_user.present?)
normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的 normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的
end end
end end

@ -178,6 +178,7 @@ class QuestionBanksController < ApplicationController
:question_type => q.question_type || 1, :question_type => q.question_type || 1,
:question_number => q.question_number, :question_number => q.question_number,
:question_score => q.question_score, :question_score => q.question_score,
:shixun_name => q.shixun_name,
:shixun_id => q.shixun_id :shixun_id => q.shixun_id
} }
exercise_question = new_exercise.exercise_questions.new option exercise_question = new_exercise.exercise_questions.new option
@ -265,11 +266,12 @@ class QuestionBanksController < ApplicationController
def quote_gtopic_bank topic, course def quote_gtopic_bank topic, course
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
new_topic = GraduationTopic.new new_topic = GraduationTopic.new
new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", "quotes",
"course_list_id", "gtopic_bank_id", "created_at", "updated_at") "course_list_id", "gtopic_bank_id", "created_at", "updated_at")
new_topic.course_id = course.id new_topic.course_id = course.id
new_topic.gtopic_bank_id = topic.id new_topic.gtopic_bank_id = topic.id
new_topic.user_id = current_user.id new_topic.user_id = current_user.id
new_topic.tea_id = current_user.id
new_topic.save new_topic.save
topic.attachments.each.try(:each) do |attachment| topic.attachments.each.try(:each) do |attachment|

@ -47,7 +47,7 @@ class ShixunsController < ApplicationController
where("challenge_tags.name like '%#{keyword}%' where("challenge_tags.name like '%#{keyword}%'
or challenges.subject like '%#{keyword}%' or challenges.subject like '%#{keyword}%'
or concat(lastname, firstname) like '%#{keyword}%' or concat(lastname, firstname) like '%#{keyword}%'
or shixuns.name like '%#{keyword.split(" ").join("%")}%'") or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct
end end
## 筛选 状态 ## 筛选 状态
@ -539,15 +539,21 @@ class ShixunsController < ApplicationController
# 其它创建关卡等操作 # 其它创建关卡等操作
challenges = @shixun.challenges challenges = @shixun.challenges
# 之所以增加user_id是为了方便统计查询性能 # 之所以增加user_id是为了方便统计查询性能
game_attrs = %i[challenge_id myshixun_id status user_id open_time identifier modify_time created_at updated_at]
Game.bulk_insert(*game_attrs) do |worker|
base_attr = { myshixun_id: myshixun.id, user_id: myshixun.user_id }
challenges.each_with_index do |challenge, index| challenges.each_with_index do |challenge, index|
status = (index == 0 ? 0 : 3) status = (index == 0 ? 0 : 3)
game_identifier = generate_identifier(Game, 12) game_identifier = generate_identifier(Game, 12)
Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, worker.add(base_attr.merge(challenge_id: challenge.id, status: status, open_time: Time.now,
:open_time => Time.now, :identifier => game_identifier, :modify_time => challenge.modify_time) identifier: game_identifier, modify_time: challenge.modify_time))
end
end end
# REDO:开启实训时更新关联作品的状态-> TODO:这个可以异步。 # REDO:开启实训时更新关联作品的状态
HomeworksService.new.update_myshixun_work_status myshixun # TODO:这个可以异步。或者放到课程里面取,不要在开启实训这边做
# HomeworksService.new.update_myshixun_work_status myshixun
UpdateMyshixunWorkStatusJob.perform_later(myshixun.id)
@current_task = myshixun.current_task @current_task = myshixun.current_task
uid_logger("## shixun exec: myshixun id is #{myshixun.id}") uid_logger("## shixun exec: myshixun id is #{myshixun.id}")
@ -558,9 +564,6 @@ class ShixunsController < ApplicationController
end end
end end
end end
end end
# gameID 及实训ID # gameID 及实训ID
# status: 0 , 1 申请过, 2实训关卡路径未填 3 实训标签未填, 4 实训未创建关卡 # status: 0 , 1 申请过, 2实训关卡路径未填 3 实训标签未填, 4 实训未创建关卡

@ -429,10 +429,17 @@ class StudentWorksController < ApplicationController
def shixun_work_report def shixun_work_report
@user = @work.user @user = @work.user
@shixun = @homework.shixuns.take @shixun = @homework.shixuns.take
@games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun # 提示: 这里如果includes outputs表的话 sum(:evaluate_count)会出现错误
@games = @work.myshixun.games if @work.myshixun
# 用户最大评测次数 # 用户最大评测次数
@user_evaluate_count = @games.sum(:evaluate_count) if @games if @games
@user_evaluate_count = @games.pluck(:evaluate_count).sum
@games = @games.includes(:challenge, :game_codes, :outputs)
else
@user_evaluate_count = 0
end
# 图形效率图的数据 # 图形效率图的数据
@echart_data = student_efficiency(@homework, @work) @echart_data = student_efficiency(@homework, @work)
end end
@ -443,7 +450,7 @@ class StudentWorksController < ApplicationController
@games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun
# 用户最大评测次数 # 用户最大评测次数
@user_evaluate_count = @games.sum(:evaluate_count) if @games @user_evaluate_count = @games.pluck(:evaluate_count).sum if @games
# 图形效率图的数据 # 图形效率图的数据
@echart_data = student_efficiency(@homework, @work) @echart_data = student_efficiency(@homework, @work)
@myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id } @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id }

@ -128,7 +128,7 @@ module ApplicationHelper
if source.class.to_s == 'User' if source.class.to_s == 'User'
File.join(relative_path, ["#{source.class}", "#{source.id}"]) File.join(relative_path, ["#{source.class}", "#{source.id}"])
else else
File.join("/images/avatars", ["#{source.class}", "#{source.id}"]) File.join("images/avatars", ["#{source.class}", "#{source.id}"])
end end
elsif source.class.to_s == 'User' elsif source.class.to_s == 'User'
str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g" str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g"
@ -146,7 +146,7 @@ module ApplicationHelper
def shixun_url_to_avatar(shixun) def shixun_url_to_avatar(shixun)
if File.exist?(disk_filename(shixun.class, shixun.id)) if File.exist?(disk_filename(shixun.class, shixun.id))
File.join("/images/#{relative_path}", "#{shixun.class}", "#{shixun.id}") File.join("images/#{relative_path}", "#{shixun.class}", "#{shixun.id}")
else else
File.join("educoder", "index", "shixun", "shixun#{rand(23)}.jpg") File.join("educoder", "index", "shixun", "shixun#{rand(23)}.jpg")
end end

@ -232,7 +232,7 @@ module CoursesHelper
course.course_groups.includes(:course_members) course.course_groups.includes(:course_members)
end end
group_info = [] group_info = []
if course_groups.count > 0 if !course_groups.blank?
course_groups.each do |group| course_groups.each do |group|
group_info << {course_group_id: group.id, group_group_name: group.name, count: group.course_members_count} group_info << {course_group_id: group.id, group_group_name: group.name, count: group.course_members_count}
end end
@ -247,15 +247,15 @@ module CoursesHelper
def left_group_info course def left_group_info course
group_info = [] group_info = []
if course.course_groups_count > 0 if course.course_groups_count > 0
none_group_count = course.students.where(course_group_id: 0).size
group_info << {category_id: 0, category_name: "未分班", position: course.course_groups.pluck(:position).max.to_i + 1,
category_count: none_group_count, category_type: false,
second_category_url: "/courses/#{@course.id}/course_groups/0"}
course.course_groups.each do |course_group| course.course_groups.each do |course_group|
group_info << {category_id: course_group.id, category_name: course_group.name, position: course_group.position, group_info << {category_id: course_group.id, category_name: course_group.name, position: course_group.position,
category_count: course_group.course_members_count, category_type: false, category_count: course_group.course_members_count, category_type: false,
second_category_url: "/courses/#{@course.id}/course_groups/#{course_group.id}"} second_category_url: "/courses/#{@course.id}/course_groups/#{course_group.id}"}
end end
none_group_count = course.students.where(course_group_id: 0).size
group_info << {category_id: 0, category_name: "未分班", position: course.course_groups.pluck(:position).max.to_i + 1,
category_count: none_group_count, category_type: false,
second_category_url: "/courses/#{@course.id}/course_groups/0"}
end end
group_info group_info
end end

@ -13,7 +13,8 @@ module ExercisesHelper
ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum
end end
if ques_score == q.question_score #满分作答为正确 if ques_score >= q.question_score #满分作答为正确
ques_score = q.question_score
stand_answer = 1 stand_answer = 1
elsif ques_score > 0.0 #部分作答 elsif ques_score > 0.0 #部分作答
stand_answer = 2 stand_answer = 2
@ -35,7 +36,8 @@ module ExercisesHelper
exercise_sub_status.each do |s| exercise_sub_status.each do |s|
sub_answer = s.exercise_answers.search_answer_users("user_id",user_id) #主观题只有一个回答 sub_answer = s.exercise_answers.search_answer_users("user_id",user_id) #主观题只有一个回答
if sub_answer.present? && sub_answer.first.score >= 0.0 if sub_answer.present? && sub_answer.first.score >= 0.0
if s.question_score == sub_answer.first.score
if s.question_score <= sub_answer.first.score
stand_status = 1 stand_status = 1
else else
stand_status = 2 stand_status = 2
@ -353,11 +355,12 @@ 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|
begin
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.where(user_id: user.id) #学生的答案
else else
answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案
end end
if q.question_type <= 2 #为选择题或判断题时 if q.question_type <= 2 #为选择题或判断题时
if answers_content.present? #学生有回答时 if answers_content.present? #学生有回答时
@ -369,7 +372,7 @@ module ExercisesHelper
standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
if standard_answer.count > 0 if standard_answer.count > 0
q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时每个answer的分数均摊。 q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时每个answer的分数均摊。
else else
q_score_1 = 0.0 q_score_1 = 0.0
end end
@ -413,30 +416,32 @@ module ExercisesHelper
score2 += 0.0 score2 += 0.0
end end
elsif q.question_type == 5 #实训题时,主观题这里不评分 elsif q.question_type == 5 #实训题时,主观题这里不评分
q.exercise_shixun_challenges.each do |exercise_cha| q.exercise_shixun_challenges&.each do |exercise_cha|
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡 game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
if game.present? if game.present?
exercise_cha_score = 0.0 exercise_cha_score = 0.0
answer_status = 0 answer_status = 0
if game.status == 2 && game.final_score >= 0 # if game.status == 2 && game.final_score >= 0
exercise_cha_score = exercise_cha.question_score #每一关卡的得分 if game.final_score > 0
exercise_cha_score = game.real_score(exercise_cha.question_score)
# exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 1 answer_status = 1
end end
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
cha_path = challenge_path exercise_cha.challenge.path cha_path = challenge_path(exercise_cha.challenge&.path)
game_challenge = game.game_codes.search_challenge_path(cha_path).first game_challenge = game.game_codes.search_challenge_path(cha_path)&.first
if game_challenge.present? if game_challenge.present?
game_code = game_challenge game_code = game_challenge
code = game_code.try(:new_code) code = game_code.try(:new_code)
else else
code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path)
end end
sx_option = { sx_option = {
:exercise_question_id => q.id, :exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id, :exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id, :user_id => user.id,
:score => exercise_cha_score, :score => exercise_cha_score.round(1),
:answer_text => code, :answer_text => code,
:status => answer_status :status => answer_status
} }
@ -450,8 +455,8 @@ module ExercisesHelper
end end
end end
end end
user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 user_scores = answers_content.blank? ? 0.0 : answers_content.score_reviewed.pluck(:score).sum
if user_scores > 0 if user_scores > 0.0
stand_answer = 1 stand_answer = 1
else else
stand_answer = 0 stand_answer = 0
@ -461,13 +466,18 @@ module ExercisesHelper
"q_type":q.question_type, "q_type":q.question_type,
"q_position":q.question_number, #该问题的位置 "q_position":q.question_number, #该问题的位置
"stand_status":stand_answer, #该问题是否正确,1为正确0为错误 "stand_status":stand_answer, #该问题是否正确,1为正确0为错误
"user_score":user_scores #每个问题的总得分 "user_score":user_scores.round(1) #每个问题的总得分
} }
ques_stand.push(ques_option) ques_stand.push(ques_option)
rescue Exception => e
Rails.logger.info("calcuclate_score_have_error____________________________#{e}")
next
end
end end
total_score = score1 + score2 + score5 total_score = score1 + score2 + score5
{ {
"total_score":total_score, "total_score":total_score.round(1),
"stand_status":ques_stand "stand_status":ques_stand
} }
end end
@ -682,17 +692,27 @@ module ExercisesHelper
def get_exercise_left_time(exercise,user) def get_exercise_left_time(exercise,user)
ex_time = exercise.time ex_time = exercise.time
user_left_time = nil user_left_time = nil
time_now_i = Time.now.to_i
if ex_time > 0 if ex_time > 0
exercise_user = exercise.exercise_users.find_by(user_id:user.id) exercise_user = exercise.exercise_users.find_by(user_id:user.id)
time_mill = ex_time * 60 #转为秒 time_mill = ex_time * 60 #转为秒
exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0
exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0 exercise_user_start = exercise_user&.start_at.present? ? exercise_user.start_at.to_i : 0
#用户未开始答题时即exercise_user_start为0
if exercise_user_start == 0
if (exercise_end_time - time_now_i) > time_mill
user_left_time = time_mill
else
user_left_time = (exercise_end_time < time_now_i) ? nil : (exercise_end_time - time_now_i)
end
else
if (exercise_user_start + time_mill) > exercise_end_time if (exercise_user_start + time_mill) > exercise_end_time
time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
end end
exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 exercise_user_left_time = time_now_i - exercise_user_start #用户已回答的时间
user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
end end
end
user_left_time user_left_time
end end

@ -89,11 +89,12 @@ module ExportHelper
if teacher_comments.present? if teacher_comments.present?
w_18 = "" w_18 = ""
teacher_comments.each do |t| teacher_comments.each do |t|
user_name = t.user.real_name user_name = t.user&.real_name
user_time = format_time(t.updated_at) user_time = format_time(t.updated_at)
user_score = t.score user_score = t&.score
user_comment = t.comment user_comment = t.comment.present? ? t.comment : "--"
w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "" + "\n" + "评语:" + user_comment + "\n\n") comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}\n评语:#{user_comment}\n\n"
w_18 = w_18 + comment_title
end end
else else
w_18 = "--" w_18 = "--"
@ -160,11 +161,13 @@ module ExportHelper
if teacher_comments.present? if teacher_comments.present?
w_18 = "" w_18 = ""
teacher_comments.each do |t| teacher_comments.each do |t|
user_name = t.user.real_name user_name = t.user&.real_name
user_time = format_time(t.updated_at) user_time = format_time(t.updated_at)
user_score = t.score user_score = t&.score
user_comment = t.comment user_comment = t.comment.present? ? t.comment : "--"
w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "" + "\n" + "评语:" + user_comment + "\n\n") comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}\n评语:#{user_comment}\n\n"
# ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n")
w_18 = w_18 + comment_title
end end
else else
w_18 = "--" w_18 = "--"

@ -15,7 +15,6 @@ module GraduationWorksHelper
end end
end end
# work_score 最终成绩; late_penalty 迟交扣分; final_score 最终评分 # work_score 最终成绩; late_penalty 迟交扣分; final_score 最终评分
{username: work.user.full_name, login: work.user.login, work_score: work_score, final_score: work.final_score, {username: work.user.full_name, login: work.user.login, work_score: work_score, final_score: work.final_score}
late_penalty:work.late_penalty }
end end
end end

@ -174,9 +174,9 @@ module HomeworkCommonsHelper
end end
# 作品数统计type 1 已提交 0 未提交 # 作品数统计type 1 已提交 0 未提交
def studentwork_count homework_common, type, user_id def studentwork_count homework_common, type, member
student_works = homework_common.teacher_works(user_id) student_works = homework_common.teacher_works(member)
type == 1 ? student_works.select{|work| work.work_status != 0}.size : student_works.select{|work| work.work_status = 0}.size type == 1 ? student_works.where("work_status != 0").size : student_works.where(work_status: 0).size
end end
# 上次查重的时间 # 上次查重的时间
@ -223,10 +223,10 @@ module HomeworkCommonsHelper
end end
# 作品状态 # 作品状态
def homework_status homework, user_id def homework_status homework, member
[{id: 0, name: "未提交", count: homework.unfinished_count(user_id)}, [{id: 0, name: "未提交", count: homework.unfinished_count(member)},
{id: 1, name: "按时提交", count: homework.finished_count(user_id)}, {id: 1, name: "按时提交", count: homework.finished_count(member)},
{id: 2, name: "延时提交", count: homework.delay_finished_count(user_id)}] {id: 2, name: "延时提交", count: homework.delay_finished_count(member)}]
end end
# 作品分数的显示 # 作品分数的显示

@ -3,8 +3,8 @@ module PollsHelper
#获取试卷的已答/未答人数 #获取试卷的已答/未答人数
def get_poll_answers(poll_users) def get_poll_answers(poll_users)
@commit_poll_users = poll_users.commit_by_status(1) #当前老师的全部学生中已提交的 @commit_poll_users = poll_users.commit_by_status(1) #当前老师的全部学生中已提交的
@poll_answers = @commit_poll_users.present? ? @commit_poll_users.count : 0 #表示已经提交了的用户 @poll_answers = @commit_poll_users.present? ? @commit_poll_users.size : 0 #表示已经提交了的用户
course_all_members_count = poll_users.present? ? poll_users.count : 0 course_all_members_count = poll_users.present? ? poll_users.size : 0
@poll_unanswers = (course_all_members_count - @poll_answers) @poll_unanswers = (course_all_members_count - @poll_answers)
end end

@ -54,13 +54,13 @@ module StudentWorksHelper
objects = objects =
myshixuns.map do |myshixun| myshixuns.map do |myshixun|
# 评测次数 # 评测次数
evaluate_count = myshixun.games.sum(:evaluate_count) evaluate_count = myshixun.games.pluck(:evaluate_count).sum
# 获取最大评测次数 # 获取最大评测次数
max_evaluate_count = (evaluate_count > max_evaluate_count ? evaluate_count : max_evaluate_count) max_evaluate_count = (evaluate_count > max_evaluate_count ? evaluate_count : max_evaluate_count)
# 通关耗时 # 通关耗时
pass_consume_time = (myshixun.games.where(status: 2).pluck(:cost_time).sum / 60.0) pass_consume_time = (myshixun.total_cost_time / 60.0)
# 总耗时 # 总耗时
all_time = (myshixun.games.sum(:cost_time) / 60.0) all_time = (myshixun.games.pluck(:cost_time).sum / 60.0)
# 通关得分 # 通关得分
user_total_score = myshixun.total_score.to_i user_total_score = myshixun.total_score.to_i
# 耗时,保留2位小数 # 耗时,保留2位小数

@ -0,0 +1,10 @@
class UpdateMyshixunWorkStatusJob < ApplicationJob
queue_as :default
def perform(myshixun_id)
myshixun = Myshixun.find_by(id: myshixun_id)
return if myshixun.blank?
HomeworksService.new.update_myshixun_work_status myshixun
end
end

@ -38,7 +38,7 @@ class Challenge < ApplicationRecord
## 选择题总分 ## 选择题总分
def choose_score def choose_score
self.challenge_chooses.sum(:score) self.challenge_chooses.pluck(:score).sum
end end
# 关卡总分 # 关卡总分

@ -20,6 +20,6 @@ class EduSetting < ApplicationRecord
private private
def expire_value_cache def expire_value_cache
Rails.cache.clear(value_cache_key) Rails.cache.write(value_cache_key, value)
end end
end end

@ -15,8 +15,8 @@ class ExerciseQuestion < ApplicationRecord
scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题
scope :next_exercise, lambda {|k| where("question_number > ?",k).first} # scope :next_exercise, lambda {|k| where("question_number > ?",k).first}
scope :last_exercise, lambda {|k| where("question_number < ?",k).last} # scope :last_exercise, lambda {|k| where("question_number < ?",k).last}
def question_type_name def question_type_name
case self.question_type case self.question_type

@ -115,9 +115,9 @@ class Game < ApplicationRecord
end end
# 评测次数 # 评测次数
def evaluate_count #def evaluate_count
self.outputs.pluck(:query_index).first # self.outputs.pluck(:query_index).first
end #end
# 用户关卡得分 # 用户关卡得分
def get_user_final_score def get_user_final_score

@ -100,8 +100,7 @@ class GraduationWork < ApplicationRecord
"未批阅" "未批阅"
else else
if self.check_score_power?(current_user, course_identity) if self.check_score_power?(current_user, course_identity)
"#{format("%.1f", self.cross_score.round(1))}(#{self.graduation_work_scores "#{format("%.1f", self.cross_score.round(1))}"
.where(reviewer_role: 2).group_by(&:user_id).count})"
else else
"**" "**"
end end
@ -109,6 +108,10 @@ class GraduationWork < ApplicationRecord
end end
end end
def cross_comment_num
graduation_work_scores.where(reviewer_role: 2).group_by(&:user_id).count
end
def scored? def scored?
graduation_work_scores.where.not(reviewer_role: 3).exists? graduation_work_scores.where.not(reviewer_role: 3).exists?
end end

@ -70,7 +70,7 @@ class HomeworkCommon < ApplicationRecord
if self.course_second_category.present? if self.course_second_category.present?
{category_id: self.course_second_category.try(:id), category_name: self.course_second_category.try(:name)} {category_id: self.course_second_category.try(:id), category_name: self.course_second_category.try(:name)}
else else
{category_id: course.shixun_course_modules.first.try(:id), category_name: course.shixun_course_modules.first.try(:module_name)} {category_id: course.shixun_course_modules.take.try(:id), category_name: course.shixun_course_modules.take.try(:module_name)}
end end
end end
end end
@ -78,20 +78,19 @@ class HomeworkCommon < ApplicationRecord
# 根据是否统一发布获取作业的作品列表 # 根据是否统一发布获取作业的作品列表
def all_works def all_works
student_works = self.unified_setting ? self.student_works : student_works = self.unified_setting ? self.student_works :
self.student_works.where(user_id: self.course.students.where( 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)})
course_group_id: self.published_settings.pluck(:course_group_id)).
pluck(:user_id))
end end
# 分班权限的老师可见的作品列表 # 分班权限的老师可见的作品列表
def teacher_works user_id def teacher_works member
member = course.course_member(user_id) # member = course.course_member(user_id)
teacher_course_groups = member.try(:teacher_course_groups) teacher_course_groups = member.try(:teacher_course_groups)
all_student_works = self.all_works all_student_works = self.all_works
# 有分班权限的统计管理的分班且已发布的学生情况 # 有分班权限的统计管理的分班且已发布的学生情况
if member.present? && teacher_course_groups.size > 0 if member.present? && teacher_course_groups.size > 0
group_ids = teacher_course_groups.pluck(:course_group_id) group_ids = teacher_course_groups.pluck(:course_group_id)
all_student_works = all_student_works.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_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})
end end
all_student_works all_student_works
end end
@ -216,17 +215,17 @@ class HomeworkCommon < ApplicationRecord
end end
# 作品未提交数 # 作品未提交数
def unfinished_count user_id def unfinished_count member
self.teacher_works(user_id).unfinished.count self.teacher_works(member).unfinished.count
end end
# 任务按时提交数 # 任务按时提交数
def finished_count user_id def finished_count member
self.teacher_works(user_id).finished.count self.teacher_works(member).finished.count
end end
def delay_finished_count user_id def delay_finished_count member
self.teacher_works(user_id).delay_finished.count self.teacher_works(member).delay_finished.count
end end
# 分组作业的最大分组id # 分组作业的最大分组id

@ -56,19 +56,13 @@ class Myshixun < ApplicationRecord
# status:0 可以测评的,正在测评的 # status:0 可以测评的,正在测评的
# 如果都完成,则当前任务为最后一个任务 # 如果都完成,则当前任务为最后一个任务
def current_task def current_task
current_game = self.games.select{|game| game.status == 1 || game.status == 0}.first games = self.games
current_game = games.select{|game| game.status == 1 || game.status == 0}.first
if current_game.blank? if current_game.blank?
if self.status == 1 current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id}
logger.info("@3333333333344444444#{self.id}") and g.challenge_id = c.id and g.status = 2 order by c.position desc").first
current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} and
g.challenge_id = c.id and g.status = 2 order by c.position desc").first
else
# 如果没开启过的status都为3所以应该进入第一关
current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} and
g.challenge_id = c.id and g.status = 3 order by c.position asc").first
end end
end current_game
return current_game
end end
@ -80,12 +74,12 @@ class Myshixun < ApplicationRecord
# 个人实训得分 # 个人实训得分
def total_score def total_score
self.games.where("status = 2 and final_score > 0").sum(:final_score).to_i self.games.select{|game| game.status == 2 && game.final_score > 0}.pluck(:final_score).sum.to_i
end end
# 个人通关数 # 个人通关数
def passed_count def passed_count
self.games.where(status: 2).count self.games.select{|game| game.status == 2}.size
end end
# 通关时间 # 通关时间
@ -95,12 +89,12 @@ class Myshixun < ApplicationRecord
# 耗时 # 耗时
def total_spend_time def total_spend_time
game_spend_time self.games.where(status: 2).sum(:cost_time).to_i game_spend_time total_cost_time
end end
# 通关总耗时 # 通关总耗时
def total_cost_time def total_cost_time
self.games.where(status: 2).sum(:cost_time).to_i self.games.select{|game| game.status == 2}.map(&:cost_time).sum.to_i
end end
end end

@ -137,16 +137,17 @@ class Poll < ApplicationRecord
#判断当前用户的答题状态 #判断当前用户的答题状态
def check_user_votes_status(user) def check_user_votes_status(user)
poll_answer_user = poll_users.find_by(user_id: user.id) poll_answer_user = poll_users.find_by(user_id: user.id)
user_poll_status = get_poll_status(user.id) # user_poll_status = get_poll_status(user.id)
user_status = 2 user_status = 2
if poll_answer_user.present? && (poll_answer_user.start_at.present? || poll_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 if poll_answer_user.present? && (poll_answer_user.start_at.present? || poll_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的
user_status = poll_answer_user.commit_status user_status = poll_answer_user.commit_status
end end
#
if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3 # if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3
user_status = 4 # # user_status = 4
end # user_status = 2 #问卷用户存在,且未开始答题,且问卷已截止时,返回未提交标示
# end
user_status user_status
end end

@ -8,8 +8,6 @@ class PollQuestion < ApplicationRecord
scope :ques_count, lambda {|k| where("question_type = ?",k)} scope :ques_count, lambda {|k| where("question_type = ?",k)}
scope :ques_necessary, -> {where("is_necessary = ?",1)} scope :ques_necessary, -> {where("is_necessary = ?",1)}
scope :insert_question, lambda {|k| where("question_number > ?",k)} scope :insert_question, lambda {|k| where("question_number > ?",k)}
scope :next_poll, lambda {|k| where("question_number > ?",k).first}
scope :last_poll, lambda {|k| where("question_number < ?",k).last}
def question_type_name def question_type_name
case self.question_type case self.question_type

@ -39,24 +39,34 @@ class StudentWork < ApplicationRecord
# 助教评分次数 # 助教评分次数
def ta_comment_count def ta_comment_count
self.student_works_scores.where(reviewer_role: 2).group_by(&:user_id).count self.student_works_scores.select{|score| score.reviewer_role == 2}.group_by(&:user_id).count
end end
# 匿评次数 # 匿评次数
def student_comment_num def student_comment_num
homework_common.homework_detail_manual.comment_status > 2 ? self.student_works_scores.where(reviewer_role: 3).group_by(&:user_id).count : 0 homework_common.homework_detail_manual.comment_status > 2 ? self.student_works_scores.select{|score| score.reviewer_role == 3}.group_by(&:user_id).count : 0
end end
# 匿评申诉总条数 # 匿评申诉总条数
def appeal_all_count def appeal_all_count
homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status != 0"). homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.
group_by(&:user_id).count : 0 select{|score| score.reviewer_role == 3 && score.appeal_status != 0}.group_by(&:user_id).count : 0
end end
# 匿评申诉待处理条数 # 匿评申诉待处理条数
def appeal_deal_count def appeal_deal_count
homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status = 1"). homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.
group_by(&:user_id).count : 0 select{|score| score.reviewer_role == 3 && score.appeal_status == 1}.group_by(&:user_id).count : 0
end
# 当前用户该作品的匿评申诉总条数
def my_appeal_all_count user_id
student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status != 0 && score.user_id = user_id}.size
end
# 当前用户该作品的匿评申诉总条数
def my_appeal_deal_count user_id
student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status == 1 && score.user_id = user_id}.size
end end
# 分组名 # 分组名

@ -81,7 +81,7 @@ class HomeworksService
pass_consume_time += (game.cost_time / 60.0).to_f pass_consume_time += (game.cost_time / 60.0).to_f
user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i
adjust_score = student_work.challenge_work_scores.where(challenge_id: setting.challenge_id).last adjust_score = student_work.challenge_work_scores.where(challenge_id: setting.challenge_id).last
final_score += adjust_score.present? ? adjust_score.score : (answer_open_evaluation ? setting.score : (game.final_score >= 0 ? setting.score : 0)) final_score += adjust_score.present? ? adjust_score.score : (answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0))
max_endtime = max_endtime == "" ? game.end_time : (game.end_time > max_endtime ? game.end_time : max_endtime) max_endtime = max_endtime == "" ? game.end_time : (game.end_time > max_endtime ? game.end_time : max_endtime)
else else
compelete = false compelete = false
@ -111,7 +111,7 @@ class HomeworksService
if homework.work_efficiency if homework.work_efficiency
if homework.max_efficiency < student_work.efficiency if homework.max_efficiency < student_work.efficiency
# homework.max_efficiency = student_work.efficiency # homework.max_efficiency = student_work.efficiency
homework.update_column("max_efficiency", homework.max_efficiency) homework.update_column("max_efficiency", student_work.efficiency)
end end
# eff_score = homework.max_efficiency == 0 ? 0 : student_work.efficiency / homework.max_efficiency * homework.eff_score # eff_score = homework.max_efficiency == 0 ? 0 : student_work.efficiency / homework.max_efficiency * homework.eff_score
# student_work.eff_score = format("%.2f", eff_score) # student_work.eff_score = format("%.2f", eff_score)
@ -177,7 +177,7 @@ class HomeworksService
pass_consume_time += (game.cost_time / 60.0).to_f pass_consume_time += (game.cost_time / 60.0).to_f
user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i
adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last
final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score >= 0 ? setting.score : 0)) final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0))
end end
end end
if work.work_status == 0 if work.work_status == 0
@ -200,7 +200,7 @@ class HomeworksService
# 如果作业的最大效率值有变更则更新所有作品的效率分 # 如果作业的最大效率值有变更则更新所有作品的效率分
if homework.work_efficiency && homework.max_efficiency < work.efficiency if homework.work_efficiency && homework.max_efficiency < work.efficiency
homework.update_column("max_efficiency", homework.max_efficiency) homework.update_column("max_efficiency", work.efficiency)
end end
end end

@ -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 = ""
@ -15,9 +15,9 @@ class ExercisePublishTask
tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end end
if exercise.unified_setting if exercise.unified_setting
course.student.find_each do |student| course.students.find_each do |student|
tid_str += "," if tid_str != "" tid_str += "," if tid_str != ""
tid_str += "(#{student.student_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end end
end end
if tid_str != "" if tid_str != ""
@ -25,7 +25,7 @@ class ExercisePublishTask
ActiveRecord::Base.connection.execute tid_sql ActiveRecord::Base.connection.execute tid_sql
end end
if exercise.exercise_users.count == 0 if exercise.exercise_users.size == 0
str = "" str = ""
course.students.find_each do |student| course.students.find_each do |student|
str += "," if str != "" str += "," if str != ""
@ -44,8 +44,8 @@ class ExercisePublishTask
end end
# 分组设置发布时间的测验 # 分组设置发布时间的测验
exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 1800, Time.now - 1800) 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,11 +71,12 @@ 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
if (exercise_user&.commit_status == 0) && (exercise_user&.start_at.present?)
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
@ -94,6 +95,11 @@ class ExercisePublishTask
} }
exercise_user.update_attributes(commit_option) exercise_user.update_attributes(commit_option)
end end
rescue Exception => e
Rails.logger.info("rescue errors ___________________________#{e}")
next
end
end end
end end
@ -101,17 +107,17 @@ 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
@ -131,6 +137,11 @@ class ExercisePublishTask
} }
exercise_user.update_attributes(commit_option) exercise_user.update_attributes(commit_option)
end end
rescue Exception => e
Rails.logger.info("unified_setting_false_rescue errors ___________________________#{e}")
next
end
end end
end end
Rails.logger.info("log--------------------------------exercise_end end") Rails.logger.info("log--------------------------------exercise_end end")

@ -241,7 +241,7 @@ p{
position: absolute; position: absolute;
display: inline-block; display: inline-block;
bottom: 9px; bottom: 9px;
left: 1px; left: 2px;
} }
table{ table{
width:100%; width:100%;

@ -249,8 +249,8 @@
<tbody> <tbody>
<% if @games.size > 0 %> <% if @games.size > 0 %>
<% @games.each_with_index do |game, index| %> <% @games.each_with_index do |game, index| %>
<% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id:game.challenge.id,user_id: @ex_user_user.id) %>
<% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %>
<% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.first&.id,user_id: @ex_user_user.id) %>
<tr> <tr>
<td><%= index + 1 %></td> <td><%= index + 1 %></td>
<td style="text-align: left;"> <td style="text-align: left;">

@ -23,7 +23,8 @@ if @exercises_count > 0
ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_)
json.extract! exercise, :id, :exercise_name,:is_public,:created_at json.extract! exercise, :id, :exercise_name,:is_public,:created_at
if @is_teacher_or == 2 if @is_teacher_or == 2
json.time get_exercise_left_time(exercise,@current_user_) second_left = get_exercise_left_time(exercise,@current_user_)
json.time second_left.present? ? (second_left / 60) : nil
end end
json.exercise_status ex_index[:ex_status] json.exercise_status ex_index[:ex_status]

@ -42,6 +42,7 @@ if @task.published? || @user_course_identity < Course::STUDENT
json.name work.user.real_name json.name work.user.real_name
json.student_id work.user.student_id json.student_id work.user.student_id
json.class_grouping_name work.class_grouping_name json.class_grouping_name work.class_grouping_name
json.ultimate_score work.ultimate_score
if @task.have_grouping? if @task.have_grouping?
json.grouping_name work.grouping_name json.grouping_name work.grouping_name
if @task.base_on_project if @task.base_on_project
@ -51,7 +52,11 @@ if @task.published? || @user_course_identity < Course::STUDENT
json.status work.work_status json.status work.work_status
json.update_time format_time work.update_time json.update_time format_time work.update_time
json.teacher_comment_score work.teacher_comment_score(@current_user, @user_course_identity) json.teacher_comment_score work.teacher_comment_score(@current_user, @user_course_identity)
if @task.cross_comment
json.cross_comment_score work.cross_comment_score(@current_user, @user_course_identity) json.cross_comment_score work.cross_comment_score(@current_user, @user_course_identity)
json.cross_comment_num work.cross_comment_num
end
json.late_penalty work.late_penalty if @task.allow_late
json.final_score work_final_score work, @current_user, @user_course_identity json.final_score work_final_score work, @current_user, @user_course_identity
json.assign work.assign_power?(@user_course_identity) json.assign work.assign_power?(@user_course_identity)
end end

@ -10,5 +10,5 @@ json.homework_name homework.name
json.homework_id homework.id json.homework_id homework.id
json.homework_type homework.homework_type json.homework_type homework.homework_type
if homework.homework_type == "practice" if homework.homework_type == "practice"
json.shixun_identifier homework.shixuns.first.try(:identifier) json.shixun_identifier homework.shixuns.take.try(:identifier)
end end

@ -2,10 +2,6 @@ json.course_identity @user_course_identity
json.homework_type @homework_type json.homework_type @homework_type
json.course_public @course.is_public == 1 json.course_public @course.is_public == 1
json.is_end @course.is_end json.is_end @course.is_end
json.all_count @all_count
json.published_count @published_count
json.unpublished_count @all_count - @published_count
json.task_count @task_count
json.main_category_id @main_category.try(:id) json.main_category_id @main_category.try(:id)
json.main_category_name @main_category.try(:module_name) json.main_category_name @main_category.try(:module_name)
json.category_id @category.try(:id) json.category_id @category.try(:id)
@ -23,8 +19,8 @@ json.homeworks @homework_commons.each do |homework|
json.allow_late homework.allow_late json.allow_late homework.allow_late
unless curr_status[:status].include?("未发布") unless curr_status[:status].include?("未发布")
json.commit_count studentwork_count homework, 1, @user.id json.commit_count studentwork_count homework, 1, @member
json.uncommit_count studentwork_count homework, 0, @user.id json.uncommit_count studentwork_count homework, 0, @member
end end
if @user_course_identity < Course::STUDENT if @user_course_identity < Course::STUDENT
@ -46,3 +42,8 @@ json.homeworks @homework_commons.each do |homework|
end end
end end
json.all_count @all_count
json.published_count @published_count
json.unpublished_count @all_count - @published_count
json.task_count @task_count

@ -20,12 +20,12 @@ if @user_course_identity < Course::STUDENT
if @homework.homework_type != "practice" if @homework.homework_type != "practice"
json.teacher_comment teacher_comment @homework, @current_user.id json.teacher_comment teacher_comment @homework, @current_user.id
end end
json.task_status homework_status @homework, @current_user.id json.task_status homework_status @homework, @member
json.course_group_info course_group_info @course, @current_user.id json.course_group_info course_group_info @course, @current_user.id
elsif @user_course_identity == Course::STUDENT elsif @user_course_identity == Course::STUDENT
json.commit_count studentwork_count @homework, 1, @current_user.id json.commit_count studentwork_count @homework, 1, @member
json.uncommit_count studentwork_count @homework, 0, @current_user.id json.uncommit_count studentwork_count @homework, 0, @member
json.left_time left_time @homework, @current_user.id json.left_time left_time @homework, @current_user.id
if @homework.homework_type == "practice" if @homework.homework_type == "practice"
@ -101,12 +101,17 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.anonymous_appeal @homework.anonymous_appeal json.anonymous_appeal @homework.anonymous_appeal
json.student_works @student_works.each do |work| json.student_works @student_works.each do |work|
if @is_evaluation if @is_evaluation
json.(work, :id, :work_status, :update_time) json.(work, :id, :work_status, :update_time)
json.student_score work_score_format(anon_comments(@current_user, work.id).last.try(:score), false, true) json.student_score work_score_format(anon_comments(@current_user, work.id).last.try(:score), false, true)
# json.student_comment_count anon_comments(@current_user, work.id).count # json.student_comment_count anon_comments(@current_user, work.id).count
# 申诉条数
if @homework.anonymous_appeal
json.appeal_all_count work.my_appeal_all_count @current_user.id
json.appeal_deal_count work.my_appeal_deal_count @current_user.id
end
else else
json.(work, :id, :work_status, :update_time, :work_score, :final_score, :teacher_score, :student_score, json.(work, :id, :work_status, :update_time, :work_score, :final_score, :teacher_score, :student_score,
:teaching_asistant_score, :ultimate_score) :teaching_asistant_score, :ultimate_score)
@ -135,7 +140,6 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
end end
json.work_group work.work_group_name json.work_group work.work_group_name
end end
end
# 申诉条数 # 申诉条数
if @homework.anonymous_appeal if @homework.anonymous_appeal
@ -143,6 +147,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.appeal_deal_count work.appeal_deal_count json.appeal_deal_count work.appeal_deal_count
json.appeal_penalty work.appeal_penalty json.appeal_penalty work.appeal_penalty
end end
end
json.user_login @is_evaluation ? "--" : work.user.try(:login) json.user_login @is_evaluation ? "--" : work.user.try(:login)
json.user_name @is_evaluation ? "匿名" : work.user.try(:real_name) json.user_name @is_evaluation ? "匿名" : work.user.try(:real_name)

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

@ -1,16 +1,14 @@
wb = xlsx_package.workbook wb = xlsx_package.workbook
wb.use_autowidth = false # wb.use_autowidth = false
wb.styles do |s| wb.styles do |s|
sz_all = s.add_style :sz => 10,:border => { :style => :thin, :color =>"000000"},:alignment => {:horizontal => :left} sz_all = s.add_style :sz => 10,:border => { :style => :thin, :color =>"000000"},:alignment => {wrap_text: true,:horizontal => :left}
blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :left} blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :left}
wb.add_worksheet(:name => "统计结果") do |sheet| wb.add_worksheet(:name => "统计结果") do |sheet|
sheet.sheet_view.show_grid_lines = false sheet.sheet_view.show_grid_lines = false
poll_users_info = %w(序号) poll_users_info = %w(序号)
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?}
poll_ques_ids = poll_questions.pluck(:id).sort #问题的全部id
poll_un_anony = @poll.un_anonymous poll_un_anony = @poll.un_anonymous
if poll_un_anony #是否匿名默认为false if poll_un_anony #是否匿名默认为false
user_info = %w(登陆名 真实姓名 邮箱 学号) user_info = %w(登陆名 真实姓名 邮箱 学号)
@ -32,25 +30,25 @@ wb.styles do |s|
sheet_answer_row.push(answer_users_count) sheet_answer_row.push(answer_users_count)
sheet_answer_percent.push(answer_percent.to_s) sheet_answer_percent.push(answer_percent.to_s)
end end
sheet.add_row sheet_row, :style => blue_cell sheet.add_row sheet_row, :height =>15,:style => blue_cell
sheet.add_row sheet_answer_row, :style => sz_all sheet.add_row sheet_answer_row, :height =>15, :style => sz_all
sheet.add_row sheet_answer_percent, :style => sz_all sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all
sheet.add_row sheet_answer_useful, :style => sz_all sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all
#合并单元格但无法填充style #合并单元格但无法填充style
# sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index))
# sheet.rows[sheet.rows.last.row_index].style = sz_all # sheet.rows[sheet.rows.last.row_index].style = sz_all
sheet.add_row [] sheet.add_row []
else #主观题答案 else #主观题答案
main_show_row = ["第#{q.question_number}题",q.question_title] main_show_row = ["第#{q.question_number}题",q.question_title]
sheet.add_row main_show_row, :style => blue_cell sheet.add_row main_show_row,:height =>15, :style => blue_cell
q.poll_votes.each do |v| #主观题的答案 q.poll_votes.each do |v| #主观题的答案
sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"], :style => sz_all sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all
end end
sheet.add_row [], :style => sz_all sheet.add_row [], :style => sz_all
end end
end #each_with_index end #each_with_index
sheet.add_row poll_users_info, :style => blue_cell sheet.add_row poll_users_info, :height =>15, :style => blue_cell
@poll.poll_users.each_with_index do |u,index| @poll.poll_users.each_with_index do |u,index|
u_user = u.user u_user = u.user
user_answer_array = [] user_answer_array = []
@ -88,7 +86,7 @@ wb.styles do |s|
user_cell += [user_login,user_name, u_user.mail, user_student_id] user_cell += [user_login,user_name, u_user.mail, user_student_id]
end end
all_user_cell = user_cell + user_answer_array all_user_cell = user_cell + user_answer_array
sheet.add_row all_user_cell, :style => sz_all sheet.add_row all_user_cell, :height =>15,:style => sz_all
end end
sheet.column_widths *([25]*sheet.column_info.count) sheet.column_widths *([25]*sheet.column_info.count)
sheet.column_info.first.width = 10 sheet.column_info.first.width = 10

@ -1,7 +1,6 @@
json.course do json.course do
json.partial! "polls/course_name",locals:{course:@course} json.partial! "polls/course_name",locals:{course:@course}
end end
json.poll_types do json.poll_types do
if @poll_current_user_status == 0 if @poll_current_user_status == 0
json.published_count @poll_publish_count json.published_count @poll_publish_count

@ -1,7 +1,8 @@
if @fuzzy_searchs # if @fuzzy_searchs
json.keyword @fuzzy_searchs # json.keyword @fuzzy_searchs
json.total_count @fuzzy_searchs.blank? ? nil : @total_count # json.total_count @fuzzy_searchs.blank? ? nil : @total_count
end # end
json.total_count @total_count
json.pagination @total_count > 16 ? true : false json.pagination @total_count > 16 ? true : false
json.search_tags @search_tags json.search_tags @search_tags
json.shixuns do json.shixuns do

@ -15,6 +15,7 @@ json.efficiency number_with_precision @work.efficiency, precision: 2
json.max_efficiency number_with_precision @homework.max_efficiency, precision: 2 json.max_efficiency number_with_precision @homework.max_efficiency, precision: 2
json.passed_time @myshixun.passed_time json.passed_time @myshixun.passed_time
json.total_spend_time @myshixun.total_spend_time json.total_spend_time @myshixun.total_spend_time
json.user_score @myshixun.total_score
# 关卡完成情况 # 关卡完成情况
index = 1 index = 1

@ -1,6 +1,6 @@
PDFKit.configure do |config| PDFKit.configure do |config|
# config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf' config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf'
config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf' # config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf'
config.default_options = { config.default_options = {
encoding: "UTF-8", encoding: "UTF-8",
page_size: 'A4', page_size: 'A4',

@ -0,0 +1,6 @@
class ModifyQuotesForGtopicBanks < ActiveRecord::Migration[5.2]
def change
GtopicBank.where("quotes is null").update_all(:quotes => 0)
change_column :gtopic_banks, :quotes, :integer, :default => 0
end
end

@ -5,37 +5,41 @@ namespace :exercise_deadline_warn do
task :deadline_warn => :environment do task :deadline_warn => :environment do
puts "--------------------------------exercise_nearly_end start" puts "--------------------------------exercise_nearly_end start"
# 统一设置发布时间的测验 # 统一设置发布时间的测验
exercises = Exercise.where("exercise_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) exercises = Exercise.where("exercise_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
exercises.each do |exercise| exercises.each do |exercise|
if exercise.tidings.where(:parent_container_type => "NearlyEnd").count == 0 if exercise.tidings.where(parent_container_type: "NearlyEnd").count == 0
course = exercise.course course = exercise.course
tid_str = "" tid_str = ""
exercise.exercise_users.where(:commit_status => 0).find_each do |student| exercise.exercise_users.where(commit_status: 0).find_each do |student|
tid_str += "," if tid_str != "" tid_str += "," if tid_str != ""
tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd',
#{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end end
if tid_str != "" if tid_str != ""
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id,
parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
ActiveRecord::Base.connection.execute tid_sql ActiveRecord::Base.connection.execute tid_sql
end end
end end
end end
# 分组设置发布时间的测验 # 分组设置发布时间的测验
exercise_group_settings = ExerciseGroupSetting.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) exercise_group_settings = ExerciseGroupSetting.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
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
members = course.course_members.where(:course_group_id => exercise_group.course_group_id) members = course.students.where(course_group_id: exercise_group.course_group_id)
if exercise.tidings.where(:parent_container_type => "NearlyEnd", :user_id => members.map(&:user_id)).count == 0 if exercise.tidings.where(parent_container_type: "NearlyEnd", user_id: members.pluck(:user_id)).count == 0
tid_str = "" tid_str = ""
exercise.exercise_users.where(:commit_status => 0, :user_id => members.map(&:user_id)).find_each do |member| exercise.exercise_users.where(commit_status: 0, user_id: members.pluck(:user_id)).find_each do |member|
tid_str += "," if tid_str != "" tid_str += "," if tid_str != ""
tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd',
#{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end end
if tid_str != "" if tid_str != ""
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id,
parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
ActiveRecord::Base.connection.execute tid_sql ActiveRecord::Base.connection.execute tid_sql
end end
end end

@ -30,7 +30,7 @@ namespace :graduation_task do
end end
task :nearly_end => :environment do task :nearly_end => :environment do
tasks = GraduationTask.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) tasks = GraduationTask.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
tasks.each do |task| tasks.each do |task|
if task.tidings.where(parent_container_type: "NearlyEnd").count == 0 if task.tidings.where(parent_container_type: "NearlyEnd").count == 0
course = task.course course = task.course

@ -4,7 +4,7 @@ namespace :homework_endtime do
desc "send a message for Job deadline" desc "send a message for Job deadline"
task :message => :environment do task :message => :environment do
# 统一设置发布时间的作业 # 统一设置发布时间的作业
homeworks = HomeworkCommon.where("unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) homeworks = HomeworkCommon.includes(:course).where("unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
homeworks.each do |homework| homeworks.each do |homework|
if homework.tidings.where(:parent_container_type => "NearlyEnd").count == 0 if homework.tidings.where(:parent_container_type => "NearlyEnd").count == 0
course = homework.course course = homework.course
@ -25,7 +25,7 @@ namespace :homework_endtime do
end end
# 分组设置发布时间的作业 # 分组设置发布时间的作业
homework_group_settings = HomeworkGroupSetting.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) homework_group_settings = HomeworkGroupSetting.includes(:homework_common).where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
homework_group_settings.each do |homework_group| homework_group_settings.each do |homework_group|
homework = homework_group.homework_common homework = homework_group.homework_common
if homework.present? if homework.present?
@ -52,8 +52,8 @@ namespace :homework_endtime do
# 匿评截止时间快到了 # 匿评截止时间快到了
task :evaluation_nearly_end => :environment do task :evaluation_nearly_end => :environment do
homework_detail_manuals = HomeworkDetailManual.where("homework_detail_manuals.comment_status = 3 and evaluation_end <=? homework_detail_manuals = HomeworkDetailManual.includes(:homework_common).where("homework_detail_manuals.comment_status = 3 and evaluation_end <=?
and evaluation_end > ? ", Time.now + 86400, Time.now + 82800) and evaluation_end > ? ", Time.now + 86400, Time.now + 84600)
homework_detail_manuals.each do |homework_detail_manual| homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common homework_common = homework_detail_manual.homework_common
if homework_common.present? if homework_common.present?
@ -85,7 +85,7 @@ namespace :homework_endtime do
# 匿评申诉截止时间快到了 # 匿评申诉截止时间快到了
task :appeal_nearly_end => :environment do task :appeal_nearly_end => :environment do
homework_detail_manuals = HomeworkDetailManual.where("homework_detail_manuals.comment_status = 4 and appeal_time <=? homework_detail_manuals = HomeworkDetailManual.where("homework_detail_manuals.comment_status = 4 and appeal_time <=?
and appeal_time > ?", Time.now + 86400, Time.now + 82800) and appeal_time > ?", Time.now + 86400, Time.now + 84600)
homework_detail_manuals.each do |homework_detail_manual| homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common homework_common = homework_detail_manual.homework_common
if homework_common.present? if homework_common.present?

@ -12,7 +12,7 @@ namespace :homework_evaluation do
task :start_evaluation => :environment do task :start_evaluation => :environment do
Rails.logger.info("log--------------------------------start_evaluation start") Rails.logger.info("log--------------------------------start_evaluation start")
puts "--------------------------------start_evaluation start" puts "--------------------------------start_evaluation start"
homework_detail_manuals = HomeworkDetailManual.where("evaluation_start <= '#{Time.now}' and homework_detail_manuals = HomeworkDetailManual.includes(homework_common: :course).where("evaluation_start <= '#{Time.now}' and
(homework_detail_manuals.comment_status < 3)") (homework_detail_manuals.comment_status < 3)")
homework_detail_manuals.each do |homework_detail_manual| homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common homework_common = homework_detail_manual.homework_common
@ -110,7 +110,7 @@ namespace :homework_evaluation do
#自动关闭匿评的任务 #自动关闭匿评的任务
task :end_evaluation => :environment do task :end_evaluation => :environment do
homework_detail_manuals = HomeworkDetailManual.where("evaluation_end <= '#{Time.now}' and homework_detail_manuals.comment_status = 3") homework_detail_manuals = HomeworkDetailManual.includes(:homework_common).where("evaluation_end <= '#{Time.now}' and homework_detail_manuals.comment_status = 3")
homework_detail_manuals.each do |homework_detail_manual| homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common homework_common = homework_detail_manual.homework_common
if homework_common.anonymous_comment #开启匿评状态才可关闭匿评 if homework_common.anonymous_comment #开启匿评状态才可关闭匿评

@ -6,8 +6,8 @@ namespace :homework_publishtime do
# 作业的分班设置时间 # 作业的分班设置时间
def homework_group_setting homework, group_id def homework_group_setting homework, group_id
setting = nil setting = nil
if homework.homework_group_settings.where(:course_group_id => group_id).first if homework.homework_group_settings.where(course_group_id: group_id).first
setting = homework.homework_group_settings.where(:course_group_id => group_id).first setting = homework.homework_group_settings.where(course_group_id: group_id).first
else else
setting = homework setting = homework
end end

@ -116,11 +116,7 @@ namespace :poll_publish do
polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = true AND end_time <=?",Time.now + 900) polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = true AND end_time <=?",Time.now + 900)
polls.each do |poll| polls.each do |poll|
poll.update_column('polls_status', 3) poll.update_column('polls_status', 3)
poll.poll_users.each do |poll_user| poll.poll_users.where("commit_status = 0 and start_at is not null").update_all(commit_status: 1, end_at: Time.now)
if poll_user.commit_status == 0 && poll_user.start_at.present?
poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
end
end
end end
#2.分班设置的截止 #2.分班设置的截止
@ -132,13 +128,13 @@ namespace :poll_publish do
if poll&.end_time <= Time.now if poll&.end_time <= Time.now
poll.update_column('polls_status', 3) poll.update_column('polls_status', 3)
end end
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.poll_users.where(user_id: users.pluck(:user_id)).where("commit_status = 0 and start_at is not null").update_all(commit_status: 1, end_at: Time.now)
poll_users.each do |poll_user| # poll_users.each do |poll_user|
if poll_user.commit_status == 0 && !poll_user.start_at.nil? # if poll_user.commit_status == 0 && !poll_user.start_at.nil?
poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) # poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
end # end
end # end
end end
# 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|

@ -5,9 +5,7 @@ namespace :resource_publish do
task :publish => :environment do task :publish => :environment do
Rails.logger.info("log--------------------------------resource_publish start") Rails.logger.info("log--------------------------------resource_publish start")
attachments = Attachment.where("publish_time < '#{Time.now}' and is_publish = 0") attachments = Attachment.where("publish_time < '#{Time.now}' and is_publish = 0")
attachments.each do |attachment| attachments.update_all(is_publish: 1)
attachment.update_attributes(:is_publish => 1)
end
Rails.logger.info("log--------------------------------resource_publish end") Rails.logger.info("log--------------------------------resource_publish end")
end end
end end
Loading…
Cancel
Save