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:
1 parent
d2cbab5d4b
commit
cbd9830143
12 files changed
+301
-35
No files matched your search
@@ -2,6 +2,7 @@ using System.Globalization;
|
||||
using System.Net;
|
||||
using Flypaper.Core.Models;
|
||||
using Flypaper.Storage.Dashboard;
|
||||
using Flypaper.Web.Components.Shared;
|
||||
|
||||
namespace Flypaper.Web.Components.Pages.Dashboard;
|
||||
|
||||
@@ -47,7 +48,7 @@ public sealed record DashboardFilter(
|
||||
Asn(provider) is { } asn ? $"AS{asn.ToString(CultureInfo.InvariantCulture)}" : null,
|
||||
IPAddress.TryParse(Clean(ip), out var address) ? address.ToString() : null,
|
||||
Clean(ziel),
|
||||
Clean(strategie),
|
||||
Clean(strategie) is { } strategy ? StrategyNames.GroupKey(strategy) : null,
|
||||
Clean(q),
|
||||
parsedLimit);
|
||||
}
|
||||
@@ -70,7 +71,7 @@ public sealed record DashboardFilter(
|
||||
Asn(Provider),
|
||||
Ip,
|
||||
Ziel,
|
||||
Strategie,
|
||||
StrategyNames.Group(Strategie),
|
||||
Q,
|
||||
Limit);
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
@foreach (var tab in tabs)
|
||||
{
|
||||
<div role="tabpanel" id="panel-@tab.Id" aria-labelledby="tab-@tab.Id" tabindex="0" hidden="@(tab != tabs[0])">
|
||||
<TopTable KeyLabel="@tab.KeyLabel" Entries="tab.Entries" ShowFlags="tab.ShowFlags" KeyFormatter="tab.KeyFormatter" LabelFormatter="tab.LabelFormatter" TitleFormatter="tab.TitleFormatter"
|
||||
<TopTable KeyLabel="@tab.KeyLabel" Entries="tab.Entries" ShowFlags="tab.ShowFlags" KeyFormatter="tab.KeyFormatter" LabelFormatter="tab.LabelFormatter" TitleFormatter="tab.TitleFormatter" BadgesFormatter="tab.BadgesFormatter"
|
||||
Href="entry => TopFilter(tab, entry).Href()" IsActive="entry => tab.Current(_filter) == entry.Key" />
|
||||
</div>
|
||||
}
|
||||
@@ -199,6 +199,10 @@
|
||||
<div class="extra extra-md">User-Agent: @(trapEvent.ClientInfo ?? "–")</div>
|
||||
<div class="extra extra-all strategy-info">
|
||||
<strong>@strategy.DisplayName</strong>
|
||||
@foreach (var badge in strategy.Badges)
|
||||
{
|
||||
<span class="badge">@badge</span>
|
||||
}
|
||||
@if (strategy.Explanation is not null)
|
||||
{
|
||||
<div>@strategy.Explanation</div>
|
||||
@@ -213,7 +217,7 @@
|
||||
<div class="extra extra-sm">Dauer: @duration · Bytes: @bytes</div>
|
||||
<div class="extra extra-xs">Datum: @started.ToString("dd.MM.yyyy") · Ausgang: @OutcomeLabel(trapEvent.Outcome)</div>
|
||||
</td>
|
||||
<td class="c-strategy" title="@strategy.Tooltip">@strategy.DisplayName</td>
|
||||
<td class="c-strategy" title="@strategy.Tooltip">@strategy.DisplayName@foreach (var badge in strategy.Badges){<span class="badge">@badge</span>}</td>
|
||||
<td class="c-agent" title="@trapEvent.ClientInfo">@trapEvent.ClientInfo</td>
|
||||
<td class="c-duration num">@duration</td>
|
||||
<td class="c-bytes num">@bytes</td>
|
||||
@@ -282,7 +286,7 @@
|
||||
new("providers", "Provider", "Provider", data.TopProviders, f => f.Provider, (f, key) => f with { Provider = key }),
|
||||
new("ips", "IPs", "IP", data.TopIps, f => f.Ip, (f, key) => f with { Ip = key }),
|
||||
new("targets", "Ziele", "Ziel", data.TopTargets, f => f.Ziel, (f, key) => f with { Ziel = key }, KeyFormatter: Formatting.Target),
|
||||
new("strategies", "Strategien", "Strategie", data.TopStrategies, f => f.Strategie, (f, key) => f with { Strategie = key }, KeyFormatter: StrategyNames.Summary, LabelFormatter: (key, _) => StrategyNames.Display(key), TitleFormatter: key => StrategyNames.Describe(key).Tooltip)
|
||||
new("strategies", "Strategien", "Strategie", StrategyNames.Rank(data.StrategyCatches, 10), f => f.Strategie, (f, key) => f with { Strategie = key }, KeyFormatter: _ => "", LabelFormatter: (key, _) => StrategyNames.Display(key), TitleFormatter: key => StrategyNames.Describe(key).Tooltip, BadgesFormatter: key => StrategyNames.Describe(key).Badges)
|
||||
];
|
||||
|
||||
private DashboardFilter TopFilter(TopTab tab, TopEntry entry) =>
|
||||
@@ -326,7 +330,8 @@
|
||||
|
||||
if (_filter.Strategie is { } strategie)
|
||||
{
|
||||
yield return ($"Strategie: {StrategyNames.Display(strategie)}", reset with { Strategie = null });
|
||||
var badges = StrategyNames.Describe(strategie).Badges;
|
||||
yield return ($"Strategie: {StrategyNames.Display(strategie)}{(badges.Count == 0 ? "" : $" ({string.Join(", ", badges)})")}", reset with { Strategie = null });
|
||||
}
|
||||
|
||||
if (_filter.Q is { } q)
|
||||
@@ -357,5 +362,6 @@
|
||||
bool ShowFlags = false,
|
||||
Func<string?, string?>? KeyFormatter = null,
|
||||
Func<string?, string?, string?>? LabelFormatter = null,
|
||||
Func<string?, string?>? TitleFormatter = null);
|
||||
Func<string?, string?>? TitleFormatter = null,
|
||||
Func<string?, IReadOnlyList<string>>? BadgesFormatter = null);
|
||||
}
|
||||
@@ -1,25 +1,40 @@
|
||||
@using System.Globalization
|
||||
@using Flypaper.Storage.Dashboard
|
||||
@using Flypaper.Web.Components.Shared
|
||||
|
||||
@{
|
||||
var byMedian = Entries.Any(entry => entry.MedianHold is not null);
|
||||
var barMax = byMedian
|
||||
? Entries.Where(entry => entry.Count >= StrategyNames.MinCatches).Select(entry => entry.MedianHold!.Value.TotalMilliseconds).DefaultIfEmpty(0).Max()
|
||||
: Entries.Count == 0 ? 0 : Entries[0].Count;
|
||||
}
|
||||
@if (Entries.Count == 0)
|
||||
{
|
||||
<p class="empty">Noch keine Einträge.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="top-table">
|
||||
<table class="top-table @(byMedian ? "by-median" : null)">
|
||||
<colgroup>
|
||||
<col />
|
||||
<col class="share" />
|
||||
<col class="count" />
|
||||
<col class="hold" />
|
||||
@if (byMedian)
|
||||
{
|
||||
<col class="hold" />
|
||||
}
|
||||
<col class="hold sum" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>@KeyLabel</th>
|
||||
<th><span class="sr-only">Anteil</span></th>
|
||||
<th class="num">Fänge</th>
|
||||
<th class="num">Haltezeit</th>
|
||||
@if (byMedian)
|
||||
{
|
||||
<th class="num" title="Mittlere Haltezeit pro Fang (Median): Einzelne Dauerhalter verfälschen sie nicht">Median</th>
|
||||
}
|
||||
<th class="num sum">@(byMedian ? "Summe" : "Haltezeit")</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -27,10 +42,18 @@ else
|
||||
{
|
||||
var key = KeyFormatter?.Invoke(entry.Key) ?? entry.Key;
|
||||
var label = LabelFormatter is null ? entry.Label : LabelFormatter(entry.Key, entry.Label);
|
||||
var share = (entry.Count * 100.0 / Entries[0].Count).ToString("0.#", CultureInfo.InvariantCulture);
|
||||
var value = byMedian ? entry.MedianHold!.Value.TotalMilliseconds : entry.Count;
|
||||
var share = (barMax == 0 ? 0 : Math.Min(100, value * 100.0 / barMax)).ToString("0.#", CultureInfo.InvariantCulture);
|
||||
var sparse = byMedian && entry.Count < StrategyNames.MinCatches;
|
||||
var badges = BadgesFormatter?.Invoke(entry.Key) ?? [];
|
||||
var active = IsActive(entry);
|
||||
var title = TitleFormatter?.Invoke(entry.Key) ?? (label is null ? key : $"{label} · {key}");
|
||||
<tr data-href="@Href(entry)" class="@(active ? "active" : null)">
|
||||
if (sparse)
|
||||
{
|
||||
title += $"\nNur {entry.Count} {(entry.Count == 1 ? "Fang" : "Fänge")}: wenig aussagekräftig";
|
||||
}
|
||||
|
||||
<tr data-href="@Href(entry)" class="@(active ? "active" : null) @(sparse ? "sparse" : null)">
|
||||
<td class="clip" title="@title">
|
||||
<a href="@Href(entry)" aria-current="@(active ? "true" : null)" title="@(active ? $"Filter {title} entfernen" : $"Fänge filtern: {title}")">
|
||||
@if (ShowFlags)
|
||||
@@ -40,6 +63,14 @@ else
|
||||
@if (label is not null)
|
||||
{
|
||||
<span class="top-label">@label</span>
|
||||
@foreach (var badge in badges)
|
||||
{
|
||||
<span class="badge">@badge</span>
|
||||
}
|
||||
@if (sparse)
|
||||
{
|
||||
<span class="badge sparse-note">wenige Daten</span>
|
||||
}
|
||||
@if (key.Length > 0)
|
||||
{
|
||||
<span class="top-key mono">@key</span>
|
||||
@@ -53,11 +84,19 @@ else
|
||||
</td>
|
||||
<td><span class="share-bar" style="--share: @(share)%"></span></td>
|
||||
<td class="num">@Formatting.Number(entry.Count)</td>
|
||||
<td class="num">@Formatting.Duration(entry.HoldTime)</td>
|
||||
@if (byMedian)
|
||||
{
|
||||
<td class="num">@Formatting.Duration(entry.MedianHold!.Value)</td>
|
||||
}
|
||||
<td class="num sum">@Formatting.Duration(entry.HoldTime)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@if (byMedian)
|
||||
{
|
||||
<p class="top-note">Balken = Median Haltezeit pro Fang. Unter @StrategyNames.MinCatches Fängen wenig aussagekräftig, diese Zeilen stehen am Ende.</p>
|
||||
}
|
||||
}
|
||||
|
||||
@code {
|
||||
@@ -73,6 +112,8 @@ else
|
||||
|
||||
[Parameter] public Func<string?, string?>? TitleFormatter { get; set; }
|
||||
|
||||
[Parameter] public Func<string?, IReadOnlyList<string>>? BadgesFormatter { get; set; }
|
||||
|
||||
[Parameter, EditorRequired] public required Func<TopEntry, string> Href { get; set; }
|
||||
|
||||
[Parameter, EditorRequired] public required Func<TopEntry, bool> IsActive { get; set; }
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Flypaper.Storage.Dashboard;
|
||||
|
||||
namespace Flypaper.Web.Components.Shared;
|
||||
|
||||
public sealed record StrategyInfo(string Raw, string BaseName, string DisplayName, string? Explanation, IReadOnlyList<string> Details)
|
||||
public sealed record StrategyInfo(string Raw, string BaseName, string DisplayName, string? Explanation, IReadOnlyList<string> Details, IReadOnlyList<string> Flags)
|
||||
{
|
||||
public string GroupKey => string.Join(' ', [BaseName, .. Flags]);
|
||||
|
||||
public IReadOnlyList<string> Badges => Flags.Select(StrategyNames.BadgeLabel).ToList();
|
||||
|
||||
public string Tooltip
|
||||
{
|
||||
get
|
||||
@@ -44,16 +49,45 @@ public static partial class StrategyNames
|
||||
["robots-bait"] = ("Köder aus der robots.txt", "Ein Pfad, der in der robots.txt als verboten steht, aber ins Link-Labyrinth führt. Wer dort landet, hat das Verbot gelesen und ignoriert. Er wird mindestens 24 Stunden festgehalten.")
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, string> Aliases = new(StringComparer.Ordinal)
|
||||
{
|
||||
["drip"] = "html-drip"
|
||||
};
|
||||
|
||||
private static readonly string[] VariantFlags = ["head", "link", "repeat"];
|
||||
|
||||
private static readonly HashSet<string> LinkedByDesign = new(StringComparer.Ordinal) { "maze-drip", "index-drip", "robots-bait" };
|
||||
|
||||
public const int MinCatches = 5;
|
||||
|
||||
public static string BadgeLabel(string flag) => flag switch
|
||||
{
|
||||
"head" => "Schnellstart",
|
||||
"link" => "Links",
|
||||
"repeat" => "Wiederholer",
|
||||
_ => flag
|
||||
};
|
||||
|
||||
public static StrategyInfo Describe(string? strategy)
|
||||
{
|
||||
var raw = strategy?.Trim() ?? "";
|
||||
var tokens = raw.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (tokens.Length == 0)
|
||||
{
|
||||
return new StrategyInfo(raw, raw, raw, null, []);
|
||||
return new StrategyInfo(raw, raw, raw, null, [], []);
|
||||
}
|
||||
|
||||
var baseName = Aliases.GetValueOrDefault(tokens[0], tokens[0]);
|
||||
var flags = VariantFlags
|
||||
.Where(flag => tokens.Skip(1).Contains(flag) && !(flag == "link" && LinkedByDesign.Contains(baseName)))
|
||||
.ToList();
|
||||
|
||||
var details = new List<string>();
|
||||
if (baseName != tokens[0])
|
||||
{
|
||||
details.Add($"früherer Name von {Known[baseName].Name}");
|
||||
}
|
||||
|
||||
for (var i = 1; i < tokens.Length; i++)
|
||||
{
|
||||
var token = tokens[i];
|
||||
@@ -71,6 +105,10 @@ public static partial class StrategyNames
|
||||
: $"alle {bytes} Byte ein Link");
|
||||
i++;
|
||||
}
|
||||
else if (token is "head" or "link")
|
||||
{
|
||||
details.Add(token == "head" ? "schneller Start: erste Bytes sofort" : "enthält Links");
|
||||
}
|
||||
else if (token == "repeat")
|
||||
{
|
||||
details.Add("Wiederholer: darf länger festgehalten werden");
|
||||
@@ -81,22 +119,58 @@ public static partial class StrategyNames
|
||||
}
|
||||
}
|
||||
|
||||
return Known.TryGetValue(tokens[0], out var known)
|
||||
? new StrategyInfo(raw, tokens[0], known.Name, known.Explanation, details)
|
||||
: new StrategyInfo(raw, tokens[0], tokens[0], null, details);
|
||||
return Known.TryGetValue(baseName, out var known)
|
||||
? new StrategyInfo(raw, baseName, known.Name, known.Explanation, details, flags)
|
||||
: new StrategyInfo(raw, baseName, baseName, null, details, flags);
|
||||
}
|
||||
|
||||
public static string Display(string? strategy) => Describe(strategy).DisplayName;
|
||||
|
||||
public static string Summary(string? strategy) =>
|
||||
string.Join(" · ", Describe(strategy).Details.Where(detail => detail.StartsWith("tröpfelt", StringComparison.Ordinal) || detail.StartsWith("Wiederholer", StringComparison.Ordinal)).Select(detail => detail.Split(':')[0]));
|
||||
public static string GroupKey(string? strategy) => Describe(strategy).GroupKey;
|
||||
|
||||
public static StrategyMatch? Group(string? strategy)
|
||||
{
|
||||
var info = Describe(strategy);
|
||||
if (info.BaseName.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var bases = Aliases.Where(pair => pair.Value == info.BaseName).Select(pair => pair.Key).Prepend(info.BaseName).ToList();
|
||||
var variableFlags = VariantFlags.Where(flag => !(flag == "link" && LinkedByDesign.Contains(info.BaseName)));
|
||||
return new StrategyMatch(bases, info.Flags, variableFlags.Except(info.Flags).ToList());
|
||||
}
|
||||
|
||||
public static IReadOnlyList<TopEntry> Rank(IEnumerable<StrategySample> samples, int take)
|
||||
{
|
||||
var groups = samples
|
||||
.GroupBy(sample => GroupKey(sample.Strategy))
|
||||
.Select(group =>
|
||||
{
|
||||
var durations = group.Select(sample => sample.DurationMs).Order().ToList();
|
||||
var middle = durations.Count / 2;
|
||||
var median = durations.Count % 2 == 1 ? durations[middle] : (durations[middle - 1] + durations[middle]) / 2d;
|
||||
return new TopEntry(group.Key, durations.Count, TimeSpan.FromMilliseconds(durations.Sum()), MedianHold: TimeSpan.FromMilliseconds(median));
|
||||
});
|
||||
|
||||
return groups
|
||||
.OrderBy(entry => entry.Count < MinCatches)
|
||||
.ThenByDescending(entry => entry.MedianHold)
|
||||
.ThenByDescending(entry => entry.Count)
|
||||
.Take(take)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static IReadOnlyList<string> Matching(string? search)
|
||||
{
|
||||
var term = search?.Trim();
|
||||
return string.IsNullOrEmpty(term)
|
||||
? []
|
||||
: Known.Where(pair => pair.Value.Name.Contains(term, StringComparison.CurrentCultureIgnoreCase)).Select(pair => pair.Key).ToList();
|
||||
if (string.IsNullOrEmpty(term))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var keys = Known.Where(pair => pair.Value.Name.Contains(term, StringComparison.CurrentCultureIgnoreCase)).Select(pair => pair.Key).ToList();
|
||||
return [.. keys, .. Aliases.Where(pair => keys.Contains(pair.Value)).Select(pair => pair.Key)];
|
||||
}
|
||||
|
||||
private static string Range(string min, string max) => min == max ? Number(min) : $"{Number(min)}–{Number(max)}";
|
||||
|
||||
Reference in new issue
Block a user