diff --git a/meshterm/demo/history.py b/meshterm/demo/history.py index 675ca28..9e315bd 100644 --- a/meshterm/demo/history.py +++ b/meshterm/demo/history.py @@ -11,7 +11,8 @@ the companion of our node would have stored after months on the mesh of Montréa message can be found again, * the traces that our node ran (:data:`~meshterm.demo.script.TRACES`), each try in the link model, and the records that the walks set in the trophy case, -* the neighbour tables of the repeaters that our node administers. +* the neighbour tables of the repeaters that our node administers, +* the place of each node that shares its location (:data:`~meshterm.demo.world.PLACES`). Each time comes from ``now`` and a fixed age, and each random value comes from a fixed seed. Thus two runs give the same database, with only the times moved to the new now. @@ -68,9 +69,21 @@ def seed(repo: Repository, now: datetime) -> None: repo.record_chat_message(message) _store_traces(repo, now, rng) _store_neighbours(repo, now, rng) + _store_places(repo) repo.set_map_view(*MAP_VIEW) +def _store_places(repo: Repository) -> None: + """Store the place of each node, at the location of the node, as the place job does. + + The places are final (a Nominatim answer, or a peak from the tiles). Thus the place job + of the demo sends no request. + """ + for name, place in world.PLACES.items(): + node = world.node(name) + repo.save_node_place(node.node_id, node.lat, node.lon, place) + + def _store_observations(repo: Repository, now: datetime, observations: list[Observation]) -> None: """Store the observations, in one ``monitor`` run for each day, as the app makes them. diff --git a/meshterm/demo/home.py b/meshterm/demo/home.py index 3ad295e..9a29079 100644 --- a/meshterm/demo/home.py +++ b/meshterm/demo/home.py @@ -50,6 +50,7 @@ _STORES = ( "settings.json", "adverts.json", "devices.json", + "places.json", ) diff --git a/meshterm/demo/world.py b/meshterm/demo/world.py index f705872..c3d51ce 100644 --- a/meshterm/demo/world.py +++ b/meshterm/demo/world.py @@ -37,6 +37,7 @@ from ..core.models import ( NODE_TYPE_ROOM, NODE_TYPE_SENSOR, ) +from ..core.places import SOURCE_NOMINATIM, SOURCE_TILES, Place # --------------------------------------------------------------------------- the nodes @@ -210,6 +211,58 @@ def clock_offset_s(name: str) -> float: return CLOCK_OFFSET_S.get(name, 0.0) +_TILES, _NOMINATIM = SOURCE_TILES, SOURCE_NOMINATIM + +#: The place of each node that shares its location, as the place finder found it on +#: 2026-11-03: the map tiles, then Nominatim (refer to :mod:`meshterm.services.places`). +#: The history stores them (refer to :mod:`meshterm.demo.history`). Thus the demo shows +#: the places at once, the place job sends no request, and each run shows the same places. +#: A node that does not share its location has no place, as on a real mesh. The finder +#: gave a peak only to Mont-St-Hilaire. The Mont-Royal repeater is 317 m from the summit, +#: and a peak counts only within :data:`~meshterm.core.places.PEAK_RADIUS_KM`. +PLACES: dict[str, Place] = { + "Alex Base": Place("La Petite-Patrie", "Montréal", _NOMINATIM), + "Mont-Royal": Place("Ville-Marie", "Montréal", _NOMINATIM), + "Oratoire": Place("Côte-des-Neiges–Notre-Dame-de-Grâce", "Montréal", _NOMINATIM), + "Centre-Ville": Place("Ville-Marie", "Montréal", _NOMINATIM), + "Stade-Olympique": Place("Maisonneuve", "Montréal", _NOMINATIM), + "Ahuntsic": Place("Ahuntsic", "Montréal", _NOMINATIM), + "Laval-Chomedey": Place("Chomedey", "Laval", _NOMINATIM), + "Verdun-Quai": Place("Verdun", "Montréal", _NOMINATIM), + "Lachine": Place("Lachine", "Montréal", _NOMINATIM), + "Pointe-Claire": Place("Pointe-Claire", None, _NOMINATIM), + "Île-Bizard": Place("Le Pain de Sucre", "Montréal", _NOMINATIM), + "Longueuil": Place("Vieux-Longueuil", "Longueuil", _NOMINATIM), + "Brossard": Place("Brossard", None, _NOMINATIM), + "Mont-St-Bruno": Place("Saint-Bruno-de-Montarville", None, _NOMINATIM), + "Mont-St-Hilaire": Place("Central Hill", None, _TILES, peak=True), + "Villeray": Place("Villeray", "Montréal", _NOMINATIM), + "Rosemont": Place("La Petite-Patrie", "Montréal", _NOMINATIM), + "MTL BBS": Place("Le Plateau-Mont-Royal", "Montréal", _NOMINATIM), + "Café Mesh": Place("Mile-End", "Montréal", _NOMINATIM), + "Verdun Weather": Place("Verdun", "Montréal", _NOMINATIM), + "Beaver Lake": Place("Ville-Marie", "Montréal", _NOMINATIM), + "River Gauge": Place("Ville-Marie", "Montréal", _NOMINATIM), + "Marie-Ève": Place("Le Plateau-Mont-Royal", "Montréal", _NOMINATIM), + "Jean-Seb": Place("Ahuntsic", "Montréal", _NOMINATIM), + "Félix": Place("Hochelaga-Maisonneuve", "Montréal", _NOMINATIM), + "Dave-Lachine": Place("Lachine", "Montréal", _NOMINATIM), + "Kim-NDG": Place("Côte-des-Neiges–Notre-Dame-de-Grâce", "Montréal", _NOMINATIM), + "Noor": Place("Côte-des-Neiges", "Montréal", _NOMINATIM), + "Chloé L.": Place("Outremont", "Montréal", _NOMINATIM), + "Sam Verdun": Place("Verdun", "Montréal", _NOMINATIM), + "Steve K.": Place("Vieux-Longueuil", "Longueuil", _NOMINATIM), + "Olivier.T": Place("Rosemont", "Montréal", _NOMINATIM), + "Raphaël": Place("Chomedey", "Laval", _NOMINATIM), + "Ana Brossard": Place("Brossard", None, _NOMINATIM), + "Tomás": Place("Pointe-Claire", None, _NOMINATIM), + "Mathilde": Place("Saint-Henri", "Montréal", _NOMINATIM), + "Gabriel": Place("Beloeil", None, _NOMINATIM), + "T1000-E": Place("Laval-des-Rapides", "Laval", _NOMINATIM), + "Wio Tracker": Place("Verdun", "Montréal", _NOMINATIM), +} + + #: The repeaters, in the order of :data:`NODES`. REPEATERS: tuple[Node, ...] = tuple(node for node in NODES if node.is_repeater) diff --git a/tests/test_demo.py b/tests/test_demo.py index 4357567..badd7e4 100644 --- a/tests/test_demo.py +++ b/tests/test_demo.py @@ -94,6 +94,35 @@ def test_a_tuned_repeater_is_heard_best_at_its_best_power() -> None: assert not far or max(far) < min(best) +def test_each_located_node_has_a_place_that_the_job_keeps(tmp_path: Path) -> None: + """Each node that shares its location has its place, and the job asks for nothing. + + The video and the screenshots show the places at once, and the demo sends no request. + """ + import logging + from types import SimpleNamespace + + from meshterm.core.place_store import PlaceStore + from meshterm.core.preferences import Preferences + from meshterm.services.places import PlaceService + + located = {node.name for node in (world.SELF, *world.NODES) if node.shares_location} + assert set(world.PLACES) == located + repo = _seed(tmp_path / "p.db", utcnow()) + ctx = SimpleNamespace( + repo=repo, + place_store=PlaceStore(tmp_path / "places.json"), + preferences=Preferences(), + log=logging.getLogger("test"), + ) + service = PlaceService(ctx) # type: ignore[arg-type] + for name, place in world.PLACES.items(): + node = world.node(name) + assert service.get(node.public_key) == place + service._locations[node.node_id] = (node.lat, node.lon) # noqa: SLF001 + assert service._step_for(node.node_id) is None # noqa: SLF001 + + def test_prepare_writes_a_home(tmp_path: Path) -> None: """The demo home gets a database and the stores of the joined room and the alerts.""" home = tmp_path / "demo"