Group strategies by base type and rank them by median hold time

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-17 19:29:53 +01:00
1 parent d2cbab5d4b
commit cbd9830143
12 files changed
+301 -35

No files matched your search

@@ -10,9 +10,11 @@ public sealed record DashboardData(
TimeSpan TotalHoldTime,
IReadOnlyList<TopEntry> TopIps,
IReadOnlyList<TopEntry> TopTargets,
IReadOnlyList<TopEntry> TopStrategies,
IReadOnlyList<StrategySample> StrategyCatches,
IReadOnlyList<TopEntry> TopCountries,
IReadOnlyList<TopEntry> TopProviders,
IReadOnlyDictionary<string, int> CatchesByCountry);
public sealed record TopEntry(string Key, int Count, TimeSpan HoldTime, string? Label = null);
public sealed record TopEntry(string Key, int Count, TimeSpan HoldTime, string? Label = null, TimeSpan? MedianHold = null);
public sealed record StrategySample(string Strategy, long DurationMs);
@@ -42,7 +42,7 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
TimeSpan.FromMilliseconds(await catches.SumAsync(e => e.DurationMs, ct)),
await TopAsync(catches.GroupBy(e => e.RemoteIp), ct),
await TopAsync(catches.Where(e => e.Target != null).GroupBy(e => e.Target!), ct),
await TopAsync(catches.GroupBy(e => e.Strategy), ct),
await catches.Select(e => new StrategySample(e.Strategy, e.DurationMs)).ToListAsync(ct),
countries
.Take(TopCount)
.Select(x => new TopEntry(x.Key, x.Count, TimeSpan.FromMilliseconds(x.DurationMs), x.Name))
@@ -107,7 +107,19 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
if (filter.Strategy is { } strategy)
{
events = events.Where(e => e.Strategy == strategy);
var bases = strategy.Bases;
events = events.Where(e => bases.Any(name => e.Strategy == name || EF.Functions.Like(e.Strategy, name + " %", "\\")));
foreach (var flag in strategy.With)
{
var pattern = $"% {flag} %";
events = events.Where(e => EF.Functions.Like(" " + e.Strategy + " ", pattern, "\\"));
}
foreach (var flag in strategy.Without)
{
var pattern = $"% {flag} %";
events = events.Where(e => !EF.Functions.Like(" " + e.Strategy + " ", pattern, "\\"));
}
}
if (!string.IsNullOrWhiteSpace(filter.Search))
@@ -10,7 +10,7 @@ public sealed record RecentFilter(
long? Asn = null,
string? Ip = null,
string? Target = null,
string? Strategy = null,
StrategyMatch? Strategy = null,
string? Search = null,
int Limit = RecentFilter.DefaultLimit,
IReadOnlyList<string>? SearchStrategies = null)
@@ -22,3 +22,5 @@ public sealed record RecentFilter(
public sealed record RecentCatches(IReadOnlyList<TrapEventEntity> Items, int Total, IReadOnlyList<CountryOption> Countries);
public sealed record CountryOption(string Code, string? Name);
public sealed record StrategyMatch(IReadOnlyList<string> Bases, IReadOnlyList<string> With, IReadOnlyList<string> Without);