Show the news and the market, and set news and calendar from the settings (refs #60)
ci / test (postgres) (pull_request) Successful in 9m38s
ci / test (sqlite) (pull_request) Successful in 5m26s
ci / image (pull_request) Successful in 2m23s
ci / test (postgres) (push) Successful in 9m28s
ci / test (sqlite) (push) Successful in 5m3s
ci / image (push) Successful in 1m56s

The news screen of SPEC 13 lists what the bot read in the last 24 hours and
what it did about each story, with the three filters of the mockup, the mood
of the market, the calendar with the effect of each event, the sources and
the spending of the day. Each note of the bot now keeps its action sentence
and the end of its restriction, so the screen shows the decision as it was.

Settings gain a news section: the rows of SPEC 10.5, the sources (enable and
trust), the key and daily cap of the language model, the Finnhub and FRED
keys and the central bank meetings. The demo seeds the F.9 data and matches
the mockup; the overview tile now shows the real news that matter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-17 15:43:09 +01:00
1 parent b087dd215b
commit 959fe6ccba
22 files changed
+1378 -25

No files matched your search

@@ -1,5 +1,231 @@
@inherits LoadedComponent
@page "/notizie"
@inject AnubisHost Host
@inject ShellData Shell
@using Anubis.News
<PageTitle>Notizie e mercato · Anubis</PageTitle>
<Pending Title="Nessuna notizia letta finora.">La lettura delle notizie, l'umore del mercato e il calendario degli eventi arrivano in una fase successiva.</Pending>
@{
var v = _view;
var rows = Filtered(v.Board.Rows).ToList();
var count = _filter switch
{
"effetto" => v.Board.Active,
"posizioni" => v.Board.OnPositions,
_ => v.Board.Read,
};
var shown = _all ? rows : rows.Take(Shown).ToList();
}
<p class="lead page-lead">@Lead(v)</p>
<div class="news-columns">
<section class="panel news-panel" aria-labelledby="letto">
<div class="panel-head">
<h2 id="letto">Cosa ho letto e cosa ne ho fatto</h2>
<nav class="segmented" aria-label="Filtro delle notizie">
<a class="@(_filter == "effetto" ? "on" : null)" href="/notizie?filtro=effetto" aria-current="@(_filter == "effetto" ? "page" : null)">Con effetto, @v.Board.Active</a>
<a class="@(_filter == "posizioni" ? "on" : null)" href="/notizie?filtro=posizioni" aria-current="@(_filter == "posizioni" ? "page" : null)">Sulle tue posizioni, @v.Board.OnPositions</a>
<a class="@(_filter == "tutte" ? "on" : null)" href="/notizie?filtro=tutte" aria-current="@(_filter == "tutte" ? "page" : null)">Tutte, @v.Board.Read</a>
</nav>
</div>
@if (rows.Count == 0)
{
<p class="note news-empty">@Empty(v)</p>
}
else
{
<ul class="news-rows">
@foreach (var n in shown)
{
<li>
<p class="news-meta">
<span>@Format.ShortDate(n.At, Shell.Now, Shell.Zone)@(n.Publisher.Length > 0 ? ", da " + n.Publisher : "")</span>
<span class="tag tag-strong">@n.About</span>
@if (n.SingleSource)
{
<span class="tag tag-outline">Una sola fonte</span>
}
</p>
<h3 class="news-title">@n.Title</h3>
<p class="news-facts">
<span class="tone @(n.Direction < 0 ? "loss" : n.Direction > 0 ? "gain" : null)">
@if (n.Direction == 0)
{
<span class="tone-flat" aria-hidden="true"></span>
}
else
{
<Arrow Up="@(n.Direction > 0)" />
}
<span class="tone-text">@n.Tone</span>
</span>
<span class="importance">
<span class="importance-bars" aria-hidden="true">
@for (var i = 1; i <= 5; i++)
{
<span class="@(i <= n.Importance ? "on" : null)"></span>
}
</span>
Importanza @n.Importance su 5
</span>
</p>
@if (n.Active)
{
<p class="notice notice-attention"><Icon Name="alert" Size="16" /><span><strong>Cosa ho fatto:</strong> @Inline(n.Action)</span></p>
}
else
{
<p class="news-action"><strong>Cosa ho fatto:</strong> @Inline(n.Action)</p>
}
</li>
}
</ul>
@if (!_all && count > shown.Count)
{
<div class="news-more"><a class="btn" href="/notizie?filtro=@_filter&amp;tutte=1">Mostra le altre @(count - shown.Count)</a></div>
}
}
</section>
<div class="journal-side news-side">
<section class="panel" aria-labelledby="umore">
<h2 id="umore">Umore del mercato</h2>
<ul class="gauges">
@foreach (var g in v.Mood)
{
<li>
<div class="gauge-head">
<span>@g.Label</span>
@if (g.Value is { } value)
{
<span><strong>@value</strong> @g.Words</span>
}
else
{
<span class="muted">non ancora letto</span>
}
</div>
<div class="gauge-track @(g.Centered ? "centered" : null)" aria-hidden="true">
@if (g.Position is { } position)
{
<span class="gauge-dot" style="left: @Css(position * 100)%"></span>
}
</div>
<div class="gauge-ends"><span>@g.Left</span><span>@g.Right</span></div>
@if (g.Stale is { } stale)
{
<p class="hint">Ultimo valore @stale.</p>
}
</li>
}
</ul>
<p class="note gauges-note">Sono indizi che il modello tiene in conto. Da soli non fanno comprare né vendere.</p>
<p class="hint">@Anubis.Data.FearGreed.Attribution.</p>
</section>
<section class="panel" aria-labelledby="calendario">
<h2 id="calendario">In calendario</h2>
@if (v.Calendar.Count == 0)
{
<p class="note">Nessun evento importante nei prossimi giorni.@(Shell.IsDemo || v.Collecting ? "" : " Il calendario si scarica con i dati di mercato.")</p>
}
else
{
<ul class="calendar-list">
@foreach (var e in v.Calendar)
{
<li>
<span class="muted">@e.When</span>
<strong>@e.Title</strong>
<span class="@(e.Matters ? "attention-text" : "muted")">@e.Effect</span>
</li>
}
</ul>
}
</section>
<section class="plain" aria-labelledby="fonti">
<h2 id="fonti">Da dove leggo</h2>
@if (v.Sources.Count == 0)
{
<p class="note">Non leggo ancora nessuna fonte. Le notizie si scaricano con i dati di mercato.</p>
}
else
{
<ul class="source-list">
@foreach (var s in v.Sources)
{
<li>
<span class="@(s.Ok ? "gain" : "loss")"><Icon Name="@(s.Ok ? "check" : "alert")" Size="16" /></span>
<span>@s.Name</span>
<span class="muted">@s.Frequency</span>
</li>
}
</ul>
}
<p class="note">@v.Spending</p>
<p class="hint"><a href="/impostazioni#notizie">Fonti e regole nelle impostazioni</a></p>
</section>
</div>
</div>
@code {
/// <summary>The rows shown before "Mostra le altre", as in the mockup.</summary>
private const int Shown = 6;
private NewsView _view = null!;
private string _filter = "posizioni";
private bool _all;
[CascadingParameter]
public HttpContext? HttpContext { get; set; }
[SupplyParameterFromQuery(Name = "filtro")]
public string? Filtro { get; set; }
[SupplyParameterFromQuery(Name = "tutte")]
public string? Tutte { get; set; }
protected override async Task LoadAsync()
{
var ct = HttpContext?.RequestAborted ?? CancellationToken.None;
_view = await NewsView.LoadAsync(Host, Shell, ct);
// Without positions the default filter would be empty: then all the news.
_filter = Filtro is "effetto" or "posizioni" or "tutte" ? Filtro : _view.Board.OnPositions > 0 ? "posizioni" : "tutte";
_all = Tutte == "1";
}
private IEnumerable<NewsBoardRow> Filtered(IEnumerable<NewsBoardRow> rows) => _filter switch
{
"effetto" => rows.Where(r => r.Active),
"posizioni" => rows.Where(r => r.OnPositions),
_ => rows,
};
private static string Lead(NewsView v)
{
var read = v.Board.Read == 1 ? "1 notizia letta" : $"{v.Board.Read} notizie lette";
var active = v.Board.Active switch
{
0 => "nessuna con un effetto in corso",
1 => "1 con un effetto in corso",
var n => $"{n} con un effetto in corso",
};
return $"{read} nelle ultime 24 ore, {active}.";
}
private string Empty(NewsView v) => _filter switch
{
"effetto" => "Nessuna notizia ha un effetto in corso: compro e vendo come dicono le strategie.",
"posizioni" => "Nessuna notizia sulle tue posizioni nelle ultime 24 ore.",
_ when !v.Collecting && !Shell.IsDemo => "Non leggo ancora notizie: la raccolta parte con i dati di mercato. Le fonti si scelgono nelle impostazioni.",
_ => "Nessuna notizia nelle ultime 24 ore.",
};
// "Niente. Confermano…" reads "niente. Confermano…" after "Cosa ho fatto:".
private static string Inline(string text) => text.Length == 0 ? text : char.ToLowerInvariant(text[0]) + text[1..];
private static string Css(double value) => value.ToString("0.##", CultureInfo.InvariantCulture);
}