
\c           @` sz  d  d l  m Z m Z m Z d  d l m Z d  d l m Z d  d l m Z d  d l Z d  d l	 m
 Z
 m Z d  d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z d  d	 l m Z d  d l  Z  d  d
 l! m" Z" d  d l# Z# d d l$ m% Z% m& Z& d d l' m( Z( d d l) m* Z* d d l$ m+ Z+ m, Z, e  j- j. d  rd d l/ m0 Z0 n d Z0 e  j- j. d  Z2 e, e2 d d Z2 d e3 f d     YZ4 d e4 f d     YZ5 d d  Z6 d e4 f d     YZ7 d e4 f d     YZ8 d  e4 f d!     YZ9 d" e4 f d#     YZ: d$ e4 f d%     YZ; d&   Z< d'   Z= d(   Z> d S()   i    (   t   print_functiont   divisiont   absolute_import(   t   bisect(   t   add(   t   timeN(   t   rowt   column(   t   ColumnDataSourcet   Plott   DataRange1dt
   LinearAxist	   HoverToolt   BoxZoomToolt	   ResetToolt   PanToolt   WheelZoomToolt   Range1dt   Quadt   TapToolt   OpenURLt   Buttont   Select(   t	   Spectral9(   t   figure(   t   geni   (   t   without_property_validationt   BOKEH_VERSIONi   (   t
   nbytes_bar(   t   profile(   t
   log_errorst   parse_timedeltas!   distributed.dashboard.export-tool(   t
   ExportTools#   distributed.worker.profile.intervalt   defaultt   mst   DashboardComponentc           B` s    e  Z d  Z d   Z d   Z RS(   sU   Base class for Dask.distributed UI dashboard components.

    This class must have two attributes, ``root`` and ``source``, and one
    method ``update``:

    *  source: a Bokeh ColumnDataSource
    *  root: a Bokeh Model
    *  update: a method that consumes the messages dictionary found in
               distributed.bokeh.messages
    c         C` s   d  |  _ d  |  _ d  S(   N(   t   Nonet   sourcet   root(   t   self(    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyt   __init__;   s    	c         C` s   d S(   s?    Reads from bokeh.distributed.messages and updates self.source N(    (   R'   t   messages(    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyt   update?   t    (   t   __name__t
   __module__t   __doc__R(   R*   (    (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR#   /   s   
	t
   TaskStreamc           B` s,   e  Z d  Z d d d  Z e d    Z RS(   sb    Task Stream

    The start and stop time of tasks as they occur on each core of the cluster.
    i  t   20sc         K` sX   | |  _  t | d d } | |  _ d |  _ t | |  \ |  _ |  _ d g |  _ d S(   sO   
        kwargs are applied to the bokeh.models.plots.Plot constructor
        R!   R"   i    N(   t   n_rectanglesR   t   clear_intervalt   lastt   task_stream_figureR%   R&   t   task_stream_index(   R'   R1   R2   t   kwargs(    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR(   I   s    			c      
   ` s*  t    | d d  | d d }  sD  d |  j d k rH d  St  |  j d       f d   | j   D }  d |  j d <| d r
t t t | d | d   } | |  j k r
| |  j |  _ } | | |  j k r|  j	 j
 j |  d  Sq
n  |  j	 j | |  j  Wd  QXd  S(	   Ns   task-eventst   indext
   rectanglesii    c         ` sE   i  |  ]; \ } } g  t    t    D] } | | ^ q( |  q S(    (   t   ranget   len(   t   .0t   kt   vt   i(   t   indR7   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pys
   <dictcomp>b   s   	 t   startt   duration(   R   R5   R   t   itemst   mint   mapR   R3   R2   R%   t   dataR*   t   streamR1   (   R'   R)   R8   t   mR3   (    (   R?   R7   s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR*   W   s     

 
(   R,   R-   R.   R(   R   R*   (    (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR/   C   s   R0   c   
      K` s  t  |  d d }  t d t d t   |  g d d g d d g d d g d	 d
 g d d g d d g d d g d d g d d g  
 } t d d  } t d d  } t d d d d d d d | d | d d d d  d! d" d# d$ |  	} | j d% | d& d d d d' d d( d) d* d	 d+ d	 d, d- d. d d/ d0  
} d9 | _ d | j	 _
 d | j	 _ d | j	 _ t | j _ t d1 d2 d3 d4  } t d5 t d6 d7   } | j | | t   t   t d8 d'  t d8 d'   t rt   }	 |	 j |  | j |	  n  | | f S(:   sG   
    kwargs are applied to the bokeh.models.plots.Plot constructor
    R!   R"   RE   R@   RA   g?t   keyt   namet   colort   whitet   duration_texts   100 mst   workert   foot   yi    t   worker_threadi   t   alphag        t   range_paddingt   task_streamt   titles   Task Streamt   ids   bk-task-stream-plott   x_ranget   y_ranget   toolbar_locationt   abovet   x_axis_typet   datetimet   min_border_righti#   t   toolsR+   R%   t   xt   widtht   heightg?t
   fill_colort
   line_colort
   line_alphag333333?t
   fill_alphat
   line_widthi   t   point_policyt   follow_mouset   tooltipss   
            <div>
                <span style="font-size: 12px; font-weight: bold;">@name:</span>&nbsp;
                <span style="font-size: 10px; font-family: Monaco, monospace;">@duration_text</span>
            </div>
            t   callbackt   urls   /profile?key=@namet
   dimensionsN(   R   R   t   dictR   R
   R   t   rectR$   t   nonselection_glypht   yaxist   major_label_text_alphat   minor_tick_line_alphat   major_tick_line_alphat   Falset   xgridt   visibleR   R   R   t	   add_toolsR   R   R   R   R    t   register_plot(
   R2   R6   R%   RV   RW   R&   Rm   t   hovert   tapt   export(    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR4   r   st    														t   MemoryUsagec           B` s&   e  Z d  Z d   Z e d    Z RS(   s;    The memory usage across the cluster, grouped by task type c         K` s
  t  d t d g  d g  d g  d g  d g  d g  d g  d	 g    |  _ t d
 d d t   d t   d d  d d  |  |  _ |  j j |  j t d d d d d d d d d d d d   |  j j	 t
   d  |  j j	 t
   d  t d d d d  } |  j j |  d  S(   NRE   RI   t   leftt   rightt   centerRJ   t   percentt   MBt   textRU   s   bk-nbytes-plotRV   RW   RX   t   outline_line_colort   topi   t   bottomi    Ra   Rd   t   belowRf   Rg   Rh   s  
                <div>
                    <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
                </div>
                <div>
                    <span style="font-size: 14px; font-weight: bold;">Percent:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@percent</span>
                </div>
                <div>
                    <span style="font-size: 14px; font-weight: bold;">MB:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@MB</span>
                </div>
                (   R   Rl   R%   R	   R
   R$   R&   t	   add_glyphR   t
   add_layoutR   R   Rv   (   R'   R6   Rx   (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR(      s@    			
	c         C` sr   t    c | d } | s d  St | d  } |  j j j |  d t | d j    d |  j j _	 Wd  QXd  S(   Nt   progresst   nbytess   Memory Use: %0.2f MBg    .A(
   R   R   R%   RE   R*   t   sumt   valuesR&   RT   R   (   R'   R)   t   msgt   nb(    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR*     s    

(   R,   R-   R.   R(   R   R*   (    (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR{      s   	9t
   Processingc           B` s5   e  Z d  Z d   Z e d    Z e d    Z RS(   s    Processing and distribution per core

    This shows how many tasks are actively running on each worker and how many
    tasks are enqueued for each worker and how many are in the common pool
    c         K` s   |  j  i i  d 6i  d 6 } t |  |  _ t d d  } t d d d d d	 | d
 d |  } | j d |  j d d d d d t d d d d d  d | j _ t	 | j
 _ t	 | j _ t   } | j |  | j t  } d | _ d | _ | |  _ d  S(   Nt
   processingt   ncoresii   RT   s   Processing and PendingR]   R+   RV   RU   s   bk-processing-stacks-plotR%   R|   i    R}   RJ   R   R   s  
        <div>
            <span style="font-size: 14px; font-weight: bold;">Host:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Processing:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@processing</span>
        </div>
        Rg   (   t   processing_updateR   R%   R   R   t   quadR   t   xaxisRq   Rs   Ro   Ru   t   ygridR   Rv   t   selectRh   Rf   R&   (   R'   R6   RE   RV   t   figRx   (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR(     s2    			
	
		c         C` s   t     | d } | j d  s' d  S|  j |  } |  j j } t | d  } t | d  } | j | k  r | d | _ n2 | j d | | k r | j d | d | _ n  |  j j j	 |  Wd  QXd  S(   NR   R   R}   i   gffffff?g?(
   R   t   getR   R&   RV   t   maxt   endR%   RE   R*   (   R'   R)   R   RE   RV   t	   max_rightt   cores(    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR*   @  s    

c      
   C` s  t     t |  d  } t |  } |  d } g  | D] } | | ^ q7 } |  d } g  | D] } | | ^ q^ } t |  } i t |  d 6| d 6t |  d 6t t | d d   d 6t t | d d d   d	 6| d 6} d
 g | | d <| SWd  QXd  S(   NR   R   RI   R}   i    iR   i   R   gffffff?RQ   (   R   t   sortedR:   t   listR9   (   R   t   namesR   RI   R   t   nt   d(    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR   Q  s"    



(   R,   R-   R.   R(   R   R*   t   staticmethodR   (    (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR     s   	*t   ProfilePlotc           B` s&   e  Z d  Z d   Z e d    Z RS(   s    Time plots of the current resource usage on the cluster

    This is two plots, one for CPU and Memory and another for Network I/O
    c         ` s   t  j   } t  j | t  } | j d    _ t  j | |  \   _   _ t	   f d    } t
 d k r   j j j d |  n   j j d |  d  S(   Nt   statesc      	   ` s   t     y | j } Wn t k
 r8 | d d } n Xy | d } Wn t k
 r[ d  SXt j   j | t  }   j 2  j j | j	 d     j
 j j |  |   j
 _ Wd  QXd  S(   Nt   1dt   indicesi    R   (   R   R   t   AttributeErrort
   IndexErrorR   t	   plot_dataR   t   profile_intervalt   extendt   popR%   RE   R*   t   selected(   t   attrt   oldt   newR   R?   RE   (   R'   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyt   cbu  s    
s   1.0.0R   R   (   R   t   createR   R   R   R   t   plot_figureR&   R%   R   R   R   t	   on_change(   R'   R6   t   stateRE   R   (    (   R'   s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR(   o  s    c         C` sW   t    H | |  _ t j |  j t  } | j d  |  _ |  j j j	 |  Wd  QXd  S(   NR   (
   R   R   R   R   R   R   R   R%   RE   R*   (   R'   R   RE   (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR*     s
    
	(   R,   R-   R.   R(   R   R*   (    (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR   i  s   	t   ProfileTimePlotc           B` s>   e  Z d  Z d d  Z e d d   Z e e d   Z RS(   s    Time plots of the current resource usage on the cluster

    This is two plots, one for CPU and Memory and another for Network I/O
    c         ` s  | d  k	 r t j |   _ y" | j j j j d d    _ Wn t	 k
 r\ d   _ n Xt
  j t  r  j d  _ n  t
  j t  r  j j    _ n  d  j g  _ n d   _ d g  _ |  _ d   _ d   _ i g  d 6g  d 6 _ t j    _ t j  j t  } | j d   _ t j | |  \  _  _ t g   t    f d    } t d k r j j  j! d	 |  n  j j! d
 |  t" i g  d 6g  d 6  _# t$ d d d d d d d d d d d t g d d |   _%  j% j& d d d  j#  j% j' d d d  j# d d  d d t  j% j( _) t  j% j* _)  f d   } t d k r j# j  j! d	 |  n  j# j! d
 |  t+ d d d d   _,  j, j-  f d     t+ d d! d d   _.  j. j-  j/  t0 d"  j d# d$  j   _1  f d%   }  j1 j! d" |  t2 t3  j1  j,  j. d& d'  j  j% |   _4 d  S((   NRH   i    t   Allt   countR   R   c      	   ` s     d r d  St     t | t  r0 | } n | d d } y | d } Wn t k
 r` d  SXt j  j | t  }  j 2 j j | j	 d   t
   d < j j j |  t | t  r |  j j _ n |  j _ t   d <Wd  QXd  S(   Ni    R   R   R   (   R   t
   isinstanceR   R   R   R   R   R   R   R   t   TrueR%   RE   R*   R   R   Rs   (   R   R   R   R   R?   RE   (   t   changingR'   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR     s&    

	
s   1.0.0R   R   RT   s   Activity over timeR`   id   RZ   R[   t   active_dragt   xbox_selectRW   i   R]   s"   xpan,xwheel_zoom,xbox_select,resetR%   RJ   t   selection_colort   orangec      	   ` s   t     y   j j j } Wn% t k
 rD   j j d d } n X| r   j j d t |  d }   j j d t |  d } t | |  t | |    _   _	 n d    _   _	   j d t  Wd  QXd  S(   NR   R   R   i  t   update_metadata(   R   t	   ts_sourceR   R   R   RE   RC   R   R@   t   stopR$   t   trigger_updateRs   (   R   R   R   R   R@   R   (   R'   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyt	   ts_change  s    
(t   labelt   Resett   button_typet   successc           ` s     j    j  S(   N(   R*   R   (    (   R'   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyt   <lambda>  R+   t   Updatet   valueit   optionsc         ` s2   | d k r d  } n  |   _   j d t  d  S(   NR   R   (   R$   RH   R   Rs   (   R   R   R   (   R'   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyt	   select_cb  s    		t   sizing_modet   scale_width(5   R$   t   weakreft   reft   doct   session_contextt   requestt	   argumentsR   RH   R   R   R   t   bytest   decodet
   task_namest   serverR@   R   t   tsR   R   R   R   R   R   R   R   t   profile_plotR%   Rs   R   R   R   R   R   R   R   t   ts_plott   linet   circleRo   Ru   t   gridR   t   reset_buttont   on_clickt   update_buttonR   R   R   R   R   R&   (   R'   R   R   R6   RE   R   R   R   (    (   R   R'   s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR(     sx    "						"	c      	   C` s  t    | |  _ t j |  j t  } | j d  |  _ |  j j j	 |  | d  k	 r| d rd g t | d  |  _ |  j |  j _ |  j r | d |  j } n
 | d } t |   \ } } i | d 6g  | D] } | d ^ q d 6|  _ |  j j j	 |  j  n  Wd  QXd  S(   NR   t   countsR   t   keysR   i  R   (   R   R   R   R   R   R   R   R%   RE   R*   R$   R   R   R   R   RH   t   zipR   R   (   R'   R   t   metadataRE   R   t   timesR   t   t(    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR*     s    
		
.c         ` s2   t  j    f d    }   j j j |  d  S(   Nc           3` s   t      j j d  j d  j d  j    rL  j j     n d    t  t	 j
  rz    g V\    n   j   j     f d    Wd  QXd  S(   NRH   R@   R   c           ` s    j      S(   N(   R*   (    (   R   t   profR'   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR   4  R+   (   R   R   t   get_profileRH   R@   R   t   get_profile_metadataR$   R   R   t   FutureR   t   add_next_tick_callback(    (   R'   R   (   R   R   s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR   (  s    
(   R   t	   coroutineR   t   loopt   add_callback(   R'   R   R   (    (   R'   R   s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR   &  s    N(	   R,   R-   R.   R$   R(   R   R*   R   R   (    (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR     s   xt   ProfileServerc           B` s8   e  Z d  Z d d  Z e d    Z e d    Z RS(   s    Time plots of the current resource usage on the cluster

    This is two plots, one for CPU and Memory and another for Network I/O
    c         ` s  | d  k	 r! t j |   _ n  |  _  j j j  _ d   _ d   _	 i g  d 6g  d 6 _
 t j  j   _ t j  j t  } | j d   _ t j | |  \  _  _ t g   t    f d    } t d k r j j j d |  n  j j d |  t i g  d 6g  d 6  _ t d d	 d
 d d d d d d d d t g d d |   _  j j d d d  j  j j d d d  j d d  d d t  j j _  t  j j! _   f d   } t d k r j j j d |  n  j j d |  t" d d d d   _#  j# j$  f d    t" d d d d   _%  j% j$  j&  t' t(  j#  j% d  d!  j  j |   _) d  S("   NR   R   R   c      	   ` s     d r d  St     t | t  r0 | } n | d d } y | d } Wn t k
 r` d  SXt j  j | t  }  j 2 j j | j	 d   t
   d < j j j |  t | t  r |  j j _ n |  j _ t   d <Wd  QXd  S(   Ni    R   R   R   (   R   R   R   R   R   R   R   R   R   R   R   R%   RE   R*   R   R   Rs   (   R   R   R   R   R?   RE   (   R   R'   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR   N  s&    

	
s   1.0.0R   R   RT   s   Activity over timeR`   id   RZ   R[   R   R   RW   i    i   R]   s"   xpan,xwheel_zoom,xbox_select,resetR%   RJ   R   R   c      	   ` s   t     y   j j j } Wn% t k
 rD   j j d d } n X| r   j j d t |  d }   j j d t |  d } t | |  t | |    _   _	 n d    _   _	   j   Wd  QXd  S(   NR   R   R   i  (   R   R   R   R   R   RE   RC   R   R@   R   R$   R   (   R   R   R   R   R@   R   (   R'   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR   |  s    
(R   R   R   R   c           ` s     j    j  S(   N(   R*   R   (    (   R'   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR     R+   R   R   R   (*   R$   R   R   R   R   t   io_loopR   t   logR@   R   R   R   R   R   R   R   R   R   R   R%   Rs   R   R   R   R   R   R   R   R   R   R   Ro   Ru   R   R   R   R   R   R   R   R   R&   (   R'   R   R   R6   RE   R   R   (    (   R   R'   s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR(   ?  sV    					c         C` sW   t    H | |  _ t j |  j t  } | j d  |  _ |  j j j	 |  Wd  QXd  S(   NR   (
   R   R   R   R   R   R   R   R%   RE   R*   (   R'   R   RE   (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR*     s
    
	c         C` s   t  j |  j d |  j d |  j |  _ t  j |  j t  } | j d  |  _	 |  j
 j j |  g  |  j D] \ } } | d ^ qk } t t j d t j d |  j    } |  j j j i | d 6| d 6 d  S(   NR@   R   R   i  R   i   R   (   R   R   R   R@   R   R   R   R   R   R   R%   RE   R*   R   t   toolzt   pluckR   (   R'   RE   R   t   _R   R   (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR     s    '&'N(   R,   R-   R.   R$   R(   R   R*   R   (    (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR   9  s   ]c         ` s9   t  j |    |  j   f d   |  t |  |  d S(   s   Add periodic callback to doc in a way that avoids reference cycles

    If we instead use ``doc.add_periodic_callback(component.update, 100)`` then
    the component stays in memory as a reference cycle because its method is
    still around.  This way we avoid that and let things clean up a bit more
    nicely.

    TODO: we still have reference cycles.  Docs seem to be referred to by their
    add_periodic_callback methods.
    c           ` s
   t     S(   N(   R*   (    (   R   (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR     R+   N(   R   R   t   add_periodic_callbackt   _attach(   R   t	   componentt   interval(    (   R   s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR     s    c         C` s&   |    } | d  k	 r" | j   n  d  S(   N(   R$   R*   (   R   t   comp(    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR*     s    	c         C` s2   t  |  d  s t   |  _ n  |  j j |  d  S(   Nt
   components(   t   hasattrt   setR   R   (   R   R   (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyR     s    (?   t
   __future__R    R   R   R   t   operatorR   R   R   t   bokeh.layoutsR   R   t   bokeh.modelsR   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   t   bokeh.palettesR   t   bokeh.plottingR   t   daskt   tornadoR   R   t   utilsR   R   t   diagnostics.progress_streamR   R+   R   R   R   t   configR   t   export_toolR    R$   R   t   objectR#   R/   R4   R{   R   R   R   R   R   R*   R   (    (    (    s;   lib/python2.7/site-packages/distributed/bokeh/components.pyt   <module>   s>   d/TIZ+v		