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

@@ -0,0 +1,86 @@
@* How often it went well against what the model said (SPEC 13.4, mockup 06): one scale, 2 px lines, faint grid, the
perfect estimate beside it, direct labels on the fullest band and on the last one, a box on hover and the table.
As in EquityChart the lines are SVG stretched to the box; texts and points are HTML placed in percent. *@
@if (Bands.Count > 0)
{
var loX = Bands.Min(b => b.From) / 10 * 10;
var hiX = (Bands.Max(b => b.To) + 9) / 10 * 10;
var loY = Math.Min(loX, (int)Math.Floor(Bands.Min(b => b.Observed)) / 10 * 10) - 5m;
var hiY = Math.Max(hiX, Bands.Max(b => b.Observed)) + 4m;
var step = hiX - loX > 60 ? 20 : 10;
var fullest = Bands.MaxBy(b => b.Cases)!;
var last = Bands[^1];
decimal X(decimal v) => (v - loX) / (hiX - loX) * 1000m;
decimal Y(decimal v) => (hiY - v) / (hiY - loY) * 1000m;
<figure class="chart calibration" aria-label="Quanto spesso è andata bene, rispetto a quello che diceva il modello">
<p class="calibration-title" aria-hidden="true">…va bene davvero</p>
<div class="calibration-box">
<div class="chart-axis" aria-hidden="true">
@for (var t = (int)Math.Ceiling(loY / step) * step; t <= hiY; t += step)
{
<span style="top:@Pct(Y(t) / 10)">@t%</span>
}
</div>
<div class="chart-plot">
<svg viewBox="0 0 1000 1000" preserveAspectRatio="none" aria-hidden="true" focusable="false">
@for (var t = (int)Math.Ceiling(loY / step) * step; t <= hiY; t += step)
{
<line class="grid" x1="0" x2="1000" y1="@Css(Y(t))" y2="@Css(Y(t))" vector-effect="non-scaling-stroke" />
}
<line class="base" x1="0" x2="1000" y1="1000" y2="1000" vector-effect="non-scaling-stroke" />
<line class="bench" x1="0" y1="@Css(Y(loX))" x2="1000" y2="@Css(Y(hiX))" vector-effect="non-scaling-stroke" />
<polyline class="equity" points="@string.Join(" ", Bands.Select(b => Css(X(b.Estimated)) + "," + Css(Y(b.Observed))))" vector-effect="non-scaling-stroke" />
</svg>
@foreach (var b in Bands)
{
<span class="end-dot hover-dot" style="left:@Pct(X(b.Estimated) / 10);top:@Pct(Y(b.Observed) / 10)"><span class="hover-box">Tra @(b.From)% e @(b.To)%<br />@Format.Number(b.Observed)% su @b.Cases casi</span></span>
}
<span class="point-label below" style="left:@Pct(X(fullest.Estimated) / 10);top:@Pct(Y(fullest.Observed) / 10)">@Label(fullest)</span>
@if (last != fullest)
{
<span class="point-label above" style="left:@Pct(X(last.Estimated) / 10);top:@Pct(Y(last.Observed) / 10)">@Label(last)</span>
}
</div>
</div>
<div class="calibration-x" aria-hidden="true">
@for (var t = loX; t <= hiX; t += step)
{
<span style="left:@Pct(X(t) / 10)">@t%</span>
}
</div>
<p class="calibration-foot" aria-hidden="true">Quando il modello dice…</p>
<figcaption class="legend">
<span class="key key-equity">Il modello</span>
<span class="key key-bench">Stima perfetta</span>
</figcaption>
<p class="calibration-text">@Text</p>
<details class="chart-table">
<summary>Vedi i numeri in una tabella</summary>
<div class="table-wrap">
<table class="table">
<thead><tr><th scope="col">Quando il modello dice</th><th scope="col" class="num">Casi</th><th scope="col" class="num">È andata bene</th><th scope="col">Affidabilità</th></tr></thead>
<tbody>
@foreach (var b in Bands)
{
<tr><td>tra @(b.From)% e @(b.To)%</td><td class="num">@b.Cases</td><td class="num">@Format.Number(b.Observed)%</td><td class="@(b.Solid ? null : "attention-text")">@(b.Solid ? "conta" : "troppo pochi casi per contarci")</td></tr>
}
</tbody>
</table>
</div>
</details>
</figure>
}
@code {
[Parameter, EditorRequired]
public IReadOnlyList<LearningBand> Bands { get; set; } = [];
[Parameter]
public string Text { get; set; } = "";
private static string Label(LearningBand b) => $"{Format.Number(b.Observed)}% su {(b.Cases == 1 ? "un caso" : b.Cases + " casi")}";
private static string Css(decimal v) => v.ToString("0.##", CultureInfo.InvariantCulture);
private static string Pct(decimal v) => v.ToString("0.###", CultureInfo.InvariantCulture) + "%";
}
+3
View File
@@ -89,6 +89,9 @@
case "tick":
<path d="m5 12.5 4.5 4.5L19 7.5" />
break;
case "eye":
<path d="M2.5 12S6 5.5 12 5.5 21.5 12 21.5 12 18 18.5 12 18.5 2.5 12 2.5 12Z" /><circle cx="12" cy="12" r="2.8" />
break;
case "logout":
<path d="M14 4h4.5A1.5 1.5 0 0 1 20 5.5v13a1.5 1.5 0 0 1-1.5 1.5H14M10 16l-4-4 4-4M6 12h10" />
break;
@@ -1,5 +1,306 @@
@inherits LoadedComponent
@page "/apprendimento"
@inject AnubisHost Host
@inject ShellData Shell
@using Anubis.Learning
<PageTitle>Apprendimento · Anubis</PageTitle>
<Pending Title="Il modello non è ancora in osservazione.">Comincia a imparare quando ci sono abbastanza segnali: qui vedrai quanti ne mancano e quanto è preciso su casi mai visti.</Pending>
@{
var v = _view;
var s = v.Summary;
var c = _currency;
}
<p class="lead page-lead">Il modello impara dall'esito di ogni segnale.</p>
@if (Ok == "promozione")
{
<p class="notice notice-gain" role="status"><Icon Name="check" Size="16" />Promozione annullata: è tornata in carica la versione precedente.</p>
}
else if (Errore is not null)
{
<p class="notice notice-loss" role="status"><Icon Name="alert" Size="16" />@(Errore == "motore" ? "Nella modalità dimostrativa non si cambia nulla." : "Non c'è nessuna promozione da annullare.")</p>
}
<section class="panel head-block learning-head" aria-labelledby="stato">
<div class="half learning-state">
<span class="state-badge @(s.State is LearningStates.Aside or LearningStates.Manual ? "warn" : s.State == LearningStates.Active ? "on" : null)"><Icon Name="@BadgeIcon(s.State)" Size="16" />@Badge(s.State)</span>
<h2 id="stato">@v.Title</h2>
<p class="learning-text">@v.Text</p>
@if (s.State != LearningStates.None)
{
<div class="limit learning-progress">
@if (s.Signals < s.Needed)
{
<div class="limit-line"><span>Segnali già valutati</span><span><strong>@s.Signals</strong> <span class="muted">su @s.Needed necessari</span></span></div>
}
else
{
<div class="limit-line"><span>Segnali già valutati</span><span><strong>@Format.Number(s.Signals)</strong> <span class="muted">(ne servivano @s.Needed)</span></span></div>
}
<span class="usage"><span style="width: @Css(Math.Min(100m, s.Signals * 100m / Math.Max(1, s.Needed)))%"></span></span>
@if (v.Pace is { } pace)
{
<span class="note">@pace</span>
}
</div>
}
@if (v.Missing.Count > 0)
{
<ul class="checks">
@foreach (var m in v.Missing)
{
<li class="wait"><Icon Name="clock" Size="16" />@m</li>
}
</ul>
}
@if (s.State == LearningStates.Manual)
{
<p><a href="/impostazioni#modello">Vai a Impostazioni</a></p>
}
</div>
<dl class="half learning-facts">
<div>
<dt>Previsioni azzeccate su casi mai visti</dt>
<dd class="learning-precision">@(s.Precision is { } precision ? precision + "%" : "—")</dd>
<dd class="note">@(s.Precision is null ? "Si misura al primo addestramento" : "Tirando a caso sarebbe il 50%")</dd>
</div>
<div><dt>Ultimo addestramento</dt><dd><strong>@Capital(v.LastTraining)</strong></dd></div>
<div><dt>@s.NextLabel</dt><dd><strong>@Capital(s.NextCheck)</strong></dd></div>
</dl>
</section>
<div class="learning-row">
<section class="panel" aria-labelledby="fiducia">
<h2 id="fiducia">Ci si può fidare delle sue probabilità?</h2>
@if (v.Bands.Count == 0)
{
<p class="note">@v.BandsText Qui vedrai quante volte va bene davvero quando il modello dice che una cosa è probabile.</p>
}
else
{
<p class="note">Più i punti stanno sulla linea, più la stima corrisponde ai fatti.@(v.BandsFromHistory ? " Per ora sono i casi storici che non aveva studiato: quelli dal vivo sono ancora troppo pochi." : "")</p>
<CalibrationChart Bands="v.Bands" Text="@v.BandsText" />
}
</section>
<section class="panel learning-weights" aria-labelledby="indizi">
<h2 id="indizi">Cosa guarda di più</h2>
@if (v.Champion is null)
{
<p class="note">Si vedrà con il primo modello.</p>
}
else
{
<p class="note">Quanto pesa ogni informazione nelle sue stime, su 100.</p>
@if (v.Weights.Count > 0)
{
var most = v.Weights.Max(w => w.Share);
<ul class="weights">
@foreach (var w in v.Weights)
{
<li class="@(w.Rest ? "rest" : null)"><span>@w.Name</span><span class="weight-bar" aria-hidden="true"><span style="width: @Css(w.Share * 100m / most)%"></span></span><strong>@w.Share</strong></li>
}
</ul>
}
<p class="note weights-text">@v.WeightsText</p>
}
</section>
</div>
<div class="learning-row learning-row-wide">
<section class="panel" aria-labelledby="versioni">
<h2 id="versioni">Il modello in carica e lo sfidante</h2>
<p class="note">Lo sfidante gira in ombra accanto al modello in carica. Ne prende il posto solo se è chiaramente migliore.</p>
@if (v.Champion is { } now)
{
var other = v.Challenger;
var same = other is null || other.GainWithout == now.GainWithout;
<div class="table-wrap">
<table class="table versions">
<thead><tr><td></td><th scope="col" class="num">In carica, versione @now.Version</th>@if (other is not null){<th scope="col" class="num">Sfidante, versione @other.Version</th>}</tr></thead>
<tbody>
<tr><th scope="row">Addestrato</th><td class="num">@now.Trained</td>@if (other is not null){<td class="num">@other.Trained</td>}</tr>
<tr><th scope="row">Casi studiati</th><td class="num">@Format.Number(now.Examples)</td>@if (other is not null){<td class="num">@Format.Number(other.Examples)</td>}</tr>
<tr><th scope="row">Previsioni azzeccate su casi mai visti</th><td class="num"><strong>@Share(now.Precision)</strong></td>@if (other is not null){<td class="num"><strong>@Share(other.Precision)</strong></td>}</tr>
<tr><th scope="row">Errore sulle probabilità <span class="muted">(più basso è meglio)</span></th><td class="num">@Error(now.Error)</td>@if (other is not null){<td class="num">@Error(other.Error)</td>}</tr>
<tr><th scope="row">Guadagno medio per operazione se filtrasse lui @if (same && now.GainWithout is { } without){<span class="muted">(senza filtro: @Shell.Money(without, c, withSign: true))</span>}</th>
<td class="num">@Gain(now, same, c)</td>@if (other is not null){<td class="num">@Gain(other, same, c)</td>}</tr>
@if (other is not null)
{
<tr><th scope="row">Casi di confronto diretto</th><td class="num muted">non serve</td><td class="num">@v.Pairs su @v.PairsNeeded</td></tr>
}
</tbody>
</table>
</div>
}
<p class="aside"><strong>@v.TrialTitle</strong> @v.TrialText</p>
@if (v.Choice is { } choice)
{
<details class="chart-table">
<summary>Come è stato scelto il modello in carica</summary>
<p class="note">@choice Sono tutte prove su casi che il modello non aveva studiato; contano anche quelle scartate.</p>
<div class="table-wrap">
<table class="table">
<thead><tr><th scope="col">Tipo di modello</th><th scope="col" class="num">Previsioni azzeccate</th><th scope="col" class="num">Errore</th><th scope="col" class="num">Guadagno per operazione</th><th scope="col">Esito</th></tr></thead>
<tbody>
@foreach (var a in v.Attempts)
{
<tr><td>@a.Learner</td><td class="num">@Share(a.Precision)</td><td class="num">@Error(a.Error)</td><td class="num nowrap">@Shell.Money(a.Gain, c, withSign: true)</td><td>@(a.Chosen ? "scelto" : "non scelto")</td></tr>
}
</tbody>
</table>
</div>
</details>
}
@if (v.UndoTo is { } back && !Shell.IsDemo)
{
<form method="post" action="/azioni/modello/annulla-promozione" class="form-inline">
<AntiforgeryToken />
<button class="btn" type="submit" data-confirm="Torna in carica la versione @back e la versione @v.Champion!.Version viene tolta. Continuare?">Annulla l'ultima promozione</button>
<span class="hint">Tornerebbe in carica la versione @back.</span>
</form>
}
</section>
<section class="panel learning-watch" aria-labelledby="sorveglianza">
<div class="panel-head">
<h2 id="sorveglianza">Sorveglianza</h2>
@if (v.Checked)
{
<span class="status-pill @(v.Anomaly ? "attention" : "gain")"><Icon Name="@(v.Anomaly ? "alert" : "check")" Size="16" />@(v.Anomaly ? "Anomalia" : "Nessuna anomalia")</span>
}
</div>
@if (!v.Checked)
{
<p class="note">Il controllo gira ogni notte alle 03:00: confronta le stime con gli esiti e il mercato di oggi con quello su cui ha studiato.</p>
}
else
{
<ul class="watch-list">
@foreach (var check in v.Checks)
{
<li class="@check.State"><Icon Name="@(check.State switch { "ok" => "tick", "warn" => "alert", _ => "clock" })" Size="16" /><span>@check.Text</span></li>
}
</ul>
<WeeklyPrecision Weeks="v.Weeks" />
}
<p class="aside">Se la precisione cala, il modello viene messo da parte da solo e le strategie proseguono senza di lui.</p>
</section>
</div>
<div class="learning-row learning-open">
<section class="plain" aria-labelledby="imparato">
<h2 id="imparato">Cosa ha imparato finora</h2>
@if (v.Found.Count == 0)
{
<p class="note">Ancora niente: le relazioni tra indizi ed esiti si cercano ogni notte, quando i casi bastano per un confronto.</p>
}
else
{
<ul class="found">
@foreach (var d in v.Found)
{
<li>
<strong>@d.Title</strong>
<span class="found-detail">@d.Detail</span>
<span class="@(d.Cases < 20 ? "attention" : "note")">@if (d.Cases < 20){<Icon Name="alert" Size="16" />}@(d.Cases == 1 ? "Un caso" : Format.Number(d.Cases) + " casi"): @d.Trust</span>
</li>
}
</ul>
}
@if (v.News.Count > 0)
{
<h3>Cosa succede ai prezzi dopo una notizia</h3>
<p class="note">Rendimento medio dalla prima chiusura dopo la notizia. È solo un'informazione: non cambia nessuna regola.</p>
<div class="table-wrap">
<table class="table">
<thead><tr><th scope="col">Tipo di notizia</th><th scope="col" class="num">Dopo 1 giorno</th><th scope="col" class="num">Dopo 5 giorni</th><th scope="col">Casi</th></tr></thead>
<tbody>
@foreach (var n in v.News)
{
<tr><td>@NewsEventNames.Label(n.Kind)</td><td class="num">@Move(n.OneDay)</td><td class="num">@Move(n.FiveDays)</td><td class="@(n.Cases < 20 ? "attention-text" : null)">@n.Cases: @n.Trust</td></tr>
}
</tbody>
</table>
</div>
}
</section>
<section class="plain" aria-labelledby="storia">
<h2 id="storia">Storia</h2>
@if (v.Story.Count == 0)
{
<p class="note">La storia comincia con il primo modello.</p>
}
else
{
<dl class="events">
@foreach (var e in v.Story.Take(LearningView.StoryRows))
{
<dt>@e.When</dt><dd>@e.Text</dd>
}
</dl>
@if (v.Story.Count > LearningView.StoryRows)
{
<details class="chart-table">
<summary>Mostra i @(v.Story.Count - LearningView.StoryRows) eventi precedenti</summary>
<dl class="events">
@foreach (var e in v.Story.Skip(LearningView.StoryRows))
{
<dt>@e.When</dt><dd>@e.Text</dd>
}
</dl>
</details>
}
}
</section>
</div>
@code {
private LearningView _view = null!;
private string _currency = "EUR";
[CascadingParameter]
public HttpContext? HttpContext { get; set; }
[SupplyParameterFromQuery(Name = "ok")]
public string? Ok { get; set; }
[SupplyParameterFromQuery(Name = "errore")]
public string? Errore { get; set; }
protected override async Task LoadAsync()
{
var ct = HttpContext?.RequestAborted ?? CancellationToken.None;
_currency = Shell.Effective((await Host.Services!.Settings.GetAsync(SettingsStore.Currency.Key, ct)).Value);
_view = await LearningView.LoadAsync(Host, Shell, ct);
}
private string Gain(LearningVersion version, bool same, string currency) => version.Gain is not { } gain ? "—"
: Shell.Money(gain, currency, withSign: true) + (same || version.GainWithout is not { } without ? "" : $" (senza: {Shell.Money(without, currency, withSign: true)})");
private static string Badge(string state) => state switch
{
LearningStates.None => "Non ancora partito",
LearningStates.Active => "Attivo",
LearningStates.Aside => "Messo da parte",
LearningStates.Manual => "Messo da parte da te",
_ => "In osservazione",
};
private static string BadgeIcon(string state) => state switch
{
LearningStates.None => "clock",
LearningStates.Active => "check",
LearningStates.Aside => "alert",
LearningStates.Manual => "pause",
_ => "eye",
};
private static string Share(int? points) => points is { } p ? p + "%" : "—";
private static string Error(decimal? value) => value is { } e ? Format.Number(e, 3) : "—";
private static string Move(double value) => Format.Percent((decimal)Math.Round(value * 100, 2), 2, withSign: true);
private static string Capital(string text) => text.Length == 0 ? text : char.ToUpper(text[0], CultureInfo.GetCultureInfo("it-IT")) + text[1..];
private static string Css(decimal v) => v.ToString("0.##", CultureInfo.InvariantCulture);
}
@@ -31,6 +31,8 @@
"fonte" => "Fonte aggiornata: vale dal prossimo giro delle notizie, tra al massimo 2 minuti.",
"chiave" => "Chiave salvata. Non la mostro più: se serve cambiarla, scrivine una nuova.",
"chiave-tolta" => "Chiave tolta.",
"apprendimento" => "Impostazioni del modello salvate: valgono dalla prossima decisione.",
"promozione" => "Promozione annullata: è tornata in carica la versione precedente.",
_ => "Fatto.",
})</p>
@@ -41,7 +43,7 @@
}
<nav class="tabs" aria-label="Sezioni delle impostazioni">
<a href="#aspetto">Aspetto</a><a href="#conti">Conti</a><a href="#rischio">Rischio</a><a href="#telegram">Telegram</a><a href="#dati">Dati</a><a href="#notizie">Notizie</a><a href="#sicurezza">Sicurezza</a><a href="#sistema">Sistema</a><a href="#modifiche">Modifiche</a>
<a href="#aspetto">Aspetto</a><a href="#conti">Conti</a><a href="#rischio">Rischio</a><a href="#telegram">Telegram</a><a href="#dati">Dati</a><a href="#notizie">Notizie</a><a href="#modello">Modello</a><a href="#sicurezza">Sicurezza</a><a href="#sistema">Sistema</a><a href="#modifiche">Modifiche</a>
</nav>
<section class="panel" id="aspetto">
@@ -405,6 +407,55 @@
</form>
</section>
<section class="panel" id="modello">
<h2>Modello</h2>
<p class="hint">Il modello non compra mai e non ingrandisce niente: quando avrà superato le sue prove potrà solo rimpicciolire, o non fare, un acquisto che giudica debole. Quanto debole lo decidi qui, in punti di probabilità sotto la frequenza con cui la strategia guadagna di solito. <a href="/apprendimento">Cosa sta facendo</a></p>
<form method="post" action="/azioni/modello" class="form-grid">
<AntiforgeryToken />
@foreach (var m in _model)
{
var definition = SettingsStore.Definition(m.Key);
<label>@ModelLabel(m.Key)
<select name="@m.Key" disabled="@(m.ReadOnly || Shell.IsDemo)">
@foreach (var choice in definition.Allowed!)
{
<option value="@choice" selected="@(choice == m.Value)">@ModelChoice(m.Key, choice)</option>
}
</select>
@if (m.ReadOnly)
{
<span class="hint">Fissato da @m.Source: si cambia lì.</span>
}
</label>
}
@if (!Shell.IsDemo)
{
@if (_anyLive)
{
<p class="note">Una strategia usa soldi veri: per rimpicciolire meno, o mettere da parte il modello, servono la frase e la password.</p>
<label>Scrivi: <code>@StageBook.RaisePhrase</code><input name="frase" autocomplete="off" /></label>
<label>Password<input name="password" type="password" autocomplete="current-password" /></label>
<label>Codice a sei cifre (se attivo)<input name="codice" inputmode="numeric" autocomplete="one-time-code" /></label>
}
<button class="btn" type="submit">Salva</button>
}
</form>
<h3>Ultima promozione</h3>
@if (_undoTo is { } undo)
{
<form method="post" action="/azioni/modello/annulla-promozione" class="form-inline">
<AntiforgeryToken />
<input type="hidden" name="ritorno" value="/impostazioni" />
<button class="btn" type="submit" data-confirm="Torna in carica la versione @undo e quella di adesso viene tolta. Continuare?">Annulla l'ultima promozione</button>
<span class="hint">Tornerebbe in carica la versione @undo.</span>
</form>
}
else
{
<p class="note">Nessuna promozione da annullare.</p>
}
</section>
<section class="panel" id="sicurezza">
<h2>Sicurezza</h2>
@if (Shell.IsDemo)
@@ -536,6 +587,8 @@
private SettingValue _meetings = new(SettingsStore.CentralBankMeetings.Key, "", false, null);
private readonly List<SettingValue> _newsRules = [];
private readonly List<SettingValue> _model = [];
private int? _undoTo;
private readonly Dictionary<string, SettingValue> _llm = [];
private IReadOnlyList<Anubis.News.NewsSource> _newsSources = [];
private readonly Dictionary<string, SecretStatus> _dataKeys = [];
@@ -573,6 +626,12 @@
_newsRules.Add(await services.Settings.GetAsync(rule.Key, ct));
}
foreach (var setting in Anubis.Learning.LearningSettings.All)
{
_model.Add(await services.Settings.GetAsync(setting.Key, ct));
}
_undoTo = Shell.IsDemo ? null : await new Anubis.Learning.ModelStore(services.Db).UndoToAsync(ct);
foreach (var setting in Anubis.News.NewsModelSettings.All)
{
_llm[setting.Key] = await services.Settings.GetAsync(setting.Key, ct);
@@ -656,6 +715,7 @@
"fonte" => "Fonte sconosciuta: ricarica la pagina e riprova.",
"chiave" => "La chiave è vuota o contiene spazi: copiala di nuovo così come la dà il servizio.",
"chiave-ambiente" => "Questa chiave arriva dalle variabili d'ambiente: si cambia nella configurazione del container.",
"promozione" => "Non c'è nessuna promozione da annullare.",
"tetto" => $"Il tetto di spesa va scritto in euro, da 0 a {Anubis.News.NewsModelSettings.MaxCap:0}, per esempio 0,50.",
"modello" => "Valore non valido per il modello linguistico: il nome come lo dà il servizio, un indirizzo https:// (http:// solo nella tua rete), prezzi da 0 a 200.",
@@ -705,6 +765,13 @@
</form>;
}
private static string ModelLabel(string key) => key == Anubis.Learning.LearningSettings.Full.Key ? "Acquisto intero fino a"
: key == Anubis.Learning.LearningSettings.Zero.Key ? "Nessun acquisto da" : "Il modello";
private static string ModelChoice(string key, string choice) => key == Anubis.Learning.LearningSettings.Aside.Key
? choice == "on" ? "Messo da parte: non conta" : "Al suo posto"
: choice == "0" ? "Solo alla frequenza di sempre o sopra" : choice + " punti sotto";
private static string ProviderName(string provider) => provider switch
{
Anubis.News.NewsModelProviders.Anthropic => "Anthropic (Claude)",
@@ -364,19 +364,23 @@
</section>
<section class="plain tile" aria-labelledby="apprendimento-sintesi">
<div class="panel-head"><h2 id="apprendimento-sintesi">Apprendimento</h2><a href="/apprendimento">Dettaglio</a></div>
@if (p.Learning is not { } m)
@{ var m = p.Learning; }
<p><strong>@m.Sentence</strong></p>
@if (m.State == LearningStates.Observation)
{
<p class="note">L'apprendimento non è ancora attivo. Quando lo sarà, il modello osserverà i segnali delle strategie e qui vedrai quanto ci azzecca, prima che possa decidere qualcosa.</p>
}
else
{
<p><strong>Il modello osserva e impara, ma non decide ancora.</strong></p>
<div class="limit">
<div class="limit-line"><span>Segnali già valutati</span><span><strong>@m.Signals</strong> <span class="muted">su @m.Needed necessari</span></span></div>
<span class="usage"><span style="width: @Css(Math.Min(100m, m.Signals * 100m / Math.Max(1, m.Needed)))%"></span></span>
</div>
}
@if (m.State == LearningStates.None)
{
<p class="note">@m.NextLabel: @m.NextCheck.</p>
}
else
{
<dl class="tile-facts">
<dt>Previsioni azzeccate</dt><dd>@m.Precision% su dati mai visti</dd>
<dt>Previsioni azzeccate</dt><dd>@(m.Precision is { } hit ? $"{hit}% su dati mai visti" : "non ancora misurate")</dd>
<dt>Ultimo addestramento</dt><dd>@m.Trained</dd>
<dt>Prossima verifica</dt><dd>@m.NextCheck</dd>
</dl>
@@ -0,0 +1,61 @@
@* The precision of the model week by week with the alarm line (SPEC 13.6, mockup 06). Weeks without enough cases leave no
point; the days on the axis keep the distance between the others. *@
@if (Weeks.Count >= 2)
{
var alarm = (decimal)(Anubis.Learning.Health.Alarm * 100);
var lo = Math.Min(Weeks.Min(w => w.Precision), alarm) - 4m;
var hi = Math.Max(Weeks.Max(w => w.Precision), alarm) + 4m;
var (first, last) = (Weeks[0], Weeks[^1]);
var lowest = Weeks.MinBy(w => w.Precision)!;
decimal X(LearningWeek w) => (w.Monday.DayNumber - first.Monday.DayNumber) * 1000m / (last.Monday.DayNumber - first.Monday.DayNumber);
decimal Y(decimal v) => (hi - v) / (hi - lo) * 1000m;
<figure class="weekly" aria-label="Precisione settimana per settimana">
<figcaption class="note">Precisione settimana per settimana</figcaption>
<div class="weekly-box">
<div class="chart-plot">
<svg viewBox="0 0 1000 1000" preserveAspectRatio="none" aria-hidden="true" focusable="false">
<line class="bench" x1="0" x2="1000" y1="@Css(Y(alarm))" y2="@Css(Y(alarm))" vector-effect="non-scaling-stroke" />
<polyline class="equity" points="@string.Join(" ", Weeks.Select(w => Css(X(w)) + "," + Css(Y(w.Precision))))" vector-effect="non-scaling-stroke" />
</svg>
@foreach (var w in Weeks)
{
<span class="end-dot hover-dot @(w == last || w == lowest ? null : "quiet")" style="left:@Pct(X(w) / 10);top:@Pct(Y(w.Precision) / 10)"><span class="hover-box">Settimana del @Day(w.Monday)<br />@w.Precision%</span></span>
}
@if (lowest != last)
{
<span class="point-label under" style="left:@Pct(X(lowest) / 10);top:@Pct(Y(lowest.Precision) / 10)">@lowest.Precision%</span>
}
</div>
<div class="weekly-side" aria-hidden="true">
<strong style="top:@Pct(Math.Min(Y(last.Precision), Y(alarm) - 300m) / 10)">@last.Precision%</strong>
<span style="top:@Pct(Y(alarm) / 10)">allarme<br />sotto @Format.Number(alarm)%</span>
</div>
</div>
<div class="weekly-x note" aria-hidden="true"><span>@Day(first.Monday)</span><span>@Day(last.Monday)</span></div>
<details class="chart-table">
<summary>Vedi i numeri in una tabella</summary>
<div class="table-wrap">
<table class="table">
<thead><tr><th scope="col">Settimana dal lunedì</th><th scope="col" class="num">Precisione</th></tr></thead>
<tbody>
@foreach (var w in Weeks.Reverse())
{
<tr><td>@Format.LongDate(w.Monday)</td><td class="num">@w.Precision%</td></tr>
}
</tbody>
</table>
</div>
</details>
</figure>
}
@code {
[Parameter, EditorRequired]
public IReadOnlyList<LearningWeek> Weeks { get; set; } = [];
private static string Day(DateOnly day) => day.ToString("d MMM", CultureInfo.GetCultureInfo("it-IT"));
private static string Css(decimal v) => v.ToString("0.##", CultureInfo.InvariantCulture);
private static string Pct(decimal v) => v.ToString("0.###", CultureInfo.InvariantCulture) + "%";
}