SDD §8 panels (PV/oil/meter-detail) + fix reference-data-in-Docker

Complete the SDD §8 dashboard views that were deferred at the M5 boundary,
and fix a shipping bug that left the Docker demo empty.

Bug: "Load reference data" created meters/tank/tariffs but imported zero
readings in Docker. Root cause: sampledata/ was excluded by .dockerignore and
never copied into the build stage, so the App csproj's linked Content glob
resolved to nothing at publish time; ReferenceDataImporter then silently
skipped the missing CSVs after already writing its marker meter, leaving the
DB permanently "loaded" but empty.
  - .dockerignore: stop excluding sampledata/
  - Dockerfile: COPY sampledata/ into the build stage
  - ReferenceDataImporter: fail-fast (validate CSVs exist before the marker
    meter) and throw instead of silently skipping a missing file
  - Program.cs + MeterVaultOptions: opt-in MeterVault__SeedReferenceData
    (compose METERVAULT_SEED=true) for a one-command populated demo

New SDD §8 panels (read models in Infrastructure/Dashboard, Blazor pages):
  - §8.4 Solar/PV (/solar): generation from GenerationCounter meters;
    self-consumption / autarky % / self-consumption % / savings derived from
    meters tagged total_load & grid_import via Meter.Meta role config
    (MeterRoles/MeterMeta) — nothing hardcoded by name.
  - §8.5 Oil/consumable (/consumables): tank level (cm→L calibrated), fill
    gauge, deliveries log, burner runtime, effective L/h (fixed/empirical),
    forecast-to-empty, tariff cost, monthly series.
  - §8.6 Meter detail (/meters/{id}): raw readings, normalized consumption,
    source status, tariff timeline, events, measured-vs-estimated markers.
  - Reusable SeriesChart component; nav links; Meters list rows link to detail.

Tests: MeterMetaTests (Core, +10); DashboardRenderTests extended to assert the
three panel services compute real figures and the new routes render (108 total,
all green). Live-verified in Docker: seed imports 302 readings / 347 consumption
rows; panels render (generation 16,481 kWh, oil 3,967 L) cross-checking the DB.

Claude-Session: https://claude.ai/code/session_01Lz2RqAsnQhetqWNoCDfexK
This commit is contained in:
2026-07-14 09:52:11 +02:00
parent 39da00d486
commit 1282acf82c
24 changed files with 1327 additions and 7 deletions
+149
View File
@@ -0,0 +1,149 @@
@page "/solar"
@rendermode InteractiveServer
@inject SolarService SolarSvc
@using MudBlazor
<PageTitle>MeterVault — Solar / PV</PageTitle>
<div class="d-flex align-center justify-space-between mb-4 flex-wrap" style="gap:1rem">
<MudText Typo="Typo.h4">Solar / PV</MudText>
<MudSelect T="int" Value="_months" ValueChanged="OnRangeChanged" Label="Range" Dense="true" Style="max-width:200px">
<MudSelectItem T="int" Value="12">Last 12 months</MudSelectItem>
<MudSelectItem T="int" Value="24">Last 24 months</MudSelectItem>
<MudSelectItem T="int" Value="60">Last 5 years</MudSelectItem>
<MudSelectItem T="int" Value="1200">All time</MudSelectItem>
</MudSelect>
</div>
@if (_summary is null)
{
<MudProgressLinear Indeterminate="true" Color="Color.Primary" />
}
else if (!_summary.HasGeneration)
{
<MudAlert Severity="Severity.Info">
No generation meters found. Add a meter with mode <b>GenerationCounter</b>, or load the reference data from
<MudLink Href="/import">Import</MudLink>.
</MudAlert>
}
else
{
<MudGrid>
<MudItem xs="12" sm="6" md="3">
<MudPaper Class="pa-4" Elevation="2">
<MudText Typo="Typo.overline" Color="Color.Secondary">Generation</MudText>
<MudText Typo="Typo.h5">@Format.Number(_summary.Generation, 0) kWh</MudText>
</MudPaper>
</MudItem>
<MudItem xs="12" sm="6" md="3">
<MudPaper Class="pa-4" Elevation="2">
<MudText Typo="Typo.overline" Color="Color.Secondary">Self-consumption</MudText>
<MudText Typo="Typo.h5">@(_summary.SelfConsumption is { } s ? $"{Format.Number(s, 0)} kWh" : "—")</MudText>
@if (_summary.SelfConsumptionRatio is { } ratio)
{
<MudText Typo="Typo.caption" Color="Color.Secondary">@Format.Number(ratio * 100, 0)% of generation</MudText>
}
</MudPaper>
</MudItem>
<MudItem xs="12" sm="6" md="3">
<MudPaper Class="pa-4" Elevation="2">
<MudText Typo="Typo.overline" Color="Color.Secondary">Autarky</MudText>
<MudText Typo="Typo.h5">@(_summary.Autarky is { } a ? $"{Format.Number(a * 100, 0)} %" : "—")</MudText>
@if (_summary.GridImport is { } grid)
{
<MudText Typo="Typo.caption" Color="Color.Secondary">Grid draw @Format.Number(grid, 0) kWh</MudText>
}
</MudPaper>
</MudItem>
<MudItem xs="12" sm="6" md="3">
<MudPaper Class="pa-4" Elevation="2">
<MudText Typo="Typo.overline" Color="Color.Secondary">Savings (Ersparnis)</MudText>
<MudText Typo="Typo.h5">@(_summary.Savings is { } sav ? Format.Euro(sav) : "—")</MudText>
</MudPaper>
</MudItem>
<MudItem xs="12" md="8">
<MudPaper Class="pa-4" Elevation="2" Style="height:100%">
<MudText Typo="Typo.h6" Class="mb-2">Generation &amp; self-consumption</MudText>
<SeriesChart Series="_chart" Decimals="0" Height="340" />
</MudPaper>
</MudItem>
<MudItem xs="12" md="4">
<MudPaper Class="pa-4" Elevation="2" Style="height:100%">
<MudText Typo="Typo.h6" Class="mb-2">Generation by meter</MudText>
<MudSimpleTable Dense="true" Hover="true">
<tbody>
@foreach (var meter in _summary.Meters)
{
<tr>
<td>@meter.Name</td>
<td style="text-align:right">@Format.Number(meter.Generation, 0) kWh</td>
</tr>
}
</tbody>
</MudSimpleTable>
@if (!_summary.HasLoadContext)
{
<MudAlert Severity="Severity.Info" Dense="true" Class="mt-3">
Tag a meter <code>total_load</code> and one <code>grid_import</code> (in meter metadata)
to unlock self-consumption, autarky and savings.
</MudAlert>
}
</MudPaper>
</MudItem>
</MudGrid>
}
@code {
private int _months = 60;
private bool _loading;
private SolarSummary? _summary;
private IReadOnlyList<SeriesChart.SeriesDef> _chart = [];
protected override Task OnInitializedAsync() => LoadAsync();
private async Task OnRangeChanged(int months)
{
_months = months;
await LoadAsync();
}
private async Task LoadAsync()
{
if (_loading)
{
return;
}
_loading = true;
_summary = null;
try
{
var asOf = DateOnly.FromDateTime(DateTime.UtcNow);
var from = asOf.AddMonths(-_months);
_summary = await SolarSvc.GetSummaryAsync(new DateOnly(from.Year, from.Month, 1), asOf.AddMonths(1));
var generation = _summary.Months
.Select(m => new SeriesChart.Point(m.Period.ToString("MMM yy", System.Globalization.CultureInfo.InvariantCulture), m.Generation))
.ToList();
var series = new List<SeriesChart.SeriesDef>
{
new("Generation", ApexCharts.SeriesType.Bar, generation),
};
if (_summary.HasLoadContext)
{
var self = _summary.Months
.Select(m => new SeriesChart.Point(m.Period.ToString("MMM yy", System.Globalization.CultureInfo.InvariantCulture), m.SelfConsumption ?? 0))
.ToList();
series.Add(new("Self-consumption", ApexCharts.SeriesType.Bar, self));
}
_chart = series;
}
finally
{
_loading = false;
}
}
}