diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 3fea82bff..b7a764999 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -109,7 +109,9 @@ class AccountController < ApplicationController
if User.current.anonymous?
redirect_to signin_path
else
+ UserActions.create(:action_id => User.current.id, :action_type => "Logout", :user_id => User.current.id)
logout_user
+ # 记录用户登出行为
redirect_to signin_path
end
# display the logout form
@@ -816,6 +818,8 @@ class AccountController < ApplicationController
call_hook(:controller_account_success_authentication_after, {:user => user })
code = /\d*/
+ # 记录用户登录行为
+ UserActions.create(:action_id => User.current.id, :action_type => "Login", :user_id => User.current.id)
#根据home_url生产正则表达式
eval("code = " + "/^" + home_url.gsub(/\//,"\\\/") + "\\\/*(welcome)?\\\/*(\\\/index\\\/*.*)?\$/")
if (code=~params[:back_url] || params[:back_url].to_s.include?('lost_password')) && last_login_on != ''
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index 97d193fbd..87c7a22cd 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -44,30 +44,29 @@ class CoursesController < ApplicationController
@user = User.current
@search = params[:search].nil? ? '' : params[:search]
@select = params[:select].nil? ? '' : params[:select]
- @is_end = params[:is_end].nil? ? 0 : params[:is_end].to_i # 是否归档
@is_over = params[:is_over] # 是否是新建课程页面跳转的查看归档
- @syllabuses_num = Course.where("is_end = #{@is_end} and is_delete = 0").count
+ @syllabuses_num = Course.where("is_end = 0 and is_delete = 0").count
#@syllabus_count = all_syllabuses.count
# 我创建的课堂
create_syllabuses = Course.where(:tea_id => @user.id)
# 我参与的课堂
join_syllabuses = @user.courses.where("is_delete = 0 and tea_id != #{@user.id}")
- @join_syllabuses_count = join_syllabuses.where(:is_end => @is_end, :is_delete => 0).count
- @create_syllabuses_count = create_syllabuses.where(:is_end => @is_end, :is_delete => 0).count
+ @join_syllabuses_count = join_syllabuses.where(:is_end => 0, :is_delete => 0).count
+ @create_syllabuses_count = create_syllabuses.where(:is_end => 0, :is_delete => 0).count
# 页面筛选的课程
if @select == "create"
- @syllabuses = create_syllabuses.where("is_end = #{@is_end} and is_delete = 0 and name like '%#{@search}%'")
+ @syllabuses = create_syllabuses.where("is_end = 0 and is_delete = 0 and name like '%#{@search}%'")
elsif @select == "join"
- @syllabuses = join_syllabuses.where("is_end = #{@is_end} and is_delete = 0 and tea_id != #{@user.id} and name like '%#{@search}%'")
+ @syllabuses = join_syllabuses.where("is_end = 0 and is_delete = 0 and tea_id != #{@user.id} and name like '%#{@search}%'")
elsif @select == "end"
# 归档的课堂
- end_syllabuses = Course.where("is_end = #{@is_end} and name like '%#{@search}%'")
+ end_syllabuses = Course.where("is_end = 1 and name like '%#{@search}%'")
@syllabuses = end_syllabuses
else
# 全部课堂
- all_syllabuses = Course.where("is_end = #{@is_end} and is_delete = 0 and name like '%#{@search}%'")
+ all_syllabuses = Course.where("is_end = 0 and is_delete = 0 and name like '%#{@search}%'")
@syllabuses = all_syllabuses
end
@@ -1849,9 +1848,9 @@ class CoursesController < ApplicationController
#sheet1.row(0).default_format = blue
#sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
sheet1[0,0] = "课程编号"
- sheet1[0,1] = course.syllabus.id
+ sheet1[0,1] = course.course_list_id
sheet1[1,0] = "课程名称"
- sheet1[1,1] = course.syllabus.title
+ sheet1[1,1] = course.course_list_name
sheet1[2,0] = "班级编号"
sheet1[2,1] = course.id
sheet1[3,0] = "班级名称"
@@ -1902,9 +1901,9 @@ class CoursesController < ApplicationController
homeworks.each_with_index do |home, i|
sheet = book.create_worksheet :name => "第#{i+1}次作业"
sheet[0,0] = "课程编号"
- sheet[0,1] = course.syllabus.id
+ sheet[0,1] = course.course_list_id
sheet[1,0] = "课程名称"
- sheet[1,1] = course.syllabus.title
+ sheet[1,1] = course.course_list_name
sheet[2,0] = "班级编号"
sheet[2,1] = course.id
sheet[3,0] = "班级名称"
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index 5a8dce761..75ba90e1b 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -600,7 +600,7 @@ class FilesController < ApplicationController
attachment.save
resource_bank = ResourceBank.create(:course_id => @course.id, :attachment_id => attachment.id, :filename => attachment.filename, :disk_filename => attachment.disk_filename, :filesize => attachment.filesize, :digest => attachment.digest, :downloads => 0,
:user_id => attachment.author_id, :description => attachment.description, :disk_directory => attachment.disk_directory, :is_public => attachment.is_public, :copy_from => attachment.copy_from,
- :quotes => 1, :applicable_syllabus => @course.syllabus.title, :major_level => @course.syllabus.major_level, :discipline_category_id => @course.syllabus.discipline_category_id, :first_level_discipline_id => @course.syllabus.first_level_discipline_id, :content_type => attachment.content_type)
+ :quotes => 1, :applicable_syllabus => @course.course_list_name, :content_type => attachment.content_type)
attachment.update_column('resource_bank_id', resource_bank.id)
end
end
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
index 3031dccbc..660596a56 100644
--- a/app/controllers/games_controller.rb
+++ b/app/controllers/games_controller.rb
@@ -3,7 +3,7 @@ class GamesController < ApplicationController
layout "base_myshixun"
skip_before_filter :verify_authenticity_token, :only => [:file_update]
before_filter :find_myshixun, :only => [:index]
- before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, :get_waiting_time,
+ before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :prev_step,:outputs_show, :file_edit, :file_update, :get_waiting_time,
:game_status, :change_status, :answer, :minus_score, :refresh_game_list, :reset_original_code, :reset_new_code, :evaluating_choice]
before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update, :reset_original_code, :reset_new_code, :html_show]
before_filter :allowd_manager
@@ -94,7 +94,7 @@ class GamesController < ApplicationController
@language = @game_challenge.shixun.language
error_position = had_test.blank? ? nil : had_test.select{|had_test| had_test.result == false}.last
logger.info("latest output id is #{error_position.id unless error_position.blank?}")
- @latest_output = error_position.try(:out_put).gsub(/\n/, '
').gsub(/\t/, ' ').to_json unless error_position.try(:out_put).blank?
+ @latest_output = error_position.try(:out_put).gsub(/\n/, '
').gsub(/\t/, ' ').to_json unless error_position.try(:out_put).blank?
logger.info(@latest_output)
respond_to do |format|
@@ -163,7 +163,7 @@ class GamesController < ApplicationController
raise("实训云平台繁忙(繁忙等级:94)")
end
render :json => {:result => "success", :onRun => res['onRun'], :waitNum => res['waitNum'], :waitingTime => res['waitingTime'], :resubmit => resubmit }
- #render :json => {:result => "success", :onRun => 1, :waitNum => 12, :waitingTime => 546 }
+ #render :json => {:result => "success", :onRun => 0, :waitNum => 12, :waitingTime => 1234 }
rescue Exception => e
render :json => {:result => "failed"}
end
@@ -278,6 +278,7 @@ class GamesController < ApplicationController
@final_score = ((@game.answer_open? || shixun.status <= 1) ? 0 : @game.final_score.to_i)
error_position = had_test.blank? ? nil : had_test.select{|had_test| had_test.result == false}.last
@latest_output = error_position.try(:out_put).gsub(/\n/, '
').gsub(/\t/, ' ') unless error_position.try(:out_put).blank?
+ logger.info("@compile_success###################{@compile_success}")
@language = game_challenge.shixun.language
render :json => {test_sets: total_test_sets,
test_sets_count: @test_sets_count,
@@ -293,7 +294,9 @@ class GamesController < ApplicationController
had_done: had_done,
language: @language,
score: score,
- tag_count: tag_count}
+ tag_count: tag_count,
+ position: game_challenge.position
+ }
end
# 选择题评测(选择题不需要重新评测)
@@ -343,7 +346,7 @@ class GamesController < ApplicationController
if @game.outputs.blank?
Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct)
end
- render :json => {correct: correct, had_done: had_done, :grade => User.where(:id => User.current.id).first.grade, score: score, tag_count: tag_count}
+ render :json => {correct: correct, had_done: had_done, :grade => User.where(:id => User.current.id).first.grade, score: score, tag_count: tag_count, position: @game_challenge.position}
end
@@ -391,6 +394,13 @@ class GamesController < ApplicationController
end
end
+ def prev_step
+ prev_game = @game.prev_game
+ respond_to do |format|
+ format.js{ redirect_to myshixun_game_path(prev_game, :myshixun_id => @myshixun)}
+ end
+ end
+
# 获取答案,第一次查看需扣掉该关卡的积分
# 如果已看过,下次可以免费查看
# viewed 1: 直接查看 2:弹框提示将要扣除积分,确定后显示内容 3:弹框提示分数不够
@@ -504,10 +514,11 @@ class GamesController < ApplicationController
unless test_sets.blank?
test_sets.each do |test_set|
output = Output.where(:game_id => @game.id, :test_set_position => test_set.position).first
- actual_output = (output.try(:actual_output).gsub(/\n/, '
').gsub(/\t/, ' ') unless output.try(:actual_output).blank?)
+ actual_output = (output.try(:actual_output).gsub(/\n/, '
').gsub(/\t/, ' ') unless output.try(:actual_output).blank?)
result = output.try(:result)
+ compile_success = (actual_output.blank? || !actual_output.match(/error/).blank?) ? 0 : 1
public_result = {:is_public => (test_set.is_public ? 1 : 0), :result => result, :input => test_set.input,
- :actual_output => actual_output, :output => test_set.output}
+ :actual_output => actual_output, :output => test_set.output, :compile_success => compile_success}
logger.info("1111#################################{public_result.to_json}")
test_result << public_result.to_json
end
diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb
index 315a69d9d..4019e1110 100644
--- a/app/controllers/homework_common_controller.rb
+++ b/app/controllers/homework_common_controller.rb
@@ -5,6 +5,7 @@ class HomeworkCommonController < ApplicationController
layout "base_courses"
include StudentWorkHelper
+ include ApplicationHelper
before_filter :find_course, :only => [:index,:new,:create]
before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,
:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works,
@@ -332,6 +333,15 @@ class HomeworkCommonController < ApplicationController
end
if @homework.homework_type == 4
+ if @homework_detail_manual.answer_open_evaluation != params[:answer_open_evaluation].to_i
+ @homework_detail_manual.answer_open_evaluation = params[:answer_open_evaluation].to_i
+ if @homework.end_time < Time.now
+ @homework.student_works.each do |student_work|
+ set_shixun_final_score @homework, student_work, @homework_detail_manual.answer_open_evaluation
+ student_work.save
+ end
+ end
+ end
@homework.score_open = params[:homework_score_open] ? 1 : 0
else
@homework.work_public = params[:homework_work_public] ? 1 : 0
diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb
index 0e05db265..448868c08 100644
--- a/app/controllers/myshixuns_controller.rb
+++ b/app/controllers/myshixuns_controller.rb
@@ -109,16 +109,18 @@ class MyshixunsController < ApplicationController
resubmit = jsonTestDetails['resubmit']
outPut = tran_base64_decode64(jsonTestDetails['outPut'])
jenkins_testsets = jsonTestDetails['msg']
+ compile_success = jsonTestDetails['compileSuccess']
# message = Base64.decode64(params[:msg]) unless params[:msg].blank?
logger.info(outPut)
+ logger.info("##################"+ compile_success)
game = Game.find(game_id)
challenge = game.challenge
unless jenkins_testsets.blank?
jenkins_testsets.each do |j_test_set|
actual_output = tran_base64_decode64(j_test_set['output'])
game_outputs = Output.create(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'],
- :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => game.query_index)
-
+ :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => game.query_index, :compile_success => compile_success.to_i)
+ logger.info("compile_success:"+ compile_success)
# output = Output.where(:game_id => game.id, :test_set_position => j_test_set['caseId'].to_i).first
# logger.info("#############{outPut}")
# if output.nil?
diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb
index 5fa93690f..9f16575b8 100644
--- a/app/controllers/shixuns_controller.rb
+++ b/app/controllers/shixuns_controller.rb
@@ -381,19 +381,31 @@ class ShixunsController < ApplicationController
redirect_to myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun)
return
end
- repository = @shixun.repository
ActiveRecord::Base.transaction do
begin
- @g = Gitlab.client
+ shixun_tomcat = Redmine::Configuration['shixun_tomcat']
+ code = down_generate_identifier("myshixun")
+ myshixun = Myshixun.create!(:shixun_id => @shixun.id, :user_id => User.current.id, :identifier => code)
+ # fork版本库,如果用户没有同步,则先同步用户
+ g = Gitlab.client
if User.current.gid.nil?
s = Trustie::Gitlab::Sync.new
s.sync_user(User.current)
end
- gshixun = @g.fork(@shixun.gpid, User.current.gid)
- logger.info("#############gshixun is #{gshixun}")
- if !gshixun.id.nil?
- # 防止fork多次的问题
- myshixun = copy_myshixun(@shixun, gshixun)
+ gshixun = g.fork(@shixun.gpid, User.current.gid)
+ if !gshixun.try(:id).blank?
+ myshixun.update_column(:gpid, gshixun.id) if myshixun.try(:gpid).blank? # 为了防止多次fork
+ rep = Repository.create!(:myshixun_id => myshixun.id, :identifier => gshixun.name,:project_id => -1, :shixun_id => -2)
+ rep.update_column(:type, "Repository::Gitlab")
+ rep_url = Base64.urlsafe_encode64(git_shixun_url_ip @shixun, "educoder") # 注意:educoder为默认给实训创建版本库的用户,如果换成别的用户,名字要相应的修改
+ uri = "#{shixun_tomcat}/bridge/game/openGameInstance"
+ params = {tpiID: "#{myshixun.id}", tpmID: "#{@shixun.id}", instanceGitURL:rep_url, operationEnvironment:"#{@shixun.try(:language)}"}
+ logger.info("openGameInstance params is #{params}")
+ res = uri_exec uri, params
+ if (res && res['code'].to_i != 0)
+ raise("实训云平台繁忙(繁忙等级:83)")
+ end
+ # 其它操作
challenges = @shixun.challenges
# 之所以增加user_id是为了方便统计查询性能
challenges.each_with_index do |challenge, index|
@@ -420,7 +432,7 @@ class ShixunsController < ApplicationController
rescue Exception => e
flash[:error] = e.message
logger.info("failed to exec shixun: current task id is #{e}")
- @g.delete_project(gshixun.id) if !gshixun.id.nil?
+ g.delete_project(gshixun.id) if !gshixun.id.nil?
redirect_to shixun_challenges_path(@shixun)
raise ActiveRecord::Rollback
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 1d9ab8c00..dc1efc6fd 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -267,6 +267,26 @@ module ApplicationHelper
end
end
+ # 已通过的关卡数 返回int类型(包含查看参考答案的)
+ def had_passed_changllenge_num shixun, user
+ myshixun = Myshixun.where(:shixun_id => shixun.id, :user_id => user.id).first
+ if myshixun.nil?
+ 0
+ else
+ myshixun.games.select{|game| game.status == 2}.count
+ end
+ end
+
+ # 已通过的关卡数 返回int类型(未查看参考答案)
+ def had_passed_no_ans_changllenge_num shixun, user
+ myshixun = Myshixun.where(:shixun_id => shixun.id, :user_id => user.id).first
+ if myshixun.nil?
+ 0
+ else
+ myshixun.games.select{|game| game.status == 2 && game.answer_open == 0}.count
+ end
+ end
+
# TPI状态 :已通关、未通关、未开启
def my_shixun_status shixun, user
status = ""
@@ -4875,8 +4895,8 @@ end
def add_to_homework_bank_f homework
homework_bank = HomeworkBank.new(:name => homework.name, :description => homework.description, :user_id => User.current.id, :homework_type => homework.homework_type,
- :quotes => 1, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.syllabus.title, :homework_common_id => homework.id,
- :reference_answer => homework.reference_answer, :syllabus_id => homework.course.syllabus_id)
+ :quotes => 1, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.course_list_name, :homework_common_id => homework.id,
+ :reference_answer => homework.reference_answer, :course_list_id => homework.course.course_list_id)
if homework.homework_type == 2 && homework.homework_detail_programing
homework_bank.language = homework.homework_detail_programing.language
homework.homework_tests.each_with_index do |homework_test|
@@ -5061,13 +5081,13 @@ def visable_course_homework course, type=0
if type != 0
homework_num = course.homework_commons.where(:homework_type => type).count
else
- homework_num = course.homework_commons.count
+ homework_num = course.homework_commons.where(:homework_type => [1, 4]).count
end
else
if type != 0
homework_num = course.homework_commons.where(:homework_type => type).where("publish_time <= '#{Time.now}'").count
else
- homework_num = course.homework_commons.where("publish_time <= '#{Time.now}'").count
+ homework_num = course.homework_commons.where("homework_type in '(1, 4)' and publish_time <= '#{Time.now}'").count
end
end
homework_num
@@ -5198,6 +5218,17 @@ def set_final_score homework,student_work
end
end
+# 实训作业的评分
+def set_shixun_final_score homework, student_work, answer_open_evaluation
+ unless student_work.work_status == 0
+ shixun = homework.homework_commons_shixuns.shixun
+ passed_count = answer_open_evaluation ? had_passed_changllenge_num(shixun, student_work.user) : had_passed_no_ans_changllenge_num(shixun, student_work.user)
+ final_score =(passed_count.to_f / shixun.challenges.count) * 100
+ student_work.final_score = format("%.2f",final_score.to_f)
+ score = student_work.final_score - student_work.late_penalty
+ student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
+ end
+end
def quote_resource_bank resource, course
atta = Attachment.new(:filename => resource.filename, :disk_filename => resource.disk_filename, :filesize => resource.filesize, :digest => resource.digest, :downloads => 0, :is_publish => 0,
diff --git a/app/models/challenge.rb b/app/models/challenge.rb
index db15195a1..dcc50dd43 100644
--- a/app/models/challenge.rb
+++ b/app/models/challenge.rb
@@ -34,6 +34,11 @@ class Challenge < ActiveRecord::Base
Challenge.where(:position => (self.position + 1), :shixun_id => self.shixun).first
end
+ def prev_challenge
+ render_404 if self.position == 1
+ Challenge.where(:position => (self.position - 1), :shixun_id => self.shixun).first
+ end
+
def last_challenge
render_404 if self.position < 2
position = self.position - 1
diff --git a/app/models/game.rb b/app/models/game.rb
index 03d1d58ae..9485f2a15 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -46,6 +46,14 @@ class Game < ActiveRecord::Base
return game
end
+ def prev_game
+ challenge = self.challenge
+ prev_challenge_id = challenge.prev_challenge
+ game = Game.where(:myshixun_id => self.myshixun_id, :challenge_id => prev_challenge_id).first
+ render_404 if game.nil?
+ return game
+ end
+
# 获取game最新的一条输出结果
def latest_output
outputs = Output.where(:game_id => self.id).order("created_at desc")
diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb
index 961aabc9d..49b9d9fb2 100644
--- a/app/models/homework_common.rb
+++ b/app/models/homework_common.rb
@@ -126,7 +126,7 @@ class HomeworkCommon < ActiveRecord::Base
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
if count == 0
ws = WechatService.new
- name = self.course.syllabus.nil? ? self.course.name : self.course.syllabus.title+" • "+self.course.name
+ name = self.course.course_list.nil? ? self.course.name : self.course.course_list_name+" • "+self.course.name
ws.homework_message_notice(m.user_id, "homework", self.id, "#{m.user.show_name},#{l(:label_new_homework_template)}", name, "新作业:"+ self.name.html_safe, "作业内容请点击“详情”查看。")
end
end
diff --git a/app/models/homework_detail_manual.rb b/app/models/homework_detail_manual.rb
index de289b54f..ffdeda060 100644
--- a/app/models/homework_detail_manual.rb
+++ b/app/models/homework_detail_manual.rb
@@ -1,7 +1,7 @@
#手动评分作业表
#comment_status: 0:挂起, 1:提交,2:补交(去掉),3:匿评中,4:申诉中,5:评阅中,6:已结束
class HomeworkDetailManual < ActiveRecord::Base
- attr_accessible :ta_proportion, :comment_status, :evaluation_start, :evaluation_end, :evaluation_num, :absence_penalty, :homework_common_id, :no_anon_penalty
+ attr_accessible :ta_proportion, :comment_status, :evaluation_start, :evaluation_end, :evaluation_num, :absence_penalty, :homework_common_id, :no_anon_penalty, :answer_open_evaluation
belongs_to :homework_common
end
diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb
index cf0579655..3986aedd1 100644
--- a/app/models/myshixun.rb
+++ b/app/models/myshixun.rb
@@ -1,6 +1,6 @@
# status 1:完成实训
class Myshixun < ActiveRecord::Base
- attr_accessible :description, :name, :parent_id, :user_id, :gpid, :forked_from, :visits, :is_public, :identifier
+ attr_accessible :description, :name, :parent_id, :user_id, :gpid, :forked_from, :visits, :is_public, :identifier, :shixun_id
# has_many :users, :through => :myshixun_members
has_many :myshixun_members, :dependent => :destroy
has_one :repository, :dependent => :destroy
@@ -32,7 +32,7 @@ class Myshixun < ActiveRecord::Base
time = 0
self.games.each do |game|
if game.status == 2
- time += (game.end_time -game.open_time).to_i > 0 ? (game.end_time -game.open_time).to_i : 0
+ time += (game.end_time.to_i - game.open_time.to_i) > 0 ? (game.end_time.to_i - game.open_time.to_i) : 0
end
end
time
diff --git a/app/models/output.rb b/app/models/output.rb
index 6c833b091..4ce462eff 100644
--- a/app/models/output.rb
+++ b/app/models/output.rb
@@ -1,6 +1,7 @@
class Output < ActiveRecord::Base
# attr_accessible :title, :body
# actual_output 编程题:实际输出, 选择题: 用户提交的答案(如: 014 对应用户选择为A B E)
+ # compile_success 1 表示程序未报错,有正常输出, 0.表示程序抛异常了,报错!
default_scope :order => 'query_index desc'
belongs_to :game
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 672696c27..a1be972e5 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -56,7 +56,10 @@ class Repository < ActiveRecord::Base
'path_encoding',
'log_encoding',
'is_default',
- 'type'
+ 'type',
+ 'myshixun_id',
+ 'shixun_id',
+ 'project_id'
safe_attributes 'url',
:if => lambda {|repository, user| repository.new_record?}
diff --git a/app/models/student_work.rb b/app/models/student_work.rb
index cc800cbb6..8d5cad339 100644
--- a/app/models/student_work.rb
+++ b/app/models/student_work.rb
@@ -13,7 +13,7 @@ class StudentWork < ActiveRecord::Base
# course's message
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
has_many :attachments, :dependent => :destroy
- has_one :myshixun
+ belongs_to :myshixun
scope :has_committed, lambda{where("work_status != 0 and work_status != 3")}
scope :all_commit, lambda{where("work_status != 0")}
@@ -51,7 +51,7 @@ class StudentWork < ActiveRecord::Base
#成绩计算
def set_final_score homework,student_work
- if homework && homework.homework_detail_manual
+ if homework && homework.homework_type != 4 && homework.homework_detail_manual
if homework.homework_type != 2 #非编程作业
if homework.teacher_priority == 1 #教师优先
if student_work.teacher_score
diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb
index 33c90383c..745f0e938 100644
--- a/app/services/courses_service.rb
+++ b/app/services/courses_service.rb
@@ -584,7 +584,7 @@ class CoursesService
type = "review_class_member"
end
- name = course.syllabus.nil? ? course.name : course.syllabus.title+" • "+course.name
+ name = course.course_list.nil? ? course.name : course.course_list_name+" • "+course.name
ws = WechatService.new
ws.class_notice user.id, type, course.id, title,name, user.show_name, format_time(Time.now), content, remark,uid
@@ -689,7 +689,7 @@ class CoursesService
rolename = role_ids.include?("7") ? "助教" : "教师"
content = current_user.show_name + "申请以"+rolename+"身份加入班级,等待您的审批。"
- name = course.syllabus.nil? ? course.name : course.syllabus.title+" • "+course.name
+ name = course.course_list.nil? ? course.name : course.course_list_name+" • "+course.name
ws = WechatService.new
ws.class_notice tea_user.id, "review_class_member", course.id, "班级成员审批通知。", name, tea_user.show_name, format_time(Time.now), content, "点击查看申请详情。",current_user.id
end
diff --git a/app/views/challenges/_edit_evaluating.html.erb b/app/views/challenges/_edit_evaluating.html.erb
index bbc795b3a..f7190a85e 100644
--- a/app/views/challenges/_edit_evaluating.html.erb
+++ b/app/views/challenges/_edit_evaluating.html.erb
@@ -35,9 +35,7 @@
测试集<%= index + 1 %> - <% if test.is_public? %> - - <% else %> + <% unless test.is_public? %> <% end %>
@@ -62,5 +60,14 @@ $("#edit_task_pass").click(function(){ $("#evaluating_edit").show(); $("#evaluating_show").hide(); + // 设置textarea的宽度到140以后出现滚动条 + var test_set_inputs = document.getElementsByName("test_set[input][]"); + var test_set_outputs = document.getElementsByName("test_set[output][]"); + if (test_set_inputs.length == test_set_outputs.length) { + for (var i = 0; i < test_set_inputs.length; i++) { + autoTextarea(test_set_inputs[i], 0, 140); + autoTextarea(test_set_outputs[i], 0, 140); + } + } }) \ No newline at end of file diff --git a/app/views/challenges/_evaluating_form.html.erb b/app/views/challenges/_evaluating_form.html.erb index 80ad18a7c..197860477 100644 --- a/app/views/challenges/_evaluating_form.html.erb +++ b/app/views/challenges/_evaluating_form.html.erb @@ -157,15 +157,6 @@ }); }); - // 设置textarea的宽度到140以后出现滚动条 - var test_set_inputs = document.getElementsByName("test_set[input][]"); - var test_set_outputs = document.getElementsByName("test_set[output][]"); - if (test_set_inputs.length == test_set_outputs.length) { - for (var i = 0; i < test_set_inputs.length; i++) { - autoTextarea(test_set_inputs[i], 0, 140); - autoTextarea(test_set_outputs[i], 0, 140); - } - } // 判断测试集是否锁定, 0未锁定,1锁定 function test_set_whether_lock(){ var lock = document.getElementsByName("test_set[lock][]"); diff --git a/app/views/challenges/edit.html.erb b/app/views/challenges/edit.html.erb index 1fb2c7480..69c247478 100644 --- a/app/views/challenges/edit.html.erb +++ b/app/views/challenges/edit.html.erb @@ -58,9 +58,11 @@
背景知识
- <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + <% if User.current.manager_of_shixun?(@shixun) %> 编辑 <% end %>已通过<%= had_passed_changllenge_count(shixun, student_work.user) %>关,共<%= shixun.challenges.count %>关 +
已通过<%= had_passed_changllenge_num(shixun, student_work.user) %>关,共<%= shixun.challenges.count %>关
-- 通关情况:<%= had_passed_changllenge_count(@shixun, @work.user).to_s+" / "+@shixun.challenges.count.to_s %>
- - 总耗时:<%=had_passed_changllenge_count(@shixun, @work.user) > 0 ? game_spend_time(total_spend_time @myshixun) : '- -' %>
+ - 通关情况:<%= had_passed_changllenge_num(@shixun, @work.user).to_s+" / "+@shixun.challenges.count.to_s %>
+ - 总耗时:<%=had_passed_changllenge_num(@shixun, @work.user) > 0 ? game_spend_time(@myshixun.total_spend_time) : '- -' %>
第<%= s_index + 1 %>章 <%= stage.name %> - <% if @subject.status == 0 && User.current.manager_of_subject?(@subject) %> + <% if User.current.manager_of_subject?(@subject) %> <% else %> @@ -74,7 +74,7 @@ <% if is_modify.blank? %> <%= link_to "模拟实战", shixun_exec_shixun_path(shixun), :class => "task-btn task-btn-green ", :style=>"display: none", :id => "shixun_operation", :target => "_blank" %> <% else %> - 模拟实战 + 模拟实战 <% end %> <% end %> <% end %> @@ -93,7 +93,7 @@ <% end %>
<%= shixun.language %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 3e9289d05..b3ffa379e 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -97,6 +97,7 @@
- <% update_visiti_count @user %> <%= @user.visits.to_i %> 次访问
diff --git a/config/routes.rb b/config/routes.rb index bc1a8e856..7a9413b83 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -140,6 +140,7 @@ RedmineApp::Application.routes.draw do match 'game_build', :via => [:get, :post] match 'get_waiting_time', :via => [:get, :post] match 'next_step', :via => [:get, :post] + match 'prev_step', :via => [:get, :post] match 'reset_original_code', :via => [:get, :post] match 'reset_new_code', :via => [:get, :post] get 'entry' diff --git a/db/migrate/20170907025441_add_compile_success_to_outputs.rb b/db/migrate/20170907025441_add_compile_success_to_outputs.rb new file mode 100644 index 000000000..ce0436c36 --- /dev/null +++ b/db/migrate/20170907025441_add_compile_success_to_outputs.rb @@ -0,0 +1,5 @@ +class AddCompileSuccessToOutputs < ActiveRecord::Migration + def change + add_column :outputs, :compile_success, :integer, :default => 1 + end +end diff --git a/db/migrate/20170907061723_modify_compile_success_to_outputs.rb b/db/migrate/20170907061723_modify_compile_success_to_outputs.rb new file mode 100644 index 000000000..c694d324a --- /dev/null +++ b/db/migrate/20170907061723_modify_compile_success_to_outputs.rb @@ -0,0 +1,13 @@ +class ModifyCompileSuccessToOutputs < ActiveRecord::Migration + def up + error_output = Output.find_by_sql("SELECT * FROM `outputs` where actual_output like '%error%'") + unless error_output.blank? + error_output.each do |e| + e.update_column(:compile_success, 0) + end + end + end + + def down + end +end diff --git a/db/migrate/20170908020109_add_answer_open_evaluation_to_homework_detail_manuals.rb b/db/migrate/20170908020109_add_answer_open_evaluation_to_homework_detail_manuals.rb new file mode 100644 index 000000000..a82ccd762 --- /dev/null +++ b/db/migrate/20170908020109_add_answer_open_evaluation_to_homework_detail_manuals.rb @@ -0,0 +1,5 @@ +class AddAnswerOpenEvaluationToHomeworkDetailManuals < ActiveRecord::Migration + def change + add_column :homework_detail_manuals, :answer_open_evaluation, :boolean, :default => false + end +end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index f55491879..36cff6723 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -2,6 +2,22 @@ namespace :homework_publishtime do desc "start publish homework and end homework" + def had_passed_changllenge_num_rake myshixun + if myshixun.nil? + 0 + else + myshixun.games.select{|game| game.status == 2}.count + end + end + + def had_passed_no_ans_changllenge_num_rake myshixun + if myshixun.nil? + 0 + else + myshixun.games.select{|game| game.status == 2 && game.answer_open == 0}.count + end + end + task :publish => :environment do Rails.logger.info("log--------------------------------homework_publish start") homework_commons = HomeworkCommon.includes(:homework_detail_manual).where("publish_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 0") @@ -43,13 +59,20 @@ namespace :homework_publishtime do end task :end => :environment do - # Rails.logger.info("log--------------------------------homework_publish_end start") - # homework_commons = HomeworkCommon.includes(:homework_detail_manual).where("end_time <= '#{Time.now}' and allow_late = 1 and homework_detail_manuals.comment_status = 1") - # homework_commons.each do |homework| - # homework_detail_manual = homework.homework_detail_manual - # homework_detail_manual.update_column('comment_status', 2) - # end - # Rails.logger.info("log--------------------------------homework_publish_end end") + Rails.logger.info("log--------------------------------homework_publish_end start") + homework_commons = HomeworkCommon.includes(:homework_detail_manual).where("homework_type = 4 and end_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 1") + homework_commons.each do |homework| + homework.homework_detail_manual.update_column("comment_status", 2) + shixun = homework.homework_commons_shixuns.shixun + homework.student_works.where("work_status != 0").each do |student_work| + passed_count = homework.homework_detail_manual.answer_open_evaluation ? had_passed_changllenge_num_rake(student_work.myshixun) : had_passed_no_ans_changllenge_num_rake(student_work.myshixun) + final_score =(passed_count.to_f / shixun.challenges.count) * 100 + student_work.update_column("final_score", format("%.2f",final_score.to_f)) + score = final_score - student_work.late_penalty + student_work.update_column("work_score", format("%.2f",(score < 0 ? 0 : score).to_f)) + end + end + Rails.logger.info("log--------------------------------homework_publish_end end") end task :archive => :environment do @@ -58,6 +81,17 @@ namespace :homework_publishtime do homework_commons.each do |homework| homework_detail_manual = homework.homework_detail_manual homework_detail_manual.update_column('comment_status', 6) + if homework.homework_type == 4 + shixun = homework.homework_commons_shixuns.shixun + homework.student_works.where("work_status != 0").each do |student_work| + passed_count = homework.homework_detail_manual.answer_open_evaluation ? had_passed_changllenge_num_rake(student_work.myshixun) : had_passed_no_ans_changllenge_num_rake(student_work.myshixun) + final_score =(passed_count.to_f / shixun.challenges.count) * 100 + student_work.final_score = format("%.2f",final_score.to_f) + score = student_work.final_score - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + student_work.save + end + end end Rails.logger.info("log--------------------------------homework_archive end") end diff --git a/public/javascripts/edu/application.js b/public/javascripts/edu/application.js index 7cb44a635..617a103e2 100644 --- a/public/javascripts/edu/application.js +++ b/public/javascripts/edu/application.js @@ -1220,7 +1220,7 @@ function search_course_ajax(str){ if($(".course_list_ul").find("li").length>5){ $(".course_list_ul").css("overflow-y","scroll"); } else{ - $(".course_list_ul").css("overflow-y","auto"); + $(".course_list_ul").css("overflow-y","hidden"); } } else{ $(".course_list_ul").hide(); diff --git a/public/javascripts/edu/base_edu.js b/public/javascripts/edu/base_edu.js index 1ebf1970d..48ea8ac4b 100644 --- a/public/javascripts/edu/base_edu.js +++ b/public/javascripts/edu/base_edu.js @@ -180,7 +180,27 @@ $(function(){ allowBlank:true, lang:'ch', format:'Y-m-d H:i', - validateOnBlur:false + validateOnBlur:false, + onSelectDate:function() { + if($.trim($("input[name='homework_end_time']").val()) == ""){ + var date = new Date(Date.parse($("input[name='homework_publish_time']").val().replace(/-/g, "/"))); + $("input[name='homework_end_time']").val(formate_time(new Date(date.setDate(date.getDate()+14)))); + } + if($.trim($("input[name='homework_archive_time']").val()) == ""){ + var date = new Date(Date.parse($("input[name='homework_end_time']").val().replace(/-/g, "/"))); + $("input[name='homework_archive_time']").val(formate_time(new Date(date.setMonth(date.getMonth()+1)))); + } + }, + onSelectTime:function() { + if($.trim($("input[name='homework_end_time']").val()) == ""){ + var date = new Date(Date.parse($("input[name='homework_publish_time']").val().replace(/-/g, "/"))); + $("input[name='homework_end_time']").val(formate_time(new Date(date.setDate(date.getDate()+14)))); + } + if($.trim($("input[name='homework_archive_time']").val()) == ""){ + var date = new Date(Date.parse($("input[name='homework_end_time']").val().replace(/-/g, "/"))); + $("input[name='homework_archive_time']").val(formate_time(new Date(date.setMonth(date.getMonth()+1)))); + } + } }); $("input[name='homework_end_time']").datetimepicker({ diff --git a/public/javascripts/edu/course.js b/public/javascripts/edu/course.js index 407cea3a3..db3dba311 100644 --- a/public/javascripts/edu/course.js +++ b/public/javascripts/edu/course.js @@ -133,58 +133,32 @@ $(function() { } }); - -// var changeColor = function(c){ -// if(c.find(".blue").css("display") == "none") { -// c.find(".blue").show(); -// c.find(".grey").hide(); -// c.find("input").attr("checked", "checked"); -// -// } else { -// c.find(".blue").hide(); -// c.find(".grey").show(); -// c.find("input").removeAttr("checked"); -// -// } -// }; -// $(".open-select").click(function() { -// changeColor($(this)); -// if($("#allselect").find("input").is(':checked')) { -// //console.log(1); -// $(".member .student .newstudent .open-select").find("input").attr("checked", "checked"); -// $(".member .student .newstudent .open-select").find(".blue").show(); -// $(".member .student .newstudent .open-select").find(".grey").hide(); -// } -// var $length = $(".member .student .newstudent .open-select input").length; -// var flag = true; -// for(i = 0; i < $length; i++) { -// var $b = $(".member .student .newstudent .open-select input").eq(i); -// if(! $b.is(':checked')) { -// //console.log(1) -// flag = false; -// break; -// } -// if(flag) { -// $("#allselect").find("input").attr("checked", "checked"); -// $("#allselect").find(".blue").show(); -// $("#allselect").find(".grey").hide(); -// } -// } -// }); -// var RadioButton = function(b,c){ -// $(b).find(".grey").show(); -// $(b).find(".blue").hide(); -// $(b).find("input").removeAttr("checked"); -// changeColor(c); -// }; -// $(".single-choice1").click(function(){ -// -// RadioButton(".single-choice1",$(this)); -// }); -// $(".single-choice2").click(function(){ -// -// RadioButton(".single-choice2",$(this)); -// }); + // 课堂设置 + $("#edit_course_list").on('input', function(e){ + throttle(search_course_list, window, e); + }); + $("#edit_course_list").on('click', function (e) { + if ($("#edit_course_list").val().trim() != '') { //如果已经有id了。肯定存在,不用去找了。 + event.stopPropagation(); + return; + } else{ + event.stopPropagation(); + search_course_ajax(''); + } + }); + $("#edit_course_list").on('blur', function(e){ + if($("#edit_course_name").val() == ""){ + $("#edit_course_name").val($("#edit_course_list").val()); + } else{ + if($("#edit_course_name").val().indexOf(course_list_name) == 0){ + $("#edit_course_name").val($("#edit_course_name").val().replace(course_list_name, $("#edit_course_list").val())); + } else{ + $("#edit_course_name").val($("#edit_course_list").val() + $("#edit_course_name").val()); + } + } + course_list_name = $("#edit_course_list").val(); + regex_course_name('edit'); + }); }); function add_new_group(id){ diff --git a/public/javascripts/edu/edu_tpi.js b/public/javascripts/edu/edu_tpi.js index c000ceba9..d9b011ad7 100644 --- a/public/javascripts/edu/edu_tpi.js +++ b/public/javascripts/edu/edu_tpi.js @@ -110,6 +110,14 @@ $(function(){ }); // end + // 上一关增加loading效果 + $("#prev_step").live("click", function(){ + nNext = $("#prev_step_area"); + html = "上一关
";
+ nNext.html(html);
+ });
+ // end
+
});
// 查看参考答案
@@ -327,6 +335,7 @@ function setupAjaxIndicatorBase() {
|| settings.url.match(/game_status/)
|| settings.url.match(/refresh_game_list/)
|| settings.url.match(/next_step/)
+ || settings.url.match(/prev_step/)
|| settings.url.match(/open_webssh/)
|| settings.url.match(/repository/)
)){
@@ -368,7 +377,6 @@ function code_evaluation(test_sets,
/**
* Created by wang on 2017/8/9.
*/
-
var $EffectDisplay , $b, $TestResult, $d, $e, $f, $g, $h, $EvaluationInformation , $n;
// 第一块 效果显示
$EffectDisplay = "
"; @@ -380,6 +388,7 @@ function code_evaluation(test_sets, "" + "" + + "" + "" + ( test_sets[i].output == null ? "空" : test_sets[i].output.replace(/\r\n/g, "
" + + "").replace(/ /g, "") ) + "
" + ( test_sets[i].output == null ? "空" : test_sets[i].output.replace(/\r\n/g, "
" + "").replace(/\t/g, " ").replace(/ /g, "") ) + "
" + (test_sets[i].actual_output == null ? "空" : test_sets[i].actual_output.replace(/\r\n/g, "
" + + "").replace(/ /g, "")) + "
" + (test_sets[i].actual_output == null ? "空" : (test_sets[i].compile_success == "1" ? test_sets[i].actual_output.replace(/\r\n/g, "
" + "").replace(/ /g, "") : test_sets[i].actual_output.replace(/\r\n/g, "
"))) + "