1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:07:25 +08:00

Simplify fill logic and add xmldoc

This commit is contained in:
Dean Herbert 2020-11-24 13:10:11 +09:00
parent 37ea65de2a
commit 44ca67c534

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -52,32 +53,30 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
Hide(); Hide();
} }
private UserHistoryCount[] fillZeroValues(UserHistoryCount[] values) /// <summary>
/// Add entries for any missing months (filled with zero values).
/// </summary>
private UserHistoryCount[] fillZeroValues(UserHistoryCount[] historyEntries)
{ {
var newValues = new List<UserHistoryCount> { values[0] }; var filledHistoryEntries = new List<UserHistoryCount>();
var newLast = values[0];
for (int i = 1; i < values.Length; i++) foreach (var entry in historyEntries)
{ {
while (hasMissingDates(newLast, values[i])) var lastFilled = filledHistoryEntries.LastOrDefault();
while (lastFilled?.Date.AddMonths(1) < entry.Date)
{ {
newValues.Add(newLast = new UserHistoryCount filledHistoryEntries.Add(lastFilled = new UserHistoryCount
{ {
Count = 0, Count = 0,
Date = newLast.Date.AddMonths(1) Date = lastFilled.Date.AddMonths(1)
}); });
} }
newValues.Add(newLast = values[i]); filledHistoryEntries.Add(entry);
} }
return newValues.ToArray(); return filledHistoryEntries.ToArray();
static bool hasMissingDates(UserHistoryCount prev, UserHistoryCount current)
{
var possibleCurrent = prev.Date.AddMonths(1);
return possibleCurrent < current.Date;
}
} }
protected abstract UserHistoryCount[] GetValues(User user); protected abstract UserHistoryCount[] GetValues(User user);