feat: Add category performance, update WebUI and OpenRouter integration, fix bugs

This commit is contained in:
Richard
2026-07-05 14:13:16 +02:00
parent d102af2965
commit e9e9ce0d5a
30 changed files with 2302 additions and 54 deletions
@@ -11,10 +11,10 @@ public class TraderRepository : ITraderRepository
public TraderRepository(AppDbContext db) => _db = db;
public async Task<Trader?> GetByIdAsync(int id, CancellationToken ct = default)
=> await _db.Traders.Include(t => t.CurrentScore).FirstOrDefaultAsync(t => t.Id == id, ct);
=> await _db.Traders.Include(t => t.CurrentScore).Include(t => t.CategoryPerformances).FirstOrDefaultAsync(t => t.Id == id, ct);
public async Task<Trader?> GetByPlatformIdAsync(PlatformType platform, string platformUserId, CancellationToken ct = default)
=> await _db.Traders.Include(t => t.CurrentScore)
=> await _db.Traders.Include(t => t.CurrentScore).Include(t => t.CategoryPerformances)
.FirstOrDefaultAsync(t => t.Platform == platform && t.PlatformUserId == platformUserId, ct);
public async Task<IReadOnlyList<Trader>> GetAllAsync(PlatformType? platform = null, int skip = 0, int take = 50, CancellationToken ct = default)
@@ -75,15 +75,18 @@ public class TraderRepository : ITraderRepository
public async Task<IReadOnlyList<Trader>> GetTradersDueForTradeUpdateAsync(int cooldownHours = 12, int take = 20, CancellationToken ct = default)
{
// Prioritize:
// 1. Traders needing initial import (IsInitialImportComplete == false)
// 2. Traders where LastTradesUpdatedAt < cutoff (cooldownHours)
var cutoff = DateTime.UtcNow.AddHours(-cooldownHours);
var normalCutoff = DateTime.UtcNow.AddHours(-cooldownHours);
var priorityCutoff = DateTime.UtcNow.AddHours(-1); // Sync priority traders more often, but not continuously
return await _db.Traders
.Where(t => !t.IsInitialImportComplete || t.LastTradesUpdatedAt == null || t.LastTradesUpdatedAt < cutoff)
.OrderBy(t => t.IsInitialImportComplete) // false (0) comes before true (1)
.Include(t => t.WatchlistEntries)
.Where(t => t.LastTradesUpdatedAt == null ||
(!t.IsInitialImportComplete) ||
((!t.IsAutoDiscovered || t.WatchlistEntries.Any()) && t.LastTradesUpdatedAt < priorityCutoff) ||
(t.IsAutoDiscovered && t.LastTradesUpdatedAt < normalCutoff))
.OrderBy(t => t.IsAutoDiscovered) // Manual first (false = 0)
.ThenByDescending(t => t.WatchlistEntries.Any()) // Watchlisted next (true = 1)
.ThenBy(t => t.IsInitialImportComplete) // New ones next (false = 0)
.ThenBy(t => t.LastTradesUpdatedAt ?? DateTime.MinValue) // Oldest first
.Take(take)
.ToListAsync(ct);