The place job also finds the places of archived contacts
An archived contact is no longer on the device, so the job never saw its location unless an advert was heard. The contact store keeps that location; the scan now reads the archived contacts of the device from it. On JP's data, 290 of 422 archived contacts had a location and only 68 had a place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e1557f86e1
commit
d159e006ea
2 files changed
+36
-3
No files matched your search
@@ -292,7 +292,9 @@ class PlaceService:
|
||||
The heard adverts give most locations. The contact table of the device adds the
|
||||
nodes that advertised before MeshTerm listened, and the self-info adds our node.
|
||||
Both come from the cache of the device state, never from the device: the job never
|
||||
sends a command.
|
||||
sends a command. The contact store adds the archived contacts of the device. They
|
||||
are not on the device now, but the store keeps their last location, and the
|
||||
Archived list shows their place.
|
||||
"""
|
||||
fresh = self._ctx.repo.node_locations(since=self._since)
|
||||
for node, (lat, lon, stamp) in fresh.items():
|
||||
@@ -307,8 +309,14 @@ class PlaceService:
|
||||
ident = (contact.public_key or contact.key_prefix or "").lower().removeprefix("0x")
|
||||
self._locate(ident[:12], contact.lat, contact.lon, newer=False)
|
||||
info = devstate.peek_self_info() or {}
|
||||
ident = str(info.get("public_key") or "").lower().removeprefix("0x")[:12]
|
||||
self._locate(ident, info.get("adv_lat"), info.get("adv_lon"), newer=True)
|
||||
self_key = str(info.get("public_key") or "").lower().removeprefix("0x")
|
||||
self._locate(self_key[:12], info.get("adv_lat"), info.get("adv_lon"), newer=True)
|
||||
store = getattr(self._ctx, "contact_store", None)
|
||||
if store is not None and self_key:
|
||||
for remembered in store.archived(self_key):
|
||||
self._locate(
|
||||
_norm(remembered.public_key), remembered.lat, remembered.lon, newer=False
|
||||
)
|
||||
|
||||
def _locate(self, node: str, lat: object, lon: object, *, newer: bool) -> None:
|
||||
"""Add a location that did not come from the heard adverts.
|
||||
|
||||
@@ -308,6 +308,31 @@ def test_the_job_uses_the_tiles_then_nominatim(
|
||||
assert len(asked) == 1 # one answer for each location: never asked again
|
||||
|
||||
|
||||
def test_the_job_finds_the_place_of_an_archived_contact(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""An archived contact is not on the device, but the store keeps its location."""
|
||||
from meshterm.core.contact_store import ContactStore
|
||||
from meshterm.core.models import Contact
|
||||
|
||||
service, _repo = _service(tmp_path, source="tiles")
|
||||
device = "dd" * 32
|
||||
store = ContactStore(tmp_path / "contacts.json")
|
||||
gone = Contact(name="Gone", public_key="cc" * 32, lat=_LAT, lon=_LON)
|
||||
store.remember_all(device, [gone])
|
||||
store.archive(device, gone, when=1_700_000_000)
|
||||
service._ctx.contact_store = store
|
||||
service._ctx.devstate = SimpleNamespace(
|
||||
peek_contacts=lambda: [], peek_self_info=lambda: {"public_key": device}
|
||||
)
|
||||
world = _Map()
|
||||
world.add("place", "village", "Val-David", _north(1.0))
|
||||
monkeypatch.setattr(service, "_load_tile", world.load)
|
||||
service._scan_after = 0.0
|
||||
_run(service.step())
|
||||
assert service.get("cc" * 32).fine == "Val-David"
|
||||
|
||||
|
||||
def test_tiles_only_never_asks_nominatim(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""With the tiles source, the job never asks Nominatim."""
|
||||
service, repo = _service(tmp_path, source="tiles")
|
||||
|
||||
Reference in new issue
Block a user