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

dev_forum
jasder 5 years ago
commit 8e37e69a5b

@ -39,6 +39,8 @@ gem 'pdfkit'
gem 'wkhtmltopdf-binary'
#gem 'iconv'
# markdown 转html
gem 'redcarpet', '~> 3.4'
gem 'rqrcode', '~> 0.10.1'
gem 'rqrcode_png'

@ -193,6 +193,7 @@ GEM
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rchardet (1.8.0)
redcarpet (3.4.0)
redis (4.1.0)
redis-actionpack (5.0.2)
actionpack (>= 4.0, < 6)
@ -328,6 +329,7 @@ DEPENDENCIES
rails (~> 5.2.0)
rails-i18n (~> 5.1)
rchardet (~> 1.8)
redcarpet (~> 3.4)
redis-rails
roo-xls
rqrcode (~> 0.10.1)

@ -427,6 +427,24 @@ class ApplicationController < ActionController::Base
container.to_json
end
# 实训中间层pod配置
def shixun_container_limit shixun
container = []
shixun.shixun_service_configs.each do |config|
mirror = config.mirror_repository
if mirror.name.present?
container << {:image => mirror.name,
:cpuLimit => config.cpu_limit,
:cpuRequest => config.lower_cpu_limit,
:memoryLimit => "#{config.memory_limit}M",
:memoryRequest => "#{config.request_limit}M",
:resourceLimit => "#{config.resource_limit}K",
:type => mirror.try(:main_type) == "1" ? "main" : "sub"}
end
end
container.to_json
end
# 毕设任务列表的赛选
def course_work(task, **option)
logger.info("#############{option}")

@ -138,7 +138,7 @@ class ChallengesController < ApplicationController
# tab 0,nil 过关任务, 1 评测设置, 2 参考答案
def edit
@tab = params[:tab].to_i
@power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0
@power = @shixun.status == 0
challenge_num = Challenge.where(:shixun_id => @shixun).count
@position = @challenge.position
@chooses = @challenge.challenge_chooses
@ -154,14 +154,14 @@ class ChallengesController < ApplicationController
current_myshixun = @shixun.current_myshixun(current_user.id)
@challenges = @shixun.challenges.includes(:games).where("games.user_id" => (current_myshixun ? current_user.id : nil))
@editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0
@editable = @shixun.status == 0 # before_action有判断权限如果没发布则肯定是管理人员
@user = current_user
end
def show
@tab = params[:tab].nil? ? 1 : params[:tab].to_i
challenge_num = Challenge.where(shixun_id: @shixun).count
@power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0
challenge_num = @shixun.challenges_count
@power = @shixun.status == 0 # 之前验证走过了是不是管理员,因此这里只用判断是否发布
@position = @challenge.position
if @position < challenge_num
@next_challenge = Challenge.where(:shixun_id => @shixun, :position => @position + 1).first
@ -279,9 +279,6 @@ class ChallengesController < ApplicationController
def find_shixun
@shixun = Shixun.find_by_identifier(params[:shixun_identifier])
if !current_user.shixun_permission(@shixun)
tip_exception(403, "..")
end
end
# 通用接口
@ -293,7 +290,7 @@ class ChallengesController < ApplicationController
def challenge_params
params.require(:challenge).permit(:subject, :task_pass, :difficulty, :score, :st, :modify_time, :test_set_average,
:path, :exec_path, :show_type, :original_picture_path, :test_set_score,
:expect_picture_path, :picture_path, :web_route, :answer)
:expect_picture_path, :picture_path, :web_route, :answer, :exec_time)
end
def chooce_params

@ -101,7 +101,7 @@ class ExercisesController < ApplicationController
@page = params[:page] || 1
@limit = params[:limit] || 15
@exercises = @exercises.page(@page).per(@limit)
@exercises = @exercises.includes(:exercise_users,:exercise_questions,:exercise_group_settings)
@exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings)
else
@exercises = []
end
@ -188,7 +188,7 @@ class ExercisesController < ApplicationController
else
@is_teacher_or = 0 #为学生
end
@exercise_questions = @exercise.exercise_questions.order("question_number ASC")
@exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_standard_answers).order("question_number ASC")
rescue Exception => e
uid_logger_error(e.message)
tip_exception("试卷创建失败!")
@ -1334,6 +1334,7 @@ class ExercisesController < ApplicationController
#导出空白试卷
def export_exercise
@exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC")
@request_url = request.base_url
filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf"
stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css"
render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets
@ -1418,7 +1419,7 @@ class ExercisesController < ApplicationController
:best_counts => best_counts,
}
@exercise_questions = @exercise.exercise_questions
@exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_answers,:exercise_standard_answers,:exercise_shixun_challenges,:exercise_shixun_answers)
@paging_type = "percent"
# 按题型排序

@ -33,7 +33,7 @@ class GamesController < ApplicationController
is_teacher = @user.is_teacher?
# 实训超时设置
time_limit = @shixun.exec_time
time_limit = game_challenge.exec_time
# 上一关、下一关
prev_game = @game.prev_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position)
@ -66,7 +66,7 @@ class GamesController < ApplicationController
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))}"}
params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}"}
res = uri_post uri, params
if res && res['code'].to_i != 0
raise("实训云平台繁忙繁忙等级99")
@ -426,12 +426,12 @@ class GamesController < ApplicationController
game_code = GameCode.where(:game_id => @game.try(:id), :path => path).first
if game_code.present?
content = game_code.try(:new_code)
@content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present?
content.gsub(/\t/, ' ')
else
content
end
update_file_content(@content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset")
# @content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present?
# content.gsub(/\t/, ' ')
# else
# content
# end
update_file_content(content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset")
else
tip_exception("代码重置失败,代码为空")
end
@ -547,7 +547,7 @@ class GamesController < ApplicationController
br_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL => "#{gitUrl}", :buildID => "#{@game.id}",
:instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}",
:times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified,
:containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}",
:containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}",
:persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}",
:timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) }

@ -186,6 +186,7 @@ class HomeworkCommonsController < ApplicationController
@work_count = @student_works.size
@work_excel = @student_works
@students = @course.students
# 分页参数
page = params[:page] || 1
@ -236,94 +237,51 @@ class HomeworkCommonsController < ApplicationController
end
def update_score
student_works = @homework.student_works
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: @course.students.pluck(:user_id))
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id).
joins("join course_members on myshixuns.user_id=course_members.user_id").where(course_members: {course_id: @course.id, role: 4}).includes(:games)
myshixuns.find_each(batch_size: 100) do |myshixun|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
setting_time = @homework.homework_group_setting work.user_id
if setting_time.end_time.present? && (setting_time.end_time > Time.now || (@homework.allow_late && @homework.late_time && @homework.late_time > Time.now))
#logger.info("#############setting_time: #{setting_time.end_time}")
user_total_score = 0
pass_consume_time = 0
final_score = 0
homework.homework_challenge_settings.each do |setting|
game = myshixun.games.where(:challenge_id => setting.challenge_id, :status => 2).first
unless game.nil?
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 ? game.real_score(setting.score) : 0))
end
end
if work.work_status == 0
is_complete = myshixun.is_complete? && (myshixun.done_time < setting_time.end_time)
work.work_status = setting_time.end_time > Time.now ? 1 : (is_complete ? 1 : 2)
work.late_penalty = setting_time.end_time > Time.now ? 0 : (is_complete ? 0 : homework.late_penalty)
work.commit_time = myshixun.created_at > setting_time.publish_time ? setting_time.publish_time : myshixun.created_at
work.myshixun_id = myshixun.id
end
games = myshixun.games.where(:challenge_id => homework.homework_challenge_settings.map(&:challenge_id))
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil
if myshixun_endtime.present?
min_efficiency_changed = min_efficiency_changed.present? ? min_efficiency_changed : false
work.compelete_status = 1
work.cost_time = myshixun_endtime.to_i - setting_time.publish_time.to_i
efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0))
work.efficiency = format("%.2f", efficiency)
begin
if @homework.unified_setting
student_works = @homework.student_works
user_ids = @course.students.pluck(:user_id)
else
user_ids = @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)).pluck(:user_id)
student_works = @homework.student_works.where(user_id: user_ids)
end
# 如果作业的最大效率值有变更则更新所有作品的效率分
if homework.work_efficiency && homework.max_efficiency < work.efficiency
homework.update_column("max_efficiency", work.efficiency)
end
myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids).
includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)})
challenge_settings = @homework.homework_challenge_settings
myshixuns.find_each(batch_size: 100) do |myshixun|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
end
work.update_time = Time.now
work.final_score = final_score
score = work.final_score + work.eff_score - work.late_penalty
work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score
#logger.info("#############work_score: #{score}")
work.save!
end
end
@homework.student_works.each do ||
@homework.update_attribute('calculation_time', Time.now)
normal_status("更新成功")
rescue Exception => e
uid_logger(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
def update_student_score
work = @homework.students_works.find_by(user_id: current_user.id)
work = @homework.student_works.find_by(user_id: current_user.id)
myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id)
if work && myshixun
# 判断作品是否关联过myshixun
if work.myshixun_id.nil?
work.myshixun_id = myshixun.id
work.update_time = myshixun.updated_at
setting_time = @homework.homework_group_setting myshixun.user_id
games = myshixun.games.where(:challenge_id => @homework.homework_challenge_settings.pluck(:challenge_id))
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil
compelete_status = 0
if myshixun_endtime.present? && myshixun_endtime < setting_time.end_time
if myshixun_endtime < setting_time.publish_time
compelete_status = 2
else
compelete_status = 1
end
end
games.each do |game|
unless game.nil?
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 ? game.real_score(setting.score) : 0))
end
ActiveRecord::Base.transaction do
begin
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
challenge_settings = @homework.homework_challenge_settings
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
normal_status("更新成功")
else
normal_status("已是最新成绩")
end
rescue Exception => e
uid_logger(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
end
@ -1036,7 +994,7 @@ class HomeworkCommonsController < ApplicationController
if homework.course_acts.size == 0
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
end
# 发消息
HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids)
else
create_homework_group_settings(homework)
@ -1057,6 +1015,7 @@ class HomeworkCommonsController < ApplicationController
homework.save!
# 更新学生状态及成绩
HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id)
end
normal_status(0, "发布成功")

@ -217,7 +217,7 @@ class MyshixunsController < ApplicationController
shixun_tomcat = edu_setting('tomcat_webssh')
uri = "#{shixun_tomcat}/bridge/webssh/getConnectInfo"
params = {tpiID:@myshixun.id, podType:@myshixun.shixun.try(:webssh),
containers:(Base64.urlsafe_encode64(container_limit @myshixun.shixun.mirror_repositories))}
containers:(Base64.urlsafe_encode64(shixun_container_limit @myshixun.shixun))}
res = uri_post uri, params
if res && res['code'].to_i != 0
tip_exception("实训云平台繁忙繁忙等级92")

@ -90,7 +90,7 @@ class PollsController < ApplicationController
@limit = params[:limit] || 15
@polls = @polls.page(@page).per(@limit)
@polls = @polls.includes(:poll_users,:poll_questions,:poll_group_settings)
@polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings)
else
@polls = []
@ -183,7 +183,7 @@ class PollsController < ApplicationController
else
@is_teacher_or = 0
end
@poll_questions = @poll.poll_questions.order("question_number ASC")
@poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC")
rescue Exception => e
uid_logger_error(e.message)
tip_exception("没有权限")
@ -1148,7 +1148,7 @@ class PollsController < ApplicationController
end
def get_questions_count
@poll_questions = @poll.poll_questions.order("question_number ASC")
@poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC")
@poll_questions_count = @poll_questions.count # 全部的题目数
@poll_question_singles = @poll_questions.ques_count(1).all.count # 单选题
@poll_question_doubles = @poll_questions.ques_count(2).all.count # 多选题

@ -315,9 +315,13 @@ class ShixunsController < ApplicationController
# 镜像-实训关联表
ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i) if main_type.present?
# 实训主镜像服务配置
ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i)
if sub_type.present?
sub_type.each do |mirror|
ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror)
# 实训子镜像服务配置
ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror)
end
end
@ -363,11 +367,6 @@ class ShixunsController < ApplicationController
end
def update
h = {test_set_permission: params[:test_set_permission], code_hidden: params[:code_hidden],
task_pass: params[:task_pass], hide_code: params[:hide_code], forbid_copy: params[:forbid_copy]}
s_params = shixun_params.merge(h)
ActiveRecord::Base.transaction do
begin
@shixun.shixun_mirror_repositories.destroy_all
@ -380,8 +379,8 @@ class ShixunsController < ApplicationController
end
end
@shixun.update_attributes(s_params)
@shixun.shixun_info.update_attributes(description: params[:description], evaluate_script: params[:evaluate_script])
@shixun.update_attributes(shixun_params)
@shixun.shixun_info.update_attributes(shixun_info_params)
@shixun.shixun_schools.delete_all
if params[:scope_partment].present? && params[:user_scope].to_i == 1
arr = []
@ -395,6 +394,13 @@ class ShixunsController < ApplicationController
use_scope = 0
end
@shixun.update_attributes!(:use_scope => use_scope)
# 超级管理员和运营人员才能保存 中间层服务器pod信息的配置
if current_user.admin? || current_user.business?
@shixun.shixun_service_configs.destroy_all
params[:shixun_service_configs].each do |config|
@shixun.shixun_service_configs.create!(config)
end
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception("实训保存失败")
@ -430,6 +436,7 @@ class ShixunsController < ApplicationController
@choice_small_type = @shixun.small_mirror_id
@main_type = shixun_main_type
@small_type = shixun_small_type
@configs = @shixun.shixun_service_configs
#@mirror_script = MirrorScript.select([:id, :script_type]).find(@shixun.mirror_script_id).attributes if @shixun.mirror_script_id && @shixun.mirror_script_id != 0
# @shixun_main_mirror = @shixun.show_shixun_mirror
# @script_type = @shixun.script_tag.try(:script_type) || "无"
@ -718,7 +725,13 @@ private
def shixun_params
raise("实训名称不能为空") if params[:name].blank?
params.require(:shixun).permit(:name, :trainee, :webssh, :can_copy, :use_scope, :vnc, :test_set_permission,
:task_pass, :repo_name, :multi_webssh, :opening_time, :mirror_script_id)
:task_pass, :repo_name, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden,
:hide_code, :forbid_copy)
end
def shixun_info_params
raise("实训描述不能为空") if params[:description].blank?
raise("评测脚本不能为空") if params[:evaluate_script].blank?
params.require(:shixun_info).permit(:description, :evaluate_script)
end
def find_shixun

@ -17,7 +17,7 @@ class ZipsController < ApplicationController
end
def export_exercises
exercises = ExportExercisesService.new(@exercise,@ex_users)
exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url)
file_name = filename_for_content_disposition(exercises.filename)
send_file exercises.ex_zip, filename: file_name, type: 'application/zip'
@ -41,6 +41,7 @@ class ZipsController < ApplicationController
ActiveRecord::Base.transaction do
begin
@exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id])
@request_url = request.base_url
group_id = params[:exercise_group_id]
if @exercise.blank?
normal_status(-1,"试卷不存在")
@ -48,19 +49,20 @@ class ZipsController < ApplicationController
@course = @exercise.course
default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed
default_ex_users_size = default_ex_users.size
@ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。
#可以分班选择
if group_id.present?
exercise_students = @course.students.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数
user_ids = exercise_students.pluck(:user_id).reject(&:blank?)
@ex_users = @ex_users.exercise_commit_users(user_ids)
exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数
user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq
@ex_users = @ex_users.where(user_id: user_ids)
end
# @ex_users = @ex_users.first(200)
default_ex_users_size = @ex_users.size
if default_ex_users_size == 0
normal_status(-1,"导出失败,暂时没有已提交的学生")
elsif default_ex_users_size > 200
normal_status(-1,"导出数量超过200,请分班导出或联系网站管理员导出")
elsif default_ex_users_size > 100
normal_status(-1,"导出数量超过100,请分班导出或联系网站管理员导出")
end
end
rescue Exception => e

@ -334,6 +334,26 @@ module ApplicationHelper
raw arr.join('')
end
def to_markdown(text)
request_url = request.base_url
return nil if text.blank?
options = {
:autolink => true,
:no_intra_emphasis => true,
:fenced_code_blocks => true,
:lax_html_blocks => true,
:strikethrough => true,
:superscript => true,
:tables => true
}
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options)
m_t = markdown.render(text)
ss = m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t
Rails.logger.info("############_____________ss________________##################{ss}")
ss
end
end

@ -110,7 +110,7 @@ module PollsHelper
poll_user_name = user.nickname
end
course_member = course_members.find_by(user_id:user.id)
course_group_id = course_members.present? ? course_member.course_group_id : nil
course_group_id = course_member.present? ? course_member.course_group_id : nil
if course_group_id == 0
course_group_name = "未分班"
else

@ -20,7 +20,7 @@ class Challenge < ApplicationRecord
# acts_as_attachable
scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time,
:web_route, :answer]) }
:web_route, :answer, :exec_time]) }
scope :choose_type, -> { where(st: 1) }
scope :practice_type, -> { where(st: 0) }

@ -1,5 +1,7 @@
class Shixun < ApplicationRecord
# status: 0编辑 1申请发布 2正式发布 3关闭 -1软删除
# hide_code 隐藏代码窗口
# code_hidden: 隐藏代码目录
has_many :challenges, dependent: :destroy
has_many :myshixuns, :dependent => :destroy
has_many :shixun_members, dependent: :destroy
@ -30,6 +32,8 @@ class Shixun < ApplicationRecord
has_one :shixun_info, dependent: :destroy
belongs_to :user
# 实训服务配置
has_many :shixun_service_configs, :dependent => :destroy
scope :search_by_name, ->(keyword) { where("name like ? or description like ? ",

@ -0,0 +1,4 @@
class ShixunServiceConfig < ApplicationRecord
belongs_to :shixun
belongs_to :mirror_repository
end

@ -5,9 +5,10 @@ class ExerciseUserPdfService
attr_reader :exercise, :ex_user
def initialize(exercise, ex_user)
def initialize(exercise, ex_user,request_url)
@exercise = exercise
@ex_user = ex_user
@request_url = request_url
@ex_user_user = @ex_user.user
@course = @exercise.course
end
@ -37,10 +38,10 @@ class ExerciseUserPdfService
kit = PDFKit.new(html)
base_css = %w(app/templates/exercise_export/exercise_export.css)
base_css.each { |css| kit.stylesheets << Rails.root.join(css) }
#-----正式需删掉
# #-----正式需删掉
# aa = File.open(Rails.root.join("public/123.html"),"w+")
# aa.syswrite(kit.source)
#正式需删掉-------
# #正式需删掉-------
file = Tempfile.new(filename)
kit.to_pdf(file.path)
file

@ -3,9 +3,10 @@ class ExportExercisesService
include StudentWorksHelper
attr_reader :exercise, :ex_users
def initialize(exercise, ex_users)
def initialize(exercise, ex_users,request_url)
@exercise = exercise
@ex_users = ex_users
@request_url = request_url
end
def filename
@ -18,7 +19,7 @@ class ExportExercisesService
pdfs = []
Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip|
ex_users.each do |ex_user|
export = ExerciseUserPdfService.new(exercise, ex_user)
export = ExerciseUserPdfService.new(exercise, ex_user,@request_url)
pdf = export.ex_pdf
pdfs << pdf
begin

@ -272,4 +272,67 @@ class HomeworksService
end
end
end
# 计算实训作品成绩
def update_myshixun_work_score work, myshixun, games, homework, challenge_settings
user_total_score = 0
pass_consume_time = 0
final_score = 0
setting_time = homework.homework_group_setting myshixun.user_id
homework_end_or_late_time = homework.allow_late ? homework.late_time : setting_time.end_time
games.each do |game|
# 在截止时间前通关的关卡才考虑得分
if game.status == 2 && game.end_time <= homework_end_or_late_time
challenge_setting = challenge_settings.select{|setting| setting.challenge_id == game.challenge_id}.first
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 => game.challenge_id).last
final_score += if adjust_score.present?
adjust_score.score
elsif homework.homework_detail_manual.answer_open_evaluation
challenge_setting.score
elsif game.final_score > 0
game.real_score(challenge_setting.score)
else
0
end
end
end
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil
if myshixun_endtime.present?
work.cost_time = myshixun_endtime.to_i - setting_time.publish_time.to_i
efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0))
work.efficiency = format("%.2f", efficiency)
if myshixun_endtime <= homework_end_or_late_time
work.compelete_status = myshixun_endtime < setting_time.publish_time ? 2 : 1
# 如果作业的最大效率值有变更则更新所有作品的效率分
homework.update_column("max_efficiency", work.efficiency) if homework.work_efficiency && homework.max_efficiency < work.efficiency
end
end
if work.work_status == 0
is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time)
if is_complete || (!homework.allow_late && myshixun.created_at < setting_time.end_time)
work.work_status = 1
elsif homework.allow_late && myshixun.created_at < homework.late_time
work.work_status = 2
end
work.late_penalty = work.work_status == 2 ? homework.late_penalty : 0
work.commit_time = myshixun.created_at > setting_time.publish_time ? setting_time.publish_time : myshixun.created_at
work.myshixun_id = myshixun.id
end
work.update_time = myshixun.updated_at
work.final_score = final_score
score = work.final_score + work.eff_score - work.late_penalty
work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score
#logger.info("#############work_score: #{score}")
work.calculation_time = Time.now
work.save!
end
end

@ -68,13 +68,17 @@
<span class="text-gray mlr5">(<%= q&.question_score %>分)</span>
</div>
<div class="pbt5">
<img src="http://47.96.87.25:48080/api/attachments/368984" alt="电脑的电路图" title="电脑的电路图">
<img class="myavatar avatar-48" alt="udasker_picture" src="http://images.udask.cn/uploaders/user/picture/2/2_udasker.jpg?v=1556452947">
<% q_markdown = to_markdown(q.question_title) %>
<% if q.question_type == 5 %>
<span class="ques-title"><%= q.shixun_name.present? ? q.shixun_name&.html_safe : "" %></span>
<% q_markdown_name = to_markdown(q.shixun_name) %>
<span class="ques-title" ><%= q_markdown_name %></span>
<div class="mt8 text-gray">
<span><%= q.question_title.present? ? q.question_title&.html_safe : "" %></span>
<span><%= q_markdown %></span>
</div>
<% else %>
<span class="ques-title"><%= q.question_title.present? ? q.question_title&.html_safe : "" %></span>
<span class="ques-title"><%= q_markdown %></span>
<% end %>
</div>
<div class="pbt5">
@ -82,14 +86,16 @@
<% q.exercise_choices.each_with_index do |s,index| %>
<p class="pbt5">
<span class="choose-radio"></span>
<span class="mr15"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%>
<span class="mr15"><%= convert_to_char((index+1).to_s)%></span>
<span class="inline-block"><%= to_markdown(s.choice_text) %></span>
</p>
<% end %>
<% elsif q.question_type == 1 %>
<% q.exercise_choices.each_with_index do |s,index| %>
<p class="pbt5">
<span class="choose-checkbox"></span>
<span class="mr20"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%>
<span class="mr20"><%= convert_to_char((index+1).to_s)%></span>
<span class="inline-block"><%= to_markdown(s.choice_text) %></span>
</p>
<% end %>
<% elsif q.question_type == 2 %>
@ -97,7 +103,7 @@
<% q.exercise_choices.each_with_index do |s,index| %>
<span class="mr15">
<span class="choose-radio"></span>
<span class="mlr5"><%= s.choice_text %></span>
<span class="mlr5 inline-block"><%= to_markdown(s.choice_text) %></span>
</span>
<% end %>
</p>
@ -132,4 +138,5 @@
</div>
</div>
</body>
</html>

@ -167,15 +167,15 @@
<% end %>
</div>
<div class="pbt5">
<% q_title = q.question_title&.html_safe %>
<% if q_type == 5 %>
<span class="ques-title"><%= q.shixun_name&.html_safe %></span>
<% q_name = q.shixun_name&.html_safe %>
<span class="ques-title"><%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %></span>
<div class="mt8 text-gray">
<span><%= q.question_title&.html_safe %></span>
<span><%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %></span>
</div>
<% elsif q_type == 4 %>
<span class="ques-title"><%= q.question_title&.html_safe %></span>
<% else %>
<span class="ques-title"><%= q.question_title&.html_safe %></span>
<span class="ques-title"><%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %></span>
<% end %>
</div>
</div>

@ -7,7 +7,7 @@ json.chooses do
end
if @tab == 0
# 本关任务tab的编辑模式
json.(@challenge, :id, :subject, :task_pass, :difficulty, :score)
json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time)
json.tags @challenge.challenge_tags.map(&:name)
elsif @tab == 1
# 评测设置的编辑模式

@ -11,4 +11,5 @@ json.homework_id homework.id
json.homework_type homework.homework_type
if homework.homework_type == "practice"
json.shixun_identifier homework.shixuns.take.try(:identifier)
json.shixun_id homework.shixuns.take.try(:id)
end

@ -16,6 +16,7 @@ json.work_public @homework.work_public
if @user_course_identity < Course::STUDENT
json.calculation_time @homework.calculation_time if @homework.homework_type == "practice"
# 教师身份的评阅、提交状态、分班过滤
if @homework.homework_type != "practice"
json.teacher_comment teacher_comment @homework, @current_user.id
@ -30,7 +31,7 @@ elsif @user_course_identity == Course::STUDENT
if @homework.homework_type == "practice"
json.(@work, :id, :work_status, :update_time, :ultimate_score)
json.calculation_time @work.calculation_time
json.late_penalty @work.late_penalty if @homework.allow_late
json.cost_time @work.myshixun.try(:total_cost_time)
json.work_score work_score_format(@work.work_score, true, @score_open)
@ -94,7 +95,7 @@ if @homework.homework_type == "practice"
json.user_login work.user.try(:login)
json.user_name work.user.try(:real_name)
json.student_id work.user.try(:student_id)
json.group_name @course.course_student(work.user_id).try(:course_group_name)
json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
end
elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.anonymous_comment @homework.anonymous_comment
@ -133,7 +134,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
end
json.student_id work.user.try(:student_id)
json.group_name @course.course_student(work.user_id).try(:course_group_name)
json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
if @homework.homework_type == "group"
if @homework.homework_detail_group.base_on_project
json.project_info project_info work, @current_user, @user_course_identity

@ -29,6 +29,14 @@ json.shixun do
json.scope_partment @shixun.schools.map(&:name) # 公开范围
json.opening_time @shixun.opening_time
json.forbid_copy @shixun.forbid_copy
# 实训服务配置
json.shixun_service_configs do
json.array! @configs do |config|
json.name config.mirror_repository&.name
json.(config, :cpu_limit, :lower_cpu_limit, :memory_limit, :request_limit, :mirror_repository_id)
end
end
end

@ -338,6 +338,8 @@ Rails.application.routes.draw do
get :publish_groups
get :end_groups
post :alter_name
get :update_score
get :update_student_score
end
collection do

@ -0,0 +1,6 @@
class AddCalculationTimeToHomework < ActiveRecord::Migration[5.2]
def change
add_column :homework_commons, :calculation_time, :datetime
add_column :student_works, :calculation_time, :datetime
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ShixunServiceConfig, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save