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>
36 lines
1.7 KiB
C#
36 lines
1.7 KiB
C#
using Marathon.Infrastructure.Persistence.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace Marathon.Infrastructure.Persistence.Configurations;
|
|
|
|
internal sealed class PlacedBetConfiguration : IEntityTypeConfiguration<PlacedBetEntity>
|
|
{
|
|
public void Configure(EntityTypeBuilder<PlacedBetEntity> builder)
|
|
{
|
|
builder.ToTable("PlacedBets");
|
|
|
|
builder.HasKey(b => b.Id);
|
|
builder.Property(b => b.Id).HasColumnType("TEXT").IsRequired();
|
|
builder.Property(b => b.EventCode).HasColumnType("TEXT").IsRequired();
|
|
|
|
builder.Property(b => b.Scope).HasColumnType("INTEGER").IsRequired();
|
|
builder.Property(b => b.PeriodNumber).HasColumnType("INTEGER");
|
|
builder.Property(b => b.Type).HasColumnType("INTEGER").IsRequired();
|
|
builder.Property(b => b.Side).HasColumnType("INTEGER").IsRequired();
|
|
builder.Property(b => b.Value).HasColumnType("TEXT");
|
|
builder.Property(b => b.Rate).HasColumnType("TEXT").IsRequired();
|
|
|
|
builder.Property(b => b.Stake).HasColumnType("TEXT").IsRequired();
|
|
builder.Property(b => b.PlacedAt).HasColumnType("TEXT").IsRequired();
|
|
builder.Property(b => b.Outcome).HasColumnType("INTEGER").IsRequired();
|
|
builder.Property(b => b.Notes).HasColumnType("TEXT");
|
|
|
|
// EventCode is intentionally NOT a foreign key — the journal is the
|
|
// user's data and must survive snapshot retention pruning the source
|
|
// event row. Existence is checked once at insert time by the use case.
|
|
builder.HasIndex(b => b.EventCode).HasDatabaseName("IX_PlacedBets_EventCode");
|
|
builder.HasIndex(b => b.Outcome).HasDatabaseName("IX_PlacedBets_Outcome");
|
|
}
|
|
}
|