Open a log N1MM wrote
Three things stopped it. A contest is keyed by ContestNR, not by ContestID. ContestID is only the ContestInstance table's primary key; DXLOG.ContestNR refers to ContestNR, which is what N1MM's SQLWhereString matches on. The two agree in a fresh log and drift apart in one that has been used for a while, so we were reading one contest's header with another contest's contacts. In a real log of 56284 contacts, joining on ContestID disagreed with the contact's own ContestName 52029 times; joining on ContestNR disagreed 109 times. N1MM names a contest per mode: CQWWCW, CQWWSSB, CQWWRTTY, never plain CQWW. Our contests now use those names, and N1mmContestNames turns one back into a contest and a mode when a log is opened. The name carries the mode, so it beats the ModeCategory column. Plain CQWW still opens, because older versions wrote it that way. The log columns were sized by counting characters, which was too narrow for the headers: those are drawn in the theme's font, not the grid's monospace. The grid sizes them now, with the character count as a floor so a column of short values does not collapse. Bandmap spots now age from when they arrived rather than from the time written in them. A node with a wrong clock, or one replaying its backlog on connect, emptied the bandmap as fast as it filled it. Checked by opening a real 56284-contact N1MM log under Xvfb and reading the contest and contacts back. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,24 +5,38 @@ namespace Nonemm.Spotting;
|
||||
/// The stations on the band, in frequency order. A spot ages out after an hour
|
||||
/// because a bandmap is a picture of the last hour, and a stale spot costs a
|
||||
/// move to an empty frequency.
|
||||
///
|
||||
/// Age is counted from when the spot arrived, not from the time written in it.
|
||||
/// A node with a wrong clock, or one replaying its backlog, would otherwise
|
||||
/// empty the bandmap as fast as it filled it.
|
||||
public sealed class Bandmap
|
||||
{
|
||||
private readonly Dictionary<string, Spot> spots = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, DateTime> arrived = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly TimeSpan lifetime;
|
||||
private readonly Func<DateTime> clock;
|
||||
|
||||
public Bandmap(TimeSpan? lifetime = null) => this.lifetime = lifetime ?? TimeSpan.FromHours(1);
|
||||
public Bandmap(TimeSpan? lifetime = null, Func<DateTime>? clock = null)
|
||||
{
|
||||
this.lifetime = lifetime ?? TimeSpan.FromHours(1);
|
||||
this.clock = clock ?? (() => DateTime.UtcNow);
|
||||
}
|
||||
|
||||
public event EventHandler? Changed;
|
||||
|
||||
public void Add(Spot spot)
|
||||
{
|
||||
spots[Key(spot)] = spot;
|
||||
string key = Key(spot);
|
||||
spots[key] = spot;
|
||||
arrived[key] = clock();
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void Remove(Callsign call, Band band)
|
||||
{
|
||||
if (spots.Remove($"{call.Text}|{band.Name}"))
|
||||
string key = $"{call.Text}|{band.Name}";
|
||||
arrived.Remove(key);
|
||||
if (spots.Remove(key))
|
||||
{
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
@@ -31,12 +45,13 @@ public sealed class Bandmap
|
||||
public void DropOlderThan(DateTime nowUtc)
|
||||
{
|
||||
List<string> stale = spots
|
||||
.Where(pair => nowUtc - pair.Value.AtUtc > lifetime)
|
||||
.Where(pair => nowUtc - arrived.GetValueOrDefault(pair.Key, nowUtc) > lifetime)
|
||||
.Select(pair => pair.Key)
|
||||
.ToList();
|
||||
foreach (string key in stale)
|
||||
{
|
||||
spots.Remove(key);
|
||||
arrived.Remove(key);
|
||||
}
|
||||
if (stale.Count > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user