
    UHj87                       d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	  ee
      j                         j                  d   Zedz  ZdddZdd	Zdd
ZddZddZddZ	 	 	 	 	 	 	 	 ddZddZddZddZddZedk(  r e        yy)zJBuild a focused route-assist page for the current confirmed-route blocker.    )annotationsN)Path	urlencode   outc                "    | dt        |        S )Nz/game.html?r   )params
web_prefixs     </home/exedev/hwanse/tools/summarize_route_assist_frontier.pyweb_hrefr      s    \Yv%6$788    c                b    | D ](  t        fd|j                         D              s&c S  i S )Nc              3  L   K   | ]  \  }}j                  |      |k(    y w)Nget).0keyvaluerows      r   	<genexpr>zfirst_match.<locals>.<genexpr>   s"     Feswws|u$Fs   !$)allitems)rowsfieldsr   s     @r   first_matchr      s2     Fv||~FFJ Ir   c                    | j                  d      xs g D cg c]  }|j                  d      |k(  s| }}|si S t        |d       S c c}w )NtargetHintstargetc                ,    | j                  d      xs g S )Nrankr   )hints    r   <lambda>ztarget_hint.<locals>.<lambda>   s    txx'7'=2 r   r   )r   min)	candidater   r"   hintss       r   target_hintr(      sP    'mmM:@badDHHXDVZ`D`TaEa	u=>> bs
   A
A
c           
         t        | |j                  d       d|j                  d       |j                  d       d|j                  d       ddd|d      S )Nx,y1routeAssist)map	startTile	focusTile	collisionoverviewtrialTransitionstransitionTargetr   r   )sourcer   samples      r   candidate_route_urlr9   "   sc    

3(&**S/):;

3(&**S/):;)"  r   c           	         |syt        | |j                  d       d|j                  d       |j                  d       d|j                  d       ddd      S )N r*   r+   r,   r-   )r/   r0   r1   eventsr3   r6   )r   r"   s     r   target_spawn_urlr=   .   s_    a7a7  r   c           
        t        ||       }g }|j                  d      xs g D ]  }t        |j                  d      xs g       }t        |j                  d      xs g       }t        ||      }||vr||vr|sW|j                  d      xs i }	|j	                  i d| d|d|j                  d      d	|j                  d	      d
|j                  d
      d|j                  d      d|	d|	j                  d      d|	j                  d      d|	j                  d      d|j                  d
      dk(  xr |	j                  d      du d|j                  d      d|j                  d      d|d|j                  d      d|j                  d      dt        | ||	      dt        ||      i        |j                  d        |S )N)r/   exitCandidatesselectorTargetCandidatesblockedTargetCandidatesr8   r7   r   sidecomponentIndexedgeDistance	tileCountsourceStandable	standablelayer0layer1autoTriggerr   TpromotionStatusreason
targetHintsourceReviewUrl	reviewUrlmapExitTrialUrltrialUrlrouteAssistUrltargetSpawnUrlc           	         | d   rdnd| j                  d      | j                  d      nddddddj                  t        | j                  d	            d
      | j                  d      xs d fS )NrJ   r   r   rD   i        )topbottomleftrightrB   	   rE   )r   str)r   s    r   r#   z&build_candidate_rows.<locals>.<lambda>X   sl    Q#&77>#:#FCQA6::3swwv;OQRS
''+

#!$	 r   r$   )r   r   setr(   appendr9   r=   sort)
r7   r   map_exit_candidatessource_exit_rowr   r&   target_candidatesblocked_targetsr"   r8   s
             r   build_candidate_rowsrd   :   s6   !"56BOD$(()9:@b 		.H I ORPimm,EFL"M9f-**v_/LUYx(.B 
f
f
 IMM&)
 imm,<=	

 IMM.9
 {3
 f
 vzz+6
 fjj*
 fjj*
 9==8A=a&**[BY]aBa
 y}}->?
 immH-
 $
 y}}[9
  y}}Z8!
" 1&&&I#
$ .vt<%
 	6 	II I  Kr   c                   g }| j                  d      xs g D ci c]%  }|j                  d      |j                  d      f|' }}| j                  d      xs g D ]u  }|j                  d      }|j                  d      xs g D ]H  }t        |||      }	|j                  ||fi       }
t        |||      }t        t	        | j                  d      xs g       i       }|j                  d	      xs i }|j                  d
      xs |dddd}|r(|j                  d       d|j                  d       |d	<   |j                  i d|d|d|	j                  d      xs |	j                  d      xs dd|	j                  d      xs |
j                  d      d|	j                  d      xs g d|	j                  d      xs |
j                  d      xs g d|
j                  d      xs |	j                  d      xs g d|
j                  d      xs |	j                  d      xs g d|	j                  d      d|	j                  d      d|
j                  d      xs ddt        |      dt        d  |D              d!|d"t        |      d#t        |ddd|d$      d%t        |ddd&      t        |ddd&      d'd(d)d*d+       K x |S c c}w ),NsaveSelectorCandidateFrontierr7   r   confirmedRouteBlockersr/   saveSelectorFrontierTargets)r7   r   confirmedEntryRoutesr0   startMapr-   r.   )r/   r<   r3   r4   r*   r+   r,   statusblockerStatusblockedpromotionRiskmissingEvidencebranchConditions	selectorsleafPointerssourceTilesetMatchtargetTilesetMatchfrontierNotepromotionNoter;   candidateExitCountautoCandidateExitCountc              3  D   K   | ]  }|j                  d       sd  yw)rJ   r   Nr   )r   r&   s     r   r   zbuild_rows.<locals>.<genexpr>   s     -lIy}}]jOka-ls     candidateExitsstartRouteAssistUrlsourceRouteAssistUrl)r/   r<   r3   r4   r5   sourceOverviewUrl)r/   r<   r3   zroute_investigation_queue.htmlzmap_exit_candidates.htmlz
trial-onlyzThis page is a focused manual route-assist index. The links keep geometry-only exits and save-selector scene links separated from confirmed normal progression; they are not promotion proof.)targetOverviewUrlqueueUrl
mapExitUrlrK   
conclusion)	r   r   rd   nextiterr^   lensumr   )playable_progressroute_investigation_queuer`   r   r   frontier_by_source_targetblockerr7   r   queuefrontier
candidatesroute_start
start_tilestart_paramss                  r   
build_rowsr   a   sf   
 D %(()HIOR! 
	CGGH-.3! ! %(()ABHb 0U#kk"?@FB .	F 9&QWXE044ff5ErJH-ff>QRJt$5$9$9:P$Q$WUWXZ\]K$5;J"z2<f$1	L /9~~c/B.C1Z^^TWEXDY,Z[)KK  & &  %))O4X		(8KXy   ?!;!\x||O?\	 
 "599->#?#E2  #EII.@$A$kX\\RdEe$kik  X\\+6V%))K:PVTV  ^ < _		.@Y _]_  %eii0D&E  %eii0D&E  _ = C  %c*o  )#-l-l*l  !*  &x'=   '!! #(5(.2 )! . $XfY\.]%^/ 0 &.fY\.]%^<8#/{;   .	0b Kk!s   *Kc                   g d}| D ]  }d|d    dd|d    dd|d    dd	|d
    dg}|j                  d|j                  d       d|j                  d       d|j                  d       d|j                  d       ddj                  |j                  d      xs g       xs d d|j                  d       d|j                  d       ddj                  |       d        |j                  g d       | D ]  }|j                  d      xs g D ]v  }|j                  d      xs i }|j                  d      xs i }|r[|j                  d       d|j                  d        d!|j                  d"       d#|j                  d$       d%|j                  d&       	nd}d'|d(    dd)|j                  d*       d|j                  d+      rd,|j                  d+       dndg}|j                  d|j                  d       d|j                  d       d|j                  d        d!|j                  d"       d-|j                  d.       d/|j                  d0       d|j                  d$       d| d|d1    d|d2    d|d3    d       y  | s|j                  d4       |j                  d5       d6j                  |      S )7N)z# Route Assist Frontierr;   zFocused manual links for the current confirmed-route blocker. These links are trial-only and do not promote a normal transition.r;   z>| source | target | status | missing evidence | exits | open |z&| --- | --- | --- | --- | ---: | --- |z[start assist](r{   )z[source assist](r|   z	[target](r~   z[queue](r   z| r7   z | r   rk    / rn   , ro   -rw    (rx   z	 auto) | z |)r;   z## Candidate Exitsr;   zb| source | side | tile | auto | target spawn hint | route assist | map-exit trial | target spawn |z1| --- | --- | --- | --- | --- | --- | --- | --- |rz   r8   rM   rB    r*   r+   r,    auto=rJ    projection=projectionDeltaz	[assist](rR   z[exit](rP   rS   z[spawn](z l0=rH    l1=rI   r   r   rU   z!| - | - | - | - | - | - | - | - |r;   
)r^   r   joinextend)r   linesr   linksr&   r8   r"   	hint_texts           r   markdownr      s1   E  
c"789;s#9:;1=/013s:'q)	
 	"#3swwx'8&9SWWX=N<OsSVSZSZ[jSkRlloyy!239r:AcB#ww+,-R8P0Q/RR[\a\f\fgl\m[nnpr	

 
LL    !128b 	I]]8,2F==.4"D  88F#$Adhhsm_Adhhsm_F488TaKbJc d"hh'89:<   I&678:)--(9:;1=AJO_A`(9==)9:;1=fiE
 LLY]]8,-Sv1F0Gs::c?#1VZZ_$5T)--:Q9RRVW`WdWdemWnVoor==/0I;c%(3uUVxjX[\abc\d[eegi	& 89	LL99Ur   c                B   g }g }| D ]  }dj                  dt        j                  |d          ddt        j                  |d          ddt        j                  |d          ddt        j                  |d	          d
g      }|j                  dt        j                  t	        |j                  d                   dt        j                  t	        |j                  d                   dt        j                  t	        |j                  d                   dt        j                  t	        |j                  d                   dt        j                  dj                  |j                  d      xs g       xs d       d|j                  d       d|j                  d       d| d       |j                  d      xs g D ]  }|j                  d      xs i }|j                  d      xs i }|r[|j                  d       d|j                  d       d|j                  d        d!|j                  d"       d#|j                  d$       	nd}|j                  d%      rdt        j                  |d%          d&nd}	|j                  dt        j                  t	        |j                  d                   dt        j                  t	        |j                  d                   d|j                  d       d|j                  d        d'|j                  d(       d)|j                  d*       d+t        j                  t	        |j                  d"                   dt        j                  |       d,t        j                  |d-          d.t        j                  t	        |j                  d/                   d0|	 d         d1j                  d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCd1j                  |      xs dDdEdFdGd1j                  |      xs dHdEdIdJg      S )KNr   z	<a href="r{   z">start assist</a>r|   z">source assist</a>r~   z">target</a>r   z">queue</a>z<tr><td>r7   z	</td><td>r   rk   r   rn   r   ro   r   rw   r   rx   z auto)</td><td>z
</td></tr>rz   r8   rM   rB   r*   r+   r,   r   rJ   r   r   rS   z">spawn</a>z<br><code>l0=rH   r   rI   z</code></td><td>z</td><td><a href="rR   z">assist</a></td><td><a href="rP   z">exit</a></td><td>r   z<!doctype html>z<html lang="en">z<head>z<meta charset="utf-8">z$<title>Route Assist Frontier</title>z<style>zMbody{font-family:system-ui,sans-serif;background:#111;color:#eee;margin:24px}z8table{border-collapse:collapse;width:100%;margin:16px 0}z?th,td{border:1px solid #444;padding:6px 8px;vertical-align:top}z#a{color:#8fd3ff}code{color:#b7f0ff}z!.note{max-width:900px;color:#bbb}z</style>z</head>z<body>z<h1>Route Assist Frontier</h1>z<p class="note">Focused manual links for the current confirmed-route blocker. These links are trial-only and do not promote a normal transition.</p>z<h2>Blockers</h2>z<table><thead><tr><th>source</th><th>target</th><th>status</th><th>missing evidence</th><th>exits</th><th>open</th></tr></thead><tbody>z<<tr><td colspan="6">No route-assist frontier rows.</td></tr>z</tbody></table>z<h2>Candidate Exits</h2>z<table><thead><tr><th>source</th><th>side</th><th>tile</th><th>auto</th><th>target spawn hint</th><th>route assist</th><th>map-exit trial</th><th>target spawn</th></tr></thead><tbody>z1<tr><td colspan="8">No candidate exits.</td></tr>z</body>z</html>)r   htmlescaper^   r\   r   )
r   summary_rowscandidate_rowsr   summary_linksr&   r8   r"   r   target_spawns
             r   	html_pager      s9   LN (C(=$>?@@RSC(>$?@AATUC(;$<=>lKC
O45[A	"
  	;;s3778#4567 8;;s3778#4567 8;;s3778#4567s4;;s377SbKcGd;e:f g;;tyy1B)C)IrJQcRS T77/01CGG<T4U3V W / "		
 !128b 	I]]8,2F==.4"D  88F#$Adhhsm_Adhhsm_F488TaKbJc d"hh'89:<   ==!12 DKK	2B(CDE[Q8;  !!{{3y}}X'>#?@A B{{3y}}V'<#=>? @zz#'qC(9y}}U]G^F__cdmdqdqrzd{c| }{{3y}}]'C#DEF G{{9-. /!!%Y7G-H!I J K!!%S?P1Q-R!S T U#n %		#(R 99 .WBI-+( 	_ 	R		,a#a" 	B		.!X%X5  r   c                    |dz  j                  t        j                  | dd      dz   d       |dz  j                  t        |       d       y )	Nzroute_assist_frontier.jsonFrU   )ensure_asciiindentr   utf-8encodingroute_assist_frontier.html)
write_textjsondumpsr   )r   out_dirs     r   write_outputsr     sS    ++77

4eA6= 8  ++77	$RY7Zr   c            	        t        j                         } | j                  dt        t        dz         | j                  dt        t        dz         | j                  dt        t        dz         | j                  dt        t               | j                         }t        t        j                  |j                  j                  d	
            t        j                  |j                  j                  d	
            t        j                  |j                  j                  d	
                  }t        ||j                         t        d|j                  dz          y )Nz--playable-progresszplayable_progress.json)typedefaultz--route-queuezroute_investigation_queue.jsonz--map-exitszmap_exit_candidates.jsonz	--out-dirr   r   zwrote route assist frontier -> r   )argparseArgumentParseradd_argumentr   OUT
parse_argsr   r   loadsr   	read_textroute_queue	map_exitsr   r   print)parserargsr   s      r   mainr   &  s   $$&F
-D#H`B`a
dCBb<bc
D#@Z:Z[
$<D

4))33W3EF

4##--w-?@

4>>++W+=>D
 $%	+DLL;W,W+X
YZr   __main__)z../web)r
   zdict[str, str]r   r\   returnr\   )r   
list[dict]r   r\   r   dict)r&   r   r   r\   r   r   )r7   r\   r   r\   r8   r   r   r\   )r   r\   r"   r   r   r\   )r7   r\   r   r\   r`   r   r   r   )r   r   r   r   r`   r   r   r   )r   r   r   r\   )r   r   r   r   r   None)r   r   )__doc__
__future__r   r   r   r   pathlibr   urllib.parser   __file__resolveparentsROOTr   r   r   r(   r9   r=   rd   r   r   r   r   r   __name__ r   r   <module>r      s    P "     " H~''*
Ul9?		$N;;); $; 	;|2jGT[[  zF r   