Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions devtools/maps/route_log.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""Reads the planned legs of a route walk from a SerialPrograms log.

walk_route() logs, per walk:
[Route] <label>: plan from Sandgem Town (20, 7), Sandgem Town (21, 7):
[Route] <label>: plan from Sandgem Town (20, 7), Sandgem Town (21, 7): east 9 (to wall) to ...; ...
[Route] Leg 1/8: east 9 (to wall) to Sandgem Town (29, 7), Sandgem Town (29, 8)
Older logs end the plan line at "plan from <tiles>:" and put each leg on a
line of its own after it; either way the legs are read from the "Leg" lines.
and while walking:
[Walk] <label>: east 9 (to wall): blocked after 2800ms, 0 wild battle(s).
"""
import re
from dataclasses import dataclass

PLACE = re.compile(r'([A-Z][\w\' .-]*?) \((-?\d+), (-?\d+)\)')
PLAN = re.compile(r'\[Route\] (.+?): plan from (.+):\s*$')
PLAN = re.compile(r'\[Route\] (.+?): plan from (.+?):(?: |\s*$)')
LEG = re.compile(r'\[Route\] Leg (\d+)/(\d+): (north|south|east|west) (\d+) \((to wall|open)\) to (.+?)\s*$')
WALK = re.compile(r'\[Walk\] (.+?): (north|south|east|west) (\d+) \((?:to wall|open)\)(?:: at the wall\?)?: (\w+) after')

Expand Down
13 changes: 13 additions & 0 deletions devtools/maps/tests/test_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
'2026-10-30 07:08:00.000]: [Route] Back to Route 202: plan from Sandgem Town (29, 2):',
]

# The plan on one line, its legs after the start tiles.
ONE_LINE_PLAN = [
'2026-11-09 07:07:09.275]: [Route] West to the Route 201 sign: plan from Sandgem Town (20, 7), Sandgem Town (21, 7):'
' east 9 (to wall) to Sandgem Town (29, 7), Sandgem Town (29, 8); west 40 (to wall) to Route 201 (53, 5), Route 201 (53, 6)',
'2026-11-09 07:07:09.275]: [Route] Leg 1/2: east 9 (to wall) to Sandgem Town (29, 7), Sandgem Town (29, 8)',
]


class GridSourceTest(unittest.TestCase):
def test_rows_tiles_and_image(self):
Expand Down Expand Up @@ -79,6 +86,12 @@ def test_legs_and_how_they_stopped(self):
def test_only_one_label(self):
self.assertEqual(len(route_log.parse(LOG, 'Back to Route 202')), 1)

def test_one_line_plan(self):
walks = route_log.parse(ONE_LINE_PLAN)
self.assertEqual([w.label for w in walks], ['West to the Route 201 sign'])
self.assertEqual(walks[0].start, [('Sandgem Town', 20, 7), ('Sandgem Town', 21, 7)])
self.assertEqual([(l.direction, l.tiles) for l in walks[0].legs], [('east', 9)])


class FetchTest(unittest.TestCase):
def test_archive_url_is_the_hash_path(self):
Expand Down
Loading