diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 47383d628..993dd72d1 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -22,22 +22,17 @@ class GamesController < ApplicationController # path:"" && path: @game.path def show @game_challenge = @game.challenge - logger.info("*** ###############") game_path = (@game_challenge.path.blank? ? @path : @game_challenge.path.strip) @rev = @rev.nil? ? "master" : @rev @git_url = git_repository_url(@myshixun, "Myshixun") - logger.info("*** git_url is###{@git_url}") @type = params[:type] - logger.info("*** ###{@rev}#######{@path}") # 默认打开文件 if @path == "" && !game_path.nil? && !@repository.cat(game_path, @rev).blank? && @type != "root" @path = game_path @file_open = true @content = @repository.cat(@path, @rev) - logger.info("content result is ###############{@content}") else @entries = @repository.entries(@path, @rev) - logger.info("result is ###############{@entries.first.try(:path)}") end @latest_output = @game.latest_output.try(:out_put) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8c48d8d5f..9d5eca2c3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,22 +37,22 @@ module ApplicationHelper # 定义实训相关方法 # myshixun 最高分 def top_score shixun, position - Game.find_by_sql("SELECT max(final_score) as score FROM `games` where stage=#{position} and myshixun_id in (SELECT id FROM `myshixuns` where parent_id=#{shixun.id})").first + Game.find_by_sql("SELECT max(final_score) as top_score FROM `games` g, `challenges` c where g.challenge_id = c.id and c.position=#{position} and g.myshixun_id in (SELECT id FROM `myshixuns` ms where ms.shixun_id=#{shixun.id})").first.try(:top_score) end # 实训平均分 def shixun_avg_score shixun, position - Game.find_by_sql("SELECT avg(final_score) as avg_score FROM `games` where stage=#{position} and myshixun_id in (SELECT id FROM `myshixuns` where parent_id=#{shixun.id})") + Game.find_by_sql("SELECT avg(g.final_score) as avg_score FROM `games` g, `challenges` c where g.challenge_id=c.id and c.position=#{position} and g.myshixun_id in (SELECT id FROM `myshixuns` ms where ms.shixun_id=#{shixun.id})").first.try(:avg_score) end # 正在进行中任务 def shixun_running shixun, position - Myshixun.find_by_sql("SELECT * FROM `myshixuns` ms, `games` g where g.myshixun_id = ms.id and shixun_id =#{shixun.id} and g.stage=#{position} and (g.status=0 or g.status=1);").count + Shixun.find_by_sql("SELECT count(*) as count FROM `myshixuns` ms, `games` g, `challenges` c where g.myshixun_id = ms.id and ms.shixun_id =#{shixun.id} and g.challenge_id=c.id and c.position=#{position} and g.status in ('0','1');").first.try(:count) end # 已完成任务 def shixun_done shixun, position - Myshixun.find_by_sql("SELECT * FROM `myshixuns` ms, `games` g where g.myshixun_id = ms.id and shixun_id =#{shixun.id} and g.stage=#{position} and g.status=2;").count + Shixun.find_by_sql("SELECT count(*) as count FROM `myshixuns` ms, `games` g, `challenges` c where g.myshixun_id = ms.id and ms.shixun_id =#{shixun.id} and g.challenge_id=c.id and c.position=#{position} and g.status=2;").first.try(:count) end # 测评次数 diff --git a/app/views/challenges/_content_list.html.erb b/app/views/challenges/_content_list.html.erb index df948737a..511c3bae9 100644 --- a/app/views/challenges/_content_list.html.erb +++ b/app/views/challenges/_content_list.html.erb @@ -21,14 +21,16 @@ <% end %> - +
<% end %>- - + 正在挑战:<%= shixun_running(@shixun, challenge.position) %> + 完成挑战:<%= shixun_done(@shixun, challenge.position) %> + 最佳表现:<%= top_score(@shixun, challenge.position) %>分 + 平均表现:<%= shixun_avg_score(@shixun, challenge.position).to_i %>分