From aba87a146a8796cd04806a1d30e6e0a44747e3c6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 19 Nov 2019 10:38:50 +0800 Subject: [PATCH 1/6] =?UTF-8?q?tpi=E8=80=97=E6=97=B6=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 6 ++++-- app/views/games/cost_time.json.jbuilder | 1 - .../20191119021843_add_close_browser_time_for_games.rb | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) delete mode 100644 app/views/games/cost_time.json.jbuilder create mode 100644 db/migrate/20191119021843_add_close_browser_time_for_games.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 1457cafcc..d4275b600 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -767,8 +767,9 @@ 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.close_browse_time.to_i + @game.update_attributes(close_browse_time: Time.now, cost_time: cost_time) end # 同步challenge的更新时间 @@ -938,6 +939,7 @@ 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) + @game.update_attribute(:close_browse_time, Time.now) if game.status < 2 && @game.close_browse_time.nil? end # vnc连接 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/20191119021843_add_close_browser_time_for_games.rb b/db/migrate/20191119021843_add_close_browser_time_for_games.rb new file mode 100644 index 000000000..3bd40b679 --- /dev/null +++ b/db/migrate/20191119021843_add_close_browser_time_for_games.rb @@ -0,0 +1,5 @@ +class AddCloseBrowserTimeForGames < ActiveRecord::Migration[5.2] + def change + add_column :games, :close_browse_time, :timestamp + end +end From 361647cf2341fba9c4857d534e349e5a796683e9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 19 Nov 2019 11:07:52 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E8=80=97=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index d4275b600..58ab09820 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -767,8 +767,8 @@ class GamesController < ApplicationController # 记录实训花费的时间 # REDO:需要添加详细的说明 def cost_time - return if @game.status >= 2 - cost_time = Time.now.to_i - @game.close_browse_time.to_i + #return if @game.status >= 2 + cost_time = (Time.now.to_i - @game.close_browse_time.to_i) + @game.cost_time.to_i @game.update_attributes(close_browse_time: Time.now, cost_time: cost_time) end From 6098ecd3ca4ee06760eb54d6cac03faba13e19bd Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 19 Nov 2019 11:47:57 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 12 +++++++++--- ...0191119021843_add_close_browser_time_for_games.rb | 5 ----- ...0191119021844_add_close_browser_time_for_games.rb | 7 +++++++ 3 files changed, 16 insertions(+), 8 deletions(-) delete mode 100644 db/migrate/20191119021843_add_close_browser_time_for_games.rb create mode 100644 db/migrate/20191119021844_add_close_browser_time_for_games.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 58ab09820..1a6fe8ac7 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -768,8 +768,8 @@ class GamesController < ApplicationController # REDO:需要添加详细的说明 def cost_time #return if @game.status >= 2 - cost_time = (Time.now.to_i - @game.close_browse_time.to_i) + @game.cost_time.to_i - @game.update_attributes(close_browse_time: Time.now, cost_time: cost_time) + cost_time = (Time.now.to_i - @game.play_time.to_i) + @game.cost_time.to_i + @game.update_attributes(play_time: Time.now, cost_time: cost_time, play_sign: 0) end # 同步challenge的更新时间 @@ -939,7 +939,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) - @game.update_attribute(:close_browse_time, Time.now) if game.status < 2 && @game.close_browse_time.nil? + # 如果异常关闭的话 更新完关卡的时间 + 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/db/migrate/20191119021843_add_close_browser_time_for_games.rb b/db/migrate/20191119021843_add_close_browser_time_for_games.rb deleted file mode 100644 index 3bd40b679..000000000 --- a/db/migrate/20191119021843_add_close_browser_time_for_games.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddCloseBrowserTimeForGames < ActiveRecord::Migration[5.2] - def change - add_column :games, :close_browse_time, :timestamp - end -end 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..bb603f8be --- /dev/null +++ b/db/migrate/20191119021844_add_close_browser_time_for_games.rb @@ -0,0 +1,7 @@ +class AddCloseBrowserTimeForGames < ActiveRecord::Migration[5.2] + def change + remove_column :games,:close_browse_time + add_column :games, :play_time, :timestamp + add_column :games, :play_sign, :integer, :default => 0 + end +end From e9a27be9df6c32e0c977b52ac961fbe8a9613679 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 19 Nov 2019 11:52:06 +0800 Subject: [PATCH 4/6] =?UTF-8?q?TPI=E7=8E=A9=E7=9A=84=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- app/models/game.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 1a6fe8ac7..23c72c5dc 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -769,7 +769,7 @@ class GamesController < ApplicationController def 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(play_time: Time.now, cost_time: cost_time, play_sign: 0) + @game.update_attributes(cost_time: cost_time, play_sign: 0) end # 同步challenge的更新时间 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") } From f8253373e48767f33126177454bf3a234c68a952 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 19 Nov 2019 11:56:52 +0800 Subject: [PATCH 5/6] 1 --- app/controllers/games_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 23c72c5dc..9ce95843d 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -770,6 +770,7 @@ class GamesController < ApplicationController #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的更新时间 From 4b28cf26645a2ae07725330c7187575d2cdae02b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 19 Nov 2019 13:46:37 +0800 Subject: [PATCH 6/6] fixbug --- db/migrate/20191119021844_add_close_browser_time_for_games.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/migrate/20191119021844_add_close_browser_time_for_games.rb b/db/migrate/20191119021844_add_close_browser_time_for_games.rb index bb603f8be..f1d694fea 100644 --- a/db/migrate/20191119021844_add_close_browser_time_for_games.rb +++ b/db/migrate/20191119021844_add_close_browser_time_for_games.rb @@ -1,6 +1,5 @@ class AddCloseBrowserTimeForGames < ActiveRecord::Migration[5.2] def change - remove_column :games,:close_browse_time add_column :games, :play_time, :timestamp add_column :games, :play_sign, :integer, :default => 0 end