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

dev_forum
jingquan huang 5 years ago
commit 4e5c228581

@ -25,51 +25,49 @@ class AttachmentsController < ApplicationController
# 2. 上传到云
upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
if upload_file
folder = edu_setting('attachment_folder')
raise "存储目录未定义" unless folder.present?
raise "未上传文件" unless upload_file
month_folder = current_month_folder
save_path = File.join(folder, month_folder)
folder = edu_setting('attachment_folder')
raise "存储目录未定义" unless folder.present?
ext = file_ext(upload_file.original_filename)
month_folder = current_month_folder
save_path = File.join(folder, month_folder)
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
ext = file_ext(upload_file.original_filename)
content_type = upload_file.content_type.presence || 'application/octet-stream'
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
content_type = upload_file.content_type.presence || 'application/octet-stream'
logger.info "local_path: #{local_path}"
logger.info "remote_path: #{remote_path}"
remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
logger.info "local_path: #{local_path}"
logger.info "remote_path: #{remote_path}"
disk_filename = local_path[save_path.size + 1, local_path.size]
#存数据库
#
@attachment = Attachment.where(disk_filename: disk_filename,
author_id: current_user.id,
cloud_url: remote_path).first
unless @attachment.present?
@attachment = Attachment.new
@attachment.filename = upload_file.original_filename
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment.filesize = upload_file.tempfile.size
@attachment.content_type = content_type
@attachment.digest = digest
@attachment.author_id = current_user.id
@attachment.disk_directory = month_folder
@attachment.cloud_url = remote_path
@attachment.save!
else
logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}"
end
disk_filename = local_path[save_path.size + 1, local_path.size]
#存数据库
#
@attachment = Attachment.where(disk_filename: disk_filename,
author_id: current_user.id,
cloud_url: remote_path).first
render_json
if @attachment.blank?
@attachment = Attachment.new
@attachment.filename = upload_file.original_filename
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment.filesize = upload_file.tempfile.size
@attachment.content_type = content_type
@attachment.digest = digest
@attachment.author_id = current_user.id
@attachment.disk_directory = month_folder
@attachment.cloud_url = remote_path
@attachment.save!
else
raise "未上传文件"
logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}"
end
render_json
end
def destroy

@ -9,46 +9,39 @@ class BoardsController < ApplicationController
end
def show
end
def new
end
def create
ActiveRecord::Base.transaction do
begin
board = @course.course_board
new_board = Board.new(board_params)
new_board.course_id = @course.id
new_board.project_id = -1
new_board.parent_id = board.try(:id)
new_board.position = board.children.count + 1
new_board.save!
normal_status(0, "添加成功")
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
board = @course.course_board
new_board = Board.new(board_params)
new_board.course_id = @course.id
new_board.project_id = -1
new_board.parent_id = board.try(:id)
new_board.position = board.children.count + 1
new_board.save!
end
normal_status(0, "添加成功")
end
# 子目录的拖动
def move_category
tip_exception("移动失败") if params[:position].blank?
unless params[:position].to_i == @board.position
course_board = @course.course_board
return normal_status(-1, "位置没有变化") if params[:position].to_i == @board.position
course_board = @course.course_board
ActiveRecord::Base.transaction do
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
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
@board.update_attributes(position: params[:position])
normal_status(0, "移动成功")
else
normal_status(-1, "位置没有变化")
end
normal_status(0, "移动成功")
end
def destroy

@ -127,7 +127,7 @@ class ExerciseQuestionsController < ApplicationController
shixun_scores = params[:question_scores] #试卷有多个的分值有多个分数表,所以为分数的数组
shixun_name = params[:shixun_name] || shixun.name
question_score = 0
shixun.challenges.each_with_index do |challenge,index|
shixun.challenges.try(:each_with_index) do |challenge,index|
shixun_option = {
:challenge_id => challenge.id,
:shixun_id => shixun.id,
@ -384,24 +384,22 @@ class ExerciseQuestionsController < ApplicationController
begin
opr = params[:opr]
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 opr.present?
if opr.to_s == "up"
last_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p - 1)) # 当前问题的前一个问题
if last_q_p.present?
@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, "问题上移成功!")
else
normal_status(-1, "移动失败,已经是第一个问题了!")
end
elsif opr.to_s == "down"
next_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p + 1)) # 当前问题的前一个问题
if next_q_p.present?
@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, "问题下移成功!")
else
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 :validate_publish_time,only: [:commit_setting] #提交设置时,需判断时间是否符合
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 :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_status,only: [:redo_modal,:redo_exercise]
before_action :check_exercise_is_end, only: [:review_exercise]
@ -32,13 +32,13 @@ class ExercisesController < ApplicationController
@exercises_all = @course.exercises
member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷
@current_user_ = current_user
@exercises_count = @exercises_all.count # 全部页面,需返回
@exercises_unpublish_counts = @exercises_all.exercise_by_status(1).count #未发布的试卷数
@exercises_published_counts = @exercises_all.exercise_by_status([2,3]).count # 已发布的试卷数,包含已截止的
@exercises_ended_counts = @exercises_all.exercise_by_status(3).count #已截止的试卷数
@exercises_count = @exercises_all.size # 全部页面,需返回
@exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数
@exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的
@exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数
# 课堂的学生人数
@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) #当前用户是否为课堂的学生
# exercises的不同用户群体的显示
@ -64,7 +64,7 @@ class ExercisesController < ApplicationController
@is_teacher_or = 0
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
end
if @exercises.count > 0
if @exercises.size > 0
if params[:type].present?
choose_type = params[:type].to_i
member_group_id = @current_student.first.try(:course_group_id).to_i
@ -321,7 +321,7 @@ class ExercisesController < ApplicationController
begin
check_ids = Exercise.where(id: params[:check_ids])
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? #当前用户的选择试卷是否已加入习题库,存在则更新习题库和问题库,否则新建习题库和问题库
ex_params = {
:name => exercise.exercise_name,
@ -402,7 +402,7 @@ class ExercisesController < ApplicationController
:position => c.position,
:challenge_id => c.challenge_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.save
@ -1006,6 +1006,7 @@ class ExercisesController < ApplicationController
def start_answer
ActiveRecord::Base.transaction do
begin
@exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first
if @exercise_user_current.blank?
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候不创建exercise_user表理论上老师是不能进入答题的
exercise_user_params = {
@ -1640,38 +1641,38 @@ class ExercisesController < ApplicationController
end
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?
normal_status(404,"答题用户不存在")
elsif @exercise.get_exercise_status(current_user.id) != 2 || @answer_committed_user.commit_status == 1 #
normal_status(-1,"提交错误,试卷已截止/用户已提交!")
# elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交
# normal_status(-1,"提交错误,试卷用户已提交!")
end
end
def commit_user_exercise
@exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id).first #查找当前用户是否有过答题
if @user_course_identity == Course::STUDENT
if @exercise_user_current.present?
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)
#当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
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
total_score = objective_score + subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => objective_score,
:score => total_score,
:subjective_score => subjective_score
}
@exercise_user_current.update_attributes(commit_option)
normal_status(0,"已交卷成功!")
end
end
end
end
# def commit_user_exercise
# @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题
# if @user_course_identity == Course::STUDENT
# if @exercise_user_current.present?
# 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)
# #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
# 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
# total_score = objective_score + subjective_score
# commit_option = {
# :status => 1,
# :commit_status => 1,
# :end_at => Time.now,
# :objective_score => objective_score,
# :score => total_score,
# :subjective_score => subjective_score
# }
# @exercise_user_current.update_attributes(commit_option)
# normal_status(0,"已交卷成功!")
# end
# end
# end
# end
#打回重做时的初步判断
def check_exercise_status

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

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

@ -104,7 +104,7 @@ class HomeworkCommonsController < ApplicationController
@shixun = @homework.shixuns.take if @homework.homework_type == "practice"
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
@student_works = []
respond_to do |format|
@ -134,15 +134,15 @@ class HomeworkCommonsController < ApplicationController
@student_works = []
end
elsif @user_course_identity < Course::STUDENT
@student_works = @homework.teacher_works(@current_user.id)
@all_member_count = @student_works.count
@student_works = @homework.teacher_works(@member)
@all_member_count = @student_works.size
elsif @user_course_identity > Course::STUDENT && @homework.work_public
@student_works = student_works
else
@student_works = []
end
unless @student_works.size == 0
unless @student_works.blank?
# 教师评阅搜索 0: 未评, 1 已评
unless params[:teacher_comment].blank?
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
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"
@student_works = @student_works.includes(user: :user_extension, myshixun: :games)
@student_works = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games)
else
@student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension)
end
# @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group)
end
respond_to do |format|
format.json
@ -203,6 +204,7 @@ class HomeworkCommonsController < ApplicationController
if @work_excel.present?
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')
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}
else
@ -458,9 +460,9 @@ class HomeworkCommonsController < ApplicationController
tip_exception("发布时间不能为空") if setting[:publish_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[:end_time] > strf_time(@course.end_date.end_of_day)
@ -585,9 +587,9 @@ class HomeworkCommonsController < ApplicationController
# anonymous_comment :true 是启用false 是不启用
if params[:anonymous_comment]
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] <= params[:evaluation_start]
tip_exception("匿评截止时间必须晚于匿评开启时间") if params[:evaluation_end] <= params[:evaluation_start]
tip_exception("匿评截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:evaluation_end] >
strf_time(@course.end_date.end_of_day)
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
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]
tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment &&
@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
@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?
@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)
end

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

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

@ -1184,7 +1184,7 @@ class PollsController < ApplicationController
def check_poll_commit_result
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) #当前用户已提交问卷的
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,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的
end
end

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

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

@ -429,10 +429,17 @@ class StudentWorksController < ApplicationController
def shixun_work_report
@user = @work.user
@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)
end
@ -443,7 +450,7 @@ class StudentWorksController < ApplicationController
@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)
@myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id }

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

@ -232,7 +232,7 @@ module CoursesHelper
course.course_groups.includes(:course_members)
end
group_info = []
if course_groups.count > 0
if !course_groups.blank?
course_groups.each do |group|
group_info << {course_group_id: group.id, group_group_name: group.name, count: group.course_members_count}
end
@ -247,15 +247,15 @@ module CoursesHelper
def left_group_info course
group_info = []
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|
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,
second_category_url: "/courses/#{@course.id}/course_groups/#{course_group.id}"}
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
group_info
end

@ -13,7 +13,8 @@ module ExercisesHelper
ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum
end
if ques_score == q.question_score #满分作答为正确
if ques_score >= q.question_score #满分作答为正确
ques_score = q.question_score
stand_answer = 1
elsif ques_score > 0.0 #部分作答
stand_answer = 2
@ -35,7 +36,8 @@ module ExercisesHelper
exercise_sub_status.each do |s|
sub_answer = s.exercise_answers.search_answer_users("user_id",user_id) #主观题只有一个回答
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
else
stand_status = 2
@ -353,121 +355,129 @@ module ExercisesHelper
score5 = 0.0 #实训题
ques_stand = [] #问题是否正确
exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges)
exercise_questions.each do |q|
if q.question_type != 5
answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案
else
answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案
end
if q.question_type <= 2 #为选择题或判断题时
if answers_content.present? #学生有回答时
answer_choice_array = []
answers_content.each do |a|
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
end
user_answer_content = answer_choice_array.sort
standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
if standard_answer.count > 0
q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时每个answer的分数均摊。
else
q_score_1 = 0.0
end
answers_content.update_all(:score => q_score_1)
score1 = score1 + q.question_score
end
exercise_questions&.each do |q|
begin
if q.question_type != 5
answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案
else
score1 += 0.0
answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案
end
elsif q.question_type == 3 #填空题
if answers_content.present?
null_standard_answer = q.exercise_standard_answers
standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text)
standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组
standard_answer_count = standard_answer_ids.count
if standard_answer_count > 0 #存在标准答案时才有分数
q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分
else
q_score_2 = 0.0
end
if q.is_ordered
answers_content.each do |u|
i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案
if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数
u.update_column('score',q_score_2)
score2 = score2 + q_score_2
if q.question_type <= 2 #为选择题或判断题时
if answers_content.present? #学生有回答时
answer_choice_array = []
answers_content.each do |a|
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
end
user_answer_content = answer_choice_array.sort
standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
if standard_answer.count > 0
q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时每个answer的分数均摊。
else
q_score_1 = 0.0
end
answers_content.update_all(:score => q_score_1)
score1 = score1 + q.question_score
end
else
st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase)
answers_content.each do |u|
u_answer_text = u.answer_text.downcase
if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分
u.update_column("score",q_score_2)
score2 = score2 + q_score_2
st_answer_text.delete(u_answer_text)
score1 += 0.0
end
elsif q.question_type == 3 #填空题
if answers_content.present?
null_standard_answer = q.exercise_standard_answers
standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text)
standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组
standard_answer_count = standard_answer_ids.count
if standard_answer_count > 0 #存在标准答案时才有分数
q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分
else
q_score_2 = 0.0
end
if q.is_ordered
answers_content.each do |u|
i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案
if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数
u.update_column('score',q_score_2)
score2 = score2 + q_score_2
end
end
else
st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase)
answers_content.each do |u|
u_answer_text = u.answer_text.downcase
if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分
u.update_column("score",q_score_2)
score2 = score2 + q_score_2
st_answer_text.delete(u_answer_text)
end
end
end
else
score2 += 0.0
end
else
score2 += 0.0
end
elsif q.question_type == 5 #实训题时,主观题这里不评分
q.exercise_shixun_challenges.each do |exercise_cha|
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
if game.present?
exercise_cha_score = 0.0
answer_status = 0
if game.status == 2 && game.final_score >= 0
exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 1
end
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
cha_path = challenge_path exercise_cha.challenge.path
game_challenge = game.game_codes.search_challenge_path(cha_path).first
if game_challenge.present?
game_code = game_challenge
code = game_code.try(:new_code)
elsif q.question_type == 5 #实训题时,主观题这里不评分
q.exercise_shixun_challenges&.each do |exercise_cha|
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
if game.present?
exercise_cha_score = 0.0
answer_status = 0
# if game.status == 2 && game.final_score >= 0
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
end
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
cha_path = challenge_path(exercise_cha.challenge&.path)
game_challenge = game.game_codes.search_challenge_path(cha_path)&.first
if game_challenge.present?
game_code = game_challenge
code = game_code.try(:new_code)
else
code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path)
end
sx_option = {
:exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id,
:score => exercise_cha_score.round(1),
:answer_text => code,
:status => answer_status
}
ExerciseShixunAnswer.create(sx_option)
else
code = git_fle_content(exercise_cha.shixun.repo_path,cha_path)
ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
end
sx_option = {
:exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id,
:score => exercise_cha_score,
:answer_text => code,
:status => answer_status
}
ExerciseShixunAnswer.create(sx_option)
score5 += exercise_cha_score
else
ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
score5 += 0.0
end
score5 += exercise_cha_score
else
score5 += 0.0
end
end
user_scores = answers_content.blank? ? 0.0 : answers_content.score_reviewed.pluck(:score).sum
if user_scores > 0.0
stand_answer = 1
else
stand_answer = 0
end
ques_option = {
"q_id":q.id, #该问题的id
"q_type":q.question_type,
"q_position":q.question_number, #该问题的位置
"stand_status":stand_answer, #该问题是否正确,1为正确0为错误
"user_score":user_scores.round(1) #每个问题的总得分
}
ques_stand.push(ques_option)
rescue Exception => e
Rails.logger.info("calcuclate_score_have_error____________________________#{e}")
next
end
user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0
if user_scores > 0
stand_answer = 1
else
stand_answer = 0
end
ques_option = {
"q_id":q.id, #该问题的id
"q_type":q.question_type,
"q_position":q.question_number, #该问题的位置
"stand_status":stand_answer, #该问题是否正确,1为正确0为错误
"user_score":user_scores #每个问题的总得分
}
ques_stand.push(ques_option)
end
total_score = score1 + score2 + score5
{
"total_score":total_score,
"total_score":total_score.round(1),
"stand_status":ques_stand
}
end
@ -682,16 +692,26 @@ module ExercisesHelper
def get_exercise_left_time(exercise,user)
ex_time = exercise.time
user_left_time = nil
time_now_i = Time.now.to_i
if ex_time > 0
exercise_user = exercise.exercise_users.find_by(user_id:user.id)
time_mill = ex_time * 60 #转为秒
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
if (exercise_user_start + time_mill) > exercise_end_time
time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
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
time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
end
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) #当前用户对试卷的回答剩余时间
end
exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间
user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
end
user_left_time
end

@ -89,11 +89,12 @@ module ExportHelper
if teacher_comments.present?
w_18 = ""
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_score = t.score
user_comment = t.comment
w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "" + "\n" + "评语:" + user_comment + "\n\n")
user_score = t&.score
user_comment = t.comment.present? ? t.comment : "--"
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
else
w_18 = "--"
@ -160,11 +161,13 @@ module ExportHelper
if teacher_comments.present?
w_18 = ""
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_score = t.score
user_comment = t.comment
w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "" + "\n" + "评语:" + user_comment + "\n\n")
user_score = t&.score
user_comment = t.comment.present? ? t.comment : "--"
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
else
w_18 = "--"

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

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

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

@ -54,13 +54,13 @@ module StudentWorksHelper
objects =
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)
# 通关耗时
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
# 耗时,保留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
self.challenge_chooses.sum(:score)
self.challenge_chooses.pluck(:score).sum
end
# 关卡总分

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

@ -15,8 +15,8 @@ class ExerciseQuestion < ApplicationRecord
scope :find_by_custom, 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 :next_exercise, lambda {|k| where("question_number > ?",k).first}
scope :last_exercise, lambda {|k| where("question_number < ?",k).last}
# scope :next_exercise, lambda {|k| where("question_number > ?",k).first}
# scope :last_exercise, lambda {|k| where("question_number < ?",k).last}
def question_type_name
case self.question_type

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

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

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

@ -18,7 +18,7 @@ class Message < ApplicationRecord
scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子
scope :reply_nodes, -> { where("parent_id IS NOT NULL") }
scope :visible, -> { where(is_hidden: false)}
scope :visible, -> { where(is_hidden: false) }
scope :by_user, ->(user) { visible if user.nil? || !user.admin? }
scope :preload_messages, -> { includes(:author, :message_detail) }
scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) }

@ -56,19 +56,13 @@ class Myshixun < ApplicationRecord
# status:0 可以测评的,正在测评的
# 如果都完成,则当前任务为最后一个任务
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 self.status == 1
logger.info("@3333333333344444444#{self.id}")
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
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
end
return current_game
current_game
end
@ -80,12 +74,12 @@ class Myshixun < ApplicationRecord
# 个人实训得分
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
# 个人通关数
def passed_count
self.games.where(status: 2).count
self.games.select{|game| game.status == 2}.size
end
# 通关时间
@ -95,12 +89,12 @@ class Myshixun < ApplicationRecord
# 耗时
def total_spend_time
game_spend_time self.games.where(status: 2).sum(:cost_time).to_i
game_spend_time total_cost_time
end
# 通关总耗时
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

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

@ -8,8 +8,6 @@ class PollQuestion < ApplicationRecord
scope :ques_count, lambda {|k| where("question_type = ?",k)}
scope :ques_necessary, -> {where("is_necessary = ?",1)}
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
case self.question_type

@ -39,24 +39,34 @@ class StudentWork < ApplicationRecord
# 助教评分次数
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
# 匿评次数
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
# 匿评申诉总条数
def appeal_all_count
homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status != 0").
group_by(&:user_id).count : 0
homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.
select{|score| score.reviewer_role == 3 && score.appeal_status != 0}.group_by(&:user_id).count : 0
end
# 匿评申诉待处理条数
def appeal_deal_count
homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status = 1").
group_by(&:user_id).count : 0
homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.
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
# 分组名

@ -81,7 +81,7 @@ class HomeworksService
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
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)
else
compelete = false
@ -111,7 +111,7 @@ class HomeworksService
if homework.work_efficiency
if 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
# eff_score = homework.max_efficiency == 0 ? 0 : student_work.efficiency / homework.max_efficiency * homework.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
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
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
if work.work_status == 0
@ -200,7 +200,7 @@ class HomeworksService
# 如果作业的最大效率值有变更则更新所有作品的效率分
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

@ -6,7 +6,7 @@ class ExercisePublishTask
Rails.logger.info("log--------------------------------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.each do |exercise|
exercises&.each do |exercise|
exercise.update_column('exercise_status', 2)
course = exercise.course
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')}')"
end
if exercise.unified_setting
course.student.find_each do |student|
course.students.find_each do |student|
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
if tid_str != ""
@ -25,7 +25,7 @@ class ExercisePublishTask
ActiveRecord::Base.connection.execute tid_sql
end
if exercise.exercise_users.count == 0
if exercise.exercise_users.size == 0
str = ""
course.students.find_each do |student|
str += "," if str != ""
@ -44,8 +44,8 @@ class ExercisePublishTask
end
# 分组设置发布时间的测验
exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 1800, Time.now - 1800)
exercise_group_settings.each do |exercise_group|
exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 900, Time.now - 900)
exercise_group_settings&.each do |exercise_group|
exercise = exercise_group.exercise
if exercise.present?
course = exercise.course
@ -71,29 +71,35 @@ class ExercisePublishTask
puts "--------------------------------exercise_end start"
# 1。统一设置的试卷
exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900)
exercises.each do |exercise|
exercises&.each do |exercise|
ex_type = exercise.exercise_questions.pluck(:question_type).uniq
exercise.update_column('exercise_status', 3)
exercise.exercise_users.each do |exercise_user|
if exercise_user.commit_status == 0 && exercise_user.start_at.present?
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
if ex_type.include?(4) #是否包含主观题
subjective_score = exercise_user.subjective_score
else
subjective_score = -1.0
exercise.exercise_users&.each do |exercise_user|
begin
if (exercise_user&.commit_status == 0) && (exercise_user&.start_at.present?)
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
if ex_type.include?(4) #是否包含主观题
subjective_score = exercise_user.subjective_score
else
subjective_score = -1.0
end
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score
}
exercise_user.update_attributes(commit_option)
end
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score
}
exercise_user.update_attributes(commit_option)
rescue Exception => e
Rails.logger.info("rescue errors ___________________________#{e}")
next
end
end
end
@ -101,36 +107,41 @@ 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)
exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")"
ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}")
ex_group_settings.each do |exercise_setting|
ex_group_settings&.each do |exercise_setting|
exercise = exercise_setting.exercise
if exercise&.end_time <= Time.now
if exercise.end_time <= Time.now
exercise.update_column('exercise_status', 3)
end
ex_types = exercise.exercise_questions.pluck(:question_type).uniq
users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id)
exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id))
exercise_users.each do |exercise_user|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
if ex_types.include?(4) #是否包含主观题
subjective_score = exercise_user.subjective_score
else
subjective_score = -1.0
exercise_users&.each do |exercise_user|
begin
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
if ex_types.include?(4) #是否包含主观题
subjective_score = exercise_user.subjective_score
else
subjective_score = -1.0
end
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score
}
exercise_user.update_attributes(commit_option)
end
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score
}
exercise_user.update_attributes(commit_option)
rescue Exception => e
Rails.logger.info("unified_setting_false_rescue errors ___________________________#{e}")
next
end
end
end
Rails.logger.info("log--------------------------------exercise_end end")

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

@ -249,8 +249,8 @@
<tbody>
<% if @games.size > 0 %>
<% @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) %>
<% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.first&.id,user_id: @ex_user_user.id) %>
<tr>
<td><%= index + 1 %></td>
<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_)
json.extract! exercise, :id, :exercise_name,:is_public,:created_at
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
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.student_id work.user.student_id
json.class_grouping_name work.class_grouping_name
json.ultimate_score work.ultimate_score
if @task.have_grouping?
json.grouping_name work.grouping_name
if @task.base_on_project
@ -51,7 +52,11 @@ if @task.published? || @user_course_identity < Course::STUDENT
json.status work.work_status
json.update_time format_time work.update_time
json.teacher_comment_score work.teacher_comment_score(@current_user, @user_course_identity)
json.cross_comment_score work.cross_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_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.assign work.assign_power?(@user_course_identity)
end

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

@ -2,10 +2,6 @@ json.course_identity @user_course_identity
json.homework_type @homework_type
json.course_public @course.is_public == 1
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_name @main_category.try(:module_name)
json.category_id @category.try(:id)
@ -23,8 +19,8 @@ json.homeworks @homework_commons.each do |homework|
json.allow_late homework.allow_late
unless curr_status[:status].include?("未发布")
json.commit_count studentwork_count homework, 1, @user.id
json.uncommit_count studentwork_count homework, 0, @user.id
json.commit_count studentwork_count homework, 1, @member
json.uncommit_count studentwork_count homework, 0, @member
end
if @user_course_identity < Course::STUDENT
@ -46,3 +42,8 @@ json.homeworks @homework_commons.each do |homework|
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"
json.teacher_comment teacher_comment @homework, @current_user.id
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
elsif @user_course_identity == Course::STUDENT
json.commit_count studentwork_count @homework, 1, @current_user.id
json.uncommit_count studentwork_count @homework, 0, @current_user.id
json.commit_count studentwork_count @homework, 1, @member
json.uncommit_count studentwork_count @homework, 0, @member
json.left_time left_time @homework, @current_user.id
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.student_works @student_works.each do |work|
if @is_evaluation
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_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
json.(work, :id, :work_status, :update_time, :work_score, :final_score, :teacher_score, :student_score,
:teaching_asistant_score, :ultimate_score)
@ -135,13 +140,13 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
end
json.work_group work.work_group_name
end
end
# 申诉条数
if @homework.anonymous_appeal
json.appeal_all_count work.appeal_all_count
json.appeal_deal_count work.appeal_deal_count
json.appeal_penalty work.appeal_penalty
# 申诉条数
if @homework.anonymous_appeal
json.appeal_all_count work.appeal_all_count
json.appeal_deal_count work.appeal_deal_count
json.appeal_penalty work.appeal_penalty
end
end
json.user_login @is_evaluation ? "--" : work.user.try(:login)

@ -1,6 +1,6 @@
json.partial! "commons/success"
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.total_count @messages.total_count
json.total_replies_count @message.total_replies_count

@ -1,16 +1,14 @@
wb = xlsx_package.workbook
wb.use_autowidth = false
# wb.use_autowidth = false
wb.styles do |s|
sz_all = s.add_style :sz => 10,: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 => {: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 => {wrap_text: true,:horizontal => :left}
wb.add_worksheet(:name => "统计结果") do |sheet|
sheet.sheet_view.show_grid_lines = false
poll_users_info = %w(序号)
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
if poll_un_anony #是否匿名默认为false
user_info = %w(登陆名 真实姓名 邮箱 学号)
@ -32,25 +30,25 @@ wb.styles do |s|
sheet_answer_row.push(answer_users_count)
sheet_answer_percent.push(answer_percent.to_s)
end
sheet.add_row sheet_row, :style => blue_cell
sheet.add_row sheet_answer_row, :style => sz_all
sheet.add_row sheet_answer_percent, :style => sz_all
sheet.add_row sheet_answer_useful, :style => sz_all
sheet.add_row sheet_row, :height =>15,:style => blue_cell
sheet.add_row sheet_answer_row, :height =>15, :style => sz_all
sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all
sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all
#合并单元格但无法填充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.rows[sheet.rows.last.row_index].style = sz_all
sheet.add_row []
else #主观题答案
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| #主观题的答案
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
sheet.add_row [], :style => sz_all
end
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|
u_user = u.user
user_answer_array = []
@ -88,7 +86,7 @@ wb.styles do |s|
user_cell += [user_login,user_name, u_user.mail, user_student_id]
end
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
sheet.column_widths *([25]*sheet.column_info.count)
sheet.column_info.first.width = 10

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

@ -1,7 +1,8 @@
if @fuzzy_searchs
json.keyword @fuzzy_searchs
json.total_count @fuzzy_searchs.blank? ? nil : @total_count
end
# if @fuzzy_searchs
# json.keyword @fuzzy_searchs
# json.total_count @fuzzy_searchs.blank? ? nil : @total_count
# end
json.total_count @total_count
json.pagination @total_count > 16 ? true : false
json.search_tags @search_tags
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.passed_time @myshixun.passed_time
json.total_spend_time @myshixun.total_spend_time
json.user_score @myshixun.total_score
# 关卡完成情况
index = 1

@ -1,6 +1,6 @@
PDFKit.configure do |config|
# config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf'
config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf'
config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf'
# config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf'
config.default_options = {
encoding: "UTF-8",
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
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|
if exercise.tidings.where(:parent_container_type => "NearlyEnd").count == 0
if exercise.tidings.where(parent_container_type: "NearlyEnd").count == 0
course = exercise.course
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 += "(#{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
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
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 = exercise_group.exercise
if exercise.present?
course = exercise.course
members = course.course_members.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
members = course.students.where(course_group_id: exercise_group.course_group_id)
if exercise.tidings.where(parent_container_type: "NearlyEnd", user_id: members.pluck(:user_id)).count == 0
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 += "(#{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
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
end
end

@ -30,7 +30,7 @@ namespace :graduation_task do
end
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|
if task.tidings.where(parent_container_type: "NearlyEnd").count == 0
course = task.course

@ -4,7 +4,7 @@ namespace :homework_endtime do
desc "send a message for Job deadline"
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|
if homework.tidings.where(:parent_container_type => "NearlyEnd").count == 0
course = homework.course
@ -25,7 +25,7 @@ namespace :homework_endtime do
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 = homework_group.homework_common
if homework.present?
@ -52,8 +52,8 @@ namespace :homework_endtime do
# 匿评截止时间快到了
task :evaluation_nearly_end => :environment do
homework_detail_manuals = HomeworkDetailManual.where("homework_detail_manuals.comment_status = 3 and evaluation_end <=?
and evaluation_end > ? ", Time.now + 86400, Time.now + 82800)
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 + 84600)
homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common
if homework_common.present?
@ -85,7 +85,7 @@ namespace :homework_endtime do
# 匿评申诉截止时间快到了
task :appeal_nearly_end => :environment do
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_common = homework_detail_manual.homework_common
if homework_common.present?

@ -12,7 +12,7 @@ namespace :homework_evaluation do
task :start_evaluation => :environment do
Rails.logger.info("log--------------------------------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.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common
@ -110,7 +110,7 @@ namespace :homework_evaluation 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_common = homework_detail_manual.homework_common
if homework_common.anonymous_comment #开启匿评状态才可关闭匿评

@ -6,8 +6,8 @@ namespace :homework_publishtime do
# 作业的分班设置时间
def homework_group_setting homework, group_id
setting = nil
if homework.homework_group_settings.where(:course_group_id => group_id).first
setting = 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
else
setting = homework
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.each do |poll|
poll.update_column('polls_status', 3)
poll.poll_users.each do |poll_user|
if poll_user.commit_status == 0 && poll_user.start_at.present?
poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
end
end
poll.poll_users.where("commit_status = 0 and start_at is not null").update_all(commit_status: 1, end_at: Time.now)
end
#2.分班设置的截止
@ -132,13 +128,13 @@ namespace :poll_publish do
if poll&.end_time <= Time.now
poll.update_column('polls_status', 3)
end
users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id)
poll_users = poll.poll_users.where(:user_id => users.map(&:user_id))
poll_users.each do |poll_user|
if poll_user.commit_status == 0 && !poll_user.start_at.nil?
poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
end
end
users = poll.course.course_members.where(course_group_id: poll_setting.course_group_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|
# if poll_user.commit_status == 0 && !poll_user.start_at.nil?
# poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
# end
# end
end
# 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
Rails.logger.info("log--------------------------------resource_publish start")
attachments = Attachment.where("publish_time < '#{Time.now}' and is_publish = 0")
attachments.each do |attachment|
attachment.update_attributes(:is_publish => 1)
end
attachments.update_all(is_publish: 1)
Rails.logger.info("log--------------------------------resource_publish end")
end
end
Loading…
Cancel
Save