Skip to content

Commit 5195c38

Browse files
committed
Reliable linking
1 parent e88d78c commit 5195c38

5 files changed

Lines changed: 21 additions & 8 deletions

File tree

term_timer/in_out.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ def load_solves(cube: int, session: str) -> list[Solve]:
1818
datas = json.load(fd)
1919

2020
return [
21-
Solve(**data, session=session)
22-
for data in datas
21+
Solve(
22+
**data,
23+
session=session,
24+
cube_size=cube,
25+
solve_id=i + 1,
26+
)
27+
for i, data in enumerate(datas)
2328
]
2429

2530
return []

term_timer/solve.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,19 @@ def __init__(self,
5151
timer: str = '',
5252
device: str = '',
5353
session: str = '',
54+
solve_id: int = 0,
55+
cube_size: int = 3,
5456
moves: str | None = None):
5557
self.date = int(date)
5658
self.time = int(time)
5759
self.scramble = scramble
5860
self.flag = flag
5961
self.timer = timer
6062
self.device = device
63+
6164
self.session = session or 'default'
65+
self.solve_id = solve_id
66+
self.cube_size = cube_size
6267

6368
self.raw_moves = moves
6469
self.solution = None
@@ -609,13 +614,14 @@ def link_cube_db(self) -> str:
609614
self.method_text,
610615
)
611616

612-
def link_term_timer(self, cube_size, solve_id) -> str:
617+
@cached_property
618+
def link_term_timer(self) -> str:
613619
domain = SERVER_CONFIG.get('domain', 'localhost')
614620
port = SERVER_CONFIG.get('port', 8333)
615621

616622
return (
617623
f'http://{ domain }:{ port }'
618-
f'/{ cube_size }/{ self.session }/{ solve_id }/'
624+
f'/{ self.cube_size }/{ self.session }/{ self.solve_id }/'
619625
)
620626

621627
@property

term_timer/stats.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,8 @@ def listing(self, limit: int, sorting: str) -> None:
387387

388388
header = f'[stats]{ index:{" "}>{max_count}}[/stats]'
389389
if solve.advanced:
390-
url = solve.link_term_timer(self.cube_size, original_index)
391390
header = (
392-
f'[localhost][link={ url }]'
391+
f'[localhost][link={ solve.link_term_timer }]'
393392
f'{ index:{" "}>{max_count}}'
394393
'[/link][/localhost]'
395394
)
@@ -590,10 +589,9 @@ def detail(self, solve_id: int, method: str,
590589

591590
if solve.advanced:
592591
if show_reconstruction:
593-
url = solve.link_term_timer(self.cube_size, solve_id)
594592
console.print(
595593
f'[title]Reconstruction { solve.method.name }[/title]',
596-
f'[localhost][link={ url }]'
594+
f'[localhost][link={ solve.link_term_timer }]'
597595
'Term-Timer[/link][/localhost]',
598596
f'[algcubing][link={ solve.link_alg_cubing }]'
599597
'alg.cubing.net[/link][/algcubing]',

term_timer/timer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ async def start(self) -> bool:
243243
and self.bluetooth_interface.device.name
244244
) or '',
245245
session=self.session,
246+
solve_id=self.counter,
247+
cube_size=self.cube_size,
246248
moves=' '.join(moves),
247249
)
248250

term_timer/trainer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ async def start(self) -> bool:
115115
and self.bluetooth_interface.device.name
116116
) or '',
117117
session='training',
118+
solve_id=self.counter,
119+
cube_size=3,
118120
moves=' '.join(moves),
119121
)
120122

0 commit comments

Comments
 (0)