Implement projected time
This commit is contained in:
@@ -9,24 +9,38 @@ module CompletionsConcern
|
||||
end
|
||||
|
||||
def display_time(time)
|
||||
if time == nil
|
||||
return ""
|
||||
end
|
||||
h = time / 3600
|
||||
m = (time % 3600) / 60
|
||||
s = (time % 3600) % 60
|
||||
if h > 0
|
||||
return h.to_s + ":" + pad(m) + ":" + pad(s)
|
||||
elsif m > 0
|
||||
return m.to_s + ":" + pad(s)
|
||||
end
|
||||
s.to_s
|
||||
m.to_s + ":" + pad(s)
|
||||
end
|
||||
|
||||
def extend_completions!(contestant)
|
||||
current_time_from_start = 0
|
||||
contestant.completions.order(:time_seconds).each do |completion|
|
||||
completion.update(display_time_from_start: display_time(completion.time_seconds),
|
||||
display_relative_time: display_time(completion.time_seconds - current_time_from_start))
|
||||
current_time_from_start = completion.time_seconds
|
||||
completions = contestant.completions
|
||||
puzzles = contestant.contest.puzzles
|
||||
if puzzles.length > 1
|
||||
current_time_from_start = 0
|
||||
completions.order(:time_seconds).each do |completion|
|
||||
completion.update(display_time_from_start: display_time(completion.time_seconds),
|
||||
display_relative_time: display_time(completion.time_seconds - current_time_from_start))
|
||||
current_time_from_start = completion.time_seconds
|
||||
end
|
||||
contestant.update(display_time: display_time(current_time_from_start), time_seconds: current_time_from_start)
|
||||
elsif puzzles.length == 1 && completions.length >= 1
|
||||
if completions[0].remaining_pieces != nil
|
||||
contestant.update(
|
||||
display_time: "#{display_time(completions[0].time_seconds)} - #{puzzles[0].pieces - completions[0].remaining_pieces}p",
|
||||
time_seconds: completions[0].projected_time
|
||||
)
|
||||
else
|
||||
contestant.update(display_time: display_time(completions[0].time_seconds), time_seconds: completions[0].time_seconds)
|
||||
end
|
||||
end
|
||||
contestant.update(display_time: display_time(current_time_from_start), time_seconds: current_time_from_start)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user