feat: prioritize trader analytics via LastAnalyzedAt and add force-analyze endpoint
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user