Remember runtime lock-outs, and let a lock-out be a span

Pressing `l` during a scan locked a frequency out for that run only, so the
same birdie had to be locked out again on every later one. It now writes
back to the settings file the run started from -- only that one key, since
a scan's config also holds whatever was passed on the command line for this
run and saving all of it would quietly make those permanent. The file is
read, its lock-outs replaced, the rest left as it was. `save_lockouts`
turns it off for anyone who would rather their config were never touched.

Lock-outs were also single frequencies only. They are now a list of
frequencies and spans -- "162.55M, 450M-455M, 88M to 108M" -- which is what
a pager band or a noisy stretch of spectrum actually is. A point is still
widened by the lock-out width; a span is taken exactly as written, because
whoever typed it already said how wide it is.

The scanner matched lock-outs by rounding a frequency into a bucket of the
lock-out width, which cannot express a span and was never exact at the
edges. It now holds intervals and tests them directly.

Settings files that predate this hold a bare number per lock-out, and still
mean the same thing: Lockout.coerce takes numbers, strings, pairs and dicts,
so old profiles load untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
The Dust Council 2026-08-21 23:44:24 -07:00
parent b69d0b7a26
commit 44c98b11e3
9 changed files with 319 additions and 46 deletions

View file

@ -516,3 +516,54 @@ def test_combined_files_are_padded_too(tmp_path):
log.add(146_520_000.0, np.full(1600, 0.2, dtype=np.float32), 16000)
names = sorted(p.name for p in tmp_path.glob("*.wav"))
assert names == ["0146.520000MHz.wav", "1090.000000MHz.wav"]
def test_a_span_of_spectrum_can_be_locked_out(tmp_path):
"""Not just single frequencies: a whole noisy stretch, as one entry."""
tx = [V(146_520_000, "nfm", 0.4, 12_500, "voice"),
V(147_000_000, "nfm", 0.4, 12_500, "voice")]
s, hits = run_scan(tmp_path, tx, "146.4M-147.1M",
lockout=["146.4M-146.8M"], max_cycles=3)
assert hits, "nothing recorded at all"
assert all(h.frequency > 146_800_000 for h in hits), \
[h.frequency for h in hits]
def test_a_lock_out_made_during_a_scan_is_remembered(tmp_path):
"""It goes back to the settings file, so the next run starts with it."""
import yaml
from bandsaunter.config import load_default, save_default
cfg = ScanConfig(ranges=parse_range_list("146.4M-146.6M"),
output_dir=str(tmp_path), record_seconds=4.0)
save_default(cfg, tmp_path)
loaded, path = load_default(tmp_path)
s = Scanner(loaded, device=SimulatedDevice().open())
s.prepare()
s.lockout(146_520_000.0)
saved = yaml.safe_load(path.read_text())
assert saved["lockout"] == [{"start": 146_520_000.0, "stop": 146_520_000.0}]
# Only that one key: the rest of the file is as it was.
assert saved["record_seconds"] == 4.0
again, _ = load_default(tmp_path)
assert [lk.start for lk in again.lockout] == [146_520_000.0]
def test_lock_outs_can_be_kept_to_the_current_run(tmp_path):
from bandsaunter.config import load_default, save_default
cfg = ScanConfig(ranges=parse_range_list("146.4M-146.6M"),
output_dir=str(tmp_path), save_lockouts=False)
save_default(cfg, tmp_path)
loaded, path = load_default(tmp_path)
s = Scanner(loaded, device=SimulatedDevice().open())
s.prepare()
s.lockout(146_520_000.0)
assert s._is_locked(146_520_000.0), "still locked out for this run"
again, _ = load_default(tmp_path)
assert not again.lockout, "but not written back"