ci / build-test (push) Successful in 2m31s
The dashboards told several stories at once. Overview asked for full calendar years, meter detail for a fixed 12-month window that was really 13, Trends for 24 months with an Apply button, and the energy pages for 60. Each page derived "today" from UTC, so the first hours of a local day belonged to yesterday. A missing tariff, a month nobody measured and a genuine zero all rendered as 0. And a virtual meter -- the one thing the spreadsheet leans on hardest -- was excluded from analysis outright: MeterPeriodService returned null for it and the page offered a flow diagram instead. docs/DASHBOARD_ANALYSIS_CHANGE_BRIEF.md is the work order. Every choice it left open is settled in docs/ANALYSIS_IMPLEMENTATION_NOTE.md as D-01..D-58 plus amendments A-01..A-30; code, tests and release notes cite those ids. The analysis layer Core/Analysis holds the pure rules: period presets resolved once in the instance zone into a local date range and a half-open UTC range, bucket plans, calendar-unit comparisons, coverage runs with a resolution class, normalized quantities and units, the totals policy, the virtual formula parser/validator/evaluator, and the cost calculator. "Now" comes from TimeProvider; services never read the clock. Normalization now writes, in the same transaction as consumption and by diff, per-meter rollups by local day and month plus coverage runs and a rollup state (AnalysisDataWriter). AnalysisReader answers a request from those tables -- month rollups for month and year buckets, day rollups otherwise, at most two partial edge days from consumption -- and CostReader prices the result month by month. Pages, /api/v1 and the CSV export read nothing else. The unused continuous aggregates are dropped. The reader's statement count per request is constant whether it covers one meter or a thousand. On a synthetic 1,000-meter, ten-year instance the brief's target request (100 meters, ten years, monthly) takes 374 ms against a two-second target, and the Overview went from 48,244 SQL statements per load to 205. Missing is not zero Every bucket carries a status -- available, partial, missing, unresolved, invalid, pending -- derived from coverage, never from the amount, with provenance and a reason code beside it. A true zero is a number and a bar on the baseline; an unknown bucket is a gap that says why; a month whose data only exists monthly says so instead of inventing daily detail; a scope with no tariff says "not priced" instead of 0. Rows whose interval closes after now are reported separately rather than counted. Virtual meters are analysis subjects A virtual meter stores a canonical definition -- expression over m<id> references, result kind, unit and cost rule -- validated on save and on read for syntax, unknown or self references, loops and unit/kind rules. It is evaluated on read from its sources' rollups over their joint coverage: a missing source makes the bucket missing, an observed zero is a valid input, a non-finite result is invalid with its dependency path, and the page lists each source's contribution. Topology links are topology only and never rewrite a saved calculation; expression-less meters from older installs are converted once at startup. The editor has Sum, Difference and Advanced modes with a live preview. Totals and the bill Per energy type the totals policy separates use, grid import, export, generation and runtime, marks breakdown meters as breakdowns and virtual meters as views, and never adds across units. The bill follows it: grid import where there is one, separately priced subsections at their own price, feed-in only on export meters, standing charges once per scope per local day, manual costs once on their start day, categories as non-overlapping covers whose composition reconciles to the bill. The seeded demo's yearly totals now match the spreadsheet. Pages and navigation The period lives in the URL and every page reads the same contract, so a link, a reload and the browser's Back button keep it. Shared components carry it: page header with breadcrumbs, period toolbar, theme-aware chart with an accessible table beside it, metric cards, comparison and availability states, attention items that each link to the one action that fixes them. Meter detail leads with an Analysis tab and resolves its tabs by key; the energy page has Overview, History, Flow and Meters; the old cost-only Trends page is a general Analysis page over portfolio, type, category, meter or a meter comparison. Records tabs are paged server-side instead of showing the latest 200. Everything is English and German, light and dark, down to 360px. Some figures change on purpose; docs/RELEASE_NOTES.md lists each one and what the first start after the update does (it rebuilds all analysis data before the web server listens). docs/SDD.md and CLAUDE.md describe the system as it now is. Tests: 1,733 Core and 746 integration, all green, plus an opt-in performance suite with a synthetic 1,000-meter generator.
105 lines
5.6 KiB
C#
105 lines
5.6 KiB
C#
using System.Net;
|
|
using MeterVault.App;
|
|
using MeterVault.Core.Domain;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace MeterVault.Integration.Tests.Editor;
|
|
|
|
/// <summary>
|
|
/// The tariff and settings pages as the server prerenders them (D-37, D-52, D-57): a scoped tariff link lists what can
|
|
/// price that meter and nothing else, Bonus/Discount/Tax say they are not applied, and settings label raw retention as
|
|
/// not enforced, with the reason, beside the analysis data state.
|
|
/// </summary>
|
|
[Collection("Timescale")]
|
|
public sealed class AdminPagesRenderTests(TimescaleFixture fx) : IAsyncLifetime
|
|
{
|
|
private short _type;
|
|
private short _otherType;
|
|
private int _meter;
|
|
private readonly List<int> _tariffs = [];
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
await using var db = fx.CreateContext();
|
|
var type = new EnergyType { Key = $"tariffs-{Guid.NewGuid():N}", DisplayName = "Tariff water", BaseUnit = "m3", DefaultMode = MeterMode.CumulativeCounter };
|
|
var other = new EnergyType { Key = $"tariffs-{Guid.NewGuid():N}", DisplayName = "Tariff heat", BaseUnit = "kWh", DefaultMode = MeterMode.CumulativeCounter };
|
|
db.EnergyTypes.AddRange(type, other);
|
|
await db.SaveChangesAsync();
|
|
_type = type.Id;
|
|
_otherType = other.Id;
|
|
|
|
var meter = new Meter { Name = "Tap meter", EnergyTypeId = _type, Mode = MeterMode.CumulativeCounter, Unit = "m3", Meta = "{}" };
|
|
db.Meters.Add(meter);
|
|
await db.SaveChangesAsync();
|
|
_meter = meter.Id;
|
|
|
|
Tariff[] tariffs =
|
|
[
|
|
Tariff(TariffScope.Meter, _meter, TariffComponent.UnitPrice, 1.2345, "EUR/m3"),
|
|
Tariff(TariffScope.EnergyType, _type, TariffComponent.Bonus, 2.3456, "EUR"),
|
|
Tariff(TariffScope.EnergyType, _otherType, TariffComponent.UnitPrice, 9.8765, "EUR/kWh"),
|
|
];
|
|
db.Tariffs.AddRange(tariffs);
|
|
await db.SaveChangesAsync();
|
|
_tariffs.AddRange(tariffs.Select(t => t.Id));
|
|
}
|
|
|
|
public async Task DisposeAsync()
|
|
{
|
|
await using var db = fx.CreateContext();
|
|
await db.Tariffs.Where(t => _tariffs.Contains(t.Id)).ExecuteDeleteAsync();
|
|
await db.Meters.Where(m => m.Id == _meter).ExecuteDeleteAsync();
|
|
await db.EnergyTypes.Where(t => t.Id == _type || t.Id == _otherType).ExecuteDeleteAsync();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task A_scoped_tariff_link_lists_what_can_price_the_meter()
|
|
{
|
|
using var factory = new MeterVaultAppFactory(fx.ConnectionString);
|
|
using var client = factory.CreateClient();
|
|
|
|
var scoped = WebUtility.HtmlDecode(await client.GetStringAsync(new Uri($"{TariffLinks.Path}?scope=meter&id={_meter}", UriKind.Relative)));
|
|
Assert.Contains("Tariffs that can price Tap meter: its own, its energy type's and global ones.", scoped, StringComparison.Ordinal);
|
|
Assert.Contains("1.2345", scoped, StringComparison.Ordinal); // its own price
|
|
Assert.Contains("2.3456", scoped, StringComparison.Ordinal); // its type's bonus …
|
|
Assert.Contains("Not applied yet", scoped, StringComparison.Ordinal); // … which is not applied yet
|
|
Assert.DoesNotContain("9.8765", scoped, StringComparison.Ordinal); // another type's price is not listed
|
|
Assert.Contains("Bonus, discount and tax tariffs are stored but not applied to costs yet.", scoped, StringComparison.Ordinal);
|
|
|
|
var all = WebUtility.HtmlDecode(await client.GetStringAsync(new Uri(TariffLinks.Path, UriKind.Relative)));
|
|
Assert.Contains("9.8765", all, StringComparison.Ordinal);
|
|
Assert.DoesNotContain("Tariffs that can price", all, StringComparison.Ordinal);
|
|
|
|
// The deep link of a missing price renders; its dialog opens only once the page is interactive.
|
|
var link = TariffLinks.New(TariffScope.Meter, _meter, TariffComponent.UnitPrice, new DateOnly(2027, 1, 1));
|
|
(await client.GetAsync(new Uri(link, UriKind.Relative))).EnsureSuccessStatusCode();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Settings_label_raw_retention_as_not_enforced_in_both_languages()
|
|
{
|
|
using var factory = new MeterVaultAppFactory(fx.ConnectionString);
|
|
using var client = factory.CreateClient();
|
|
|
|
var english = WebUtility.HtmlDecode(await client.GetStringAsync(new Uri("/admin/settings", UriKind.Relative)));
|
|
Assert.Contains("Not enforced", english, StringComparison.Ordinal);
|
|
Assert.Contains("Raw readings are kept indefinitely (configured: 1095 days).", english, StringComparison.Ordinal);
|
|
Assert.Contains("Analysis data", english, StringComparison.Ordinal);
|
|
Assert.Contains("Meters with current analysis data", english, StringComparison.Ordinal);
|
|
Assert.DoesNotContain("could not be read", english, StringComparison.Ordinal);
|
|
|
|
using var german = factory.CreateClient();
|
|
german.DefaultRequestHeaders.Add(
|
|
"Cookie",
|
|
CookieRequestCultureProvider.DefaultCookieName + "="
|
|
+ Uri.EscapeDataString(CookieRequestCultureProvider.MakeCookieValue(new RequestCulture("de"))));
|
|
var deutsch = WebUtility.HtmlDecode(await german.GetStringAsync(new Uri("/admin/settings", UriKind.Relative)));
|
|
Assert.Contains("Nicht aktiv", deutsch, StringComparison.Ordinal);
|
|
Assert.Contains("Auswertungsdaten", deutsch, StringComparison.Ordinal);
|
|
}
|
|
|
|
private static Tariff Tariff(TariffScope scope, int id, TariffComponent component, double value, string unit) =>
|
|
new() { ScopeType = scope, ScopeId = id, Component = component, Value = value, Unit = unit, ValidFrom = new DateOnly(2020, 1, 1) };
|
|
}
|