1ad896b07e
Adds a manual bet-tracking journal that turns the analyzer into an actual bet tracker. Users record wagers; the journal auto-grades them when event results land and computes per-bet Closing-Line-Value against the latest pre-match snapshot — the strongest long-run indicator of betting skill. Domain: - PlacedBet entity (reuses Bet vocabulary for Scope/Type/Side/Value/Rate) with stake, placed-at, outcome, and notes. Derived GrossReturn / NetProfit. - BetOutcome enum (Pending / Won / Lost / Void). - BetOutcomeResolver: pure function grading any Match-scope bet against an EventResult. Handles 1X2, draws, handicap (incl. push), and totals. Period-scope bets stay manual since EventResult only carries full-time. Application: - IPlacedBetRepository abstraction. - ClosingLineValueCalculator: pure CLV math (implied-probability delta) + snapshot-matching predicate by Scope/Type/Side/Value. - BetJournalReport + BetJournalStats records. - Four use cases: Record / ResolvePending / BuildReport / Delete. - New ISnapshotRepository.GetLatestPreMatchAsync pushes the closing-line pick into a single SQLite query rather than materialising the 30-day window in memory per event. - ROI turnover excludes Void stakes — pushes are not real turnover and including them would dilute the user's edge. Infrastructure: - PlacedBetEntity / Configuration / Repository / Mapping helpers. - 20260516 migration adding the PlacedBets table with EventCode and Outcome indices. Intentionally NO foreign key to Events — the journal is user data and must survive snapshot-retention pruning. Covered by an explicit round-trip test. UI: - Pages/MyBets/Journal.razor: hero header, 4-card KPI strip (ROI / strike rate / avg CLV / net profit, tinted by tone), inline add-bet form with the same invariants as the Bet record, drill-down table with per-row outcome pills, CLV percentage-points column, P&L, notes underline, and inline-confirm delete. RU + EN i18n. - Nav entry under Analysis. Tests: +55 across Domain / Application / Infrastructure (resolver math including handicap push and total push boundaries, PlacedBet invariants and derived properties, CLV math + null-handling, four use cases under NSubstitute, EF round-trip including survives-event-deletion). All 379 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
70 lines
3.2 KiB
C#
70 lines
3.2 KiB
C#
using Marathon.Application.Storage;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using MudBlazor.Services;
|
|
|
|
namespace Marathon.UI.Services;
|
|
|
|
/// <summary>
|
|
/// DI registration helpers for the Marathon.UI Razor Class Library.
|
|
/// Hosts call <see cref="AddMarathonUi(IServiceCollection, IConfiguration, string)"/>
|
|
/// during startup.
|
|
/// </summary>
|
|
public static class UiServicesExtensions
|
|
{
|
|
/// <summary>
|
|
/// Registers MudBlazor services, localization, the theme/locale observable
|
|
/// state objects, the file-backed settings writer, and binds all
|
|
/// configuration sections that the Settings page surfaces.
|
|
/// </summary>
|
|
/// <param name="services">DI container.</param>
|
|
/// <param name="configuration">Host configuration root.</param>
|
|
/// <param name="settingsLocalPath">
|
|
/// Absolute path to <c>appsettings.Local.json</c>, used by the writer.
|
|
/// </param>
|
|
public static IServiceCollection AddMarathonUi(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration,
|
|
string settingsLocalPath)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
ArgumentNullException.ThrowIfNull(configuration);
|
|
ArgumentException.ThrowIfNullOrEmpty(settingsLocalPath);
|
|
|
|
services.AddMudServices();
|
|
|
|
// No ResourcesPath: the SharedResource type already lives in the
|
|
// Marathon.UI.Resources namespace, so its compiled .resources name
|
|
// is "Marathon.UI.Resources.SharedResource.{culture}.resources" which
|
|
// matches the type's FullName directly. Setting ResourcesPath="Resources"
|
|
// here would cause the resolver to look for "...Resources.Resources..."
|
|
// and silently fall back to displaying the keys.
|
|
services.AddLocalization();
|
|
|
|
// Strongly typed options bound to appsettings.json sections.
|
|
services.Configure<LocalizationOptions>(configuration.GetSection(LocalizationOptions.SectionName));
|
|
services.Configure<WorkerOptions>(configuration.GetSection(WorkerOptions.SectionName));
|
|
services.Configure<AnomalyOptions>(configuration.GetSection(AnomalyOptions.SectionName));
|
|
services.Configure<StorageOptions>(configuration.GetSection(StorageOptions.SectionName));
|
|
services.Configure<ScrapingSettingsForm>(configuration.GetSection(ScrapingSettingsForm.SectionName));
|
|
|
|
// Singletons that drive UI chrome state.
|
|
services.AddSingleton<ThemeState>();
|
|
services.AddSingleton<LocaleState>();
|
|
services.AddSingleton<EventBrowsingState>();
|
|
services.AddSingleton<AnomalyBrowsingState>();
|
|
|
|
// Browsing facades — Scoped so they capture the per-circuit repository scope.
|
|
services.AddScoped<IEventBrowsingService, EventBrowsingService>();
|
|
services.AddScoped<IAnomalyBrowsingService, AnomalyBrowsingService>();
|
|
services.AddScoped<IAnomalyInsightsService, AnomalyInsightsService>();
|
|
services.AddScoped<IResultsBrowsingService, ResultsBrowsingService>();
|
|
services.AddScoped<IBetJournalService, BetJournalService>();
|
|
|
|
// Settings writer — file path is host-resolved.
|
|
services.AddSingleton<ISettingsWriter>(_ => new JsonSettingsWriter(settingsLocalPath));
|
|
|
|
return services;
|
|
}
|
|
}
|