challenge列表的一些统计

This commit is contained in:
huang 2017-03-30 15:49:28 +08:00
parent ddf7a6e4a0
commit 15872d0da5
3 changed files with 9 additions and 12 deletions

View File

@ -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)

View File

@ -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
# 测评次数

View File

@ -27,8 +27,10 @@
<% end %>
<div class="cl"></div>
<p class="ml15 mt15 color-grey">
<!--<span class=" mr10">平均表现:<%#= shixun_avg_score(@shixun, challenge.position).avg_score.to_i %>分 </span>-->
<span class=" mr10">正在挑战:<%= shixun_running(@shixun, challenge.position) %></span>
<span class=" mr10">完成挑战:<%= shixun_done(@shixun, challenge.position) %></span>
<span class=" mr10">最佳表现:<%= top_score(@shixun, challenge.position) %>分</span>
<span class=" mr10">平均表现:<%= shixun_avg_score(@shixun, challenge.position).to_i %>分 </span>
</p>
</div>
<script>