
    'Ij#                       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Z	 d	 	 	 	 	 	 	 	 	 dd	Zdd
ZdddZdddZedfddZddZedk(  r e        yy)zMSummarize broad coordinate candidates that are not strict transition records.    )annotationsN)Path)	urlencode   outc                    i }| xs g D ]M  }|j                  d      }|j                  d      }t        |t              s6t        |t              sG||||f<   O |S )NmaprecordVa)get
isinstancestrint)scene_manifestindexrecordmap_name	record_vas        A/home/exedev/hwanse/tools/summarize_transition_extraction_gaps.pymanifest_indexr      s`    E &B 2::e$JJz*	h$Is)C+1E8Y'(	2
 L    c                f   |D ch c]$  }|j                  d      |j                  d      f& }}t        |      }g }| D ]  }|j                  d      |j                  d      f}	|	|v r+|j                  d      xs g }
|
D cg c]  }|j                  dd      dk\  r| }}|sg|j                  |	      }|ri n|j                  |d   i       }|rdnd}|rd	nd
}d }|D ],  }|j                  d      xs g }|s|d   d   |d   d   d} n |j                  d      xs |r|j                  dg       ng }|j                  |d   |j                  d      |j                  d      t        |j                  d      t              r	d|d   dndt        |      t        d |D              |j                  d      xs g ||| ||d d D cg c]9  }|j                  d      |j                  d      |j                  dg       d d d; c}|d        t        |d       S c c}w c c}w c c}w )Nr	   r
   
candidates
pointCountr      zscene manifest payloadzcoordinate candidatez=scene manifest resource payload without strict event dispatchz0coordinate candidate without strict event targetpointsxy)r   r   tilesets
sceneIdHex0x08x c              3  @   K   | ]  }|j                  d d        yw)r   r   N)r   .0	candidates     r   	<genexpr>zbuild_rows.<locals>.<genexpr>G   s      XI|Q!? Xs   	fieldMaps   
fieldIndex   )r*   r   r   )r	   r   r
   recordVaHexcandidateCountmaxPointCountr(   r   
recordTypestrictTransitionCandidate
firstPointfirstCandidatesreasonc                H    t        | d         dk(  | d    | d   | d   xs dfS )Nr(   r   r.   r	   r
   )len)rows    r   <lambda>zbuild_rows.<locals>.<lambda>Y   s9    K !Q&!!J
O q	
 r   )key)r   r   appendr   r   r5   maxsorted)coordinate_candidatesevent_transitionsscene_linksr   r6   strict_recordsmanifest_recordsrowsr   r8   r   r&   usablemanifest	link_inforecord_typer3   first_pointr   r   s                       r   
build_rowsrG      s    % 
,-N  &n5D' 0zz% &**Z"89. ZZ-3
 (
}}\1-2 
 

 #'',"Bur(J	2:.@V  LC 	
  	I]]8,2F$*1IcN3H		
 ==,bQYj"1M_a%= **\2

:.<FvzzR\G]_b<cRz 2378ik!&k  XQW XX"{39r %-5% "(  	 #,--"="+--"='mmHb9"1=  )
 	70b 
 o
D s   )H$H)>H. c                :    | rdj                  d | D              S dS )N, c              3  6   K   | ]  }|d     d|d      yw)r   ,r   N )r%   points     r   r'   zpoint_text.<locals>.<genexpr>c   s#     Fec
|1U3ZL1Fs   -)join)r   s    r   
point_textrP   b   s    JP499FvFFYVYYr   c                   dddddt        |        ddddg}| D ]!  }|d   d	d	d
}|j                  d      r%|d   }|d    d|d    |d<   |d    d|d    |d<   | dt        |       }dj                  d |d   D              }|j	                  d|d    d|j                  d      xs d d|d    d|d    ddj                  |d         xs d ddj                  |d         xs d d|j                  d      xs d d|j                  d       xs d d!| d|j                  d"      xs d d#| d$       $ | s|j	                  d%       |j	                  d       d&j                  |      S )'Nz# Transition Extraction Gapsr"   zMBroad coordinate candidates that are not strict event transition records yet.zRows: .zp| map | type | candidates | max points | field maps | tilesets | scene | record | sample | reason | debug open |zE| --- | --- | ---: | ---: | --- | --- | --- | --- | --- | --- | --- |r	   1r	   eventsoverviewr1   r   rK   r   	startTile	focusTile/game.html?; c           
   3  V   K   | ]!  }d |d    d|d    dt        |d           # ywir*   z n=r    r   NrP   r$   s     r   r'   zmarkdown.<locals>.<genexpr>x   D      
 	,'(Il,C+DAjQZ[cQdFeEfg
   ')r2   z| z | r/   rN   r-   r.   rI   r(   r   r   z | `r,   z` | r3   z | [debug](z) |z-| - | - | - | - | - | - | - | - | - | - | - |
)r5   r   r   rO   r9   )rA   
web_prefixlinesr6   paramsrM   hrefsampless           r   markdownrh   f   s   &
W

T1
zO	E  
UsD77< %E%*3ZL%*">F;%*3ZL%*">F;[6):(;<)) 
 !23
 
 	UC 5 <=S#$%S_)=(>cyy[)*1c2#diiJ6P6WTW5XX[ww|$+,D1G1N30OtT[S\\_wwx 'C(D6	>	

$ DE	LL99Ur   c                ,   g }| D ]  }|d   ddd}|j                  d      r%|d   }|d    d|d    |d<   |d    d|d    |d	<   | d
t        |       }dj                  d |d   D              }|j                  dt	        j
                  |d          dt	        j
                  |j                  d      xs d       d|d    d|d    dt	        j
                  dj                  |d         xs d       dt	        j
                  dj                  |d         xs d       dt	        j
                  |j                  d      xs d       dt	        j
                  |j                  d      xs d       dt	        j
                  |       dt	        j
                  |j                  d      xs d       dt	        j
                  |       d        dj                  dd d!d"d#d$d%t        |        d&d'|rdj                  |      d)g
      S d(d)g
      S )*Nr	   rS   rT   r1   r   rK   r   rW   rX   rY   rZ   c           
   3  V   K   | ]!  }d |d    d|d    dt        |d           # ywr\   r_   r$   s     r   r'   zhtml_page.<locals>.<genexpr>   r`   ra   r2   z<tr><td>z	</td><td>r/   rN   r-   r.   rI   r(   r   r   z</td><td><code>r,   z</code></td><td>r3   z</td><td><a href="z">debug</a></td></tr>rb   z<!doctype html>z<meta charset="utf-8">z)<title>Transition Extraction Gaps</title>z<style>body{font-family:system-ui,sans-serif;background:#111;color:#ddd;margin:24px}a{color:#8fd3ff}table{border-collapse:collapse;width:100%}td,th{border:1px solid #333;padding:6px 8px;text-align:left;vertical-align:top}th{background:#1f1f1f}</style>z#<h1>Transition Extraction Gaps</h1>z<p>Broad coordinate candidates that are not strict event transition records yet. Scene manifest payload rows are kept as blockers, not auto-confirmable transitions.</p>z	<p>Rows: z.</p>z<table><thead><tr><th>map</th><th>type</th><th>candidates</th><th>max points</th><th>field maps</th><th>tilesets</th><th>scene</th><th>record</th><th>sample</th><th>reason</th><th>debug open</th></tr></thead><tbody>z2<tr><td colspan="11">No extraction gaps.</td></tr>z</tbody></table>)r   r   rO   r9   htmlescaper5   )rA   rc   bodyr6   re   rM   rf   rg   s           r   	html_pagern      sl   D 
UsD77< %E%*3ZL%*">F;%*3ZL%*">F;[6):(;<)) 
 !23
 
 	;;s5z*+ ,;;sww|4;<= >'() *'( );;tyy[)9:AcBC D;;tyyZ9@SAB C;;sww|4;<= >SWW]%;%BsCD E;;w'( );;swwx07C89 : KK-. /	

4 99 3 	F- 	s
CI;e$ 	b		$   &Z  r   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |:|j                  j                  dd       |j                  t        |       d	       y y )
NT)parentsexist_oktransition_extraction_gaps.jsonF)rK   :)ensure_ascii
separatorsrb   utf-8encoding)mkdir
write_textjsondumpsparentrn   )rA   out_dirhtml_outs      r   write_outputsr      s~    MM$M.00<<

4e
CdJ =  dT:IdOg> r   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        d	z         | j                  d
t        t               | j                  dt        d d       | j                         }t        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       }t        ||j                   |j"                         t%        dt'        |       d|j                   dz          y )Nz--coordinatesz scene_coordinate_candidates.json)typedefaultz--transitionszevent_transitions.jsonz--scene-linkszscene_links.jsonz--scene-manifestzscene_manifest.jsonz	--out-dirz
--html-outz!Optional HTML report output path.)r   r   helprv   rw   zwrote z transition extraction gaps -> rr   )argparseArgumentParseradd_argumentr   OUT
parse_argsrG   r{   loadscoordinates	read_texttransitionsr>   r   existsr   r~   r   printr5   )parserargsrA   s      r   mainr      s   $$&F
dCBd<de
dCBZ<Z[
dCBT<TU
*sEZ?Z[
$<
4DghD

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

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

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

4&&00'0BCim	D $dmm4	F3t9+<T\\Lm=m<n
opr   __main__)r   list[dict] | Nonereturnzdict[tuple[str, int], dict])N)
r<   
list[dict]r=   r   r>   dictr   r   r   r   )r   r   r   r   )z../web)rA   r   rc   r   r   r   )rA   r   r~   r   r   zPath | Noner   None)r   r   )__doc__
__future__r   r   rk   r{   pathlibr   urllib.parser   __file__resolverp   ROOTr   r   rG   rP   rh   rn   r   r   __name__rL   r   r   <module>r      s    S "     " H~''*
Ul )-	E%E!E E &	E
 EPZ F'T 58QU ?q( zF r   