WIP(initial-implementation): parallel batch P2/P3/P5 — code complete, unreviewed

Snapshot of the parallel batch (Phases 2 + 3 + 5) at session pause. Solution does
NOT build cleanly yet — known cross-phase compile issues remain to be resolved
before review. See plans/initial-implementation/PLAN.md "Resume Notes" section
for the exact tomorrow-morning action list.

Phase 2 (Storage):
- Repository interfaces in Marathon.Application/Abstractions
- DateRange, ExportKind, StorageOptions in Marathon.Application/Storage
- EF Core 8 + SQLite (WAL) persistence: 7 entities + configurations + 4 repos
- Hand-written InitialCreate migration (dotnet ef blocked by parallel work)
- ClosedXML ExcelExporter with exact customer-spec wide columns
- PersistenceModule.AddMarathonPersistence DI extension
- Round-trip + export tests (cannot run yet — see cross-phase issues)

Phase 3 (Scraping):
- IOddsScraper, IBetPlacer in Marathon.Application/Abstractions
- ScrapingOptions in Marathon.Infrastructure/Configuration
- MarathonbetScraper with 4 parsers (Upcoming, Live, EventOdds, Results)
- Helpers: ServerTimeProvider, PeriodScopeMapper, OutcomeCodeMapper, MoscowDateParser
- UserAgentRotatorHandler + Polly v8 resilience pipeline
- ScrapingModule.AddMarathonScraping DI extension
- GlobalUsings.cs aliases for EventId / Configuration disambiguation
- Parser tests with trimmed HTML fixtures
- ScrapeResultsAsync interim no-op (Phase 8 will replace via watch-list polling)

Phase 5 (UI shell — killed mid-final-verify, assumed ~95%):
- Marathon.UI populated: MainLayout, App.razor, Pages (Home, Settings),
  Components, Theme (MarathonTheme.cs + Tokens.cs + app.css), Resources
  (SharedResource.{cs,ru.resx,en.resx}), Services (ISettingsWriter), wwwroot
- WPF host: App.xaml(.cs), MainWindow.xaml(.cs), Marathon.Hosts.WpfBlazor.csproj
  with Microsoft.AspNetCore.Components.WebView.Wpf + MudBlazor + Serilog
- appsettings.json + appsettings.Development.json with all sections wired
- bUnit tests: MainLayoutTests, LocaleSwitcherTests, ThemeToggleTests,
  JsonSettingsWriterTests + Support helpers

Cross-phase issues to resolve at next session:
1. Phase 2 repository classes are 'internal' — Phase 3's tests can't reference
   them. Fix: add InternalsVisibleTo to Marathon.Infrastructure.csproj.
2. Phase 5: LocalizationOptions namespace ambiguity (AspNetCore vs Extensions).
3. Phase 5: WpfBlazor Serilog API mismatch.

Reviewer has NOT run on this batch. Move to Phase 4 only after build is green
and a combined parallel-batch reviewer passes.
This commit is contained in:
2026-05-05 01:56:53 +03:00
parent 144c936e90
commit e4d8476782
129 changed files with 8524 additions and 121 deletions
@@ -0,0 +1,8 @@
using Marathon.Domain.Entities;
namespace Marathon.Application.Abstractions;
/// <summary>
/// Repository for <see cref="Anomaly"/> domain entities.
/// </summary>
public interface IAnomalyRepository : IRepository<Guid, Anomaly>;
@@ -0,0 +1,21 @@
namespace Marathon.Application.Abstractions;
/// <summary>
/// Marker interface for the future bet-placing feature.
/// </summary>
/// <remarks>
/// <para>
/// This interface is intentionally empty. It acts as an extension point for
/// a future implementation that interacts with a bookmaker's authenticated
/// betting API.
/// </para>
/// <para>
/// Phase 3 scope is analyze-only. Register a stub / no-op implementation if
/// needed for DI graph completeness, but the interface itself is not consumed
/// by any application service in the current release.
/// </para>
/// </remarks>
public interface IBetPlacer
{
// Future: PlaceBetAsync(BetRequest request, CancellationToken ct)
}
@@ -0,0 +1,15 @@
using Marathon.Application.Storage;
using Marathon.Domain.Entities;
using Marathon.Domain.ValueObjects;
namespace Marathon.Application.Abstractions;
/// <summary>
/// Repository for <see cref="Event"/> domain entities.
/// </summary>
public interface IEventRepository : IRepository<EventId, Event>
{
Task<IReadOnlyList<Event>> ListByDateRangeAsync(DateRange range, CancellationToken ct = default);
Task<IReadOnlyList<Event>> ListBySportAsync(SportCode sport, CancellationToken ct = default);
}
@@ -0,0 +1,22 @@
using Marathon.Application.Storage;
namespace Marathon.Application.Abstractions;
/// <summary>
/// Exports odds snapshots to an Excel file matching the customer's wide-column specification.
/// </summary>
public interface IExcelExporter
{
/// <summary>
/// Exports snapshots for the given date range to an XLSX file.
/// </summary>
/// <param name="range">The inclusive date range to export.</param>
/// <param name="kind">Which snapshots to include: pre-match, live, or combined.</param>
/// <param name="outputPath">
/// Directory where the file will be written. The filename is auto-generated as
/// <c>Marathon_yyyy-MM-dd_to_yyyy-MM-dd.xlsx</c>.
/// </param>
/// <param name="ct">Cancellation token.</param>
/// <returns>The full path of the created file.</returns>
Task<string> ExportAsync(DateRange range, ExportKind kind, string outputPath, CancellationToken ct = default);
}
@@ -0,0 +1,53 @@
using Marathon.Application.Storage;
using Marathon.Domain.Entities;
using Marathon.Domain.Enums;
using Marathon.Domain.ValueObjects;
namespace Marathon.Application.Abstractions;
/// <summary>
/// Scrapes upcoming events, live odds snapshots, and completed event results
/// from a bookmaker's public web interface.
/// </summary>
/// <remarks>
/// The infrastructure implementation (<c>MarathonbetScraper</c>) uses
/// HttpClient + AngleSharp + Polly. All methods are non-blocking and
/// honour the caller's <see cref="CancellationToken"/>.
/// </remarks>
public interface IOddsScraper
{
/// <summary>
/// Returns the list of upcoming (pre-match) events, optionally filtered to one sport.
/// </summary>
/// <param name="sportFilter">When non-null, restricts results to the given sport code.</param>
/// <param name="ct">Cancellation token.</param>
Task<IReadOnlyList<Event>> ScrapeUpcomingAsync(
SportCode? sportFilter,
CancellationToken ct);
/// <summary>
/// Fetches a full odds snapshot (all markets) for a single event.
/// </summary>
/// <param name="id">The bookmaker's event identifier.</param>
/// <param name="source">Whether this is a pre-match or live scrape.</param>
/// <param name="ct">Cancellation token.</param>
Task<OddsSnapshot> ScrapeEventOddsAsync(
EventId id,
OddsSource source,
CancellationToken ct);
/// <summary>
/// Returns completed event results within a date range.
/// </summary>
/// <remarks>
/// <para>
/// <b>Interim no-op (Phase 3):</b> marathonbet.by has no public results archive
/// endpoint (<c>/su/results</c> → 404). This method returns an empty list and
/// logs a warning. Results harvesting is implemented in Phase 8 via polling
/// event-detail pages until <c>matchIsComplete=true</c>.
/// </para>
/// </remarks>
Task<IReadOnlyList<EventResult>> ScrapeResultsAsync(
DateRange range,
CancellationToken ct);
}
@@ -0,0 +1,23 @@
namespace Marathon.Application.Abstractions;
/// <summary>
/// Generic repository abstraction providing CRUD operations for a domain entity.
/// </summary>
/// <typeparam name="TKey">The type of the entity's primary key.</typeparam>
/// <typeparam name="TEntity">The domain entity type.</typeparam>
public interface IRepository<TKey, TEntity>
where TKey : notnull
where TEntity : class
{
Task<TEntity?> GetAsync(TKey key, CancellationToken ct = default);
Task<IReadOnlyList<TEntity>> ListAsync(CancellationToken ct = default);
Task AddAsync(TEntity entity, CancellationToken ct = default);
Task UpdateAsync(TEntity entity, CancellationToken ct = default);
Task DeleteAsync(TKey key, CancellationToken ct = default);
Task SaveChangesAsync(CancellationToken ct = default);
}
@@ -0,0 +1,9 @@
using Marathon.Domain.Entities;
using Marathon.Domain.ValueObjects;
namespace Marathon.Application.Abstractions;
/// <summary>
/// Repository for <see cref="EventResult"/> domain entities.
/// </summary>
public interface IResultRepository : IRepository<EventId, EventResult>;
@@ -0,0 +1,16 @@
using Marathon.Domain.Entities;
using Marathon.Domain.ValueObjects;
namespace Marathon.Application.Abstractions;
/// <summary>
/// Repository for <see cref="OddsSnapshot"/> domain entities.
/// </summary>
public interface ISnapshotRepository : IRepository<Guid, OddsSnapshot>
{
Task<IReadOnlyList<OddsSnapshot>> ListByEventAsync(
EventId eventId,
DateTimeOffset from,
DateTimeOffset to,
CancellationToken ct = default);
}
@@ -0,0 +1,21 @@
namespace Marathon.Application.Storage;
/// <summary>
/// An inclusive date-time range used for querying and exporting snapshots.
/// </summary>
public sealed record DateRange
{
public DateTimeOffset From { get; }
public DateTimeOffset To { get; }
public DateRange(DateTimeOffset from, DateTimeOffset to)
{
if (from > to)
throw new ArgumentException(
$"DateRange.From ({from:O}) must be less than or equal to DateRange.To ({to:O}).",
nameof(from));
From = from;
To = to;
}
}
@@ -0,0 +1,16 @@
namespace Marathon.Application.Storage;
/// <summary>
/// Controls which odds snapshots are included in an Excel export.
/// </summary>
public enum ExportKind
{
/// <summary>Include only pre-match snapshots (columns prefixed with <c>Bet_</c>).</summary>
PreMatch,
/// <summary>Include only live snapshots (columns prefixed with <c>Live_</c>).</summary>
Live,
/// <summary>Include both pre-match and live snapshots on separate sheets.</summary>
Combined,
}
@@ -0,0 +1,18 @@
namespace Marathon.Application.Storage;
/// <summary>
/// Configuration options for the storage layer, bound to the <c>Storage:*</c> configuration section.
/// </summary>
public sealed class StorageOptions
{
public const string SectionName = "Storage";
/// <summary>Path to the SQLite database file. Default: <c>./data/marathon.db</c>.</summary>
public string DatabasePath { get; set; } = "./data/marathon.db";
/// <summary>Directory where Excel exports are written. Default: <c>./exports</c>.</summary>
public string ExportDirectory { get; set; } = "./exports";
/// <summary>Number of days to retain odds snapshots before pruning. Default: 90.</summary>
public int SnapshotRetentionDays { get; set; } = 90;
}