dev_auth
cxt 5 years ago
parent be0dabc7ec
commit 6e47e7a52b

@ -60,7 +60,7 @@ class Admins::CompetitionStagesController < Admins::BaseController
end
# 如果计算的是最后一个阶段,则同时计算总成绩(只有一个阶段则不需计算)
if current_stage.max_end_time == current_competition.max_stage_end_time && current_competition.competition_stages.size != 0
if current_stage.max_end_time == current_competition.max_stage_end_time && current_competition.competition_stages.size > 1
calculate_total_score current_competition
end
end
@ -174,6 +174,7 @@ class Admins::CompetitionStagesController < Admins::BaseController
end
def calculate_total_score competition
competition.competition_scores.where(competition_stage_id: 0).destroy_all
competition.competition_teams.each do |team|
total_score = 0
total_time = 0
@ -183,8 +184,11 @@ class Admins::CompetitionStagesController < Admins::BaseController
total_score += stage_score.try(:score).to_f * stage.score_rate
total_time += stage_score.try(:cost_time).to_i
end
CompetitionScore.create!(user_id: team.user_id, competition_team_id: team.id, competition_id: competition.id,
competition_stage_id: 0, score: total_score, cost_time: total_time)
unless team.competition_scores.exists?(competition_id: competition.id, competition_stage_id: 0)
CompetitionScore.create!(user_id: team.user_id, competition_team_id: team.id, competition_id: competition.id,
competition_stage_id: 0, score: total_score, cost_time: total_time)
end
end
end
end

@ -39,9 +39,11 @@ module CompetitionsHelper
stages = []
statistic_stages = competition.competition_stages.where("score_rate > 0")
end_time = competition.max_stage_end_time || competition.end_time
if end_time && end_time < Time.now
stages << {id: nil, name: statistic_stages.size > 1 ? "总排行榜" : "排行榜", rate: 1.0, start_time: competition.start_time, end_time: competition.end_time}
unless statistic_stages.size == 1
end_time = competition.max_stage_end_time || competition.end_time
if end_time && end_time < Time.now
stages << {id: nil, name: statistic_stages.size > 1 ? "总排行榜" : "排行榜", rate: 1.0, start_time: competition.start_time, end_time: competition.end_time}
end
end
statistic_stages.each do |stage|

Loading…
Cancel
Save