core: plan the daily budget per day, start forecasts at 2 % and follow the limit week
agent-review agent review: fail
agent-review agent review: fail
The budget was the rest of the week over the time left, so each use today lowered it and a partial first day was held to a full day. Now each day of the instance has its share, its even pace and its budget. Today's budget starts from the use at the day start and does not move with today's use (D7). Forecasts start at 2 % of a window, so an early reset no longer hides them for most of a day. Limit tiles of one kind show the same rows, with placeholders that say why a value is missing. The week chart draws per-day steps and marks the instance start and reset (D8). Week token totals follow the provider's limit week and say since when, with the calendar week as fallback (D9). Refs #13
This commit is contained in:
@@ -245,17 +245,18 @@ public sealed class HistoryStore
|
||||
}
|
||||
public TokenCounts Total(Provider provider, DateTimeOffset from, DateTimeOffset to)
|
||||
{ lock (gate) return Sum(Range(provider, from, to).Select(b => b.Counts)); }
|
||||
public (TokenCounts Today, TokenCounts? Session, TokenCounts Week) Totals(Provider provider, DateTimeOffset now,
|
||||
LimitWindow? session, TimeZoneInfo? zone = null)
|
||||
public (TokenCounts Today, TokenCounts? Session, TokenCounts Week, DateTimeOffset WeekStart, string? WeekWindow) Totals(Provider provider, DateTimeOffset now,
|
||||
LimitWindow? session, TimeZoneInfo? zone = null, LimitWindow? weekWindow = null)
|
||||
{
|
||||
zone ??= TimeZoneInfo.Local;
|
||||
var local = TimeZoneInfo.ConvertTime(now, zone);
|
||||
var today = local.Date;
|
||||
var week = today.AddDays(-(((int)today.DayOfWeek + 6) % 7));
|
||||
var todayUtc = CalendarDays.Start(today, zone);
|
||||
var weekUtc = CalendarDays.Start(week, zone);
|
||||
var followsLimit = weekWindow is { ResetsAt: { } r, Length: { Ticks: > 0 } l } && r > now;
|
||||
var weekUtc = followsLimit ? weekWindow!.ResetsAt!.Value - weekWindow.Length!.Value : CalendarDays.Start(week, zone);
|
||||
return (Total(provider, todayUtc, now), session is { ResetsAt: { } reset, Length: { } length } && reset > now
|
||||
? Total(provider, reset - length, now) : null, Total(provider, weekUtc, now));
|
||||
? Total(provider, reset - length, now) : null, Total(provider, weekUtc, now), weekUtc, followsLimit ? weekWindow!.Id : null);
|
||||
}
|
||||
private IEnumerable<TokenBucket> Range(Provider provider, DateTimeOffset from, DateTimeOffset to) =>
|
||||
SelectMonths(from, to).SelectMany(m => GetPartition(m).Buckets.Values)
|
||||
|
||||
Reference in New Issue
Block a user