
    UHj;                    f   d Z ddlmZ ddlZddlZddlZddlmZ  ee      j                         j                  d   Zedz  ZdZdZd	ZdZdd
ZddZddZddZdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZd dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZd"dZd"dZefd#dZd$dZedk(  r e        yy)%zIContrast the confirmed map1_02b entry pattern with the map1_01a frontier.    )annotationsN)Path   outmap1_01amap2_02dmap1_02bc                    d| dS )N0x08x )values    G/home/exedev/hwanse/tools/summarize_map1_01a_record_pattern_contrast.pyhex32r      s    c{    c                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)pathfallbacks     r   	load_jsonr      s*    ;;=::dnngn677r   c                R    | sy| j                  d       d| j                  d       S )N-clusterStartHexz..clusterEndHexget)clusters    r   cluster_ranger$      s.    kk+,-RO0L/MNNr   c                    t        | j                  d      t              rt        | d         S | j                  d      xs dS )NrecordVarecordVaHexr   )
isinstancer"   intr   )events    r   event_record_hexr+   #   s9    %))J'-U:&''99]#*s*r   )classificationmanifest_mapevent_source
event_linkcurrent_frontierc               F   | j                  d      xs g D ]  }|r|j                  d      |k7  r|r||j                  d      xs g vr4|r||j                  d      xs g vrN|r||j                  d      xs g vrh|t        |j                  d            |ur|c S  y )Nclustersr,   manifestMapseventSourceseventFieldLinkscurrentFrontierPairCount)r"   bool)field_map_rootsr,   r-   r.   r/   r0   r#   s          r   find_clusterr9   )   s     #&&z28b gkk*:;~ML^1L1RPRSL^1L1RPRS*W[[9J-K-QrR'D=W1X,Yaq,q r   c                   | D ]{  }|j                  d      |k7  rg }|j                  d      xs g D ]B  }|j                  d      xs g D ](  }|j                  d      s|j                  |d d        * D ||v sy|c S  y )NmapeventDispatchRefsconditionLinkedStringsz.cns)r"   endswithappend)eventssourcetargetr*   linksrefr   s          r   
find_eventrF   A   s     	99Uv%99017R 	-C!9:@b ->>&)LLs,-	- U?L	 r   c           
        | j                         D cg c],  }|j                  d      |k(  r|j                  d      |k(  r|. }}t        |      t        d |D              t        d |D              |D cg c]9  }|j                  d      dk(  r#|j                  d      |j                  d      d	; c}d
S c c}w c c}w )NrB   rC   c              3  J   K   | ]  }|j                  d       dk(  sd  yw)state	confirmedr   Nr!   .0rows     r   	<genexpr>z review_counts.<locals>.<genexpr>W   s      Nscggg.>+.MN   ##c              3  J   K   | ]  }|j                  d       dk(  sd  yw)rI   rejectedr   Nr!   rK   s     r   rN   z review_counts.<locals>.<genexpr>X   s      LcSWWW-=-KLrO   rI   rJ   xy)rR   rS   )totalrJ   rQ   confirmedTiles)valuesr"   lensum)transition_reviewsrB   rC   rM   rowss        r   review_countsr[   O   s     &,,.778&3778+<+F 	D  TNdNNLTLL 
www;. ''#,SWWS\2
		 	
s   1B96>B>
c                R    | j                  d      xs g }t        d |D        i       S )NrZ   c              3     K   | ]6  }|j                  d       t        k(  r|j                  d      t        k(  r| 8 yw)rB   rC   N)r"   SOURCETARGETrK   s     r   rN   z*scene_list_frontier_row.<locals>.<genexpr>d   s9      	
wwx F*swwx/@F/J 	
s   <>)r"   next)scene_list_contextrZ   s     r   scene_list_frontier_rowrb   a   s6    !!&)/RD	
	
 	 r   c                ,   t        | dt        t        t              }t        | dt        d      }t	        |t        t              }	t        |      }
|
j                  d      xs g }|r|d   ni }t        |t        t              }t         dt         t        |      |xs i j                  d	      |xs i j                  d
d      t        |	xs i       |	xs i j                  d      xs" t        |	xs i j                  d      xs g       t        |	xs i j                  d      xs g       t        |	xs i j                  d      xs g       |xs i j                  d      xs g |d   |d   |d   |d   d}i dt         dt         dt        |      d	|xs i j                  d	      d
|xs i j                  d
d      d|xs i j                  dd      d|xs i j                  dd      d|j                  dd      d|j                  dd      d|j                  dd      d|
j                  d      d|j                  d      d|j                  d	      d|j                  d      xs i j                  d       d!|j                  d!      xs i j                  d       d"|j                  d"d      d#|j                  d#d      d$|j                  d$      }g d%}t        t        t         dt         ||d&|d
   dkD  d&|d   du |d'd(d)}|S )*Nzstrict event-linked cluster)r,   r-   r.   r/   z&current frontier selector-only clusterT)r,   r-   r0   branchStepsr    -> r,   eventRecordCountrawPointCountpointsactivePointsr<   r5   rT   rJ   rQ   rU   )routeclusterRangeHexr,   rf   eventRecordHexeventPointCounteventActivePointCounteventDispatchRefCountr5   transitionReviewTotaltransitionReviewConfirmedtransitionReviewRejectedrU   rj   rk   saveSelectorRefCountr6   resourceReferenceCountrouteExitPointCandidateCount strictSourceTargetCandidateCountselectorOnlySceneListbranchTargetKindbranchClassificationnearestSourceRecordAfterBranchr'   nearestTargetRecordAfterBranchadjacentSceneRecordCountgeometryExitWordHitCountstrictCoordinateEvidenceFound)z*strict event record for map1_01a as sourcez5event dispatch condition linking map1_01a to map2_02dz:event point table or active tile points for the source mapzGroute-exit point candidate in nearby map1_01a/map2_02d resource windowszHgeometry exit word hit inside the current selector scene-record sequenceFblockeda  The confirmed map1_02b -> map1_01a transition has a strict event-linked cluster, an event dispatch condition, and a 24-point event table with reviewed confirmed tiles. The current map1_01a -> map2_02d frontier has adjacent scene records and many save-selector references, but no event record, no source point table, no route-exit point candidate, and no geometry exit word hit. Its branch target is a resource gate before scene records, so the pattern does not match a promotable confirmed transition.)rB   rC   confirmedReferenceRouteconfirmedPatternfrontierPatternconfirmedLikePatternFoundfrontierHasStrictEventRecordfrontierHasStrictSourceHotspot frontierHasOnlySelectorSceneListmissingComparedToConfirmedpromotionStatus
conclusion)r9   CONFIRMED_TARGETCONFIRMED_SOURCEr^   rF   rb   r"   r[   r$   r+   rW   r_   )r8   rA   rY   resource_ref_scanra   scene_record_sequencecoordinate_variant_scanconfirmed_clusterfrontier_clusterconfirmed_event	scene_rowbranch_stepsbranch_stepreviewsconfirmed_patternfrontier_patternmissingsummarys                     r   build_summaryr   l   s    %4%%# $?	 !)9;KLO'(:;I==/52L%1,q/rK.0@BRSG$%T*:);<():;,2778HI.4"99:LaP*?+@bA+1r66G{3P_PeceOjOjksOtOzxzK{!$o&;%@%@%P%VTV!W!$o&;%@%@AT%U%[Y[!\-3889JKQr!(!1%,[%9$+J$7!"23F84x(=)9: 	+1r667GH 	-3889KQO	
 	!1!7R < <=SUV W 	#%5%;$@$@A[]^$_ 	!"3"7"78PRS"T 	'(9(=(=>\^_(` 	+,=,A,ABdfg,h 	 /F!G 	KOO,>? 	0@ A 	);??;[+\+b`b*g*ghu*v 	);??;[+\+b`b*g*ghu*v 	#$9$=$=>XZ[$\  	#$9$=$=>XZ[$\!" 	()@)D)DEd)e#&G &6%7t<L;M#N-+%*(89K(Lq(P*/,<=T,UY],]&-$sG( Nr   c           
        | d   }| d   }g ddd| d    d| d    d	d
| d    d	d| d    d| d    d| d    d| d    d| d    d	d| d   dddddd|d    d|d    dd|d    d |d!    d"|d    d |d!    d#	d$|d%    d&|d%    d#d'|d(    d)d*|d+    d,|d-    d.d/|d0    d1d2d3j                  |d4         xs d5 d1d6|d7    d8|d9    d:d;|d<    d#d=|d>   xs d5 d?|d@   xs d5 dAdB|dC    dDdE|dF    dGdH|dI    d#dJ|dK    d#dL|dM    d#ddNd}|j                  dO | dP   D               |j                  d       dQj                  |      S )RNr   r   z"# map1_01a Record Pattern Contrast z- route under test: `rB   re   rC   `z- confirmed reference route: `r   z - confirmed-like pattern found: r   z$- frontier has strict event record: r   z&- frontier has strict source hotspot: r   z)- frontier has only selector scene list: r   z- promotion status: `r   r   z## Pattern Comparisonz/| signal | confirmed entry | current frontier |z| --- | --- | --- |z| route | `rj   z` | `z` |z| cluster | `rk   z` r,   z | `z |z| event records | rf   z | z| event record | `rl   z` | - |z| event points | rm    raw / rn   z active | - |z| dispatch refs | ro   z | - |z| event field links | , r5   r   z| transition reviews | rq    confirmed / rr   z rejected | - |z| save-selector refs | - | rs   z| branch target | - | rx    (ry   z) |z| scene adjacency | - | r|   z adjacent rows |z| resource refs | - | rt   z direct refs |z$| route-exit point candidates | - | ru   z | geometry exit word hits | - | r}   z#| strict coordinate evidence | - | r~   z ## Missing Compared To Confirmedc              3  &   K   | ]	  }d |   yw)z- Nr   rL   items     r   rN   zmarkdown.<locals>.<genexpr>   s     O2dVOs   r   
)joinextendr@   )r   rJ   frontierliness       r   markdownr      s   *+I()H#,#
#   12$wx7H6IK# )1J)K(LAN	#
 +73N+O*PQ# /w7U/V.WX# 19Y1Z0[\# 4G<^4_3`a#  (9 :;1=# 	# 	# 	# 	 # 	# 	:#  	!#" i()x/@.AE##$ 	"345R	BR8S7TTXYabsYtXuuw  yA  BR  yS  xT  TV  	W%#& Y'9:;3xHZ?[>\\^_'#( Y'789A)#* I&789KbAc@ddqr+#, Y'>?@G-#. !95F+G!H!OC PPVW/#0 "),G"H!IW`a{W|V}  ~M  	N1#2 &h/E&F%GrJ3#4 !*<!=!D ERQgHhHoloGppst5#6 #8,F#G"HHXY7#8 !*B!C DNS9#: /x8V/W.XXZ[;#< +84N+O*PPRS=#> .h7V.W-XXZ[?#@ 	A#B 	+C#D 	E#EH 
LLO1M)NOO	LL99Ur   c                n   | d   }| d   }d|d   |d   fd|d    d|d    |d    d|d    fdt        |d	         t        |d	         fd
|d   dfd|d    d|d    ddfdt        |d         dfddj                  |d         xs ddfd|d    d|d    ddfddt        |d         fdd|j                  d      xs d d |j                  d!      xs d d"fd#d|d$    d%fd&d|d'    d(fd)dt        |d*         fd+dt        |d,         fd-dt        |d.         fg}d/j                  d0 |D              }d1j                  d2 | d3   D              }d/j                  d4d5d6d7d8d9d:d;d<d=d>| d?    d@| dA    dB| dC    dD| dE    dF| dG    dHdIt        j                  | dJ          dKdL|dMdNdO| dPdQdRd1g      S )SNr   r   rj   r#   rk    r,   zevent recordsrf   zevent recordrl   r   zevent pointsrm   r   rn   z activezdispatch refsro   zevent field linksr   r5   ztransition reviewsrq   r   rr   z	 rejectedzsave-selector refsrs   zbranch targetrx   r   ry   )zscene adjacencyr|   z adjacent rowszresource refsrt   z direct refszroute-exit point candidatesru   zgeometry exit word hitsr}   zstrict coordinate evidencer~   r   c           	   3     K   | ]M  \  }}}d t        j                  |       dt        j                  |       dt        j                  |       d O yw)z<tr><td>z	</td><td>z
</td></tr>Nhtmlescape)rL   signalleftrights       r   rN   zhtml_page.<locals>.<genexpr>  sa        FD%	{{6"# ${{4 ! "{{5!" #	s   AAr   c              3  N   K   | ]  }d t        j                  |       d  yw)z<li>z</li>Nr   r   s     r   rN   zhtml_page.<locals>.<genexpr>  s#     h$T[[./u5hs   #%r   z<!doctype html>z<html lang="en">z<head>z  <meta charset="utf-8">zF  <meta name="viewport" content="width=device-width, initial-scale=1">z1  <title>map1_01a Record Pattern Contrast</title>a    <style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;margin:24px}table{border-collapse:collapse;width:100%;max-width:1180px}td,th{border:1px solid #333;padding:6px 8px;text-align:left;vertical-align:top}th{background:#1f1f1f}code{color:#9bd4ff}</style>z</head>z<body>z+  <h1>map1_01a Record Pattern Contrast</h1>z  <p>route <code>rB   re   rC   z#</code>; confirmed reference <code>r   z'</code>; confirmed-like pattern found: r   z; promotion status <code>r   z</code>.</p>z  <p>r   z</p>zh  <table><thead><tr><th>signal</th><th>confirmed entry</th><th>current frontier</th></tr></thead><tbody>z  </tbody></table>z(  <h2>Missing Compared To Confirmed</h2>z  <ul>z</ul>z</body>z</html>)strr   r"   r   r   )r   rJ   r   rZ   
table_rowsr   s         r   	html_pager      s7   *+I()H	)G$hw&78	y!234Ai@P6Q5RSX`arXsWttuv~  @P  wQ  vR  VS  	T	#i(:;<c(K]B^>_`	#34c:	I&789KbAc@ddklnqr	#i(?@A3G	dii	2C(DELcR	),G"H!IW`a{W|V}  ~G   H  JM  	N	sC1G(H$IJ	#(,,/A"B"Ic!J"X\\ZpMqMxuxLyyz{|	CH-G$H#I!XY	#(+C"D!E\RS	&S:X1Y-Z[	"CX6P-Q)RS	%sC9X0Y,Z[D"   $( J ggh'JfBghhG99"P; 	\5
GH-.d783D2EEhip  rK  jL  iM  Mt  u|  }X  uY  tZ  Zs  t{  |M  tN  sO  O[  	\
GL12348r2
	
)  r   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       y )
NT)parentsexist_ok%map1_01a_record_pattern_contrast.jsonF   )ensure_asciiindentr   r   r   )mkdir
write_textr   dumps)r   out_dirs     r   write_outputsr   (  sD    MM$M.66BB

7q9D@ C r   c                 V   t        j                  t              } | j                  dt        t
               | j                         }t        t        |j                  dz  i       t        |j                  dz  g       t        |j                  dz  i       t        |j                  dz  i       t        |j                  dz  i       t        |j                  d	z  i       t        |j                  d
z  i             }t        ||j                         t        d|j                  dz          y )N)descriptionz	--out-dir)typedefaultzfield_map_record_roots.jsonzscene_events.jsonztransition_reviews.jsonzmap1_01a_resource_ref_scan.jsonz%save_selector_scene_list_context.jsonz(save_selector_scene_record_sequence.jsonz*map1_01a_exit_coordinate_variant_scan.jsonz*wrote map1_01a record pattern contrast -> r   )argparseArgumentParser__doc__add_argumentr   OUT
parse_argsr   r   r   r   print)parserargsr   s      r   mainr   0  s    $$9F
$<D$,,!>>C$,,!44b9$,,!::B?$,,!BBBG$,,!HH"M$,,!KKRP$,,!MMrRG '4<<(	6t||Fm7m6n
opr   __main__)r   r)   returnr   )r   r   )r#   dict | Noner   r   )r*   dictr   r   )r8   r   r,   
str | Noner-   r   r.   r   r/   r   r0   zbool | Noner   r   )rA   
list[dict]rB   r   rC   r   r   r   )rY   r   rB   r   rC   r   r   r   )ra   r   r   r   )r8   r   rA   r   rY   r   r   r   ra   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   None)r   r   )r   
__future__r   r   r   r   pathlibr   __file__resolver   ROOTr   r^   r_   r   r   r   r   r$   r+   r9   rF   r[   rb   r   r   r   r   r   __name__r   r   r   <module>r      s^   O "     H~''*
Ul		  8O+ "&##!$(  	
   " 0$XXX X 	X
 X  X "X 
Xv)X2j 25 q" zF r   