|
|
|
@ -1,4 +1,41 @@
|
|
|
|
|
class MigrateExerciseAnswerScore < ActiveRecord::Migration[5.2]
|
|
|
|
|
def challenge_path(path)
|
|
|
|
|
cha_path = path.present? ? path.split(";") : []
|
|
|
|
|
cha_path.reject(&:blank?)[0].try(:strip)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 版本库文件内容,带转码
|
|
|
|
|
def git_fle_content(repo_path, path)
|
|
|
|
|
begin
|
|
|
|
|
Rails.logger.info("git file content: repo_path is #{repo_path}, path is #{path}")
|
|
|
|
|
|
|
|
|
|
content = GitService.file_content(repo_path: repo_path, path: path)
|
|
|
|
|
|
|
|
|
|
Rails.logger.info("git file content: content is #{content}")
|
|
|
|
|
decode_content = nil
|
|
|
|
|
if content.present?
|
|
|
|
|
content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass
|
|
|
|
|
|
|
|
|
|
content = Base64.decode64(content)
|
|
|
|
|
cd = CharDet.detect(content)
|
|
|
|
|
Rails.logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}"
|
|
|
|
|
# 字符编码问题,GB18030编码识别率不行
|
|
|
|
|
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
|
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
|
raise Educoder::TipException.new("文档内容获取异常")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def calculate_student_score(exercise,user)
|
|
|
|
|
score5 = 0.0 #实训题
|
|
|
|
|
exercise_questions = exercise.exercise_questions.includes(:exercise_standard_answers,:exercise_shixun_challenges)
|
|
|
|
|