dev_course
SylorHuang 6 years ago
parent 2f5d7ca451
commit 88c1d7c48a

@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
include RenderExpand include RenderExpand
include RenderHelper include RenderHelper
include ControllerRescueHandler include ControllerRescueHandler
include GitHelper
include LoggerHelper
protect_from_forgery prepend: true, unless: -> { request.format.json? } protect_from_forgery prepend: true, unless: -> { request.format.json? }
@ -202,55 +204,6 @@ class ApplicationController < ActionController::Base
# end # end
end end
# 版本库目录空间
def repo_namespace(user_login, shixun_identifier)
"#{user_login}/#{shixun_identifier}.git"
end
# 版本库文件内容,带转码
def git_fle_content(repo_path, path)
begin
content = GitService.file_content(repo_path: repo_path, path: path)["content"]
logger.info("@@@@@@@@@@@@@@@@@@#{content}")
decode_content = nil
if content.present?
content = Base64.decode64(content)
cd = CharDet.detect(content)
logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}"
decode_content =
if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8
content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '})
else
content.force_encoding('UTF-8')
end
end
decode_content
rescue Exception => e
uid_logger_error(e.message)
raise Educoder::TipException.new("文档内容获取异常")
end
end
# 更新文件代码
# content 文件内容message提交描述
def update_file_content(content, repo_path, path, mail, username, message)
GitService.update_file(repo_path: repo_path, file_path: path, message: message,
content: content, author_name: username, author_email: mail)
end
# 版本库Fork功能
def project_fork(container, original_rep_path, username)
raise Educoder::TipException.new("fork源路径为空,fork失败!") if original_rep_path.blank?
# 将要生成的仓库名字
new_repo_name = "#{username}/#{container.try(:identifier)}#{ Time.now.strftime("%Y%m%d%H%M%S")}"
uid_logger("start fork container: repo_name is #{new_repo_name}")
GitService.fork_repository(repo_path: original_rep_path, fork_repository_path: (new_repo_name + ".git"))
container.update_attributes!(:repo_name => new_repo_name)
end
def start_user_session(user) def start_user_session(user)
session[:user_id] = user.id session[:user_id] = user.id
session[:ctime] = Time.now.utc.to_i session[:ctime] = Time.now.utc.to_i
@ -330,16 +283,6 @@ class ApplicationController < ActionController::Base
end end
end end
# 以用户id开始的日志定义
def uid_logger(message)
Rails.logger.info("##:#{current_user.try(:id)} --#{message}")
end
# 以用户id开始的日志定义
def uid_logger_error(message)
Rails.logger.error("##:#{current_user.try(:id)} --#{message}")
end
## 输出错误信息 ## 输出错误信息
def error_status(message = nil) def error_status(message = nil)
@status = -1 @status = -1

@ -0,0 +1,52 @@
module GitHelper
extend ActiveSupport::Concern
# 版本库目录空间
def repo_namespace(user_login, shixun_identifier)
"#{user_login}/#{shixun_identifier}.git"
end
# 版本库文件内容,带转码
def git_fle_content(repo_path, path)
begin
content = GitService.file_content(repo_path: repo_path, path: path)["content"]
logger.info("@@@@@@@@@@@@@@@@@@#{content}")
decode_content = nil
if content.present?
content = Base64.decode64(content)
cd = CharDet.detect(content)
logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}"
decode_content =
if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8
content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '})
else
content.force_encoding('UTF-8')
end
end
decode_content
rescue Exception => e
uid_logger_error(e.message)
raise Educoder::TipException.new("文档内容获取异常")
end
end
# 更新文件代码
# content 文件内容message提交描述
def update_file_content(content, repo_path, path, mail, username, message)
GitService.update_file(repo_path: repo_path, file_path: path, message: message,
content: content, author_name: username, author_email: mail)
end
# 版本库Fork功能
def project_fork(container, original_rep_path, username)
raise Educoder::TipException.new("fork源路径为空,fork失败!") if original_rep_path.blank?
# 将要生成的仓库名字
new_repo_name = "#{username}/#{container.try(:identifier)}#{ Time.now.strftime("%Y%m%d%H%M%S")}"
uid_logger("start fork container: repo_name is #{new_repo_name}")
GitService.fork_repository(repo_path: original_rep_path, fork_repository_path: (new_repo_name + ".git"))
container.update_attributes!(:repo_name => new_repo_name)
end
end

@ -0,0 +1,16 @@
module LoggerHelper
extend ActiveSupport::Concern
extend LoggerHelper
# 以用户id开始的日志定义
def uid_logger(message)
Rails.logger.info("##:#{current_user.try(:id)} --#{message}")
end
# 以用户id开始的日志定义
def uid_logger_error(message)
Rails.logger.error("##:#{current_user.try(:id)} --#{message}")
end
end

@ -0,0 +1,111 @@
class ExercisePublishTask
include ExercisesHelper
include GitHelper
def publish
Rails.logger.info("log--------------------------------exercise_publish start")
puts "--------------------------------exercise_publish start"
exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
exercises.each do |exercise|
exercise.update_column('exercise_status', 2)
course = exercise.course
tid_str = ""
course.teachers.find_each do |member|
tid_str += "," if tid_str != ""
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|
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')}')"
end
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
ActiveRecord::Base.connection.execute tid_sql
end
if exercise.exercise_users.count == 0
str = ""
course.students.find_each do |student|
str += "," if str != ""
str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if str != ""
sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str
ActiveRecord::Base.connection.execute sql
end
end
if exercise.course_acts.size == 0
exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id)
end
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 = exercise_group.exercise
if exercise.present?
course = exercise.course
exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1
tid_str = ""
members = course.students.where(:course_group_id => exercise_group.course_group_id)
members.find_each do |member|
tid_str += "," if tid_str != ""
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 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
Rails.logger.info("log--------------------------------exercise_publish end")
puts "--------------------------------exercise_publish end"
end
def end
exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now)
exercises.each do |exercise|
course = exercise.course
exercise.update_column('exercise_status', 3)
exercise.exercise_users.each do |exercise_user|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0)))
if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
exercise_user.update_attributes(:subjective_score => 0)
end
end
end
end
all_exercises = Exercise.where("end_time > ? and exercise_status = 2",Time.now)
exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")"
ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}").each do |exercise_setting|
exercise = exercise_setting.exercise
users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id)
exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id))
exercise_users.each do |exercise_user|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0)))
if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
exercise_user.update_attributes(:subjective_score => 0)
end
end
end
end
Rails.logger.info("log--------------------------------exercise_end completed")
end
end

@ -1,31 +1,31 @@
#coding=utf-8 # #coding=utf-8
#
namespace :exercise_publish do # namespace :exercise_publish do
desc "publish exercise and end exercise" # desc "publish exercise and end exercise"
def get_mulscore(question, user) # def get_mulscore(question, user)
ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id)
arr = [] # arr = []
ecs.each do |ec| # ecs.each do |ec|
arr << ec.exercise_choice.choice_position # arr << ec.exercise_choice.choice_position
end # end
#arr = arr.sort # #arr = arr.sort
str = arr.sort.join("") # str = arr.sort.join("")
return str # return str
end # end
#
def tran_base64_decode64 str # def tran_base64_decode64 str
if str.blank? # if str.blank?
str # str
else # else
s_size = str.size % 4 # s_size = str.size % 4
if s_size != 0 # if s_size != 0
str += "=" * (4 - s_size) # str += "=" * (4 - s_size)
end # end
Base64.decode64(str.tr("-_", "+/")).force_encoding("utf-8") # Base64.decode64(str.tr("-_", "+/")).force_encoding("utf-8")
end # end
end # end
#
#计算试卷的总分和试卷的答题状态 # #计算试卷的总分和试卷的答题状态
# def calculate_student_score(exercise,user) # def calculate_student_score(exercise,user)
# score1 = 0.0 #选择题/判断题 # score1 = 0.0 #选择题/判断题
# score2 = 0.0 #填空题 # score2 = 0.0 #填空题
@ -89,7 +89,7 @@ namespace :exercise_publish do
# if game.present? # if game.present?
# exercise_cha_score = 0 # exercise_cha_score = 0
# answer_status = 0 # answer_status = 0
# cha_path = challenge_path exercise_cha.challenge.path # cha_path = exercise_cha.challenge.path.present? ? exercise_cha.challenge.path.split("").reject(&:blank?) : []
# if game.status == 2 && game.final_score >= 0 # if game.status == 2 && game.final_score >= 0
# exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分 # exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分
# answer_status = 1 # answer_status = 1
@ -100,6 +100,24 @@ namespace :exercise_publish do
# game_code = game_challenge # game_code = game_challenge
# code = game_code.try(:new_code) # code = game_code.try(:new_code)
# else # else
# begin
# content = GitService.file_content(repo_path: exercise_cha.shixun.repo_path, path: cha_path)["content"]
# decode_content = nil
# if content.present?
# content = Base64.decode64(content)
# cd = CharDet.detect(content)
# decode_content =
# if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8
# content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '})
# else
# content.force_encoding('UTF-8')
# end
# end
# decode_content
# rescue Exception => e
# uid_logger_error(e.message)
# raise Educoder::TipException.new("文档内容获取异常")
# end
# code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) # code = git_fle_content(exercise_cha.shixun.repo_path,cha_path)
# end # end
# sx_option = { # sx_option = {
@ -138,113 +156,113 @@ namespace :exercise_publish do
# "stand_status":ques_stand # "stand_status":ques_stand
# } # }
# end # end
#
task :publish => :environment do # task :publish => :environment do
Rails.logger.info("log--------------------------------exercise_publish start") # Rails.logger.info("log--------------------------------exercise_publish start")
puts "--------------------------------exercise_publish start" # puts "--------------------------------exercise_publish start"
exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) # exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
exercises.each do |exercise| # exercises.each do |exercise|
exercise.update_column('exercise_status', 2) # exercise.update_column('exercise_status', 2)
course = exercise.course # course = exercise.course
tid_str = "" # tid_str = ""
course.teachers.find_each do |member| # course.teachers.find_each do |member|
tid_str += "," if tid_str != "" # tid_str += "," if tid_str != ""
tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" # tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end # end
if exercise.unified_setting # if exercise.unified_setting
course.student.find_each do |student| # course.student.find_each do |student|
tid_str += "," if tid_str != "" # tid_str += "," if tid_str != ""
tid_str += "(#{student.student_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" # tid_str += "(#{student.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')}')"
end # end
end # end
if tid_str != "" # if tid_str != ""
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str # tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
ActiveRecord::Base.connection.execute tid_sql # ActiveRecord::Base.connection.execute tid_sql
end # end
#
if exercise.exercise_users.count == 0 # if exercise.exercise_users.count == 0
str = "" # str = ""
course.student.find_each do |student| # course.student.find_each do |student|
str += "," if str != "" # str += "," if str != ""
str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" # str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end # end
#
if str != "" # if str != ""
sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str # sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str
ActiveRecord::Base.connection.execute sql # ActiveRecord::Base.connection.execute sql
end # end
end # end
#
if exercise.course_acts.size == 0 # if exercise.course_acts.size == 0
exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) # exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id)
end # end
end # end
#
# 分组设置发布时间的测验 # # 分组设置发布时间的测验
exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 1800, Time.now - 1800) # exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 1800, Time.now - 1800)
exercise_group_settings.each do |exercise_group| # exercise_group_settings.each do |exercise_group|
exercise = exercise_group.exercise # exercise = exercise_group.exercise
if exercise.present? # if exercise.present?
course = exercise.course # course = exercise.course
exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1 # exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1
tid_str = "" # tid_str = ""
members = course.students.where(:course_group_id => exercise_group.course_group_id) # members = course.students.where(:course_group_id => exercise_group.course_group_id)
members.find_each do |member| # members.find_each do |member|
tid_str += "," if tid_str != "" # tid_str += "," if tid_str != ""
tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" # tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end # end
if tid_str != "" # if tid_str != ""
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str # tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
ActiveRecord::Base.connection.execute tid_sql # ActiveRecord::Base.connection.execute tid_sql
end # end
end # end
end # end
Rails.logger.info("log--------------------------------exercise_publish end") # Rails.logger.info("log--------------------------------exercise_publish end")
puts "--------------------------------exercise_publish end" # puts "--------------------------------exercise_publish end"
end # end
#
task :end => :environment do # task :end => :environment do
# include ExercisesHelper # # include ExercisesHelper
# include ApplicationController # # include ApplicationController
#
exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) # exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now)
exercises.each do |exercise| # exercises.each do |exercise|
course = exercise.course # course = exercise.course
exercise.update_column('exercise_status', 3) # exercise.update_column('exercise_status', 3)
#
exercise.exercise_users.each do |exercise_user| # exercise.exercise_users.each do |exercise_user|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? # if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
#
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] # s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) # exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0)))
if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
exercise_user.update_attributes(:subjective_score => 0) # exercise_user.update_attributes(:subjective_score => 0)
end # end
end # end
end # end
end # end
#
all_exercises = Exercise.where("end_time > ? and exercise_status = 2",Time.now) # all_exercises = Exercise.where("end_time > ? and exercise_status = 2",Time.now)
exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" # exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")"
ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}").each do |exercise_setting| # ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}").each do |exercise_setting|
exercise = exercise_setting.exercise # exercise = exercise_setting.exercise
#
users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) # users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id)
exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id)) # exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id))
#
exercise_users.each do |exercise_user| # exercise_users.each do |exercise_user|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? # if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
#
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] # s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) # exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0)))
if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
exercise_user.update_attributes(:subjective_score => 0) # exercise_user.update_attributes(:subjective_score => 0)
end # end
end # end
end # end
end # end
Rails.logger.info("log--------------------------------exercise_end completed") # Rails.logger.info("log--------------------------------exercise_end completed")
end # end
end # end

Loading…
Cancel
Save