
    UHj;                       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d	Zdd
Z	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZddZddZedk(  r e        yy)zISummarize why map1_01a still has no strict hotspot for the current route.    )annotationsN)Path   outmap1_01amap2_02dc                ~    | j                  d      r| d   S | j                  d      }t        |t              rd|dS y)NrecordVaHexrecordVa0x08xnone)get
isinstanceint)row	record_vas     ;/home/exedev/hwanse/tools/summarize_map1_01a_hotspot_gap.py
record_hexr      sC    
ww}=!!
#I)S!Ic?##    c                   g }| xs i j                  d      xs g D ]  }|j                  d      xs g }|j                  d      xs g }t        |v xs t        d |D              }|sLt        d |D        d       }|j	                  |j                  d      |j                  d      |j                  d      |j                  d	d
      |j                  dd
      |t        |      |d ud        |D cg c]
  }|d	   s	| }}|D cg c]  }|d   s	|d	   r| }	}t        d |D        d       }
t        t        |      t        |      t        |	      |
|dS c c}w c c}w )NclustersmanifestMaps
routePairsc              3     K   | ]6  }|j                  d       t        k(  xs |j                  d      t        k(   8 yw)sourcetargetN)r   TARGET.0r   s     r   	<genexpr>z)target_context_summary.<locals>.<genexpr>   s<      9
 GGH'F3778+<+FF9
s   <>c              3     K   | ]G  }|j                  d       t        k(  r-|j                  d      t        k(  r|j                  d      r| I yw)r   r   isCurrentFrontierN)r   MAPr   r   s     r   r!   z)target_context_summary.<locals>.<genexpr>&   sH      778$+0AV0KPSPWPWXkPl s   AAclusterStartHexclusterEndHexclassificationeventRecordCountr   saveSelectorRefCount)r%   r&   r'   r(   r)   r   manifestMapCounthasCurrentFrontierPairc              3  ,   K   | ]  }|d    s	|  yw)r+   N r   s     r   r!   z)target_context_summary.<locals>.<genexpr>8   s     UCs;S7TCUs   
)r   contextCountstrictEventContextCountselectorOnlyContextCountcurrentFrontierContextcontexts)r   r   anynextappendlen)field_map_rootsr2   clustermanifest_mapsroute_pairscontains_targetcurrent_pairr   strict_contextsselector_only_contextscurrent_contexts              r   target_context_summaryr@      s   H#)r..z:@b N39rkk,/52 M1 
S 9
"9
 6
 * 
 	&{{+<=$[[9%kk*:; ',> B$+KK0F$J) #M 2&2$&>	
 		!4 '/Js#6H2IsJOJ-5uc=S9T]`as]tcuuU8UW[\OH#&#7$'(>$?"1  Kus   3
E>E
EEEc                   | D cg c]  }|j                  d      t        k(  s| }	}|D cg c]  }|j                  d      t        k(  s| }
}|D cg c]  }|j                  d      t        k(  s| }}|D cg c]  }|j                  d      t        k(  s| }}t        d |j                  d      xs g D        i       }|j                  d      xs g }|xs i }t        d |j                  d      xs g D              }|j                  dd      }t	        |      }|d	   r
|d
   dk(  rdnd}|xs i }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  d      xs i }dt        |	      ddj                  d |	D              xs ddd|dd| ddd|dd| d| d | d!|j                  d"d       dd#t        |      d$d%dd&t        |
      d'd(dd)t        |      d*d+dd,t        |      d-d.d/j                  |      xs d0 dd1|d	   |d2|d
    d3|d4    d5|d6   xs i j                  d7d       dg}d8}i dt        d9t        d:|	d;t        |      d<t        |
      d=t        |      d>|d?|d@|||||j                  dA      |j                  d"      dBdC|d|dDdEdFdGdH|dIg dJdK|S c c}w c c}w c c}w c c}w )LNmapc              3  R   K   | ]  }|j                  d       t        k(  s| ! yw)rB   N)r   r$   r   s     r   r!   z build_summary.<locals>.<genexpr>Q   s%     iCSVSZSZ[`SaehShCis   ''confirmedRouteBlockerssaveSelectorFrontierTargetsc              3  @   K   | ]  }|j                  d d        yw)promotableSourcePointCountr   N)r   )r    records     r   r!   z build_summary.<locals>.<genexpr>T   s$      ! 	

/3!s   recordsincomingPointTableCountr   r.   r/   z8target appears only in selector-only scene-list clustersztarget has strict event contextresourceReferenceCountpointCandidateCountrouteExitPointCandidateCount strictSourceTargetCandidateCountcurrentFrontierReferencescene_manifestzselector-only scene rowsz; c           
   3     K   | ]H  }|j                  d        dt        |       ddj                  |j                  d      xs g         J yw)
sceneIdHexz record=z
 tilesets=,tilesetsN)r   r   joinr   s     r   r!   z build_summary.<locals>.<genexpr>j   sU        77<()*S/1B*SXXVYV]V]^hViVomoMpLqr s   AAr   )r   countstatusdetailmap1_01a_manifest_point_scanz no promotable source point tablez#incoming strict-event point tables=zU; 0x00503364->0x0050336c belongs to map1_02b->map1_01a, not a map1_01a source hotspotmap1_01a_resource_ref_scanz)direct resource refs still non-promotablezresource refs=z; point-like payloads=z; route-exit point hits=z; current frontier ref=refVaHexevent_transitionszno strict event transitionz/no strict hotspot record extracted for map1_01ascene_coordinate_candidateszno broad coordinate candidatez<broad coordinate scan has no map1_01a row to manually reviewtransition_extraction_gapszno extraction-gap rowzIthe gap report has no map1_01a coordinate candidate waiting for promotionplayable_progresszsave-selector frontier onlyz"confirmed route blocker points to , zno save selector targetfield_map_record_rootszstrict event contexts=z; selector-only contexts=r0   z; current cluster=r1   r%   a8  map1_01a still has no strict source hotspot for map2_02d. The current evidence is selector-only: playable progress sees a save-selector frontier, but neither strict event extraction nor broad coordinate candidate extraction produces a map1_01a coordinate row, and the manifest point scan only confirms an incoming map1_02b->map1_01a point table. The target map2_02d appears in selector-only scene-list clusters with no strict event-linked target context, and the current cluster also lists many neighboring map2_* records. The save-selector branch context therefore points at resource/scene-list loading rather than a map-transition target. The next productive step is to find a strict event/hotspot source or a non-coordinate runtime source for the branch gate, not to promote a transition from existing selector adjacency.r   sceneManifestRowseventTransitionCountcoordinateCandidateCountextractionGapCount"manifestPointPromotableSourceCountmanifestPointIncomingCountresourceRefScancurrentFrontierReferenceFound)rK   rL   rM   rN   ri   currentFrontierReferenceHextargetContextstrictHotspotFoundFpromotionStatusblockedevidencenextActions)zPlook outside the scanned manifest point tables for a strict event/hotspot sourcez9find a non-coordinate source for the map1_01a branch gatezXkeep map1_01a->map2_02d out of normal confirmed transitions until a strict source exists
conclusion)r   r$   r4   sumr@   r6   rU   r   )rP   scene_coordinatesextraction_gapsr\   playablemanifest_point_scanr7   resource_ref_scanr   manifest_rowscoordinate_rowsgap_rowstransition_rowsblockersave_selector_targetsmanifest_point_sourcesmanifest_point_incomingtarget_contexttarget_context_statusresource_ref_countresource_point_countresource_exit_point_countresource_strict_countresource_current_refro   rq   s                             r   build_summaryr   C   sd    %3LScggen6KSLML&7Qs3775>S;PsQOQ.H#''%.C2GHHH&7Qs3775>S;PsQOQi8<<0H#I#ORikmnG#KK(EFL"-3  !)--i8>B!  2556OQRS+O<N .)n=V.W[\.\ 	C. 
 */R*../GK,001FJ 1 5 56TVW X-112TVWX,001KLRPR ''0ii  (    		
 5+856M5N Of f	
 3*A !3 44JK_J` a))B(C D((<(@(@V(T'UW		
 *)2G		
 4)5T		
 3]-a		
 *./3:499EZ;[;x_x:yz		
 /#N3+(8Q)R(S T**89S*T)U V#$23K$L$RPR#W#WXikq#r"su		
m@HD	{ s& 	] 	O 4	
 	#C$8 	c(m 	-.D 	%&= 	&8#7,E0E->-B-BCb-c+?+C+CJ+O
" 	#$ 	&'<%& 	e'( 	9)* 	H+, 	 
-6 	j7 G MQHQs-   K.K.K3K3K83K8=K=K=c                   ddd| d    dd| d    d| d	    d
dj                  | d         xs d d| d   d    d| d   d    d| d   dddddg}| d   D ],  }|j                  d|d    d|d    d|d    d|d    d	       . |j                  g d       | d   d    D ]M  }|j                  d!|d"    d#|d$    d%|d&    d|d'    d|d(    ddj                  |d)          d|d*    d       O |j                  g d+       |j                  d, | d-   D               |j                  d       d.j                  |      S )/Nz# map1_01a Hotspot Gap z- target: `r   `z- strict hotspot found: rl   z- promotion status: rm   z"- save-selector frontier targets: r`   rE   r   z - target strict event contexts: rk   r/   z!- target selector-only contexts: r0   rq   z## Evidencez$| source | count | status | detail |z| --- | ---: | --- | --- |ro   z| r   z | rV   rW   rX   z |)r   z## Target Contextsr   zF| cluster | class | events | selector refs | maps | current frontier |z'| --- | --- | ---: | ---: | --- | --- |r2   z| `r%   z`..`r&   z` | r'   r(   r)   r   r+   )r   z## Next Actionsr   c              3  &   K   | ]	  }d |   yw)z- Nr-   r    items     r   r!   zmarkdown.<locals>.<genexpr>   s     @2dV@s   rp   
)rU   r5   extend)summarylinesr   s      r   markdownr      s    

gh'(*
"7+?#@"AB
w'89:;
,TYYw?\7]-^-hbh,ij
*7?+CD]+^*_`
+GO,DE_,`+ab


.$E" z" br#h-CL>S]O3sS[}o]_`ab	LL   '
3 
#'()c/.B-C4L\H]G^^a%&'s3/E+F*Gsyy^,-.c#6N2O1PPRT	

 
LL,-	LL@)?@@	LL99Ur   c                p   dj                  d | d   D              }dj                  d | d   D              }dj                  d | d   d	   D              }dj                  d
ddd| d    d| d    dt        j                  | d          ddt        j                  | d          dd|ddd|ddd| dg      S )Nr   c              3     K   | ]X  }d t        j                  |d          d|d    dt        j                  |d          dt        j                  |d          d	 Z yw)z<tr><td>r   	</td><td>rV   rW   rX   
</td></tr>Nhtmlescaper   s     r   r!   zhtml_page.<locals>.<genexpr>   su       	{{3x=)* +7|n {{3x=)* +{{3x=)* +		s   AA ro   r   c              3  N   K   | ]  }d t        j                  |       d  yw)z<li>z</li>Nr   r   s     r   r!   zhtml_page.<locals>.<genexpr>   s#     Y$T[[./u5Ys   #%rp   c              3  D  K   | ]  }d t        j                  |d   xs d       dt        j                  |d   xs d       dt        j                  |d   xs d       d|d    d|d	    dt        j                  d
j                  |d                d|d    d  yw)z<tr><td><code>r%   -z</code>..<code>r&   z</code></td><td>r'   r   r(   r)   r`   r   r+   r   N)r   r   rU   r   s     r   r!   zhtml_page.<locals>.<genexpr>  s      
 	[[%6!7!>3?@PTP[P[\_`o\p\wtwPxOy z{{3/07C89 :%&' ()*+ ,{{499S%89:; <+,- .	
s   BB rk   r2   zH<!doctype html><meta charset="utf-8"><title>map1_01a Hotspot Gap</title>z<style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;max-width:1100px;margin:24px auto}table{border-collapse:collapse}td,th{border:1px solid #444;padding:6px 8px;vertical-align:top}code{color:#9bd4ff}</style>z<h1>map1_01a Hotspot Gap</h1>z<p>target <code>r   z</code>; strict hotspot found: rl   z; promotion status: rm   z</p>z<p>rq   za<table><thead><tr><th>source</th><th>count</th><th>status</th><th>detail</th></tr></thead><tbody>z</tbody></table>z<h2>Target Contexts</h2>z<table><thead><tr><th>cluster</th><th>class</th><th>events</th><th>selector refs</th><th>maps</th><th>current frontier</th></tr></thead><tbody>z<h2>Next Actions</h2>z<ul>z</ul>)rU   r   r   )r   rowsactionstarget_rowss       r   	html_pager      s/   99  :& D ggY'-BXYYG)) 
 ?+J7
 
K 99T 	n'
78,--LWUiMjLkk  AE  AL  AL  MT  Uf  Mg  Ah  @i  im  	n
dkk',/016k" 	Z
wiu  r   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |d
z  j                  t	        |       d	       y )NT)parentsexist_okzmap1_01a_hotspot_gap.jsonF   )ensure_asciiindentr   utf-8encodingmap1_01a_hotspot_gap.html)mkdir
write_textjsondumpsr   )r   out_dirs     r   write_outputsr     sd    MM$M.**66

7q9D@ 7  **66y7IT[6\r   c                 v   t        j                         } | j                  dt        t        dz         | j                  dt        t        dz         | j                  dt        t        dz         | j                  dt        t        d	z         | j                  d
t        t        dz         | j                  dt        t        dz         | j                  dt        t        dz         | j                  dt        t        dz         | j                  dt        t               | j                         }|j                  j                         r/t        j                  |j                  j                  d            nd }t        t        j                  |j                  j                  d            t        j                  |j                  j                  d            t        j                  |j                  j                  d            t        j                  |j                  j                  d            t        j                  |j                   j                  d            ||j"                  j                         r/t        j                  |j"                  j                  d            nd |j$                  j                         r/t        j                  |j$                  j                  d            nd       }t'        ||j(                         t+        d|j(                  dz          y )Nz--scene-manifestzscene_manifest.json)typedefaultz--scene-coordinatesz scene_coordinate_candidates.jsonz--extraction-gapsztransition_extraction_gaps.jsonz--event-transitionszevent_transitions.jsonz
--playablezplayable_progress.jsonz--manifest-point-scanz!map1_01a_manifest_point_scan.jsonz--field-map-rootszfield_map_record_roots.jsonz--resource-ref-scanzmap1_01a_resource_ref_scan.jsonz	--out-dirr   r   zwrote map1_01a hotspot gap -> r   )argparseArgumentParseradd_argumentr   OUT
parse_argsrv   existsr   loads	read_textr   rP   rs   rt   r\   ru   r7   rw   r   r   print)parserargsrv   r   s       r   mainr   '  s   $$&F
*sEZ?Z[
-D#HjBjk
+$Fg@gh
-D#H`B`a
4?W9WX
/dCJmDmn
+$Fc@cd
-D#HiBij
$<D ##**, 	

4++55w5GH 
 

4&&00'0BC

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

4''1171CD

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

4==**G*<=HLH\H\HcHcHe

4''1171CDkoJNJ`J`JgJgJi

4))33W3EFos	G '4<<(	*4<<:U+U*V
WXr   __main__)r   dictreturnstr)r7   dict | Noner   r   )NNN)rP   
list[dict]rs   r   rt   r   r\   r   ru   r   rv   r   r7   r   rw   r   r   r   )r   r   r   r   )r   r   r   r   r   None)r   r   )__doc__
__future__r   r   r   r   pathlibr   __file__resolver   ROOTr   r$   r   r   r@   r   r   r   r   r   __name__r-   r   r   <module>r      s    O "     H~''*
Ul	&^ (,#'%)II!I  I "	I
 I %I !I #I 
IX$N%P]Y> zF r   