
    j2(                        d Z ddlmZ dZdZdZdZdZdZdZ	dZ
dZd	Zd
ZdZdZdZdZddZdddZdedf	 	 	 	 	 ddZdddZy)u  Presentation layer for the viewership report.

Formats only. Kept apart from vr_report so the numbers and the way they are
dressed can be changed independently.

House rules, applied to every sheet:

  * a branded band at the top carrying the EVENT name, so a sheet still
    identifies itself once it has been copied out of the book — which is what
    always happens to a good sheet.
  * one header row, frozen, with the filter already on.
  * banded rows, thin rules, right-aligned figures on a monospaced face so
    decimal points line up down a column.
  * print set up before anyone asks: landscape, fit to width, header row
    repeated on every page, page numbers in the footer.
    )annotationsz#1F2937z#177F78z#C0392Bz#B4690Ez#CCCCCCz#D9D9D9z#E7F3F1z#5B6472z#FFFFFFzAptos DisplayCalibriConsolasc           
     `  	 i }| j                   	 	t        t        t        ddddd      |d<    	t        t
        t        dddd	      |d
<    	t        t        t        dddd      |d<    	t        t        t        ddddd      |d<    	dt        i      |d<   t        ddt        t        dddt        d	} 	i |ddd      |d<    	i |ddi      |d<    	i |ddi      |d<   i |ddi} 	i |ddd      |d<    	i |ddi      |d<    	i |ddi      |d<   dh	fd!	}di	fd"	}d#D ]  }|rd$nd%} |d&di|      |d'| <    |ddd(|      |d)| <    |t        dt        dd*|      |d+| <    |t        dt        ddd,|      |d-| <    |d.d |      |d/| <    |d.dt
        d0|      |d1| <    |d2d |      |d3| <    |d2dt
        d0|      |d4| <    |d2d |      |d5| <    |d6d |      |d7| <    |d8d |      |d9| <    |d:ddi|      |d;| <    |d<ddi|      |d=| <    |d<d |      |d>| <    t        d?dd@dt        ddA} 	i |dBd.i      |dC<    	i |dBd2i      |dD<    	i |dBd<i      |dE<    	i |dBd2i      |dF<    	t        d?dd@dt        ddG      |dH<    	t        dIdt
        dJ      |dK<    	t        d?t        dL      |dM<    	t        dNt        t        ddt        dO      |dP<    	t        dQdt        t        dd.dR      |dS<    	t        dQdt        t        dd2dR      |dT<    	t        dNt        t        ddt        dU      |dV<    	t        ddt
        dt        dW      |dX<    	t        d?t
        ddYdZ      |d[<    	t        d?t        ddYdZ      |d\<    	t        d?t        dddYd]      |d^<    	t        dt        dddYd_      |d`<    	t        dt        dadddbdc      |dd<    	t        dt        dedddfdc      |dg<   |S )jz&Every format the book uses, made once.   Tvcenter   )bg_color
font_color	font_name	font_sizeboldvalignindentband	      )r
   r   r   r   r   r   band_subright)r
   r   r   r   r   alignband_r   band_bigr
   rule      #@)	r   r   r   r   r
   r   	text_wrapborderborder_colorleft)r   r   hdrr   hdrncenterhdrcr      hdr_bighdrn_bighdrc_bigNc                Z    t         ddt        dd}|r	t        |d<    i || xs i       S )N
   r	   r   )r   r   r   r   r   r
   )UI2RULE2BAND)extrabandedbasems      1/var/www/html/crystal/crystal2/engine/vr_style.pycellzbuild.<locals>.cellK   s>     rQPU#%#D*D*U[b*++    c                ^    t         d| dt        ddd}|r	t        |d<    i ||xs i       S )Nr   r	   r   r   )r   r   
num_formatr   r   r   r   r
   )MONOr+   r,   )fmtr-   r.   r/   r0   s       r1   numzbuild.<locals>.numR   sC    !3RS %WN#D*D*U[b*++r3   )r   r	   _b r   t)r   r   tb)r   r   r   r   tm)r   r   r   r   r   twz#,##0.0#n)r   r   nbz#,##0nwnwbniz0.#npz0.0%npctzyyyy-mm-dd hh:mmndz	[h]:mm:ssndurnhmsr)   z#D5E9E6)r   r   r   r
   topr   r   r5   tottotwtothmstoti)r   r   r   r
   rI   r   r   totl   )r   r   r   r   cov_ev)r   r   r   cov_sub   )r   r   r   r
   r   rI   r   kpi_l   )r   r   r   r   r
   r   r5   kpi_vkpi_vw)r   r   r   r
   r   bottomr   kpi_n)r   r   r   r   rW   r   h2rI   )r   r   r   r   r   bodybodym)r   r   r   r   r   r   bodyw)r   r   r   italicr   r   notez#E6F4F1z#CBE7E1)r   r   r   r
   r   r   r   pill_okz#FBE9E7z#F0C8C2pill_no)NF)z#,##0.##NF)
add_formatBRANDWHITEr*   r,   INKr6   MUTEDINDIGOBRAND2CRIMSONRULETEAL)
wbFr    bigr2   r8   bkrJ   r0   s
            @r1   buildrp   )   s   
A
A uE "DI  !AfI 4s$%aI JAjMU"#y7L MAhK
 5C$&	!"$ %AjM :v&'AfI #t50C 6C6&A67AeH+S+'7+,AfI,S,'8,-AfI
"S
"+r
"C::f:;AiL//gw/0AjM00gx01AjM,,  2D28Q-+AaS'
DA6:Bqc(AU&')*+-Bqc(AW$(A789;Bqc(T1-AaS'
*t3&GKBqc('4+Bqc(7T$EqICs)'4+Bqc(%q)Bqc( FD!,D*,w.A1EBqc( K'8)<a@D*Kq1D*/24 2tVg?C2C2z23AeH0S0,01AfI6s6L+67AhK0S0,01AfI"dPYVqB CAfI #BTWXYAhK4bNOAiLAU $xSY[ \AgJ2tSY $xzS TAgJ#BTZ!%Q RAhKAU $x1$(* +AgJ cDPSf6 7AdG"C $7 8AfI2U!%8 9AgJ2W tuF GAgJ#U!G HAfI4at"+h!&/1 2AiL 4aw"+h!&/1 2AiL Hr3   r:   c                    	 t        |       j                         }|dk(  r|rd|z   S d|z   S |dk(  r|rd|z   S d|z   S |dk(  r|rdS dS |dk(  r|rd	S dS ||z   S # t        t        f$ r d}Y Pw xY w)
u6  Which format a number should wear.

    Excel prints "125." for the format #,##0.## — the decimal separator
    survives even when no digits follow it. Rather than fight that with one
    format, pick from the value: a whole number gets a whole-number format and
    a fraction keeps up to two decimals.
    Fr?   rA   r@   rB   rJ   rK   rU   rV   )float
is_integer	TypeError
ValueError)vr/   r.   wholes       r1   numkeyrx      s    a##% s{&003&00t|F22DF22u}v)E)w x-g-&= z" s   A A,+A,Fc           	        t        |d      }| j                  d|rdnd       | j                  d|rdnd       | j                  ddd|dz
  d| ||rd	nd
          | d}|dk\  rC| j                  ddd|dz
  |rd| nd|d          | j                  d|dz
  d|dz
  ||d          n| j                  ddd|dz
  d| |d          | j                  dd       | j                  |       y)a  Brand band across the top of a sheet. Returns the first free row.

    The event name goes on EVERY sheet on purpose: sheets get copied out of
    books, and one that cannot say which tournament it belongs to is a
    liability the moment it lands in someone else's deck.
       r   (      r	   rT      z  r   r         z   r:   r   r   r   )maxset_rowmerge_rangeset_tab_color)	wsrl   widtheventsheet_titler^   tabrm   r   s	            r1   headerr      s     qMEJJq"$JJq"$NN1aEAIE7|3ZF35m2Ez
q!Q	4S<R:W
q%!)Q	5!H+F
q!Q	S+>*NJJq!Sr3   c                    |r| j                          | j                  d       | j                  dd       | j                  dddd       | j	                  d|       | j                  d       | j                  d       y )Nr   r	   r   g333333?g?z6&L&"Calibri,Bold"&10&K177F78GSIQ Crystal&R&9&K5B6472&DuF   &L&9&K5B6472Estimates — not audited actuals&R&9&K5B6472Page &P of &N)set_landscape	set_paperfit_to_pagesset_marginsrepeat_rows
set_header
set_footer)r   r   	title_row	landscapes       r1   print_setupr      sd    
LLOOOAqNN3T4(NN1i MMJKMMZ[r3   N)returndict)r:   )r/   strr.   r   r   r   )r   intr   r   r   r   r^   r   r   r   rm   boolr   r   )T)r   r   r   r   r   r   r   None)__doc__
__future__r   rd   rb   rg   rf   rj   rh   AMBERri   r+   r,   re   rc   UIr*   r6   rp   rx   r   r    r3   r1   <module>r      s     # 		
pf. IK%#'470\r3   