Skip to content

Commit d0ddeb7

Browse files
committed
fix: solve group matches issue
1 parent 355ada7 commit d0ddeb7

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

app/controllers/cup_controller.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,14 @@ def results
6868
@h2h = build_h2h(@schedule)
6969
@streak_map = build_streak_map(@schedule)
7070

71-
tbd = ->(m) { m["Team1"].to_s.strip.downcase == "tbd" || m["Team2"].to_s.strip.downcase == "tbd" }
71+
@group_matches = @schedule.reject { |m| playoff_phase?(m["Phase"]) || tbd_match?(m) }
72+
@playoff_matches = @schedule.select { |m| playoff_phase?(m["Phase"]) || tbd_match?(m) }
7273

73-
@group_matches = @schedule.reject { |m| playoff_phase?(m["Phase"]) || tbd.(m) }
74-
@playoff_matches = @schedule.select { |m| playoff_phase?(m["Phase"]) || tbd.(m) }
75-
76-
# Group by calendar date (YYYY-MM-DD) and assign sequential day numbers
77-
grouped_by_date = @group_matches
78-
.group_by { |m| m["DateTime_UTC"].to_s[0, 10] }
79-
.sort.to_h
80-
day_index = grouped_by_date.keys.each_with_index.to_h
81-
@group_by_day = grouped_by_date.transform_keys { |date| day_index[date] + 1 }
74+
# Group by calendar date so each real day gets its own section
75+
sorted_dates = @group_matches.map { |m| m["DateTime_UTC"].to_s[0, 10] }.uniq.sort
76+
@group_by_day = sorted_dates.each_with_index.each_with_object({}) do |(date, i), h|
77+
h[i + 1] = @group_matches.select { |m| m["DateTime_UTC"].to_s.start_with?(date) }
78+
end
8279

8380
@playoff_by_phase = @playoff_matches
8481
.group_by { |m| m["Phase"] }
@@ -188,6 +185,10 @@ def parse_utc(dt_str)
188185
nil
189186
end
190187

188+
def tbd_match?(match)
189+
match["Team1"].to_s.strip.casecmp?("tbd") || match["Team2"].to_s.strip.casecmp?("tbd")
190+
end
191+
191192
def playoff_phase?(phase)
192193
phase.to_s.match?(/quarter|semi|final/i)
193194
end

0 commit comments

Comments
 (0)