Files
maraphon-app/src/Marathon.Infrastructure/Persistence/Entities/PlacedBetEntity.cs
T
alexei.dolgolyov 1ad896b07e feat(my-bets): personal bet journal with CLV tracking
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>
2026-05-16 17:45:42 +03:00

48 lines
2.1 KiB
C#

namespace Marathon.Infrastructure.Persistence.Entities;
/// <summary>
/// EF Core persistence entity for a user-tracked <see cref="Marathon.Domain.Entities.PlacedBet"/>.
/// Flattens the embedded <c>Bet</c> selection (Scope / Type / Side / Value / Rate)
/// into columns so SQLite can index by event and outcome cheaply.
/// </summary>
public sealed class PlacedBetEntity
{
/// <summary>GUID primary key stored as TEXT.</summary>
public string Id { get; set; } = default!;
/// <summary>Foreign key to <see cref="EventEntity.EventCode"/>.</summary>
public string EventCode { get; set; } = default!;
// ─── Embedded Bet selection ──────────────────────────────────────────────
/// <summary>Scope discriminator: 0 = Match, 1 = Period.</summary>
public int Scope { get; set; }
/// <summary>Period number when <see cref="Scope"/> = 1; null otherwise.</summary>
public int? PeriodNumber { get; set; }
/// <summary>BetType as int (Win / Draw / WinFora / Total).</summary>
public int Type { get; set; }
/// <summary>Side as int (Side1 / Side2 / Draw / Less / More).</summary>
public int Side { get; set; }
/// <summary>Handicap or total threshold; null for Win / Draw markets.</summary>
public decimal? Value { get; set; }
/// <summary>Decimal odds the user took.</summary>
public decimal Rate { get; set; }
// ─── Wager fields ────────────────────────────────────────────────────────
/// <summary>Stake in the user's currency.</summary>
public decimal Stake { get; set; }
/// <summary>ISO 8601 timestamp when the bet was recorded (Moscow time).</summary>
public string PlacedAt { get; set; } = default!;
/// <summary>BetOutcome as int (Pending / Won / Lost / Void).</summary>
public int Outcome { get; set; }
/// <summary>Optional free-text note from the user.</summary>
public string? Notes { get; set; }
}