ci / build-test (push) Failing after 35s
The last open item on the M7 list. Number and currency formatting was already locale-aware, but every string in the UI was an English literal, so a German instance read half in each language -- German data, English chrome. This translates all of it and adds the machinery to keep it translated. Strings live in Localization/Strings.resx (English, neutral) and Strings.de.resx. The neutral file generates a strongly-typed accessor at build time, aliased as S in _Imports.razor, so components reference compiled properties -- @S.Common_Save, not a string key. That choice is the point: across 4,500 lines of markup, a key lookup that silently falls back to its own name is a defect you find in production, while a renamed property is a build error. Generation runs in MSBuild rather than the IDE designer, so dotnet build alone reproduces it anywhere. Resource fallback is the hazard here. Ask for a key the German satellite lacks and ResourceManager quietly serves the English one -- correct at runtime, disastrous at release time, because a half-translated build looks perfectly healthy. StringResourceTests reads each satellite with tryParents: false, which is the only way to see what one actually contains, and fails on a missing or blank translation, a placeholder that changed arity, an orphan, or a key nothing references. Three things needed more than substitution: - Domain enums reached the screen as bare identifiers. They stay bare in the model -- they are persisted as text and appear in the REST API, so their names are part of the data contract -- and DisplayNames is now the single place that decides how each value is spoken. Every arm ends in a fallback returning the identifier, so a value added later cannot throw mid-render; EnumDisplayNameTests is what stops that safety net quietly becoming the shipping behaviour. - Infrastructure was writing display text: FlowService's "Other (X)", MeterPeriodView's "Generation"/"Consumption", the HA connection-test verdicts, the updater's snackbar, the CSV importer's row warnings. Each now returns an outcome value and the UI supplies the words, which is where the reader's language is known. Diagnostics that are not ours -- an HTTP status, systemd's stderr, an exception message -- are passed through untranslated, and every English summary is kept alongside the outcome so log lines never move with the UI language. The UpdateRunner change is additive only; no gate was touched. - Importer warnings carry their arguments rather than a finished sentence, so the numbers inside them pick up the reader's grouping. A register that reads 2.940,19 everywhere else must not read 2940.19 only inside a warning. Switching language is a redirect through /culture/set followed by a full reload, not an interactive state change: a Blazor Server circuit is fixed to the culture of the request that opened it. That makes the endpoint a redirector taking its target from the query string, so anything but a local path is refused rather than followed. Preference order is the cookie, then Accept-Language, then MeterVault__Locale -- an instance can be pinned to one language and a reader can still switch. Locale keeps its documented default of "en". Format now follows CurrentCulture instead of a hardcoded de-DE, so an instance with nothing configured and a browser asking for English will show English number formatting where it previously showed German; set MeterVault__Locale=de to pin the old behaviour. The importer's de-DE parsing is untouched and stays that way -- that dialect is a property of the spreadsheets, not of whoever is looking at the dashboard. Anything that comes from the database -- meter names, energy-type display names, category names -- is user data and is never translated. Claude-Session: https://claude.ai/code/session_0112ezeWqaZ85kTj5bYu9JHx
95 lines
4.2 KiB
C#
95 lines
4.2 KiB
C#
using MeterVault.Core.Domain;
|
||
|
||
namespace MeterVault.Infrastructure.Dashboard;
|
||
|
||
/// <summary>A raw reading row for the meter-detail table.</summary>
|
||
public sealed record ReadingRow(DateTimeOffset Time, double Value, ReadingQuality Quality, ReadingFlags Flags);
|
||
|
||
/// <summary>A normalized consumption row for the meter-detail table.</summary>
|
||
public sealed record ConsumptionDetailRow(DateTimeOffset Time, double Amount, ConsumptionKind Kind, ReadingQuality Quality);
|
||
|
||
/// <summary>One calendar month of a meter's normalized history, bucketed in the instance timezone.</summary>
|
||
public sealed record MeterMonthPoint(DateOnly Month, double Amount, double Cost);
|
||
|
||
/// <summary>
|
||
/// A meter framed the way it is actually read: what it used this period, how that compares with the
|
||
/// last one, and where the year is heading. Amounts are generation for a generation counter and
|
||
/// consumption otherwise, so <see cref="Kind"/> says which — as the enum, not a word, because the
|
||
/// wording belongs to whichever language the reader picked.
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// Month- and year-to-date are compared against a <em>projection</em> of the current period rather
|
||
/// than its raw running total: three days into a month, "12 kWh vs 340 kWh last month" reads as a
|
||
/// collapse in usage when nothing has changed. Projections are flagged so the UI can mark them.
|
||
/// </remarks>
|
||
public sealed record MeterPeriodView(
|
||
ConsumptionKind Kind,
|
||
string Unit,
|
||
string Currency,
|
||
double MonthToDate,
|
||
double MonthProjected,
|
||
double LastMonth,
|
||
double YearToDate,
|
||
double YearProjected,
|
||
double LastYear,
|
||
double YearToDateCost,
|
||
double YearProjectedCost,
|
||
double LastYearCost,
|
||
bool MonthIsPartial,
|
||
IReadOnlyList<MeterMonthPoint> Last12Months)
|
||
{
|
||
/// <summary>Projected month against last month, as a fraction (+0.12 = 12% more). Null if no basis.</summary>
|
||
public double? MonthChange => Ratio(MonthProjected, LastMonth);
|
||
|
||
/// <summary>Projected year against last year, as a fraction. Null if no basis.</summary>
|
||
public double? YearChange => Ratio(YearProjected, LastYear);
|
||
|
||
public bool HasHistory => Last12Months.Count > 0;
|
||
|
||
/// <summary>
|
||
/// Percentage change is only meaningful against a positive baseline. Dividing by a negative one
|
||
/// inverts the sign — a net-export meter going from −100 to −150 would report "+50% more used"
|
||
/// when it exported half as much again — so those report no basis rather than a confident lie.
|
||
/// </summary>
|
||
private static double? Ratio(double current, double previous) =>
|
||
previous <= 1e-9 ? null : (current - previous) / previous;
|
||
}
|
||
|
||
/// <summary>A meter lifecycle/correction event row.</summary>
|
||
public sealed record EventRow(DateTimeOffset Time, MeterEventType Type, double? Amount, double? PrevValue, double? NewValue, string? Unit, string? Notes);
|
||
|
||
/// <summary>A tariff applicable to the meter (own / energy-type / global scope), for the timeline.</summary>
|
||
public sealed record TariffRow(TariffScope Scope, int? ScopeId, TariffComponent Component, double Value, string Unit, DateOnly ValidFrom, DateOnly? ValidTo);
|
||
|
||
/// <summary>
|
||
/// The meter-detail read model (SDD §8.6): identity, register span, totals, recent raw readings
|
||
/// and normalized consumption (measured-vs-estimated markers via quality), the applicable tariff
|
||
/// timeline, and lifecycle events (swaps/deliveries/corrections). Source management loads the
|
||
/// source entities directly (they are editable), so it is not part of this read model.
|
||
/// </summary>
|
||
public sealed record MeterDetailView(
|
||
int Id,
|
||
string Name,
|
||
string EnergyType,
|
||
MeterMode Mode,
|
||
string Unit,
|
||
string? Location,
|
||
string? SerialNumber,
|
||
string? Manufacturer,
|
||
string? Model,
|
||
double InitialBaseline,
|
||
bool IsActive,
|
||
int ReadingCount,
|
||
int ConsumptionCount,
|
||
DateTimeOffset? FirstReadingTime,
|
||
DateTimeOffset? LastReadingTime,
|
||
double? FirstReadingValue,
|
||
double? LastReadingValue,
|
||
double TotalConsumption,
|
||
double TotalGeneration,
|
||
IReadOnlyList<ReadingRow> RecentReadings,
|
||
IReadOnlyList<ConsumptionDetailRow> RecentConsumption,
|
||
IReadOnlyList<EventRow> Events,
|
||
IReadOnlyList<TariffRow> Tariffs,
|
||
int SourceCount);
|