Cache what has been looked up, make it browsable, and say where this lives
Four things asked for in turn, landing together because they run through the same files. THE MAPS. The tiles were already cached and always had been -- a second evening on the same view was measured at nought network requests -- but the work done on them was not. Every window open decoded forty PNGs and resampled a megapixel and a half into this program's own projection, for an answer that cannot have changed, because a coastline does not move. The finished map is kept beside the tiles now: 0.61 seconds become 0.01, byte for byte identical, two hundred kilobytes a view. Both windows and both kinds of still picture get it, all four reaching the ground through one function. A map with squares missing is deliberately not kept, since caching a hole would keep it for a month and the point of calling a partial map provisional is that it is asked for again. And because this adds a disk consumer, the whole cache is now pruned to four hundred megabytes, least recently *used* first: a tile fetched a year ago and looked at last night is the receiver's own neighbourhood, and discarding that to keep last week's holiday is the wrong way round. THE LOOKUPS. APRS and FT8 now ask who each station is licensed to. Every other mode that hears a callsign already did -- speech transcripts, Morse idents, the recording browser -- and all five resolve through one file, so a callsign heard on two bands is asked about once. The rules for finding the licensed callsign inside a heard one are now in one place rather than per band, because getting them wrong is silent: a register asked about W1AW-9 returns nothing, which looks exactly like a station that is not licensed. An SSID, a rover suffix, a guest prefix, a digipeater alias and an unspelled hash all come off or are refused. The bug worth recording is that the first cut of this did the lookups and threw them away. The book has to be told to save and was not, so every evening would have asked the register about the same net again -- which is the one thing caching them was for, and is invisible from inside a single run because the answers are all in memory while it lasts. Caught by looking at the file on disk rather than at the display. There is a test for each side of it now, and a register of which modules resolve callsigns at all, which fails when a new one starts so that somebody has to decide whether it should. THE REGISTER. c in saunterbrowse opens everything ever looked up: sixty-odd callsigns and sixteen hundred aircraft here, every field of each in two columns because a licence has a dozen and a screen is wider than it is tall. tab switches, / searches every field rather than the name -- the question is usually "who was in Arizona" rather than "which callsign" -- and g opens the place in a browser. Only the coordinates go into that link: a map does not need to be told whose licence it is looking at, and the link is the one part of this that leaves the machine. A headless box, which is the normal case for a receiver, gets the coordinates printed instead. Callsigns no register could place are kept rather than dropped, because "asked about, and in no register reachable from here" is a fact about a station. THE FRONT OF IT. A title screen for each program: five rows of blocks cut by hand, a figlet dependency to draw eleven letters being the largest thing that would then be in the requirements, coloured blue to red across the width, which is the ramp every waterfall here already uses because it is what a spectrum looks like. The interesting part is where it does not appear -- everything here can be piped into something else and a banner in the middle of that is corruption rather than decoration, so anything that is not a terminal gets nothing, --help is untouched because it is drawn after parsing, --no-splash turns it off for a run and BANDSAUNTER_NO_SPLASH=1 for good. And the address. INSTALL.md said "git clone <the repository>" for a long time: a placeholder in the first command anybody types, unnoticed because nothing reads install instructions except somebody installing, who then cannot. It is filled in, along with the readme, the metadata, both manuals and the Homepage field of all three packages. The tile server's User-Agent pointed at a topic listing on somebody else's site for want of an address of its own; the usage policy of that service asks for one naming the application and giving somewhere to look it up, so an operator with a question about the traffic has somebody to ask, and now it gives the real one. Seven tests so the placeholder cannot come back, verified by putting it back and watching two of them fail. One thing forced by all this: the keys page in saunterbrowse was exactly as tall as an eighty-by-twenty-four terminal, so the register entry pushed "q quit" off the bottom. A test caught it. Home and End have merged into the Page Up line, which were always the same thought. THE WINDOWS. They open maximised now, this being a map and the thing anybody wants more of being map; f goes to true full screen and back, and is written along the top of the screen because a window with no frame is one somebody has to know a key to get out of. Maximised rather than frameless by default, because the title bar is where the band and the frequency are written. And a map made bigger now gets a sharper map, which it did not. The window only ever re-examined the ground when the view left the box that had been fetched, so a window opened at its default size and taken to the whole screen kept the map it started with until an aircraft wandered far enough to move it -- on a quiet band, a long time to look at a blurred coastline. Measured before it was believed: 1100 to 1920 asked for nothing and stretched a 1364-pixel map across 1920, then across 3840. It now compares map pixels per degree in hand against what the view wants, and asks when it is being blown up by more than fifteen per cent. That comparison has to be per degree rather than pixel against pixel, which a surviving mutation was what established: the fetched box is a quarter wider than the view, so a map with exactly as many pixels as the window is wide has only four fifths of them on the screen. The two ways of measuring agree everywhere except a narrow band, and the realistic case sits inside it. There is a test pinning that case now. Asking is safe at any size, because the request is keyed on the window's dimensions: once answered, nothing more is asked, which is what stops a window larger than the tile budget can cover from asking all evening. The braille, while this was open. The banners were blocks in capitals; they are braille in mixed case, two dots wide and four tall to a character, which is eight times the detail and is what makes room for two heights of letter at once -- a five-row block font has no second height to spend, so the name came out shouted. Two attempts failed first: thin one-dot strokes came out as confetti, because braille dots render as dots and a one-dot stroke reads as a dotted line rather than a line. What worked was cutting the font small, at cap height seven where there is only one way to draw each letter, and doubling it. Coloured deep blue through cyan to a cool white, which is deliberately not the waterfall ramp the rest of the program draws in: that one has to run to red because it stands in for a spectrum, and a title screen stands in for nothing. One hundred and four new tests. Full suite 2892 passed. Built as 2026-09-24_01. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016PsWPTweCT6pwxKngvVxcg
This commit is contained in:
parent
93120b80a6
commit
2665a17a22
27 changed files with 3733 additions and 49 deletions
|
|
@ -837,3 +837,235 @@ def test_nothing_claims_to_be_listening_before_there_is_a_receiver(tmp_path):
|
|||
shown = caught.get()
|
||||
assert "cannot open the receiver" in shown
|
||||
assert "listening on" not in shown
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Who each station is
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _register(tmp_path, entries=()):
|
||||
"""A licence register that knows what it is told and asks nobody."""
|
||||
from bandsaunter.callsign import CACHE_VERSION, Callsign, CallsignBook
|
||||
|
||||
book = CallsignBook(online=False, cache=tmp_path / "callsigns.json")
|
||||
for call, name, where in entries:
|
||||
book._entries[call] = Callsign(
|
||||
call=call, name=name, location=where, status="found",
|
||||
version=CACHE_VERSION, fetched_at=time.time())
|
||||
return book
|
||||
|
||||
|
||||
def _heard_from(band, text, calls, grid="", at=1_700_000_000.0):
|
||||
band.add(ft8wave.Decode(text=text, kind="standard", calls=calls,
|
||||
grid=grid, hertz=1200.0, offset=0.2,
|
||||
snr_db=-7.0, calling=text.startswith("CQ"),
|
||||
at=at))
|
||||
|
||||
|
||||
def test_both_callsigns_in_an_exchange_are_looked_up(tmp_path):
|
||||
"""The station being answered may never transmit within earshot, and is
|
||||
still a station this receiver knows about."""
|
||||
register = _register(tmp_path)
|
||||
band = ft8.Band()
|
||||
band.register = register
|
||||
_heard_from(band, "W1AW KU0W DM42", ("W1AW", "KU0W"), "DM42")
|
||||
assert set(register._entries) == {"W1AW", "KU0W"}
|
||||
|
||||
|
||||
def test_a_station_is_asked_about_once_however_often_it_transmits(tmp_path):
|
||||
register = _register(tmp_path)
|
||||
band = ft8.Band()
|
||||
band.register = register
|
||||
for i in range(6):
|
||||
_heard_from(band, "CQ W1AW FN31", ("W1AW",), "FN31",
|
||||
at=1_700_000_000.0 + i * 15)
|
||||
assert set(register._entries) == {"W1AW"}
|
||||
|
||||
|
||||
def test_a_callsign_nobody_has_spelled_out_is_not_asked_about(tmp_path):
|
||||
"""FT8 carries a compound callsign as a hash and expects the receiver to
|
||||
have heard it in full earlier. Until it has, there is nothing to ask."""
|
||||
register = _register(tmp_path)
|
||||
band = ft8.Band()
|
||||
band.register = register
|
||||
_heard_from(band, "<...> ON7EE JO10", ("<...>", "ON7EE"), "JO10")
|
||||
assert set(register._entries) == {"ON7EE"}
|
||||
|
||||
|
||||
def test_a_rover_is_looked_up_under_its_licence(tmp_path):
|
||||
"""ET3RFG/R is ET3RFG operating away from the licensed address, and no
|
||||
register has heard of the suffix."""
|
||||
register = _register(tmp_path)
|
||||
band = ft8.Band()
|
||||
band.register = register
|
||||
_heard_from(band, "ET3RFG/R IN3ADG -23", ("ET3RFG/R", "IN3ADG"))
|
||||
assert set(register._entries) == {"ET3RFG", "IN3ADG"}
|
||||
|
||||
|
||||
def test_the_name_is_shown_when_it_has_arrived(tmp_path):
|
||||
register = _register(tmp_path, [("W1AW", "ARRL HQ Operators Club",
|
||||
"Newington, CT")])
|
||||
band = ft8.Band()
|
||||
band.register = register
|
||||
_heard_from(band, "CQ W1AW FN31", ("W1AW",), "FN31")
|
||||
assert ft8.who_text(ft8.licensee(band, "W1AW")) == \
|
||||
"ARRL HQ Operators Club — Newington, CT"
|
||||
|
||||
|
||||
def test_the_dx_the_register_cannot_know_still_says_which_country():
|
||||
"""Which on this band is the point: the databases are United States
|
||||
registers and the interesting stations are all somewhere else."""
|
||||
from bandsaunter.callsign import Callsign
|
||||
|
||||
who = Callsign(call="VK4BLE", country="Australia", status="unlisted")
|
||||
assert ft8.who_text(who) == "Australia"
|
||||
|
||||
|
||||
def test_nothing_is_looked_up_without_a_register():
|
||||
band = ft8.Band()
|
||||
_heard_from(band, "CQ W1AW FN31", ("W1AW",), "FN31")
|
||||
assert ft8.licensee(band, "W1AW") is None
|
||||
assert ft8.open_register(ft8.Ft8Options(lookup=False)).online is False
|
||||
|
||||
|
||||
def test_the_report_gives_a_column_for_who_each_station_is(tmp_path):
|
||||
from rich.console import Console
|
||||
|
||||
band = ft8.Band()
|
||||
band.register = _register(tmp_path, [("W1AW", "ARRL HQ Operators Club",
|
||||
"Newington, CT")])
|
||||
band.slots = 2
|
||||
_heard_from(band, "CQ W1AW FN31", ("W1AW",), "FN31")
|
||||
console = Console(width=150, force_terminal=False)
|
||||
with console.capture() as caught:
|
||||
ft8.report(console, band, ft8.Ft8Options(lookup=True))
|
||||
shown = caught.get()
|
||||
assert "licensed to" in shown and "ARRL HQ Operators Club" in shown
|
||||
|
||||
|
||||
def test_the_report_leaves_the_column_out_when_lookups_are_off(tmp_path):
|
||||
from rich.console import Console
|
||||
|
||||
band = ft8.Band()
|
||||
band.slots = 2
|
||||
_heard_from(band, "CQ W1AW FN31", ("W1AW",), "FN31")
|
||||
console = Console(width=150, force_terminal=False)
|
||||
with console.capture() as caught:
|
||||
ft8.report(console, band, ft8.Ft8Options(lookup=False))
|
||||
assert "licensed to" not in caught.get()
|
||||
|
||||
|
||||
def test_what_was_learned_is_written_to_the_disk(tmp_path):
|
||||
"""Otherwise every evening asks the register about the same band again,
|
||||
which is the one thing caching it was for."""
|
||||
from bandsaunter.callsign import CallsignBook
|
||||
|
||||
where = tmp_path / "callsigns.json"
|
||||
band = ft8.Band()
|
||||
band.register = _register(tmp_path, [("W1AW", "ARRL HQ", "Newington, CT")])
|
||||
band.register._dirty = True
|
||||
ft8.keep_lookups(band)
|
||||
assert where.exists()
|
||||
assert CallsignBook(online=False, cache=where).get("W1AW").name == "ARRL HQ"
|
||||
|
||||
|
||||
def test_listening_ends_by_writing_what_it_learned(tmp_path, monkeypatch):
|
||||
"""Through the real path rather than by calling the helper directly."""
|
||||
from rich.console import Console
|
||||
from bandsaunter.callsign import CACHE_VERSION, Callsign, CallsignBook
|
||||
|
||||
where = tmp_path / "callsigns.json"
|
||||
monkeypatch.setattr(ft8, "open_register",
|
||||
lambda options: CallsignBook(online=False,
|
||||
cache=where))
|
||||
monkeypatch.setattr(ft8, "open_device", lambda console, options: None)
|
||||
console = Console(width=100, force_terminal=False)
|
||||
options = ft8.defaults()
|
||||
options.log = False
|
||||
heard = ft8.Heard()
|
||||
heard.band.register = CallsignBook(online=False, cache=where)
|
||||
heard.band.register._entries["KU0W"] = Callsign(
|
||||
call="KU0W", name="Rod R Gowdy", status="found",
|
||||
version=CACHE_VERSION, fetched_at=time.time())
|
||||
heard.band.register._dirty = True
|
||||
with console.capture():
|
||||
ft8.finish(console, options, str(tmp_path), heard)
|
||||
assert CallsignBook(online=False, cache=where).get("KU0W").name == \
|
||||
"Rod R Gowdy"
|
||||
|
||||
|
||||
def test_every_mode_that_hears_callsigns_looks_them_up_and_caches_them():
|
||||
"""The whole of the answer to "all possible features", as a test rather
|
||||
than as a promise.
|
||||
|
||||
Written as a register of what is known to resolve callsigns, so that a
|
||||
module which starts doing it later fails here until somebody has
|
||||
decided whether it should. Checking only that the current ones work
|
||||
would say nothing about the next one.
|
||||
|
||||
Aircraft are deliberately absent: a registration is not an amateur
|
||||
callsign and no amateur register has heard of one. They have their own
|
||||
cached book, which test_flights covers.
|
||||
"""
|
||||
import ast
|
||||
import importlib
|
||||
|
||||
from bandsaunter import aprs, browse, scanner
|
||||
from bandsaunter.callsign import CallsignBook, _cache_path
|
||||
|
||||
known = {
|
||||
"scanner": "speech transcripts and Morse idents",
|
||||
"browse": "the recording browser",
|
||||
"aprs": "APRS stations",
|
||||
"ft8": "FT8 exchanges",
|
||||
}
|
||||
found = {}
|
||||
for path in sorted(Path(aprs.__file__).parent.glob("*.py")):
|
||||
if path.stem in ("callsign", "__init__"):
|
||||
continue
|
||||
tree = ast.parse(path.read_text())
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom) and node.module == "callsign":
|
||||
if any(a.name in ("CallsignBook", "find_callsigns",
|
||||
"licensed_call") for a in node.names):
|
||||
found[path.stem] = True
|
||||
assert set(found) == set(known), (
|
||||
f"modules resolving callsigns changed: {sorted(found)} "
|
||||
f"vs {sorted(known)} -- add it here and give it a lookup, or "
|
||||
f"explain why it should not have one")
|
||||
|
||||
# And every one of them resolves through the same file, so a callsign
|
||||
# heard on two bands is asked about once rather than twice.
|
||||
for book in (aprs.open_book(aprs.defaults()),
|
||||
ft8.open_register(ft8.defaults()),
|
||||
CallsignBook(online=False)):
|
||||
assert book.cache_path == _cache_path()
|
||||
assert browse is not None and scanner is not None
|
||||
|
||||
|
||||
def test_a_callsign_heard_on_two_bands_is_asked_about_once(tmp_path):
|
||||
"""The point of one shared file: APRS and FT8 hear the same operators,
|
||||
and a register asked twice for the same answer is a register being
|
||||
asked one time too many."""
|
||||
from bandsaunter import aprs
|
||||
from bandsaunter.callsign import CACHE_VERSION, Callsign, CallsignBook
|
||||
|
||||
where = tmp_path / "callsigns.json"
|
||||
asked = []
|
||||
|
||||
class Counting(CallsignBook):
|
||||
def _request(self, url, call):
|
||||
asked.append(call)
|
||||
raise AssertionError("no network in tests")
|
||||
|
||||
first = Counting(online=False, cache=where)
|
||||
first._entries["W1AW"] = Callsign(call="W1AW", name="ARRL HQ",
|
||||
status="found", version=CACHE_VERSION,
|
||||
fetched_at=time.time())
|
||||
first._dirty = True
|
||||
first.save()
|
||||
|
||||
# A different mode, a later evening, the same file.
|
||||
second = Counting(online=True, cache=where)
|
||||
assert second.get("W1AW").name == "ARRL HQ"
|
||||
assert asked == [], "it went back to the register for an answer it had"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue