You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
module CompetitionsHelper
|
|
|
|
def chart_school_str user_ids
|
|
|
|
chart_school_name = ""
|
|
|
|
chart_school_name = School.where(id: UserExtension.where(user_id: user_ids).pluck(:school_id).uniq).pluck(:name).join("、")
|
|
|
|
end
|
|
|
|
|
|
|
|
# 耗时:小时、分、秒 00:00:00
|
|
|
|
# 小于1秒钟则不显示
|
|
|
|
def com_spend_time time
|
|
|
|
hour = time / (60*60)
|
|
|
|
min = time % (60*60) / 60
|
|
|
|
sec = time % (60*60) % 60
|
|
|
|
hour_str = "00"
|
|
|
|
min_str = "00"
|
|
|
|
sec_str = "00"
|
|
|
|
if hour >= 1 && hour < 10
|
|
|
|
hour_str = "0#{hour}"
|
|
|
|
elsif hour >= 10
|
|
|
|
hour_str = "#{hour}"
|
|
|
|
end
|
|
|
|
|
|
|
|
if min >= 1 && min < 10
|
|
|
|
min_str = "0#{min}"
|
|
|
|
elsif min >= 10
|
|
|
|
min_str = "#{min}"
|
|
|
|
end
|
|
|
|
|
|
|
|
if sec >= 1 && sec < 10
|
|
|
|
sec_str = "0#{sec}"
|
|
|
|
elsif sec >= 10
|
|
|
|
sec_str = "#{sec}"
|
|
|
|
end
|
|
|
|
|
|
|
|
time = "#{hour_str} : #{min_str} : #{sec_str}"
|
|
|
|
return time
|
|
|
|
end
|
|
|
|
|
|
|
|
def chart_stages competition
|
|
|
|
stages = []
|
|
|
|
statistic_stages = competition.competition_stages.where("score_rate > 0")
|
|
|
|
if competition.end_time && competition.end_time < Time.now && statistic_stages.size > 1
|
|
|
|
stages << {id: nil, name: "总排行榜", rate: 1.0, start_time: competition.start_time, end_time: competition.end_time}
|
|
|
|
end
|
|
|
|
|
|
|
|
statistic_stages.each do |stage|
|
|
|
|
if stage.max_end_time && stage.max_end_time < Time.now
|
|
|
|
stages << {id: stage.id, name: "#{stage.name}排行榜", rate: stage.score_rate, start_time: stage.min_start_time, end_time: stage.max_end_time}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
stages = stages.sort { |a, b| b[:end_time] <=> a[:end_time] } if stages.size > 0
|
|
|
|
return stages
|
|
|
|
end
|
|
|
|
end
|