Files
poli0981andClaude Fable 5.2 15aaa65059 feat(app): the Advanced page - This PC, Session and Sources; its navigation item and Ctrl+6 there only while the option is on; every catalog entry in en, vi and ja; a guide page (Advanced PR-7, D101/D105/D107) (#393)
Pages/AdvancedPage over ViewModels/AdvancedViewModel. This PC is what the Agent reads now, asked only while the page
is on screen and never stored: the facts under the catalog's groups, every series with the time it was read at, and
one entry's last five minutes. Session is what a session recorded with the option on stored: the PC as it was, the
session's own facts, the statistics, and the entry's series over the session. Sources is every catalog entry with
whether it is read, or why not.

The navigation item is the menu's last and is bound to Services.AdvancedOption.IsOn - set at start and by the
Settings switch - and Ctrl+6 opens the page only while it is on; Ctrl+1..5 keep their pages. A session's summary has
"Advanced metrics..." where the session stored them. A viewer opens on Session and asks no Agent.

245 strings in en, vi and ja (ja marked for review): the English label of an entry is its summary in the catalog. A
family of more than eight series is drawn as its lowest, average and highest. ISessionRepository.ListAdvancedAsync;
SessionSeriesLoader.LoadAdvancedAsync. The guide gains a page; ACCESSIBILITY.md, LIMITATIONS.md, 08_UI §Advanced, the
accuracy block and Privacy Policy 2.15 follow. Nothing in src/native changes.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-11 13:26:09 +00:00

184 lines
8.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.IO;
using FrameLedger.App.Services;
using FrameLedger.Application.Persistence;
using FrameLedger.Domain.Consent;
using FrameLedger.Domain.Sessions;
using FrameLedger.Infrastructure.Persistence;
namespace FrameLedger.App.Tests;
/// <summary>A scratch ledger per test with the App's own repositories over it — never the real one under %LOCALAPPDATA%.</summary>
internal sealed class ScratchLedger : IAsyncDisposable
{
private readonly string _dir = Path.Combine(Path.GetTempPath(), "fl-app-" + Guid.NewGuid().ToString("N"));
public LedgerDatabase Db { get; private set; } = null!;
public SqliteGameRepository Games { get; private set; } = null!;
public SqliteSessionRepository Sessions { get; private set; } = null!;
public SqliteSessionAnnotationRepository Annotations { get; private set; } = null!;
public GameLibrary Library { get; private set; } = null!;
public static async Task<ScratchLedger> OpenAsync(TimeProvider? clock = null)
{
var s = new ScratchLedger();
s.Db = await LedgerDatabase.OpenAsync(Path.Combine(s._dir, LedgerPaths.DatabaseFileName), ct: TestContext.Current.CancellationToken).ConfigureAwait(false);
s.Games = new SqliteGameRepository(s.Db);
s.Sessions = new SqliteSessionRepository(s.Db);
s.Annotations = new SqliteSessionAnnotationRepository(s.Db);
s.Library = new GameLibrary(s.Games, s.Sessions, s.Annotations, clock);
return s;
}
public async Task<GameRow> GameAsync(string name, string exe = null!)
{
exe ??= Path.Combine(_dir, name + ".exe");
return await Games.EnsureAsync(new ExecutableFingerprint { ExePath = exe, SizeBytes = 1, MtimeUnixMs = 1 }, name, TestContext.Current.CancellationToken).ConfigureAwait(false);
}
public async Task<long> SessionAsync(long gameId, DateTimeOffset startedAt, int seconds = 600, bool hooked = true, string fgMode = "none", double? native = 60, double? displayed = null, double? factor = null, ExitStatus exit = ExitStatus.Normal, string? fgRefusal = null, double? presented = null, string? qualifier = null,
IReadOnlyList<SensorBlob>? sensors = null, Domain.Display.DisplaySummary? display = null, bool settingsChanged = false,
Func<SessionRow, SessionRow>? shape = null, AdvancedSessionRow? advanced = null)
{
long snapshotId = await new SqliteHardwareSnapshotRepository(Db).EnsureAsync(new HardwareSnapshot { GpuName = "G" }, startedAt, TestContext.Current.CancellationToken).ConfigureAwait(false);
var row = new SessionRow
{
SessionGuid = Guid.NewGuid(),
GameId = gameId,
SnapshotId = snapshotId,
StartedAt = startedAt,
EndedAt = startedAt.AddSeconds(seconds),
QpcEpoch = 0,
QpcFrequency = 1,
Tier = hooked ? CaptureTier.Hooked : CaptureTier.NotHooked,
Mode = CaptureMode.Launch,
ExitStatus = exit,
FrameCount = hooked ? seconds * 60 : 0,
FgMode = hooked ? fgMode : "na",
NativeFps = hooked ? native : null,
DisplayedFps = displayed,
FgFactor = factor,
FgRefusal = fgRefusal,
PresentedFps = presented,
PresentedQualifier = qualifier,
Api = hooked ? "d3d12" : null,
Upscaler = hooked ? "dlss" : null,
RenderW = hooked ? 1485 : null,
RenderH = hooked ? 835 : null,
OutputW = hooked ? 2560 : null,
OutputH = hooked ? 1440 : null,
RtFlag = hooked ? "yes" : "na",
RtSource = hooked ? "measured" : null,
P1LowFps = hooked ? 48 : null,
MaxGpuTemp = 71,
SettingsChangedMidSession = settingsChanged,
};
row = Application.Recording.SessionDisplayColumns.WithDisplay(row, display);
row = shape?.Invoke(row) ?? row;
return await Sessions.InsertFinalizedAsync(new FinalizedSession { Row = row, Sensors = sensors ?? [], Advanced = advanced }, TestContext.Current.CancellationToken).ConfigureAwait(false);
}
/// <summary>A session that was not hooked, with the sensors a Tier-2 row keeps (since 2026-09-22): three ticks of GPU temperature and power.</summary>
public Task<long> NotHookedWithSensorsAsync(long gameId, DateTimeOffset startedAt) => SessionAsync(gameId, startedAt, hooked: false, sensors:
[
new SensorBlob { Series = "t_ms", Hz = 1, Codec = Infrastructure.Blobs.SeriesCodec.Tag, Data = Infrastructure.Blobs.SeriesCodec.EncodeFloat32([500, 1500, 2500]) },
new SensorBlob { Series = "gpu_temp", Hz = 1, Codec = Infrastructure.Blobs.SeriesCodec.Tag, Data = Infrastructure.Blobs.SeriesCodec.EncodeFloat32([55, 56, 57]) },
new SensorBlob { Series = "gpu_power", Hz = 1, Codec = Infrastructure.Blobs.SeriesCodec.Tag, Data = Infrastructure.Blobs.SeriesCodec.EncodeFloat32([150, 160, 170]) },
]);
/// <summary>A hooked session WITH blobs: <paramref name="frames"/> presents at 60 fps, a 4× spike every <paramref name="spikeEvery"/> frames, one segment, a gpu_temp series.</summary>
public async Task<long> SessionWithFramesAsync(long gameId, DateTimeOffset startedAt, int frames, int spikeEvery, Func<SessionRow, SessionRow>? shape = null)
{
long snapshotId = await new SqliteHardwareSnapshotRepository(Db).EnsureAsync(new HardwareSnapshot { GpuName = "G" }, startedAt, TestContext.Current.CancellationToken).ConfigureAwait(false);
float[] frametimes = new float[frames];
byte[] flags = new byte[frames];
uint[] index = new uint[frames];
flags[0] = 4; // the first present carries no interval (FrameFlagBits.Gap = 1 << 2)
for (int i = 1; i < frames; i++)
{
frametimes[i] = spikeEvery > 0 && i % spikeEvery == 0 ? 66.667f : 16.667f;
index[i] = (uint)i;
}
double seconds = frametimes.Sum() / 1000.0;
SessionRow row = HookedRow(gameId, snapshotId, startedAt, frames, spikeEvery, seconds);
row = shape is null ? row : shape(row);
return await Sessions.InsertFinalizedAsync(new FinalizedSession
{
Row = row,
Segments = [new SegmentRow { SwapchainId = 1, StartFrame = 0, EndFrame = frames - 1, RenderW = 1485, RenderH = 835, OutputW = 2560, OutputH = 1440, Upscaler = "dlss", UpscalerQuality = "Quality", FgMode = "none", NativeFps = 60 }],
Frames = new FrameBlobs
{
Codec = Infrastructure.Blobs.SeriesCodec.Tag,
SampleCount = frames,
FrameTimes = Infrastructure.Blobs.SeriesCodec.EncodeFloat32(frametimes),
FrameFlags = Infrastructure.Blobs.SeriesCodec.EncodeBytes(flags),
FrameIndex = Infrastructure.Blobs.SeriesCodec.EncodeUInt32(index),
FirstPresentMs = 0, // schema 0013: the frames and the sensors share a zero, so the overlay is drawn
},
Sensors =
[
new SensorBlob { Series = "t_ms", Hz = 1, Codec = Infrastructure.Blobs.SeriesCodec.Tag, Data = Infrastructure.Blobs.SeriesCodec.EncodeFloat32([0, 1000, 2000]) },
new SensorBlob { Series = "gpu_temp", Hz = 1, Codec = Infrastructure.Blobs.SeriesCodec.Tag, Data = Infrastructure.Blobs.SeriesCodec.EncodeFloat32([60, 61, 62]) },
],
}, TestContext.Current.CancellationToken).ConfigureAwait(false);
}
private static SessionRow HookedRow(long gameId, long snapshotId, DateTimeOffset startedAt, int frames, int spikeEvery, double seconds) => new()
{
SessionGuid = Guid.NewGuid(),
GameId = gameId,
SnapshotId = snapshotId,
StartedAt = startedAt,
EndedAt = startedAt.AddSeconds(seconds),
QpcEpoch = 0,
QpcFrequency = 10_000_000,
Tier = CaptureTier.Hooked,
Mode = CaptureMode.Launch,
ExitStatus = ExitStatus.Normal,
FrameCount = frames,
AppFrameCount = frames,
DisplayedFrameCount = frames,
FgMode = "none",
FgSource = "none",
NativeFps = 60,
MedianFps = 60,
P1LowFps = 48,
P01LowFps = 40,
MinFps = 15,
MaxFps = 61,
FrametimeStdDevMs = 1.5,
StutterCount = spikeEvery > 0 ? (frames - 1) / spikeEvery : 0,
StutterTimePct = 1.2,
Api = "d3d12",
PresentMode = "flip",
Upscaler = "dlss",
UpscalerQuality = "Quality",
RenderW = 1485,
RenderH = 835,
OutputW = 2560,
OutputH = 1440,
RtFlag = "yes",
RtSource = "measured",
MaxGpuTemp = 71,
};
public async ValueTask DisposeAsync()
{
await Db.DisposeAsync().ConfigureAwait(false);
try
{
Directory.Delete(_dir, recursive: true);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
}
}
}