diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 1457cafcc..9ce95843d 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -767,8 +767,10 @@ class GamesController < ApplicationController # 记录实训花费的时间 # REDO:需要添加详细的说明 def cost_time - cost_time = params[:time].to_i - @game.update_attribute(:cost_time, cost_time) + #return if @game.status >= 2 + cost_time = (Time.now.to_i - @game.play_time.to_i) + @game.cost_time.to_i + @game.update_attributes(cost_time: cost_time, play_sign: 0) + render_ok end # 同步challenge的更新时间 @@ -938,6 +940,13 @@ class GamesController < ApplicationController game.update_attributes(status: 0, open_time: Time.now) if game.open_time.blank? || game.status == 3 # 开启实训更新myshixuns的时间,方便跟踪用于的学习进度。 game.myshixun.update_column(:updated_at, Time.now) + # 如果异常关闭的话 更新完关卡的时间 + if game.status < 2 && @game.play_sign == 0 + @game.update_attributes(play_time: Time.now, play_sign: 1) + elsif game.status < 2 && @game.play_sign == 1 + cost_time = Time.now.to_i - (@game.play_time.presence || Time.now).to_i + cost_time.to_i + @game.update_attributes(play_time: Time.now, cost_time: cost_time, play_sign: 1) + end end # vnc连接 diff --git a/app/models/game.rb b/app/models/game.rb index 7aa2e7264..d82392a59 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -3,7 +3,7 @@ # modify_time: 与challenges表的modify_time联合使用,2个字段一致,则标识测试集未修改,反之,被修改 # answer_open: 查看查看答案的深度, 0: 未查看过答案, 其他数值与challenge_answer的level值相关 # answer_deduction: 查看答案扣分的百分比;如 查看答案 扣除70% -# +#play_sign 与play_time: sign记录浏览器是否正常关闭, 0表示正常,1表示非正常; play_time:表示游玩时间 class Game < ApplicationRecord default_scope { order("games.created_at desc") } diff --git a/app/views/games/cost_time.json.jbuilder b/app/views/games/cost_time.json.jbuilder deleted file mode 100644 index efe6fc949..000000000 --- a/app/views/games/cost_time.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.game @game \ No newline at end of file diff --git a/db/migrate/20191119021844_add_close_browser_time_for_games.rb b/db/migrate/20191119021844_add_close_browser_time_for_games.rb new file mode 100644 index 000000000..f1d694fea --- /dev/null +++ b/db/migrate/20191119021844_add_close_browser_time_for_games.rb @@ -0,0 +1,6 @@ +class AddCloseBrowserTimeForGames < ActiveRecord::Migration[5.2] + def change + add_column :games, :play_time, :timestamp + add_column :games, :play_sign, :integer, :default => 0 + end +end