The reset history builds on #13's panel and day budgets, so its PR stacks on #15. Conflicts: D8 lists both the per-day budgets and the reset history. The weight helper from #13 now takes the instance's exclusive token end, so the day baseline counts tokens like its instance does, without the boundary hour a later instance owns (D7). Refs #14
This commit is contained in:
@@ -28,8 +28,9 @@ public static partial class LimitAnalysis
|
||||
var observations = spans.SelectMany(s => s.Samples).ToArray();
|
||||
var weighted = WeightedTokens(window, tokens);
|
||||
var currentSpan = spans.Single(g => SameInstance(g.Anchor, window));
|
||||
var currentTokenEnd = TokenEnd(currentSpan.End, spans);
|
||||
var current = BuildInstance(window, observations, weighted, currentSpan.Start, currentSpan.End,
|
||||
now < currentSpan.End ? now : currentSpan.End, null, TokenEnd(currentSpan.End, spans), now, zone);
|
||||
now < currentSpan.End ? now : currentSpan.End, null, currentTokenEnd, now, zone);
|
||||
var realPast = spans.Where(g => g.Start < currentSpan.Start).OrderByDescending(g => g.Start).ToArray();
|
||||
var past = new List<LimitInstance>();
|
||||
var realIndex = 0;
|
||||
@@ -53,8 +54,7 @@ public static partial class LimitAnalysis
|
||||
if (length > TimeSpan.FromDays(1))
|
||||
{
|
||||
var today = current.Days.FirstOrDefault(d => d.IsToday);
|
||||
days = new(current.Days, past.FirstOrDefault()?.Days ?? [], today?.Used, 100 / length.TotalDays,
|
||||
reset > now ? (100 - window.UsedPercent) / (reset - now).TotalDays : null, today?.Origin ?? UseOrigin.Measured);
|
||||
days = PlanDays(window, current, past.FirstOrDefault(), today, observations, weighted, currentTokenEnd, now, zone);
|
||||
}
|
||||
return new(current, past, days);
|
||||
}
|
||||
@@ -63,12 +63,7 @@ public static partial class LimitAnalysis
|
||||
(DateTimeOffset Time, double Weight)[] weighted, DateTimeOffset start, DateTimeOffset end, DateTimeOffset until,
|
||||
double? fallback, DateTimeOffset tokenEnd, DateTimeOffset now, TimeZoneInfo zone)
|
||||
{
|
||||
double Weight(DateTimeOffset from, DateTimeOffset to)
|
||||
{
|
||||
var hour = Hour(from < start ? start : from);
|
||||
var exclusiveEnd = tokenEnd;
|
||||
return weighted.Where(p => p.Time >= hour && p.Time < to && p.Time < exclusiveEnd).Sum(p => p.Weight);
|
||||
}
|
||||
double Weight(DateTimeOffset from, DateTimeOffset to) => WeightedTokens(weighted, start, tokenEnd, from, to);
|
||||
var measured = Instance(anchor, observations).Where(s => s.SampleTime >= start - TimeSpan.FromMinutes(15) && s.SampleTime <= until)
|
||||
.GroupBy(s => s.SampleTime).Select(g => g.Last()).OrderBy(s => s.SampleTime).ToArray();
|
||||
var last = measured.LastOrDefault();
|
||||
|
||||
Reference in New Issue
Block a user