Add explanation rules for catches, editable over MCP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4086fa3da3
commit
2437880013
37 files changed
+1867
-37
No files matched your search
@@ -1,10 +1,11 @@
|
||||
using Flypaper.Core.Models;
|
||||
using Flypaper.Storage.Entities;
|
||||
using Flypaper.Storage.Explanations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Flypaper.Storage.Dashboard;
|
||||
|
||||
public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbContextFactory, TimeProvider timeProvider)
|
||||
public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbContextFactory, TimeProvider timeProvider, ExplanationRuleStore explanations)
|
||||
{
|
||||
private const int TopCount = 10;
|
||||
|
||||
@@ -64,12 +65,24 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
|
||||
.Select(g => new CountryOption(g.Key, g.Max(e => e.Country)))
|
||||
.ToListAsync(ct);
|
||||
|
||||
return new RecentCatches(
|
||||
await events.OrderByDescending(e => e.StartedAt).ThenByDescending(e => e.Id)
|
||||
.Take(Math.Clamp(filter.Limit, 1, RecentFilter.MaxLimit))
|
||||
.ToListAsync(ct),
|
||||
await events.CountAsync(ct),
|
||||
countries);
|
||||
var ordered = events.OrderByDescending(e => e.StartedAt).ThenByDescending(e => e.Id);
|
||||
var take = Math.Clamp(filter.Limit, 1, RecentFilter.MaxLimit);
|
||||
|
||||
if (filter.Unexplained)
|
||||
{
|
||||
var rules = await explanations.GetRuleSetAsync(ct);
|
||||
var candidates = await ordered.Where(e => e.Target != null).Select(e => new { e.Id, e.Target }).ToListAsync(ct);
|
||||
var ids = candidates
|
||||
.Where(c => rules.Winner(ExplanationKind.Target, ExplanationText.Path(c.Target)!) is null)
|
||||
.Select(c => c.Id)
|
||||
.ToList();
|
||||
var page = ids.Take(take).ToList();
|
||||
var items = (await db.TrapEvents.AsNoTracking().Where(e => page.Contains(e.Id)).ToListAsync(ct))
|
||||
.OrderByDescending(e => e.StartedAt).ThenByDescending(e => e.Id).ToList();
|
||||
return new RecentCatches(items, ids.Count, countries);
|
||||
}
|
||||
|
||||
return new RecentCatches(await ordered.Take(take).ToListAsync(ct), await events.CountAsync(ct), countries);
|
||||
}
|
||||
|
||||
private IQueryable<TrapEventEntity> Apply(IQueryable<TrapEventEntity> events, RecentFilter filter)
|
||||
|
||||
Reference in new issue
Block a user