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
@@ -1,2 +1,11 @@
|
||||
// Composition root for Linux and Docker. Filled in by milestones M3–M5.
|
||||
using Febe.Server;
|
||||
|
||||
if (SimulateCommand.Matches(args))
|
||||
{
|
||||
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||
return await SimulateCommand.RunAsync(args, Console.Out, Console.Error);
|
||||
}
|
||||
|
||||
Console.WriteLine("Febe");
|
||||
return 0;
|
||||
@@ -0,0 +1,136 @@
|
||||
using System.Globalization;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Simulation;
|
||||
using Febe.Data;
|
||||
|
||||
namespace Febe.Server;
|
||||
|
||||
/// <summary>
|
||||
/// <c>--simula 30g --profilo prudente [--csv percorso] [--seme n]</c> (spec §14.3): runs the engine under the virtual
|
||||
/// clock against the fake world, in a temporary database, and prints the Italian report. Never opens a browser and
|
||||
/// never contacts any site. Exit code 0 when no budget was exceeded, 1 otherwise, 2 for wrong arguments.
|
||||
/// </summary>
|
||||
internal static class SimulateCommand
|
||||
{
|
||||
public const string Flag = "--simula";
|
||||
|
||||
public static bool Matches(string[] args) => args.Any(a => string.Equals(a, Flag, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
public static async Task<int> RunAsync(string[] args, TextWriter output, TextWriter error, CancellationToken ct = default)
|
||||
{
|
||||
if (!TryParse(args, out var options, out var csv, out var problem))
|
||||
{
|
||||
await error.WriteLineAsync(problem).ConfigureAwait(false);
|
||||
await error.WriteLineAsync("Uso: --simula 30g --profilo prudente|equilibrato|rapido [--csv percorso.csv] [--seme numero]").ConfigureAwait(false);
|
||||
return 2;
|
||||
}
|
||||
|
||||
var folder = Path.Combine(Path.GetTempPath(), "febe-simulazione-" + Guid.NewGuid().ToString("N")[..10]);
|
||||
Directory.CreateDirectory(folder);
|
||||
try
|
||||
{
|
||||
var report = await EngineSimulation.RunAsync(
|
||||
options,
|
||||
async token => await FebeDatabase.OpenAsync(folder, token).ConfigureAwait(false),
|
||||
ct).ConfigureAwait(false);
|
||||
await output.WriteAsync(report.ToText()).ConfigureAwait(false);
|
||||
if (csv is not null)
|
||||
{
|
||||
await report.WriteCsvAsync(csv, ct).ConfigureAwait(false);
|
||||
await output.WriteLineAsync($"Resoconto CSV scritto in {csv}").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return report.Overruns == 0 && report.OverrunsOfFullBudgets == 0 ? 0 : 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(folder, recursive: true);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool TryParse(string[] args, out SimulationOptions options, out string? csv, out string problem)
|
||||
{
|
||||
options = new SimulationOptions();
|
||||
csv = null;
|
||||
problem = string.Empty;
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var arg = args[i];
|
||||
string? Next() => i + 1 < args.Length ? args[++i] : null;
|
||||
switch (arg.ToLowerInvariant())
|
||||
{
|
||||
case Flag:
|
||||
{
|
||||
var value = Next();
|
||||
var digits = value?.TrimEnd('g', 'G');
|
||||
if (!int.TryParse(digits, NumberStyles.Integer, CultureInfo.InvariantCulture, out var days) || days < 1 || days > 366)
|
||||
{
|
||||
problem = $"Durata non valida: «{value}». Scrivi per esempio 30g.";
|
||||
return false;
|
||||
}
|
||||
|
||||
options = options with { Days = days };
|
||||
break;
|
||||
}
|
||||
|
||||
case "--profilo":
|
||||
{
|
||||
var value = Next();
|
||||
CautionProfileKind? kind = value?.ToLowerInvariant() switch
|
||||
{
|
||||
"prudente" => CautionProfileKind.Prudent,
|
||||
"equilibrato" => CautionProfileKind.Balanced,
|
||||
"rapido" => CautionProfileKind.Fast,
|
||||
_ => null,
|
||||
};
|
||||
if (kind is null)
|
||||
{
|
||||
problem = $"Profilo sconosciuto: «{value}». I profili sono prudente, equilibrato, rapido.";
|
||||
return false;
|
||||
}
|
||||
|
||||
options = options with { Profile = kind.Value };
|
||||
break;
|
||||
}
|
||||
|
||||
case "--csv":
|
||||
csv = Next();
|
||||
if (string.IsNullOrWhiteSpace(csv))
|
||||
{
|
||||
problem = "Dopo --csv serve il percorso del file.";
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "--seme":
|
||||
{
|
||||
var value = Next();
|
||||
if (!int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var seed))
|
||||
{
|
||||
problem = $"Seme non valido: «{value}».";
|
||||
return false;
|
||||
}
|
||||
|
||||
options = options with { Seed = seed };
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
problem = $"Argomento sconosciuto: «{arg}».";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user