Show what the model knows on its own screen and let the user set it aside

The Apprendimento screen says in plain words whether the model counts, how
well its probabilities hold, which clues it weighs, how the challenger is
doing and what it has learned. Thresholds, set-aside and the undo of a
promotion live in Impostazioni; anything that shrinks less with real money
asks for the phrase. The new tests also caught a wrong column name that
broke the Panoramica as soon as the first model existed.

refs #66

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 12:44:37 +01:00
1 parent 14e8a872dc
commit f69943f70a
22 files changed
+1680 -27

No files matched your search

+62
View File
@@ -42,6 +42,8 @@ internal static partial class Forms
signed.MapPost("/assenza/{id:guid}/vista", AbsenceSeenAsync);
signed.MapPost("/laboratorio", PlanTrialAsync);
signed.MapPost("/stime-di-costo/{id:guid}/{choice}", DecideCostAsync);
signed.MapPost("/modello", SetModelAsync);
signed.MapPost("/modello/annulla-promozione", UndoPromotionAsync);
signed.MapPost("/strategie/{strategy}/{choice}", StrategyStageAsync);
signed.MapPost("/rischio/limiti", SetLimitsAsync);
signed.MapPost("/rischio/{key}", SetRiskSettingAsync);
@@ -783,6 +785,66 @@ internal static partial class Forms
return Results.Redirect(done ? "/laboratorio#stime" : "/laboratorio?errore=stima#stime");
}
/// <summary>
/// The thresholds of the multiplier and the manual set-aside (SPEC 13.5), all at once. A choice that lets operations be
/// bigger while a strategy has real money needs the phrase and the password, like a risk limit (SPEC 12.4).
/// </summary>
private static async Task<IResult> SetModelAsync(IFormCollection form, AnubisHost host, IClock clock, HttpContext context, CancellationToken ct)
{
const string back = "/impostazioni";
if (host.IsDemo || host.Services is not { } services)
{
return Results.Redirect(back + "?errore=motore#modello");
}
var current = new Dictionary<string, string>(StringComparer.Ordinal);
var next = new Dictionary<string, string>(StringComparer.Ordinal);
foreach (var definition in Anubis.Learning.LearningSettings.All)
{
var value = await services.Settings.GetAsync(definition.Key, ct).ConfigureAwait(false);
current[definition.Key] = value.Value;
var chosen = form[definition.Key].ToString();
if (value.ReadOnly || chosen.Length == 0)
{
next[definition.Key] = value.Value;
continue;
}
if (!definition.Allowed!.Contains(chosen, StringComparer.Ordinal))
{
return Results.Redirect(back + "?errore=impostazione#modello");
}
next[definition.Key] = chosen;
}
if (Anubis.Learning.LearningSettings.Raised(k => current[k], k => next[k]) && await RaiseRefusalAsync(services, clock, null, form, ct).ConfigureAwait(false) is { } refusal)
{
return Results.Redirect(back + "?errore=" + refusal + "#modello");
}
var by = context.User.Identity?.Name ?? "utente";
foreach (var (key, value) in next.Where(n => n.Value != current[n.Key]))
{
await services.Settings.SetAsync(key, value, by, ct).ConfigureAwait(false);
}
return Results.Redirect(back + "?ok=apprendimento#modello");
}
/// <summary>One click takes back the last promotion (SPEC 11.4).</summary>
private static async Task<IResult> UndoPromotionAsync(IFormCollection form, AnubisHost host, CancellationToken ct)
{
var (page, anchor) = Back(form, "/apprendimento") == "/impostazioni" ? ("/impostazioni", "#modello") : ("/apprendimento", "");
if (host.IsDemo || host.Services is not { } services)
{
return Results.Redirect(page + "?errore=motore" + anchor);
}
var done = await Anubis.Learning.LearningCycle.UndoPromotionAsync(services.Db, host.Clock, ct).ConfigureAwait(false);
return Results.Redirect(page + (done ? "?ok=promozione" : "?errore=promozione") + anchor);
}
private static DateOnly? ParseDay(string text) =>
DateOnly.TryParseExact(text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out var day) ? day : null;