Read call history files, and fill the exchange from them

N1MM's format, so a file published for a contest is read as it is: # comments,
!!Order!! naming the columns of the lines after it, semicolons in preference to
commas so user text can hold a comma, and a default column order for a file
that names none. The directives that change what is stored are acted on;
!!Order!! can appear again part way through, because these files are usually
several files stuck together.

Leaving the callsign box fills what the file knows into the exchange boxes that
are still empty. A box with something in it is left alone: what the station
actually sends beats what somebody published months ago. The zone comes from
the CqZone or the ITUZone column depending on which the contest asks for, and a
file with no Sect falls back to State.

The check window's two missing columns are in. History lists matching calls
from the file. Exchange is not about callsigns at all: it offers the values the
exchange box with the cursor in it can hold, which is what N1MM's exchange pane
does — it searches the contest's list of valid exchanges, not the log.
CheckCandidate.Call is now Text, because an exchange value is not a call.

The section-validating directives are read and passed over rather than acted
on. Acting on them means holding N1MM's section lists and its rules about
retired sections, and getting that wrong throws away good data.

Running it caught what the unit tests could not: the exchange was filled and
scored but the boxes on screen still looked empty, because nothing resynced
them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-27 18:15:41 +00:00
parent 28eed33e88
commit 1fda1696f2
17 changed files with 706 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
using Nonemm.Contests;
using Nonemm.Contests.Rules;
using Nonemm.Core;
using Nonemm.Core.Calls;
using Nonemm.Core.Country;
using Nonemm.Storage;
@@ -295,4 +296,90 @@ public class RadioPositionTests
Assert.Single(second.Log.Qsos);
Assert.Equal(3, second.Log.Tally.Points);
}
private static RadioPosition WithHistory(Contest contest, string file)
{
FakeLogStore store = new();
ContestInstance instance = store.AddContest(new ContestInstance
{
ContestNumber = 0,
ContestName = contest.Name,
});
return new RadioPosition(new ContestSession(
store,
contest,
instance,
Me,
CountryFile.Parse(Countries),
CallHistory.Parse(file)));
}
[Fact]
public void TheCallHistoryFillsTheExchangeIn()
{
RadioPosition session = WithHistory(
new Sweepstakes(ModeCategory.Cw),
"!!Order!!,Call,Sect,CK\nW3LPL,MDC,56");
session.Entry.Call = "W3LPL";
Assert.True(session.FillFromHistory());
Assert.Equal("MDC", session.Entry.ValueOf(ExchangeSlot.Section));
Assert.Equal("56", session.Entry.ValueOf(ExchangeSlot.Check));
}
/// What the other station actually sends beats what was published, so a box
/// with something in it is left alone.
[Fact]
public void WhatIsAlreadyTypedIsNotOverwritten()
{
RadioPosition session = WithHistory(
new Sweepstakes(ModeCategory.Cw),
"!!Order!!,Call,Sect\nW3LPL,MDC");
session.Entry.Call = "W3LPL";
session.Entry.Set(ExchangeSlot.Section, "EPA");
session.FillFromHistory();
Assert.Equal("EPA", session.Entry.ValueOf(ExchangeSlot.Section));
}
[Fact]
public void ACallTheHistoryDoesNotHoldFillsNothing()
{
RadioPosition session = WithHistory(
new Sweepstakes(ModeCategory.Cw),
"!!Order!!,Call,Sect\nW3LPL,MDC");
session.Entry.Call = "JA1XYZ";
Assert.False(session.FillFromHistory());
Assert.Equal("", session.Entry.ValueOf(ExchangeSlot.Section));
}
/// CQ WW exchanges the CQ zone, so the CQ zone column is the one to use.
[Fact]
public void TheZoneComesFromTheColumnTheContestAsksFor()
{
RadioPosition session = WithHistory(
new CqWorldWide(ModeCategory.Cw),
"!!Order!!,Call,CqZone,ITUZone\nJA1XYZ,25,45");
session.Entry.Call = "JA1XYZ";
session.FillFromHistory();
Assert.Equal("25", session.Entry.ValueOf(ExchangeSlot.Zone));
}
/// A file for a section contest often carries the state instead.
[Fact]
public void TheStateFillsASectionWhenTheFileHasNoSection()
{
RadioPosition session = WithHistory(
new Sweepstakes(ModeCategory.Cw),
"!!Order!!,Call,Sect,State\nK1TTT,,CT");
session.Entry.Call = "K1TTT";
session.FillFromHistory();
Assert.Equal("CT", session.Entry.ValueOf(ExchangeSlot.Section));
}
}