Files
frameledger/src/FrameLedger.App/ViewModels/SessionSummaryViewModel.cs
T
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

651 lines
32 KiB
C#

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Text;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FrameLedger.App.Charts;
using FrameLedger.App.Controls;
using FrameLedger.App.Services;
using FrameLedger.Application.Persistence;
using FrameLedger.Application.TriState;
using FrameLedger.Domain.Sessions;
using ScottPlot;
namespace FrameLedger.App.ViewModels;
/// <summary>
/// The session summary (<c>08_UI</c> §Session summary): stat cards from the stored aggregates (never recomputed),
/// the chips with FR-8.3's override, the crash and safety-unhook bars, the decoded series for the charts, the
/// tags/notes editor, and FR-9's three exports.
/// </summary>
[SuppressMessage("Performance", "CA1863:Use 'CompositeFormat'", Justification = "the format strings are resources that follow the UI culture, which changes at runtime")]
public sealed partial class SessionSummaryViewModel : ObservableObject
{
/// <summary>Whether this session stored advanced metrics — it was recorded with the option on (owner decision D101).</summary>
[ObservableProperty]
private bool _hasAdvanced;
private readonly ISessionRepository _sessions;
private readonly IGameRepository _games;
private readonly ISessionAnnotationRepository _annotations;
private readonly IHardwareSnapshotRepository _hardware;
private readonly SessionSeriesLoader _loader;
private readonly ITriStateOverridePrompt _override;
private readonly IFileSaver _saver;
private readonly IMessageStrip _strip;
private SessionAnnotation? _annotation;
private IReadOnlyList<SegmentRow> _segments = [];
private HardwareSnapshot? _snapshot;
[ObservableProperty]
private string _title = string.Empty;
[ObservableProperty]
private string _line = string.Empty;
/// <summary>The session's hardware snapshot in one line (2026-09-21): it was loaded for the export and shown nowhere.</summary>
[ObservableProperty]
private string _hardwareLine = string.Empty;
/// <summary>
/// The runtime libraries the hooked game had loaded (<c>sessions.runtime_modules</c>, written since P2 and shown nowhere
/// until beta.8), each against the copy the game ships where they differ; null when the row has none.
/// </summary>
[ObservableProperty]
private string? _librariesLine;
/// <summary>
/// beta.24 (D64): the DLSS the session ran — a generation only where the session shows one, each DLSS library's version
/// and where it was loaded from, the preset the driver reports, DLSS 5's runtime when loaded; null with no DLSS at all.
/// </summary>
[ObservableProperty]
private string? _dlssLine;
/// <summary>
/// The NVIDIA driver profile the game ran under and what it overrides (<c>sessions.driver_profile</c>, beta.8) — the
/// NVIDIA App's DLSS and frame-generation overrides; null where no NVIDIA driver was there to ask.
/// </summary>
[ObservableProperty]
private string? _driverProfileLine;
/// <summary>What the driver reported applying in the game's process (<c>sessions.ngx_driver_words</c>); null when it reported no override.</summary>
[ObservableProperty]
private string? _driverStateLine;
[ObservableProperty]
private FpsReadoutModel _readout = FpsReadoutModel.Unavailable;
[ObservableProperty]
private bool _isHooked;
[ObservableProperty]
private bool _isCrashed;
[ObservableProperty]
private bool _isUnhooked;
/// <summary>How the session ended (beta.8): a crash with its exception, End task's exit code said as what it is.</summary>
[ObservableProperty]
private string _exitLine = string.Empty;
/// <summary>D33: the session was hooked under the game's user-mode exception, and for which anti-cheat; null otherwise.</summary>
[ObservableProperty]
private string? _exceptionLine;
/// <summary>
/// How the game was shown (beta.10, schema 0016): every mode's share, the window on its monitor, the back buffer and what
/// the facts rested on — in either tier; null for a row recorded before, or recovered from its crash file.
/// </summary>
[ObservableProperty]
private string? _displayLine;
/// <summary>Tier 2's payload (2026-09-22): why this session measured nothing, from the row's notes; empty for a hooked row.</summary>
[ObservableProperty]
private string _tier2Reason = string.Empty;
[ObservableProperty]
private bool _notFound;
[ObservableProperty]
private bool _hasDisplayed;
[ObservableProperty]
private bool _showDisplayed;
/// <summary>
/// The frametime chart can draw the sensors over the frames: they were recorded and the blob says where the first present
/// sits on their clock (schema 0013). A session recorded before keeps the overlay off rather than drawn out of step.
/// </summary>
[ObservableProperty]
private bool _hasSensors;
/// <summary>The Sensors section has something to draw — in either tier (beta.8).</summary>
[ObservableProperty]
private bool _hasSensorCharts;
[ObservableProperty]
private bool _showSensors;
/// <summary>beta.12: the session stored per-series statistics (<c>sensor_stats_json</c>), so the table is shown.</summary>
[ObservableProperty]
private bool _hasSensorStats;
/// <summary>
/// Why there is no table for a session that has sensors (beta.12): it was recorded before the statistics were stored. Null
/// when the table is shown, or when the session recorded no sensor at all — nothing is missing then.
/// </summary>
[ObservableProperty]
private string? _sensorStatsMissing;
/// <summary>beta.24 (D62): the session stored a mix of two rows or more, so the block is shown.</summary>
[ObservableProperty]
private bool _hasFgMix;
/// <summary>The mix as the bar draws it, in the table's order.</summary>
[ObservableProperty]
private IReadOnlyList<FgMixSegment> _fgMixSegments = [];
/// <summary>The bar's spoken name: every row with its share.</summary>
[ObservableProperty]
private string _fgMixName = string.Empty;
/// <summary>How frame generation was set — in the NVIDIA App, or in the game — when an NVIDIA profile was read; null otherwise.</summary>
[ObservableProperty]
private string? _fgMixContext;
/// <summary>What "not classified" means, when the mix has such a row; null otherwise.</summary>
[ObservableProperty]
private string? _fgMixUnclassifiedNote;
/// <summary>Why a session that counted frame generation shows no mix (<see cref="FgMixPresentation.Missing"/>); null otherwise.</summary>
[ObservableProperty]
private string? _fgMixMissing;
[ObservableProperty]
private string _tags = string.Empty;
[ObservableProperty]
private string _notes = string.Empty;
[ObservableProperty]
private string _decimationNote = string.Empty;
public SessionSummaryViewModel(ISessionRepository sessions, IGameRepository games, ISessionAnnotationRepository annotations,
IHardwareSnapshotRepository hardware, SessionSeriesLoader loader, ITriStateOverridePrompt overridePrompt, IFileSaver saver, IMessageStrip strip)
{
_sessions = sessions ?? throw new ArgumentNullException(nameof(sessions));
_games = games ?? throw new ArgumentNullException(nameof(games));
_annotations = annotations ?? throw new ArgumentNullException(nameof(annotations));
_hardware = hardware ?? throw new ArgumentNullException(nameof(hardware));
_loader = loader ?? throw new ArgumentNullException(nameof(loader));
_override = overridePrompt ?? throw new ArgumentNullException(nameof(overridePrompt));
_saver = saver ?? throw new ArgumentNullException(nameof(saver));
_strip = strip ?? throw new ArgumentNullException(nameof(strip));
}
public static string Tier2Text => Strings.Summary_Tier2_Body;
public static string CrashTitle => Strings.Summary_Crash_Title;
public static string CrashBody => Strings.Summary_Crash_Body;
public static string UnhookedTitle => Strings.Summary_Unhooked_Title;
public static string UnhookedBody => Strings.Summary_Unhooked_Body;
public static string NotFoundText => Strings.Summary_NotFound;
public static string FrametimeHeader => Strings.Summary_Frametime_Header;
public static string DistributionHeader => Strings.Summary_Distribution_Header;
public static string RenderScaleHeader => Strings.Summary_RenderScale_Header;
public static string SensorsHeader => Strings.GameDetail_Tab_Sensors;
public static string SensorStatsHeader => Strings.SensorStats_Header;
public static string SensorStatsNote => Strings.SensorStats_Note;
public static string SensorStatsSeriesHeader => Strings.SensorStats_Col_Series;
public static string SensorStatsMeanHeader => Strings.SensorStats_Col_Mean;
public static string SensorStatsMedianHeader => Strings.SensorStats_Col_Median;
public static string SensorStatsMinHeader => Strings.SensorStats_Col_Min;
public static string SensorStatsMaxHeader => Strings.SensorStats_Col_Max;
public static string SensorStatsReadingsHeader => Strings.SensorStats_Col_Samples;
public static string ShowDisplayedText => Strings.Summary_Show_Displayed;
public static string ShowSensorsText => Strings.Summary_Show_Sensors;
public static string FgMixHeader => Strings.FgMix_Header;
public static string FgMixStateHeader => Strings.FgMix_Col_State;
public static string FgMixShareHeader => Strings.FgMix_Col_Share;
public static string FgMixRatesHeader => Strings.FgMix_Col_Rates;
public static string FgMixTimeHeader => Strings.FgMix_Col_Time;
public static string AnnotationsHeader => Strings.Summary_Annotations_Header;
public static string TagsPlaceholder => Strings.Summary_Tags_Placeholder;
public static string NotesPlaceholder => Strings.Summary_Notes_Placeholder;
public static string SaveText => Strings.Summary_Save;
public static string ExportCsvText => Strings.Summary_Export_Csv;
public static string ExportJsonText => Strings.Summary_Export_Json;
public static string ExportPngText => Strings.Summary_Export_Png;
public static string AdvancedText => Strings.Summary_Advanced_Button;
/// <summary>
/// Opens this session on the Advanced page (owner decision D101); set by whoever opened the window. Null — a test, a
/// host with no shell — and the button does nothing.
/// </summary>
public Action<long>? ShowAdvanced { get; set; }
public SessionRow? Row { get; private set; }
public GameRow? Game { get; private set; }
public SessionSeries? Series { get; private set; }
/// <summary>What the Sensors section draws: <see cref="Series"/> for a hooked session, the sensors alone for one that was not.</summary>
public SessionSeries? SensorSeries { get; private set; }
public ObservableCollection<StatCardModel> Stats { get; } = [];
/// <summary>beta.12: every series' stored mean, median, minimum and peak (<see cref="SensorStatsTable"/>).</summary>
public ObservableCollection<SensorStatRowModel> SensorStats { get; } = [];
public ObservableCollection<TriStateChipModel> Chips { get; } = [];
/// <summary>beta.24 (D62): every frame-generation state the session held, then no frame generation, then the time no state claims.</summary>
public ObservableCollection<FgMixRowModel> FgMix { get; } = [];
/// <summary>The action in flight, for a test to await.</summary>
public Task Pending { get; private set; } = Task.CompletedTask;
/// <summary>Raised after a load or an override so the window redraws the charts and chips.</summary>
public event EventHandler? Presented;
public async Task LoadAsync(long sessionId, CancellationToken ct = default)
{
Row = await _sessions.FindByIdAsync(sessionId, ct).ConfigureAwait(true);
Game = Row is null ? null : await _games.FindByIdAsync(Row.GameId, ct).ConfigureAwait(true);
if (Row is null || Game is null)
{
NotFound = true;
return;
}
NotFound = false;
// Recorded with Advanced metrics on: the row is there, and the button that leads to it is shown (D101).
HasAdvanced = await _sessions.FindAdvancedAsync(sessionId, ct).ConfigureAwait(true) is not null;
_annotation = await _annotations.FindAsync(sessionId, ct).ConfigureAwait(true);
_segments = await _sessions.FindSegmentsAsync(sessionId, ct).ConfigureAwait(true);
_snapshot = await _hardware.FindAsync(Row.SnapshotId, ct).ConfigureAwait(true);
Series = Row.Tier == CaptureTier.Hooked ? await _loader.LoadAsync(sessionId, ct).ConfigureAwait(true) : null;
SensorSeries = Series ?? (await _loader.LoadSensorsAsync(sessionId, ct).ConfigureAwait(true) is { Count: > 0 } sensors ? SessionSeries.SensorsOnly(sensors) : null);
Present();
}
[RelayCommand]
private Task OverrideAsync(TriStateChipModel? chip) => Run(() => OverrideCoreAsync(chip));
[RelayCommand]
private Task SaveAnnotationAsync() => Run(SaveAnnotationCoreAsync);
[RelayCommand]
private void OpenAdvanced()
{
if (Row is { } row)
{
ShowAdvanced?.Invoke(row.Id);
}
}
[RelayCommand]
private Task ExportCsvAsync() => Run(() => ExportAsync("csv", "CSV|*.csv", WriteCsv));
[RelayCommand]
private Task ExportJsonAsync() => Run(() => ExportAsync("json", "JSON|*.json", WriteJson));
/// <summary>FR-9.3: the window hands in the plot it shows; the picker and the strip are the same as the other two.</summary>
public Task ExportPngAsync(Plot plot)
{
ArgumentNullException.ThrowIfNull(plot);
return Run(() => ExportAsync("png", "PNG|*.png", path => ChartTheme.SavePng(plot, path, 1600, 700)));
}
private async Task Run(Func<Task> work)
{
Task running = work();
Pending = running;
await running.ConfigureAwait(true);
}
private async Task OverrideCoreAsync(TriStateChipModel? chip)
{
if (chip is null || Row is null || Game is null)
{
return;
}
TriStateOverrideChoice? choice = await _override.AskAsync(chip).ConfigureAwait(true);
if (choice is null)
{
return;
}
TriStateKind kind = chip.Kind;
SessionAnnotation current = _annotation ?? new SessionAnnotation { SessionId = Row.Id };
SessionAnnotation next = kind switch
{
TriStateKind.RayTracing => current with { RtOverride = choice.Override },
TriStateKind.PathTracing => current with { PtOverride = choice.Override },
_ => current with { RrOverride = choice.Override },
};
await _annotations.UpsertAsync(next, CancellationToken.None).ConfigureAwait(true);
if (choice.SetAsGameDefault)
{
await _games.SetTriStateDefaultAsync(Game.Id, kind, choice.Override ?? Domain.Metrics.Tri.NotApplicable, CancellationToken.None).ConfigureAwait(true);
Game = await _games.FindByIdAsync(Game.Id, CancellationToken.None).ConfigureAwait(true) ?? Game;
}
_annotation = await _annotations.FindAsync(Row.Id, CancellationToken.None).ConfigureAwait(true);
PresentChips();
Presented?.Invoke(this, EventArgs.Empty);
}
private async Task SaveAnnotationCoreAsync()
{
if (Row is null)
{
return;
}
string[] tags = [.. Tags.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).Distinct(StringComparer.CurrentCultureIgnoreCase)];
SessionAnnotation current = _annotation ?? new SessionAnnotation { SessionId = Row.Id };
await _annotations.UpsertAsync(current with { Tags = tags, Notes = string.IsNullOrWhiteSpace(Notes) ? null : Notes.Trim() }, CancellationToken.None).ConfigureAwait(true);
_annotation = await _annotations.FindAsync(Row.Id, CancellationToken.None).ConfigureAwait(true);
_strip.Success(Strings.Summary_Annotations_Header, Strings.Summary_Saved);
}
private async Task ExportAsync(string extension, string filter, Action<string> write)
{
if (Row is null || Game is null)
{
return;
}
string suggested = Sanitise(Game.Name) + "-" + Row.StartedAt.ToLocalTime().ToString("yyyyMMdd-HHmm", CultureInfo.InvariantCulture) + "." + extension;
string? path = _saver.PickSavePath(filter, suggested);
if (path is null)
{
return;
}
try
{
await Task.Run(() => write(path)).ConfigureAwait(true);
_strip.Success(Strings.Games_Header, string.Format(CultureInfo.CurrentCulture, Strings.Summary_Exported_Format, path));
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
_strip.Warn(Strings.Games_Header, string.Format(CultureInfo.CurrentCulture, Strings.Summary_Export_Failed_Format, ex.Message));
}
}
private void WriteCsv(string path)
{
using var writer = new StreamWriter(path, false, new UTF8Encoding(false));
SessionExporter.WriteCsv(writer, Row!, Game!, _snapshot, _segments, Series);
}
private void WriteJson(string path)
{
using FileStream stream = File.Create(path);
SessionExporter.WriteJson(stream, SessionExporter.Document(Row!, Game!, _snapshot, _segments, _annotation));
}
private void Present()
{
SessionRow row = Row!;
Title = string.Format(CultureInfo.CurrentCulture, Strings.Summary_Title_Format, Game!.Name, Formats.Date(row.StartedAt));
IsHooked = row.Tier == CaptureTier.Hooked;
IsCrashed = row.ExitStatus == ExitStatus.Crashed;
IsUnhooked = row.ExitStatus == ExitStatus.UnhookedSafety;
Tier2Reason = IsHooked ? string.Empty : Formats.Tier2Reason(row.CaptureNotes);
ExitLine = string.Format(CultureInfo.CurrentCulture, Strings.Exit_Line_Format,
Formats.ExitText(row.ExitStatus, Application.Recording.CaptureNotes.Parse(row.CaptureNotes)));
ExceptionLine = row.AcExceptionFamily is { } family
? string.Format(CultureInfo.CurrentCulture, Strings.Session_UnderException_Format, family)
: null;
Readout = FpsPresentation.FromRow(row);
Line = string.Format(CultureInfo.CurrentCulture, Strings.Summary_Line_Format,
IsHooked ? Formats.Api(row.Api) : Strings.Tier_NotHooked, row.PresentMode ?? Strings.Common_NotAvailable,
IsHooked ? Formats.UpscalerOf(row) : Strings.Common_NotAvailable, Formats.Resolution(row.RenderW, row.RenderH, row.OutputW, row.OutputH));
HardwareLine = _snapshot is null
? string.Empty
: string.Join(" · ", SystemInfoViewModel.Describe(_snapshot).Where(static l => !string.Equals(l.Value, Strings.Common_NotAvailable, StringComparison.Ordinal)).Select(static l => l.Value));
LibrariesLine = LoadedLibraries(row.RuntimeModulesJson, Game.Libraries);
DlssLine = IsHooked ? DlssText.Line(row) : null;
DriverProfileLine = NvidiaOverrides.ProfileLine(row.DriverProfileJson);
DriverStateLine = NvidiaOverrides.DriverLine(row.NgxDriverWordsJson);
DisplayLine = DisplayText.Line(DisplayText.Of(row));
Tags = _annotation is null ? string.Empty : string.Join(", ", _annotation.Tags);
Notes = _annotation?.Notes ?? string.Empty;
HasDisplayed = Series?.HasGenerated == true;
HasSensors = Series is { SensorsAligned: true, Sensors.Count: > 0 };
HasSensorCharts = SensorSeries is { Sensors.Count: > 0 };
DecimationNote = Series is null ? string.Empty : string.Format(CultureInfo.CurrentCulture, Strings.Chart_Decimated_Format, Series.Presents, Math.Min(Series.Presents, Decimator.DefaultBuckets * 2));
PresentStats(row);
PresentFgMix(row);
PresentChips();
Presented?.Invoke(this, EventArgs.Empty);
}
/// <summary>beta.24 (D62): the stored mix as rows and a bar, the setting that framed it, and why a session has none.</summary>
private void PresentFgMix(SessionRow row)
{
IReadOnlyList<FgMixRowModel> rows = FgMixPresentation.Rows(row);
FgMix.Clear();
foreach (FgMixRowModel line in rows)
{
FgMix.Add(line);
}
HasFgMix = rows.Count > 0;
FgMixSegments = [.. rows.Select(static r => r.Segment)];
FgMixName = HasFgMix ? FgMixPresentation.AccessibleName(rows) : string.Empty;
FgMixContext = HasFgMix ? NvidiaOverrides.FrameGenerationContext(row.DriverProfileJson) : null;
FgMixUnclassifiedNote = rows.Any(static r => r.Segment.Kind == Domain.Metrics.FgMixKind.Unclassified) ? Strings.FgMix_Unclassified_Note : null;
FgMixMissing = FgMixPresentation.Missing(row);
}
private void PresentStats(SessionRow row)
{
IReadOnlyDictionary<string, Application.Recording.SensorSeriesStats> stats = Application.Recording.SensorSeriesStats.Parse(row.SensorStatsJson);
string? presented = IsHooked && FpsPresentation.FromRow(row).Kind == FpsReadoutKind.Presented ? Strings.Summary_Lows_Presented : null;
Stats.Clear();
AddFrameCards(row, presented);
AddPacingCards(row, presented);
AddMachineCards(row, stats);
// The table reads what finalize stored; a session from before beta.12 says so rather than computing it here.
SensorStats.Clear();
foreach (SensorStatRowModel line in SensorStatsTable.Rows(stats))
{
SensorStats.Add(line);
}
HasSensorStats = SensorStats.Count > 0;
SensorStatsMissing = !HasSensorStats && (HasSensorCharts || row.AvgGpuLoad is not null || row.MaxGpuTemp is not null) ? Strings.SensorStats_NotStored : null;
}
/// <summary>The frame rate's cards; <paramref name="presented"/> labels the statistics a present-only session has over presents.</summary>
private void AddFrameCards(SessionRow row, string? presented)
{
// CLAUDE.md rule 6 (beta.14): where frames were generated the 1% low is the game's own frames', and the presents' —
// what the display received — stands beside it, never instead of it.
string? displayedLow = IsHooked && Readout.Kind == FpsReadoutKind.Generated && row.DisplayedP1LowFps is double shown
? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_DisplayedLow_Format, Formats.Fps(shown))
: null;
Stats.Add(new StatCardModel(Strings.Summary_Stat_Avg, Readout.Line));
Stats.Add(new StatCardModel(Strings.Summary_Stat_Median, IsHooked ? Formats.Fps(row.MedianFps) : Strings.Common_NotAvailable));
Stats.Add(new StatCardModel(Strings.Summary_Stat_P1Low, IsHooked ? Formats.Fps(row.P1LowFps) : Strings.Common_NotAvailable, presented ?? displayedLow));
Stats.Add(new StatCardModel(Strings.Summary_Stat_P01Low, IsHooked ? Formats.Fps(row.P01LowFps) : Strings.Common_NotAvailable, presented));
Stats.Add(new StatCardModel(Strings.Summary_Stat_MinMax, IsHooked ? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_MinMax_Format, Formats.Fps(row.MinFps), Formats.Fps(row.MaxFps)) : Strings.Common_NotAvailable));
Stats.Add(new StatCardModel(Strings.Summary_Stat_StdDev, IsHooked && row.FrametimeStdDevMs is double sd ? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_StdDev_Format, sd) : Strings.Common_NotAvailable));
Stats.Add(new StatCardModel(Strings.Summary_Stat_Stutter, IsHooked && row.StutterCount is long count && row.StutterTimePct is double pct
? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_Stutter_Format, count, pct) : Strings.Common_NotAvailable));
Stats.Add(new StatCardModel(Strings.Summary_Stat_Duration, Formats.Duration(row.DurationSeconds)));
// beta.10, both tiers: the mode the game was shown in longest, and the window's size in it.
Domain.Display.DisplaySummary? display = DisplayText.Of(row);
string window = DisplayText.Window(display);
Stats.Add(new StatCardModel(Strings.Summary_Stat_Display, DisplayText.Headline(display),
string.Equals(window, Strings.Common_NotAvailable, StringComparison.Ordinal) ? null : window));
}
/// <summary>
/// beta.14 (D49), hooked sessions: how the frames were paced, what the presents asked for, ray tracing where it was
/// measured, focus, and how complete the record is. A session recorded before beta.14 reads N/A on the new ones.
/// </summary>
private void AddPacingCards(SessionRow row, string? presented)
{
string na = Strings.Common_NotAvailable;
var below = new List<string>(3);
if (IsHooked && row.TimeBelow30Pct is double below30)
{
below.Add(string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_Below30_Format, Formats.Share(below30)));
}
// The refresh share is over what the display received — generated frames included — so it is named for the display.
if (IsHooked && row.TimeBelowRefreshPct is double belowRefresh && row.DisplayMonitorHz is int hz)
{
below.Add(string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_BelowRefresh_Format, hz, Formats.Share(belowRefresh)));
}
if (presented is not null)
{
below.Add(presented);
}
Stats.Add(new StatCardModel(Strings.Summary_Stat_TimeBelow60, IsHooked ? Formats.Share(row.TimeBelow60Pct) : na, below.Count == 0 ? null : string.Join(" · ", below)));
Stats.Add(new StatCardModel(Strings.Summary_Stat_FrameToFrame, IsHooked ? Formats.Milliseconds(row.FrametimeDeltaMeanMs) : na, presented));
Stats.Add(new StatCardModel(Strings.Summary_Stat_Vsync,
IsHooked && row.VsyncPresentPct is double vsync ? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_OfFrames_Format, Formats.Share(vsync)) : na,
IsHooked && row.TearingAllowedPct is double tearing ? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_Tearing_Format, Formats.Share(tearing)) : null));
if (IsHooked && row.RtFramePct is double rt)
{
Stats.Add(new StatCardModel(Strings.Summary_Stat_RayTracing, string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_OfFrames_Format, Formats.Share(rt)),
row.RaysPerPixel is double rays ? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_RaysPerPixel_Format, rays) : null));
}
Stats.Add(new StatCardModel(Strings.Summary_Stat_Focus,
IsHooked && row.DrainTicks is > 0 && row.ForegroundTicks is long focused
? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_Focus_Format, Formats.Share(focused * 100.0 / row.DrainTicks.Value))
: na));
Stats.Add(new StatCardModel(Strings.Summary_Stat_Capture,
IsHooked ? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_Capture_Format, row.GapCount, row.DroppedRecords, row.FaultCount) : na));
}
/// <summary>The machine, both tiers: telemetry is what a not-hooked session still has.</summary>
private void AddMachineCards(SessionRow row, IReadOnlyDictionary<string, Application.Recording.SensorSeriesStats> stats)
{
// Load is the average, temperature the peak.
Stats.Add(new StatCardModel(Strings.Summary_Stat_Gpu, string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_LoadTemp_Format, Formats.Percent(row.AvgGpuLoad), Formats.Temperature(row.MaxGpuTemp))));
Stats.Add(new StatCardModel(Strings.Summary_Stat_Cpu, string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_LoadTemp_Format, Formats.Percent(row.AvgCpuLoad), Formats.Temperature(row.MaxCpuTemp))));
// beta.12 (D43), both tiers: the game's own memory, read from outside it — the median, with the peak beneath.
Stats.Add(GameMemoryText.VramCard(row));
Stats.Add(GameMemoryText.RamCard(row, stats));
// beta.14 (D49): the card's clocks, fan and memory temperature, what held it back (NVIDIA only), and frames per watt.
bool clocks = row.AvgGpuCoreClockMhz is not null || row.AvgGpuMemClockMhz is not null;
bool fan = row.AvgGpuFanRpm is not null || row.MaxGpuMemTemp is not null;
Stats.Add(new StatCardModel(Strings.Summary_Stat_GpuClocks,
clocks ? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_Clocks_Format, Formats.Frequency(row.AvgGpuCoreClockMhz), Formats.Frequency(row.AvgGpuMemClockMhz)) : Strings.Common_NotAvailable,
fan ? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_FanMemTemp_Format, Formats.Rpm(row.AvgGpuFanRpm), Formats.Temperature(row.MaxGpuMemTemp)) : null));
Stats.Add(new StatCardModel(Strings.Summary_Stat_GpuLimits,
row.PowerLimitPct is not null || row.ThermalLimitPct is not null
? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Stat_Limits_Format, Formats.Share(row.PowerLimitPct), Formats.Share(row.ThermalLimitPct))
: Strings.Common_NotAvailable));
Stats.Add(new StatCardModel(Strings.Summary_Stat_Efficiency, Formats.FramesPerJoule(row.AppFramesPerJoule),
row.AppFramesPerJoule is null ? null : Strings.Summary_Stat_Efficiency_Note));
}
/// <summary>
/// <c>runtime_modules</c> ({file: version}) as one line, each module beside the version the game's own copy states when
/// the two differ: a DLSS the NVIDIA App or the driver substituted is loaded from elsewhere under the same name. Null
/// for a row with none — a Tier-2 session, or one written before the census existed.
/// </summary>
internal static string? LoadedLibraries(string? runtimeModulesJson, IReadOnlyList<Domain.Detection.LibraryFile> shipped)
{
if (string.IsNullOrWhiteSpace(runtimeModulesJson))
{
return null;
}
Dictionary<string, string>? modules;
try
{
modules = System.Text.Json.JsonSerializer.Deserialize(runtimeModulesJson, AppJsonContext.Default.DictionaryStringString);
}
catch (System.Text.Json.JsonException)
{
return null;
}
if (modules is null || modules.Count == 0)
{
return null;
}
IEnumerable<string> items = modules.OrderBy(static m => m.Key, StringComparer.OrdinalIgnoreCase).Select(m =>
{
// A module with no version resource is stored as null (RuntimeModuleSnapshot.Describe).
string? stated = m.Value;
string version = stated ?? Strings.Common_NotAvailable;
string? own = shipped.FirstOrDefault(l => string.Equals(l.FileName, m.Key, StringComparison.OrdinalIgnoreCase))?.FileVersion;
return Formats.SameVersion(stated, own) == false
? string.Format(CultureInfo.CurrentCulture, Strings.Summary_Library_Differs_Format, m.Key, version, own)
: m.Key + " " + version;
});
return string.Format(CultureInfo.CurrentCulture, Strings.Summary_Libraries_Format, string.Join(" · ", items));
}
private void PresentChips()
{
Chips.Clear();
foreach (TriStateKind kind in new[] { TriStateKind.RayTracing, TriStateKind.PathTracing, TriStateKind.RayReconstruction })
{
Chips.Add(TriStateChipModel.Of(kind, TriStateResolution.Resolve(kind, Row!, _annotation, Game!)));
}
}
private static string Sanitise(string name)
{
char[] invalid = Path.GetInvalidFileNameChars();
return new string([.. name.Select(c => invalid.Contains(c) ? '_' : c)]);
}
}