Skip to content

Commit

Permalink
Improve legibility of LINQ queries for recent/upcoming matches
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Aug 31, 2023
1 parent 5fa31b7 commit 7aa1505
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,25 @@ protected override void LoadComplete()

private void refresh()
{
IEnumerable<TournamentMatch> upcoming =
allMatches
.Where(p => !p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4);
const int days_for_displays = 4;

IEnumerable<ConditionalTournamentMatch> conditionals =
allMatches
.Where(p => !p.Completed.Value && (p.Team1.Value == null || p.Team2.Value == null) && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4)
.Where(m => !m.Completed.Value && (m.Team1.Value == null || m.Team2.Value == null) && Math.Abs(m.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < days_for_displays)
.SelectMany(m => m.ConditionalMatches.Where(cp => m.Acronyms.TrueForAll(a => cp.Acronyms.Contains(a))));

upcoming = upcoming.Concat(conditionals);
upcoming = upcoming.OrderBy(p => p.Date.Value).Take(8);
IEnumerable<TournamentMatch> upcoming =
allMatches
.Where(m => !m.Completed.Value && m.Team1.Value != null && m.Team2.Value != null && Math.Abs(m.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < days_for_displays)
.Concat(conditionals)
.OrderBy(m => m.Date.Value)
.Take(8);

var recent =
allMatches
.Where(m => m.Completed.Value && m.Team1.Value != null && m.Team2.Value != null && Math.Abs(m.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < days_for_displays)
.OrderByDescending(m => m.Date.Value)
.Take(8);

ScheduleContainer comingUpNext;

Expand All @@ -146,12 +154,7 @@ private void refresh()
{
RelativeSizeAxes = Axes.Both,
Width = 0.4f,
ChildrenEnumerable = allMatches
.Where(p => p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null
&& Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4)
.OrderByDescending(p => p.Date.Value)
.Take(8)
.Select(p => new ScheduleMatch(p))
ChildrenEnumerable = recent.Select(p => new ScheduleMatch(p))
},
new ScheduleContainer("upcoming matches")
{
Expand Down

0 comments on commit 7aa1505

Please sign in to comment.