From b29d4063a87c1fcbc09c7c46bfcc8c2639b3cdcd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 09:53:58 +0800 Subject: [PATCH 01/23] fix bug --- .../exercise_export/blank_exercise.html.erb | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 74cea75f1..995d04995 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -57,7 +57,7 @@
- <% @exercise_questions.each do |q| %> + <% @exercise_questions.each_with_index do |q,index| %>
@@ -68,15 +68,27 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.html_safe %> + <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.question_title&.html_safe %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.html_safe %> - <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.shixun_name&.html_safe %> + <%= q_name %>
- <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= q_title %>
+ <% else %> - <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= q_title %> + <% end %>
@@ -134,4 +146,6 @@
+<%= ApplicationController.helpers.pdf_load_sources(*%w(react/public/js/jquery-1.8.3.min.js react/public/js/editormd/marked.min.js))%> + \ No newline at end of file From 93d18fac5dbba3bd15d925dcc958c42b681b06dd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:12:26 +0800 Subject: [PATCH 02/23] fix bug --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/helpers/application_helper.rb | 12 +++++++++++ .../exercise_export/blank_exercise.html.erb | 21 +++++-------------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 31af87f14..b8b174a6f 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 83bd79628..86f524bc2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d8ea8cd60..8d92362cc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -334,6 +334,18 @@ module ApplicationHelper raw arr.join('') end + def to_markdown(text) + nil if text.blank? + html_render_options = { + fenced_code_blocks: true, + tables: true, + autolink: true + } + + markdown = Redcarpet::Markdown.new(html_render_options) + raw markdown.render(h(text)).html_safe + end + end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 995d04995..bdb86d9d9 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -57,7 +57,7 @@
- <% @exercise_questions.each_with_index do |q,index| %> + <% @exercise_questions.each do |q| %>
@@ -68,27 +68,17 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.question_title&.html_safe %> + <% q_markdown = to_markdown(q.question_title) %> + <% q_title = q_markdown&.include?("src=\"") ? q_markdown&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.shixun_name&.html_safe %> + <% q_markdown_name = to_markdown(q.shixun_name) %> + <% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %> <%= q_name %>
<%= q_title %>
- <% else %> <%= q_title %> - <% end %>
@@ -146,6 +136,5 @@
-<%= ApplicationController.helpers.pdf_load_sources(*%w(react/public/js/jquery-1.8.3.min.js react/public/js/editormd/marked.min.js))%> \ No newline at end of file From 4f21bcb3bb479f43b08ba755dbcd3e5e947a2255 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:17:09 +0800 Subject: [PATCH 03/23] fix bug --- app/helpers/application_helper.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8d92362cc..34848fd51 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,15 +335,19 @@ module ApplicationHelper end def to_markdown(text) - nil if text.blank? - html_render_options = { - fenced_code_blocks: true, - tables: true, - autolink: true + 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(html_render_options) - raw markdown.render(h(text)).html_safe + markdown = Redcarpet::Markdown.new(options) + markdown.render(h(text)).html_safe end end From 5bfd514211a3ab67621230684ef04c3990373bb4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:22:03 +0800 Subject: [PATCH 04/23] fix bug --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 34848fd51..acb1089ec 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -346,7 +346,7 @@ module ApplicationHelper :tables => true } - markdown = Redcarpet::Markdown.new(options) + markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) markdown.render(h(text)).html_safe end From a6ea8d139a1c9861701d28bfbfa498f76e46d3f9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:23:02 +0800 Subject: [PATCH 05/23] fix bug --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index acb1089ec..055731168 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -347,7 +347,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - markdown.render(h(text)).html_safe + markdown.render(text).html_safe end end From 1044209d4f995b3c6bee369b183986d53e9f1160 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 10:25:14 +0800 Subject: [PATCH 06/23] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 18 ++++++++++++++++++ app/controllers/challenges_controller.rb | 4 ++-- app/controllers/games_controller.rb | 6 +++--- app/controllers/myshixuns_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 16 ++++++++++++++++ app/models/challenge.rb | 2 +- app/models/shixun.rb | 2 ++ app/models/shixun_service_config.rb | 4 ++++ app/views/challenges/edit.json.jbuilder | 2 +- spec/models/shixun_service_config_spec.rb | 5 +++++ 10 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 app/models/shixun_service_config.rb create mode 100644 spec/models/shixun_service_config_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index afe2129a9..cbd2962b6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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}") diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index d56c3ecbd..856afeb01 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -154,7 +154,7 @@ 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 @@ -290,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 diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 76e15f9e2..7e7b6e082 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -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)") @@ -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) } diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index a4a3b7222..909533301 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -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)") diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b3069bc5d..f079aed1e 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -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 @@ -395,6 +399,18 @@ 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[:mirror_id].each_with_index do |mirror_id, index| + ShixunServiceConfig.create!(:shixun_id => @shixun.id, + :cpu_limit => params[:cpu_limit][index], + :lower_cpu_limit => params[:lower_cpu_limit][index], + :memory_limit => params[:memory_limit][index], + :request_limit => params[:request_limit][index], + :mirror_repository_id => mirror_id) + end + end rescue Exception => e uid_logger_error(e.message) tip_exception("实训保存失败") diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 07a49196d..18b177e1c 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -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) } diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 556a4400f..18d5c5fae 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -30,6 +30,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 ? ", diff --git a/app/models/shixun_service_config.rb b/app/models/shixun_service_config.rb new file mode 100644 index 000000000..6d106fc07 --- /dev/null +++ b/app/models/shixun_service_config.rb @@ -0,0 +1,4 @@ +class ShixunServiceConfig < ApplicationRecord + belongs_to :shixun + belongs_to :mirror_repository +end diff --git a/app/views/challenges/edit.json.jbuilder b/app/views/challenges/edit.json.jbuilder index 64848a4e6..2774b5a05 100644 --- a/app/views/challenges/edit.json.jbuilder +++ b/app/views/challenges/edit.json.jbuilder @@ -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 # 评测设置的编辑模式 diff --git a/spec/models/shixun_service_config_spec.rb b/spec/models/shixun_service_config_spec.rb new file mode 100644 index 000000000..d79cd19f7 --- /dev/null +++ b/spec/models/shixun_service_config_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ShixunServiceConfig, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 3533f2e7b6204fc033dacd9c3106648e52b9200e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 1 Jul 2019 10:30:19 +0800 Subject: [PATCH 07/23] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E8=AE=A1=E7=AE=97=E6=88=90=E7=BB=A9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 119 ++++++------------ app/services/homeworks_service.rb | 63 ++++++++++ .../_homework_public_navigation.json.jbuilder | 1 + .../homework_commons/works_list.json.jbuilder | 7 +- config/routes.rb | 2 + ...013243_add_calculation_time_to_homework.rb | 6 + 6 files changed, 115 insertions(+), 83 deletions(-) create mode 100644 db/migrate/20190701013243_add_calculation_time_to_homework.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2a1dfb14a..8ce99cb79 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -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, "发布成功") diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 1e155dde0..48db76295 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -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 \ No newline at end of file diff --git a/app/views/homework_commons/_homework_public_navigation.json.jbuilder b/app/views/homework_commons/_homework_public_navigation.json.jbuilder index 2c548074c..243c6aecd 100644 --- a/app/views/homework_commons/_homework_public_navigation.json.jbuilder +++ b/app/views/homework_commons/_homework_public_navigation.json.jbuilder @@ -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 diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 60441909b..f740959d0 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -13,6 +13,7 @@ json.ta_mode @homework_detail_manual.ta_mode json.is_evaluation @is_evaluation ? @is_evaluation : false json.work_public @homework.work_public +json.calculation_time @homework.calculation_time if @homework.homework_type == "practice" if @user_course_identity < Course::STUDENT @@ -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 diff --git a/config/routes.rb b/config/routes.rb index f81d90267..0f47cda76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20190701013243_add_calculation_time_to_homework.rb b/db/migrate/20190701013243_add_calculation_time_to_homework.rb new file mode 100644 index 000000000..4a622ee92 --- /dev/null +++ b/db/migrate/20190701013243_add_calculation_time_to_homework.rb @@ -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 From 9c7523a8527679f1711f63ebb4de3d9b4da29e4c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:31:00 +0800 Subject: [PATCH 08/23] fix bug --- app/helpers/application_helper.rb | 3 +-- app/templates/exercise_export/blank_exercise.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 055731168..f77e9a313 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -345,9 +345,8 @@ module ApplicationHelper :superscript => true, :tables => true } - markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - markdown.render(text).html_safe + markdown.render(text) end end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index bdb86d9d9..63b7fb8bc 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -75,10 +75,10 @@ <% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %> <%= q_name %>
- <%= q_title %> + <%= q_markdown %>
<% else %> - <%= q_title %> + <%= q_markdown %> <% end %>
From 5db1bbd18a8fcd73d28c414a044fc77533582ca2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:33:57 +0800 Subject: [PATCH 09/23] fix bug --- app/helpers/application_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f77e9a313..cb2f487cb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,6 +335,7 @@ module ApplicationHelper end def to_markdown(text) + Rails.logger.info("#########################text______________tedxt_________________###{text}") return nil if text.blank? options = { :autolink => true, @@ -346,7 +347,10 @@ module ApplicationHelper :tables => true } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - markdown.render(text) + ss = markdown.render(text) + Rails.logger.info("#########################text______________markdown.render(text)________________###{ss}") + ss + end end From 53b0f2efcd8b6810278ffe8d5ccb1558b3a299ec Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 1 Jul 2019 10:37:05 +0800 Subject: [PATCH 10/23] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/works_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index f740959d0..a7dc292b8 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -13,10 +13,10 @@ json.ta_mode @homework_detail_manual.ta_mode json.is_evaluation @is_evaluation ? @is_evaluation : false json.work_public @homework.work_public -json.calculation_time @homework.calculation_time if @homework.homework_type == "practice" 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 From 6110df20bd10d12b72ad2c125c6377b12cb0f810 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:38:47 +0800 Subject: [PATCH 11/23] fix bug --- app/helpers/application_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cb2f487cb..df024264e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -336,6 +336,8 @@ module ApplicationHelper def to_markdown(text) Rails.logger.info("#########################text______________tedxt_________________###{text}") + Rails.logger.info("#########################text______________request_base_url________________###{request.base_url}") + return nil if text.blank? options = { :autolink => true, @@ -347,10 +349,10 @@ module ApplicationHelper :tables => true } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - ss = markdown.render(text) - Rails.logger.info("#########################text______________markdown.render(text)________________###{ss}") - ss - + m_t = markdown.render(text) + q_title = m_t &.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : m_t + Rails.logger.info("#########################text______________markdown.render(text)________________###{q_title }") + q_title end end From b320715e6e9ff22b45cf5e742337b309a2f02ea7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:45:45 +0800 Subject: [PATCH 12/23] fix bug --- app/helpers/application_helper.rb | 9 ++++----- .../exercise_export/blank_exercise.html.erb | 14 ++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index df024264e..67e899820 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,8 +335,7 @@ module ApplicationHelper end def to_markdown(text) - Rails.logger.info("#########################text______________tedxt_________________###{text}") - Rails.logger.info("#########################text______________request_base_url________________###{request.base_url}") + request_url = request.base_url return nil if text.blank? options = { @@ -350,9 +349,9 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) - q_title = m_t &.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : m_t - Rails.logger.info("#########################text______________markdown.render(text)________________###{q_title }") - q_title + ss = m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}")&.html_safe : m_t + Rails.logger.info("############_____________ss________________##################{ss}") + ss end end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 63b7fb8bc..d562224da 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -69,16 +69,14 @@
<% q_markdown = to_markdown(q.question_title) %> - <% q_title = q_markdown&.include?("src=\"") ? q_markdown&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown %> <% if q.question_type == 5 %> <% q_markdown_name = to_markdown(q.shixun_name) %> - <% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %> - <%= q_name %> + <%= q_markdown_name %>
- <%= q_markdown %> + <%= q_markdown %>
<% else %> - <%= q_markdown %> + <%= q_markdown %> <% end %>
@@ -86,14 +84,14 @@ <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> + <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> + <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 2 %> @@ -101,7 +99,7 @@ <% q.exercise_choices.each_with_index do |s,index| %> - <%= s.choice_text %> + <%= to_markdown(s.choice_text) %> <% end %>

From fec939b098c167812f7b7f7bd55c11e13cf92115 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:58:26 +0800 Subject: [PATCH 13/23] fix bug --- app/helpers/application_helper.rb | 2 +- app/templates/exercise_export/blank_exercise.html.erb | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 67e899820..fd5a8b233 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -349,7 +349,7 @@ module ApplicationHelper } 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}")&.html_safe : m_t + ss = m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t Rails.logger.info("############_____________ss________________##################{ss}") ss end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index d562224da..b43dc1923 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,6 +68,7 @@ (<%= q&.question_score %>分)
+ 电脑的电路图 <% q_markdown = to_markdown(q.question_title) %> <% if q.question_type == 5 %> <% q_markdown_name = to_markdown(q.shixun_name) %> @@ -84,14 +85,14 @@ <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %> + <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %> + <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 2 %> @@ -99,7 +100,7 @@ <% q.exercise_choices.each_with_index do |s,index| %> - <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text) %> <% end %>

From decedbe354ac222e9a90a9e3884cc3e6971b19ad Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 11:28:42 +0800 Subject: [PATCH 14/23] fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index b43dc1923..9ee1d40f7 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -69,6 +69,7 @@
电脑的电路图 + udasker_picture <% q_markdown = to_markdown(q.question_title) %> <% if q.question_type == 5 %> <% q_markdown_name = to_markdown(q.shixun_name) %> @@ -85,14 +86,16 @@ <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %> + <%= convert_to_char((index+1).to_s)%> + <%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %> + <%= convert_to_char((index+1).to_s)%> + <%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 2 %> From 4d2943973fc156ee5c51352e72b3b2222e3c2252 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 11:31:17 +0800 Subject: [PATCH 15/23] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 27 +++++++++++------------- app/models/shixun.rb | 2 ++ app/views/shixuns/settings.json.jbuilder | 8 +++++++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f079aed1e..5631d03a7 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -367,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 @@ -384,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 = [] @@ -402,13 +397,8 @@ class ShixunsController < ApplicationController # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 if current_user.admin? || current_user.business? @shixun.shixun_service_configs.destroy_all - params[:mirror_id].each_with_index do |mirror_id, index| - ShixunServiceConfig.create!(:shixun_id => @shixun.id, - :cpu_limit => params[:cpu_limit][index], - :lower_cpu_limit => params[:lower_cpu_limit][index], - :memory_limit => params[:memory_limit][index], - :request_limit => params[:request_limit][index], - :mirror_repository_id => mirror_id) + params[:shixun_service_configs].each do |config| + @shixun.shixun_service_configs.create!(config) end end rescue Exception => e @@ -446,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) || "无" @@ -734,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 diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 18d5c5fae..c4345f90a 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -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 diff --git a/app/views/shixuns/settings.json.jbuilder b/app/views/shixuns/settings.json.jbuilder index e97331388..ed7d93039 100644 --- a/app/views/shixuns/settings.json.jbuilder +++ b/app/views/shixuns/settings.json.jbuilder @@ -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 From 029aac355491a4ee5a44823ea0cc55875719dab4 Mon Sep 17 00:00:00 2001 From: jasder Date: Mon, 1 Jul 2019 11:35:27 +0800 Subject: [PATCH 16/23] FIX delete message permission --- app/controllers/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index bad54b88e..f684b27f3 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -128,7 +128,7 @@ class MessagesController < ApplicationController def destroy begin - return normal_status(403, "您没有权限进行该操作") unless @message.author == current_user || current_user.teacher_of_course?(@message.board.course) + return normal_status(403, "您没有权限进行该操作") if current_user.course_identity(@message.board.course) >= 5 || @message.author != current_user @message.destroy! rescue Exception => e uid_logger_error(e.message) From 4a257c29603b67ab17d2d59f66b6ba2ce580e172 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:24:00 +0800 Subject: [PATCH 17/23] fix bug --- .../exercise_export/blank_exercise.html.erb | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 9ee1d40f7..f281a55a0 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -83,30 +83,28 @@
<% if q.question_type == 0 %> - <% q.exercise_choices.each_with_index do |s,index| %> -

- - <%= convert_to_char((index+1).to_s)%> - <%= to_markdown(s.choice_text) %> -

+ <% q.exercise_choices.each do |s| %> +
+ + <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q.question_type == 1 %> - <% q.exercise_choices.each_with_index do |s,index| %> -

- - <%= convert_to_char((index+1).to_s)%> - <%= to_markdown(s.choice_text) %> -

+ <% q.exercise_choices.each do |s| %> +
+ + <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q.question_type == 2 %> -

- <% q.exercise_choices.each_with_index do |s,index| %> - - - <%= to_markdown(s.choice_text) %> +

+ <% q.exercise_choices.each do |s| %> + + + <%= to_markdown(s.choice_text) %> <% end %> -

+
<% elsif q.question_type == 3 %> <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> <% st_counts.each_with_index do |s,index| %> From 8f3be9a7f6e42c8e3678df80eb6b0f660b748d4c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:37:13 +0800 Subject: [PATCH 18/23] fix bug --- .../exercise_export/blank_exercise.html.erb | 16 ++++++---------- .../exercise_export/exercise_export.css | 6 ++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index f281a55a0..b253d86b9 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,17 +68,13 @@ (<%= q&.question_score %>分)
- 电脑的电路图 - udasker_picture - <% q_markdown = to_markdown(q.question_title) %> <% if q.question_type == 5 %> - <% q_markdown_name = to_markdown(q.shixun_name) %> - <%= q_markdown_name %> + <%= to_markdown(q.shixun_name) %>
- <%= q_markdown %> + <%= to_markdown(q.question_title) %>
<% else %> - <%= q_markdown %> + <%= to_markdown(q.question_title) %> <% end %>
@@ -86,14 +82,14 @@ <% q.exercise_choices.each do |s| %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 2 %> @@ -101,7 +97,7 @@ <% q.exercise_choices.each do |s| %> - <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text) %> <% end %>
diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 9190e9251..bbe523972 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -309,6 +309,12 @@ textarea{ clear:both; zoom:1; } +.line-20{ + line-height: 20px; +} +.line-20 P{ + margin-bottom:0; +} From 0922155a1cdd9a603bd59b193506b2537c165896 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:50:01 +0800 Subject: [PATCH 19/23] fix bug --- app/helpers/application_helper.rb | 4 +--- .../exercise_export/blank_exercise.html.erb | 15 +++++++-------- app/templates/exercise_export/exercise_export.css | 4 +++- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fd5a8b233..c49e5e775 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -349,9 +349,7 @@ module ApplicationHelper } 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 + m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t end end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index b253d86b9..5727d0f62 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -44,7 +44,6 @@ 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %> <% end %> - <% if @exercise_ques_count > 0 %> <%= @exercise_ques_scores %>分 @@ -59,7 +58,7 @@
<% @exercise_questions.each do |q| %>
-
+
<%= q.question_number %>、 @@ -80,15 +79,15 @@
<% if q.question_type == 0 %> <% q.exercise_choices.each do |s| %> -
- +
+ <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %> -
- +
+ <%= to_markdown(s.choice_text) %>
<% end %> @@ -96,8 +95,8 @@
<% q.exercise_choices.each do |s| %> - - <%= to_markdown(s.choice_text) %> + + <%= s.choice_text %> <% end %>
diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index bbe523972..140db58ef 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -315,6 +315,8 @@ textarea{ .line-20 P{ margin-bottom:0; } - +.v-middle{ + vertical-align: middle; +} From b69d705ed77f4f81f78b32d323a03f05d5ca5aef Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:52:42 +0800 Subject: [PATCH 20/23] Fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 8 ++++---- app/templates/exercise_export/exercise_export.css | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 5727d0f62..aed7acdcd 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -80,15 +80,15 @@ <% if q.question_type == 0 %> <% q.exercise_choices.each do |s| %>
- - <%= to_markdown(s.choice_text) %> + + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %>
- - <%= to_markdown(s.choice_text) %> + + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 2 %> diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 140db58ef..3efda43bb 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -309,8 +309,8 @@ textarea{ clear:both; zoom:1; } -.line-20{ - line-height: 20px; +.line-24{ + line-height: 24px; } .line-20 P{ margin-bottom:0; From e365005af14682e96f3bc080ac32ab1c733f1438 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:55:04 +0800 Subject: [PATCH 21/23] fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 4 ++-- app/templates/exercise_export/exercise_export.css | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index aed7acdcd..99b8e6683 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -79,14 +79,14 @@
<% if q.question_type == 0 %> <% q.exercise_choices.each do |s| %> -
+
<%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %> -
+
<%= to_markdown(s.choice_text) %>
diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 3efda43bb..53dc5b3c8 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -312,11 +312,9 @@ textarea{ .line-24{ line-height: 24px; } -.line-20 P{ +.line-24 p{ margin-bottom:0; } -.v-middle{ - vertical-align: middle; -} + From 81950469b4c33cdd8e139a8ac26a4717c7c87f6b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 13:15:13 +0800 Subject: [PATCH 22/23] fix bug --- .../exercise_export/blank_exercise.html.erb | 8 ++-- .../exercise_export/exercise_export.css | 10 +++++ .../exercise_export/exercise_user.html.erb | 40 +++++++++---------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 99b8e6683..7e7c14977 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -80,15 +80,15 @@ <% if q.question_type == 0 %> <% q.exercise_choices.each do |s| %>
- - <%= to_markdown(s.choice_text) %> + + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %>
- - <%= to_markdown(s.choice_text) %> + + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 2 %> diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 53dc5b3c8..a72b26782 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -44,6 +44,9 @@ p{ .mbt10{ margin: 10px 0; } +.mt5{ + margin-top:5px; +} .pull-right{ float:right; } @@ -82,9 +85,15 @@ p{ .ml20{ margin-left:20px; } +.ml10{ + margin-left:10px; +} .mr3{ margin-right:3px; } +.mr8{ + margin-right:8px; +} .mr15{ margin-right:15px; } @@ -318,3 +327,4 @@ textarea{ + diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 5770c5921..1679692b3 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -167,41 +167,39 @@ <% end %>
- <% q_title = q.question_title&.html_safe %> - <% if q_type == 5 %> - <% q_name = q.shixun_name&.html_safe %> - <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %> + <% if q.question_type == 5 %> + <%= to_markdown(q.shixun_name) %>
- <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= to_markdown(q.question_title) %>
<% else %> - <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= to_markdown(q.question_title) %> <% end %>
<% if q_type == 0 %> - <% q.exercise_choices.each_with_index do |s,index| %> + <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> -

- - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

+
+ + <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q_type == 1 %> - <% q.exercise_choices.each_with_index do |s,index| %> + <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %> -

+

<% if check_answer %> - + <% else %> - + <% end %> - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

+ <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q_type == 2 %> -

+

<% q.exercise_choices.each do |s| %> <% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %> <% check_answer = 'choose-answer' %> @@ -213,7 +211,7 @@ <%= s.choice_text %> <% end %> -

+
<% elsif q_type == 3 %> <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> <% st_counts.each_with_index do |s,index| %> @@ -224,13 +222,13 @@ <% end %>

答案(填空<%= index+1 %>): - <%= check_answer&.html_safe %> + <%= to_markdown(check_answer) %>

<% end %> <% elsif q_type == 4 %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %>

- <%= check_answer&.html_safe %> + <%= to_markdown(check_answer) %>

<% else %>
From 065669bc2b2a0c7dcdadbdfa450a61b0d559df7d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 13:38:18 +0800 Subject: [PATCH 23/23] =?UTF-8?q?fork=E5=AE=9E=E8=AE=AD=E5=B8=A6=E7=9D=80?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5631d03a7..f7172021c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -179,6 +179,16 @@ class ShixunsController < ApplicationController ShixunTagRepertoire.create!(:tag_repertoire_id => str.tag_repertoire_id, :shixun_id => @new_shixun.id) end + # 同步配置 + @shixun.shixun_service_configs.each do |config| + ShixunServiceConfig.create!(:shixun_id => @new_shixun.id, + :cpu_limit => config.cpu_limit, + :lower_cpu_limit => config.lower_cpu_limit, + :memory_limit => config.memory_limit, + :request_limit => config.request_limit, + :mirror_repository_id => config.mirror_repository_id) + end + # fork版本库 logger.info("###########fork_repo_path: ######{@repo_path}") project_fork(@new_shixun, @repo_path, current_user.login)