Ship the recorded HafenCity MAPEMs with the app and match SPATEMs to them
A SPATEM can now be placed on its lanes without the intersection's MAPEM being received. The bundle (assets/mapem/hamburg.txt, built by tools/mapem_bundle.py) holds 15 intersections, 16 revisions, from the 2026-03-18 drive. Matching is on region, intersection id and revision, never on station id, and a stored map more than 2 km from the rider is ignored. A live MAPEM of the SPATEM's revision wins; a stored one of another revision is never used.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""Builds the stored-MAPEM bundle the app ships with, from the MAPEM test corpus.
|
||||
|
||||
python tools/mapem_bundle.py
|
||||
|
||||
Reads app/src/test/resources/mapem/corpus.txt (tools/mapem_corpus.py: every distinct MAPEM on record,
|
||||
UPER plus asn1tools' fields) and writes app/src/main/assets/mapem/hamburg.txt: one UPER MAPEM per
|
||||
intersection and revision. Intersections without a region are left out: their id is not unique, and
|
||||
the only one on record is the bench RSU's test crossroads.
|
||||
"""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
CORPUS = ROOT / 'app/src/test/resources/mapem/corpus.txt'
|
||||
OUT = ROOT / 'app/src/main/assets/mapem/hamburg.txt'
|
||||
RECORDED = '2026-03-18'
|
||||
|
||||
|
||||
def main():
|
||||
messages = [] # (hex, [(key, revision, name)])
|
||||
for line in CORPUS.read_text(encoding='ascii').splitlines():
|
||||
if line.startswith('#hex '):
|
||||
messages.append((line[5:], []))
|
||||
elif line.startswith('I '):
|
||||
key, revision, name = re.match(r'I key=(\S+) rev=(\d+) name=(.*?) ref=', line).groups()
|
||||
messages[-1][1].append((key, int(revision), name))
|
||||
|
||||
seen = set()
|
||||
body = []
|
||||
for uper, intersections in messages:
|
||||
new = {(k, r) for k, r, _ in intersections if not k.startswith('-1/')} - seen
|
||||
if not new:
|
||||
continue
|
||||
seen |= new
|
||||
body += [f'# {k} rev {r} {name}' for k, r, name in intersections]
|
||||
body.append(uper)
|
||||
|
||||
header = [f'# Stored MAPEMs, recorded on the {RECORDED} drive in Hamburg. {len(seen)} intersection revisions.',
|
||||
'# One UPER MAPEM per line, hex. Generated by tools/mapem_bundle.py; do not edit.']
|
||||
OUT.parent.mkdir(parents=True, exist_ok=True)
|
||||
OUT.write_text('\n'.join(header + body) + '\n', encoding='utf-8', newline='\n')
|
||||
print(f'{OUT.relative_to(ROOT)}: {len(seen)} intersection revisions, {len({k for k, _ in seen})} intersections')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user