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