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

issues25489
杨树林 5 years ago
commit 5dbe17e1d0

@ -107,7 +107,7 @@ class ExerciseAnswersController < ApplicationController
normal_status(-1,"已提交/已结束的试卷不允许修改!")
else
if (@exercise_user_status == Exercise::DEADLINE && @exercise_user.commit_status == 0) || (@exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + @exercise.time.to_i.minutes) < Time.now))
objective_score = calculate_student_score(@exercise,current_user)[:total_score]
objective_score = calculate_student_score(@exercise,current_user,Time.now)[:total_score]
subjective_score = @exercise_user.subjective_score < 0.0 ? 0.0 : @exercise_user.subjective_score
total_score = objective_score + subjective_score
commit_option = {

@ -886,7 +886,7 @@ class ExercisesController < ApplicationController
ex_user_ids = exercise_users.pluck(:id)
EndExerciseCalculateJob.perform_later(ex_user_ids,exercise)
EndExerciseCalculateJob.perform_later(ex_user_ids,exercise,Time.now)
# exercise_users.each do |user|
# if user.commit_status == 0 && user.start_at.present?
# objective_score = calculate_student_score(exercise,user.user)[:total_score]
@ -1019,7 +1019,6 @@ class ExercisesController < ApplicationController
#学生开始答题页面
def start_answer
ActiveRecord::Base.transaction do
begin
ex_users_current = ExerciseUser.where(user_id:@exercise_current_user_id,exercise_id:@exercise.id) #不能用@exercise.exercise_users因为exercise_users删除时只是状态改变未删除
@exercise_user_current = ex_users_current&.first
@ -1073,7 +1072,6 @@ class ExercisesController < ApplicationController
raise ActiveRecord::Rollback
end
end
end
#提交试卷前的弹窗
def begin_commit
@ -1125,6 +1123,7 @@ class ExercisesController < ApplicationController
# 学生提交试卷
def commit_exercise
tip_exception(-1, "试卷已提交") if @answer_committed_user.commit_status == 1
ActiveRecord::Base.transaction do
begin
can_commit_exercise = false
@ -1140,7 +1139,7 @@ class ExercisesController < ApplicationController
can_commit_exercise = true
end
if can_commit_exercise
objective_score = calculate_student_score(@exercise,current_user)[:total_score]
objective_score = calculate_student_score(@exercise,current_user,Time.now)[:total_score]
subjective_score = @answer_committed_user.subjective_score
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = objective_score + total_score_subjective_score
@ -1204,7 +1203,6 @@ class ExercisesController < ApplicationController
#答题列表
def exercise_lists
ActiveRecord::Base.transaction do
begin
@current_user_id = current_user.id
exercise_ids = [@exercise.id]
@ -1354,7 +1352,6 @@ class ExercisesController < ApplicationController
raise ActiveRecord::Rollback
end
end
end
#导出空白试卷
def export_exercise
@ -1391,7 +1388,6 @@ class ExercisesController < ApplicationController
#学生的统计结果
def exercise_result
ActiveRecord::Base.transaction do
begin
exercise_ids = [@exercise.id]
@exercise_publish_count = get_user_permission_course(exercise_ids,Exercise::PUBLISHED).size #判断是否有已发布的分班
@ -1487,7 +1483,6 @@ class ExercisesController < ApplicationController
raise ActiveRecord::Rollback
end
end
end
private

@ -125,6 +125,9 @@ class MessagesController < ApplicationController
@message.message_detail_attributes = {content: params[:content]}
@message.save!
Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name)
if @board.course.email_notify && params[:email_notify]
notify_course_students @message, @board.course
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
@ -201,4 +204,10 @@ class MessagesController < ApplicationController
def message_params
params.require(:message).permit(:subject, :sticky)
end
def notify_course_students message, course
course.students.includes(:user).each do |student|
UserMailer.course_message_email(student&.user&.mail, message.id).deliver_now if student&.user&.mail
end
end
end

@ -412,12 +412,13 @@ module ExercisesHelper
end
#计算试卷的总分和试卷的答题状态
def calculate_student_score(exercise,user)
def calculate_student_score(exercise,user,end_time)
score1 = 0.0 #选择题/判断题
score2 = 0.0 #填空题
score5 = 0.0 #实训题
ques_stand = [] #问题是否正确
exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges)
exercise_end_time = end_time || Time.now
exercise_questions = exercise.exercise_questions.includes(:exercise_standard_answers,:exercise_shixun_challenges)
exercise_questions&.each do |q|
begin
if q.question_type != 5
@ -505,7 +506,7 @@ module ExercisesHelper
exercise_cha_score = 0.0
answer_status = 0
# if game.status == 2 && game.final_score >= 0
if game.final_score > 0
if game.final_score > 0 && game.end_time && game.end_time < exercise_end_time
exercise_cha_score = game.real_score(exercise_cha.question_score)
# exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 1

@ -5,11 +5,11 @@ class EndExerciseCalculateJob < ApplicationJob
queue_as :default
def perform(ex_user_ids,exercise)
def perform(ex_user_ids,exercise,end_time)
exercise_users = ExerciseUser.where(id: ex_user_ids)
exercise_users.each do |user|
if user.commit_status == 0 && user.start_at.present?
objective_score = calculate_student_score(exercise,user.user)[:total_score]
objective_score = calculate_student_score(exercise,user.user,end_time)[:total_score]
user_sub_score = user.subjective_score
subjective_score = user_sub_score < 0.0 ? 0.0 : user_sub_score
total_score = objective_score + subjective_score

@ -7,4 +7,11 @@ class UserMailer < ApplicationMailer
@code = code
mail(to: mail, subject: '验证你的电子邮件')
end
# 课堂讨论区的邮件通知
def course_message_email(mail, message_id)
@message = Message.find_by(id: message_id)
@course = @message&.board&.course
mail(to: mail, subject: '课堂通知') if @message.present? && @course.present?
end
end

@ -376,7 +376,7 @@ class Course < ApplicationRecord
case type
when 'activity' then '动态'
when 'announcement' then '公告栏'
when 'online_learning' then '在线学习'
when 'online_learning' then '课程学习'
when 'shixun_homework' then '实训作业'
when 'common_homework' then '普通作业'
when 'group_homework' then '分组作业'

@ -70,7 +70,7 @@ class Exercise < ApplicationRecord
if unified_setting
self&.end_time
else
user_course_group = course.course_members.find_by(user_id: user_id)&.course_group_id
user_course_group = course.students.find_by(user_id: user_id)&.course_group_id
exercise_group_settings.find_by(course_group_id:user_course_group)&.end_time
end
end

@ -41,20 +41,21 @@ class ExercisePublishTask
puts "--------------------------------exercise_publish end"
end
def end
Rails.logger.info("log--------------------------------exercise_end start")
puts "--------------------------------exercise_end start"
# 1。统一设置的试卷
exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND
unified_setting = true AND end_time <= ?",Time.now + 900)
exercises&.each do |exercise|
exercises = Exercise.includes(:exercise_questions).where("exercise_status = 2 AND end_time <= ?",Time.now + 900)
exercises.each do |exercise|
Rails.logger.info("end_exercise_id: #{exercise.id}")
exercise.update_attributes!('exercise_status', 3)
if exercise.unified_setting
ex_type = exercise.exercise_questions.pluck(:question_type).uniq
exercise.update_column('exercise_status', 3)
exercise.exercise_users&.each do |exercise_user|
exercise.exercise_users.where("commit_status = 0 and start_at is not null").each do |exercise_user|
begin
Rails.logger.info("true: user_id:#{exercise_user.user_id}--commit_status:#{exercise_user.commit_status}")
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, exercise.end_time)[:total_score]
if ex_type.include?(4) #是否包含主观题
subjective_score = exercise_user.subjective_score
else
@ -68,45 +69,37 @@ class ExercisePublishTask
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:end_at => exercise.end_time,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score,
:commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3
}
exercise_user.update_attributes(commit_option)
end
rescue Exception => e
Rails.logger.info("rescue errors ___________________________#{e}")
next
end
end
end
end
# 2.非统一的试卷
all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900)
exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")"
ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}")
ex_group_settings&.each do |exercise_setting|
ExerciseGroupSetting.where("end_time < ? and end_time > ?", Time.now + 900, Time.now - 900).each do |exercise_setting|
exercise = exercise_setting.exercise
if exercise.end_time <= Time.now
exercise.update_column('exercise_status', 3)
end
Rails.logger.info("exercise_group_setting: exercise_id:#{exercise.id}--group_settings_id:#{exercise_setting.id}")
users = exercise.course.course_members.where(:course_group_id => exercise_setting.course_group_id)
exercise_users = exercise.exercise_users.where(user_id: users.pluck(:user_id)).where("commit_status = 0 and start_at is not null")
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|
begin
exercise_users.each do |exercise_user|
Rails.logger.info("false: user_id:#{exercise_user.user_id}--commit_status:#{exercise_user.commit_status}")
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
begin
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]
s_score = calculate_student_score(exercise, exercise_user.user, exercise_setting.end_time)[:total_score]
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = s_score + total_score_subjective_score
Rails.logger.info("false: user_id:#{exercise_user.user_id}--s_score:#{s_score}")
@ -115,23 +108,20 @@ class ExercisePublishTask
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:end_at => exercise_setting.end_time,
:objective_score => s_score,
:score => total_score,
:subjective_score => subjective_score,
:commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3
}
exercise_user.update_attributes(commit_option)
end
rescue Exception => e
Rails.logger.info("unified_setting_false_rescue errors ___________________________#{e}")
next
end
end
end
Rails.logger.info("log--------------------------------exercise_end end")
puts "--------------------------------exercise_end end"
end
end

@ -3,7 +3,7 @@ json.author do
end
json.id message.id
json.content message.contents_show(identity)
json.content content_safe(message.contents_show(identity))
json.time time_from_now(message.created_at)
json.hidden message.hidden
# 主贴与子贴不一致

@ -0,0 +1,62 @@
<html>
<head>
<meta charset="utf-8">
<title><%= @course.name %>通知</title>
<style type="text/css">
/* 验证链接页面 */
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{ margin:0; padding:0;}
body,table,input,textarea,select,button { font-family: "微软雅黑","宋体"; font-size:12px;line-height:1.5; background:#eaebec;}
div,img,tr,td,table{ border:0;}
table,tr,td{border:0;}
ol,ul,li{ list-style-type:none}
.new_content{ background:#fff; width: 100%;}
.email-page-link{ }
.email-link-top{ }
.c_white{ color:#fff;}
.email-link-con{ }
.email-link-line{ }
.email-link-footer{ padding:15px; color:#333; line-height: 1.9; }
.c_grey02{ color: #888;}
.fb{ font-weight: normal;}
.f14{ }
</style>
</head>
<body style="background:#fff;">
<div class="new_content">
<div style="width: 598px; background:#fff; margin:20px auto; font-size:14px; ">
<div style="height:50px; width: 578px; background:#46484c; padding:9px 10px 6px;border:1px solid #ddd; border-bottom:none;">
<a href="https://www.educoder.net">
<img src="https://www.educoder.net/images/educoder/headNavLogo.png" width="36" style="float:left; margin-top: 8px;" >
</a>
<div style="clear:both; overflow:hidden;"></div>
</div>
<div style="width: 558px; border-left:1px solid #ddd;border-right:1px solid #ddd; background:#fff; padding:30px 20px; color:#333; line-height: 1.9;">
<p style="color:#333; font-size:16px; margin-bottom:15px;font-weight: bold">
您好!
</p>
<p style="color:#333;">
您正在注册Educoder请在10分钟内在注册页输入此验证码并进行下一步操作。
如非你本人操作,请忽略此邮件。
</p>
<div style="text-align: center;">
<div style="display:block; height: 45px; line-height:45px;padding:0 30px; width:100px; font-size: 20px; font-weight: bold; background:#ffd9d9; color:#e72c37; margin:30px auto;">
<p><%= @code %></p>
</div>
<span style="font-weight: normal;color:#666;">
此邮件为系统所发,请勿直接回复。<br/>
要解决问题或了解您的帐户详情,您可以访问 <a href="https://www.educoder.net/help?index=5" style="font-weight: normal; color:#ff7500;">帮助中心</a>。
</span>
</div>
<p style="color:#666; margin-top:30px;">
如果您并未发过此请求,则可能是因为其他用户在注册时误输了您的邮件地址,而使您收到了这封邮件,那么您可以放心的忽略此邮件,无需进一步采取任何操作。
</p>
</div>
<div style="padding:20px; color:#333; line-height: 1.9;background:#46484c;border:1px solid #ddd; border-top:none; width: 558px;">
<a href="https:///www.educoder.net/" style="font-weight: normal; color:#fff;">www.educoder.net</a>
</div>
</div>
</div>
</body>
</html>

@ -0,0 +1,5 @@
class AddEmailNotifyToCourse < ActiveRecord::Migration[5.2]
def change
add_column :courses, :email_notify, :boolean, default: 0
end
end

@ -0,0 +1,60 @@
class Migrate2796ExerciseScore < ActiveRecord::Migration[5.2]
def calculate_student_score(exercise,user)
score1 = 0.0 #实训题
exercise_questions = exercise.exercise_questions.includes(:exercise_standard_answers)
exercise_questions.each do |q|
answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案
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 #该问题的标准答案,可能有多个
#TODO: 旧版多选题的标准答案是放在一个里面的新版又做成了一个题有多个标准答案exercise_choice_id存放的是标准答案的位置..
if q.question_type == 1 && standard_answer.size == 1
standard_answer = standard_answer.first.to_s.split("").map(&:to_i).sort
end
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
if standard_answer.size > 0
q_score_1 = q.question_score
# 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
else
answers_content.update_all(:score => -1.0)
score1 += 0.0
end
else
score1 += 0.0
end
end
end
score1
end
def change
exercise = Exercise.find_by(id: 2796)
if exercise
exercise_users = exercise.exercise_users.where("start_at is not null and commit_status = 0")
exercise_users.each do |exercise_user|
calculate_score = calculate_student_score(exercise, exercise_user.user)
subjective_score = exercise_user.subjective_score
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = calculate_score + total_score_subjective_score
if exercise_user.end_at.nil?
exercise_user.update_attributes!(score:total_score,objective_score:calculate_score,end_at:exercise.end_time,commit_status:1,status:1,commit_method:3)
else
exercise_user.update_attributes!(score:total_score,objective_score:calculate_score)
end
puts exercise_user.id
end
end
end
end

@ -110,7 +110,7 @@ namespace :poll_publish do
# # 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 + 900, Time.now - 900).each do |poll_setting|
poll = poll_setting.poll
# poll.update_column('polls_status',3)

Loading…
Cancel
Save