feat: prioritize trader analytics via LastAnalyzedAt and add force-analyze endpoint

This commit is contained in:
Richard
2026-07-05 18:58:33 +02:00
parent c38b4d498f
commit 0b799123db
5 changed files with 45 additions and 17 deletions
@@ -224,11 +224,12 @@ public class PositionPnLEngine : IPositionPnLEngine
// Sync back to Trader record for quick sorting / UI display
trader.TotalPnl = overallPnl;
trader.WinRate = winRateOverall;
trader.LastAnalyzedAt = DateTime.UtcNow;
// Calculate Category Performance
var existingCatPerf = await _db.TraderCategoryPerformances
.Where(tcp => tcp.TraderId == traderId)
.ToDictionaryAsync(tcp => tcp.Category, ct);
.ToDictionaryAsync(tcp => (tcp.Category, tcp.Subcategory), ct);
var newCatPerf = CalculateCategoryPerformances(trades, tempPositions);
@@ -348,11 +349,11 @@ public class PositionPnLEngine : IPositionPnLEngine
return false;
}
private static Dictionary<MarketCategory, TraderCategoryPerformance> CalculateCategoryPerformances(
private static Dictionary<(MarketCategory, string), TraderCategoryPerformance> CalculateCategoryPerformances(
List<Trade> trades,
Dictionary<int, TraderPosition> finalPositions)
{
var result = new Dictionary<MarketCategory, TraderCategoryPerformance>();
var result = new Dictionary<(MarketCategory, string), TraderCategoryPerformance>();
var tradesByMarket = trades
.Where(t => t.MarketOutcome?.Market != null)
@@ -362,11 +363,14 @@ public class PositionPnLEngine : IPositionPnLEngine
{
var market = marketGroup.Key;
var category = market.Category;
var subcat = market.Subcategory ?? "";
if (!result.TryGetValue(category, out var perf))
var key = (category, subcat);
if (!result.TryGetValue(key, out var perf))
{
perf = new TraderCategoryPerformance { Category = category };
result[category] = perf;
perf = new TraderCategoryPerformance { Category = category, Subcategory = subcat };
result[key] = perf;
}
// Add volume