M3 Motore: Governatore con tetti da action_log, interruttore con fermi 1/6/24 ore e ripresa manuale, fascia giornaliera spostata a caso e salvata, sessioni con pause log-normali e pavimento, composizione delle sessioni sulla coda persistente, «Controlla ora» con conferma fuori fascia, cruscotto per l'interfaccia e calcolatore «Con queste impostazioni», simulazione con orologio virtuale e comando --simula; prove del motore e dell'interruttore
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
38 files changed
+9308
No files matched your search
@@ -0,0 +1,71 @@
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Engine;
|
||||
using Febe.Core.Storage;
|
||||
|
||||
namespace Febe.Tests.Engine.Support;
|
||||
|
||||
/// <summary>
|
||||
/// Independent check of the budgets from <c>action_log</c>: at every action, the rolling hour and the local day so far
|
||||
/// must stay within the profile's full limits (reductions only make them lower).
|
||||
/// </summary>
|
||||
internal static class BudgetAudit
|
||||
{
|
||||
private static readonly TimeSpan Hour = TimeSpan.FromMinutes(60);
|
||||
|
||||
public static async Task<IReadOnlyList<string>> OverrunsAsync(IFebeStorage storage, CautionProfile profile, TimeZoneInfo zone, DateTimeOffset from, DateTimeOffset to)
|
||||
{
|
||||
var actions = await storage.ActionLog.ListAsync(from, to);
|
||||
var problems = new List<string>();
|
||||
foreach (var kind in Enum.GetValues<ActionKind>())
|
||||
{
|
||||
var list = actions.Where(a => a.Category == kind).OrderBy(a => a.At).ThenBy(a => a.Id).ToList();
|
||||
var first = 0;
|
||||
long hour = 0;
|
||||
long day = 0;
|
||||
DateOnly? current = null;
|
||||
foreach (var action in list)
|
||||
{
|
||||
hour += action.Amount;
|
||||
while (list[first].At <= action.At - Hour)
|
||||
{
|
||||
hour -= list[first].Amount;
|
||||
first++;
|
||||
}
|
||||
|
||||
var today = LocalCalendar.Today(action.At, zone);
|
||||
if (today != current)
|
||||
{
|
||||
current = today;
|
||||
day = 0;
|
||||
}
|
||||
|
||||
day += action.Amount;
|
||||
var over = kind == ActionKind.DataDownload
|
||||
? day > profile.DataPerDayBytes
|
||||
: hour > profile.Budgets[kind].PerHour || day > profile.Budgets[kind].PerDay;
|
||||
if (over)
|
||||
{
|
||||
problems.Add($"{kind} at {action.At:O}: hour {hour}, day {day}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return problems;
|
||||
}
|
||||
|
||||
/// <summary>Actions (data excluded) that fall outside the active window of their day.</summary>
|
||||
public static async Task<IReadOnlyList<ActionLogRecord>> OutsideWindowAsync(IFebeStorage storage, DayPlanner planner, DateTimeOffset from, DateTimeOffset to)
|
||||
{
|
||||
var outside = new List<ActionLogRecord>();
|
||||
foreach (var action in (await storage.ActionLog.ListAsync(from, to)).Where(a => a.Category != ActionKind.DataDownload))
|
||||
{
|
||||
if (await planner.GetWindowAtAsync(action.At) is null)
|
||||
{
|
||||
outside.Add(action);
|
||||
}
|
||||
}
|
||||
|
||||
return outside;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user