<s> """<STR_LIT>""" <EOL> import matplotlib <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> import pylab <EOL> import numpy <EOL> from matplotlib . dates import date2num <EOL> import datetime <EOL> from . event import nodes_to_events <EOL> from . utils . date import total_seconds <EOL> from matplotlib . dates import DateFormatter , WeekdayLocator , DayLocator , MONDAY <EOL> FIGSIZE = ( <NUM_LIT:4> , <NUM_LIT:3> ) <EOL> mondays = WeekdayLocator ( MONDAY ) <EOL> alldays = DayLocator ( ) <EOL> weekFormatter = DateFormatter ( '<STR_LIT>' ) <EOL> dayFormatter = DateFormatter ( '<STR_LIT>' ) <EOL> def set_xaxis_format_date ( ax ) : <EOL> ax . xaxis . set_major_locator ( mondays ) <EOL> ax . xaxis . set_minor_locator ( alldays ) <EOL> ax . xaxis . set_major_formatter ( weekFormatter ) <EOL> pylab . setp ( ax . get_xticklabels ( ) , rotation = <NUM_LIT> , ha = "<STR_LIT:right>" ) <EOL> def within_ndays_before ( n ) : <EOL> now = datetime . datetime . now ( ) <EOL> maxsec = n * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> <EOL> def predicate ( ev ) : <EOL> date = ev . date . start <EOL> if isinstance ( date , datetime . date ) : <EOL> date = datetime . datetime ( * date . timetuple ( ) [ : <NUM_LIT:3> ] ) <EOL> return <NUM_LIT:0> <= total_seconds ( now - date ) <= maxsec <EOL> return predicate <EOL> def plot_clocked_per_day ( ax , orgnodes , days , <EOL> ylabel = '<STR_LIT>' ) : <EOL> events = nodes_to_events ( <EOL> orgnodes , filters = [ within_ndays_before ( days ) ] , eventclass = [ '<STR_LIT>' ] ) <EOL> clocked = numpy . array ( <EOL> [ ( date2num ( e . date . start ) , total_seconds ( e . date . duration ) / <NUM_LIT> / <NUM_LIT> ) <EOL> for e in events ] , <EOL> dtype = [ ( '<STR_LIT:start>' , int ) , ( '<STR_LIT>' , int ) ] ) <EOL> if len ( clocked ) == <NUM_LIT:0> : <EOL> return <EOL> lastday = clocked [ '<STR_LIT:start>' ] . max ( ) <EOL> firstday = clocked [ '<STR_LIT:start>' ] . min ( ) <EOL> dates = numpy . arange ( lastday - firstday + <NUM_LIT:1> ) <EOL> cpd = numpy . zeros ( len ( dates ) , dtype = '<STR_LIT:float>' ) <EOL> for i in dates : <EOL> cpd [ i ] = numpy . extract ( clocked [ '<STR_LIT:start>' ] == firstday + i , <EOL> clocked [ '<STR_LIT>' ] ) . sum ( ) <EOL> ax . bar ( dates + firstday , cpd , width = <NUM_LIT:1> , color = '<STR_LIT:b>' , alpha = <NUM_LIT> ) <EOL> ax . set_ylabel ( ylabel ) <EOL> def gene_clocked_par_day ( orgnodes , done , days = <NUM_LIT:30> ) : <EOL> """<STR_LIT>""" <EOL> fig = pylab . figure ( figsize = FIGSIZE ) <EOL> fig . subplots_adjust ( bottom = <NUM_LIT> ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> plot_clocked_per_day ( ax , orgnodes , days ) <EOL> set_xaxis_format_date ( ax ) <EOL> return fig <EOL> def time_array_closed ( orgnodes , done , start ) : <EOL> time_array = numpy . array ( date2num ( [ c . start for c in ( <EOL> node . closed <EOL> for node in orgnodes <EOL> if node . todo == done <EOL> ) if c ] ) ) <EOL> return numpy . take ( time_array , numpy . where ( time_array > start ) ) [ <NUM_LIT:0> ] <EOL> def plot_done_par_day ( ax , orgnodes , done , days , <EOL> ylabel = '<STR_LIT>' ) : <EOL> today = int ( date2num ( datetime . datetime . now ( ) ) ) + <NUM_LIT:1> <EOL> start = today - days <EOL> time_array = time_array_closed ( orgnodes , done , start ) <EOL> ax . hist ( time_array , bins = days , range = ( start , today ) , <EOL> color = '<STR_LIT:b>' , alpha = <NUM_LIT> ) <EOL> ax . set_ylabel ( ylabel ) <EOL> def gene_done_par_day ( orgnodes , done , days = <NUM_LIT:30> ) : <EOL> """<STR_LIT>""" <EOL> fig = pylab . figure ( figsize = FIGSIZE ) <EOL> fig . subplots_adjust ( bottom = <NUM_LIT> ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> plot_done_par_day ( ax , orgnodes , done , days ) <EOL> set_xaxis_format_date ( ax ) <EOL> return fig <EOL> def plot_tags_dist ( ax , orgnodes , days = <NUM_LIT> , num = <NUM_LIT:10> ) : <EOL> event_tags = ( e . tags for e in nodes_to_events ( <EOL> orgnodes , <EOL> filters = [ within_ndays_before ( days ) ] , <EOL> eventclass = [ '<STR_LIT>' ] ) ) <EOL> counter = { } <EOL> for tags in event_tags : <EOL> for t in tags : <EOL> if t in counter : <EOL> counter [ t ] += <NUM_LIT:1> <EOL> else : <EOL> counter [ t ] = <NUM_LIT:1> <EOL> if not counter : <EOL> return <EOL> taglen = max ( map ( len , counter ) ) <EOL> data = numpy . array ( <EOL> list ( counter . items ( ) ) , <EOL> dtype = [ ( '<STR_LIT>' , '<STR_LIT>' . format ( taglen ) ) , ( '<STR_LIT:count>' , int ) ] ) <EOL> data . sort ( order = [ '<STR_LIT:count>' ] ) <EOL> data = data [ : : - <NUM_LIT:1> ] [ : num ] <EOL> x = numpy . arange ( len ( data ) ) <EOL> ax . bar ( x , data [ '<STR_LIT:count>' ] , width = <NUM_LIT:1> , color = '<STR_LIT:b>' , alpha = <NUM_LIT> ) <EOL> ax . set_xticks ( x + <NUM_LIT:0.5> ) <EOL> ax . set_xticklabels ( data [ '<STR_LIT>' ] ) <EOL> pylab . setp ( ax . get_xticklabels ( ) , <EOL> rotation = <NUM_LIT> , <EOL> y = <NUM_LIT> , <EOL> horizontalalignment = "<STR_LIT:left>" , <EOL> verticalalignment = '<STR_LIT>' ) <EOL> def gene_tags_dist ( orgnodes , done = '<STR_LIT>' , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> fig = pylab . figure ( figsize = FIGSIZE ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> plot_tags_dist ( ax , orgnodes , ** kwds ) <EOL> return fig <EOL> def decompose_in_day_and_hour ( dates ) : <EOL> decomposed = numpy . zeros ( len ( dates ) , dtype = [ ( '<STR_LIT>' , int ) , ( '<STR_LIT>' , float ) ] ) <EOL> decomposed [ '<STR_LIT>' ] = dates <EOL> decomposed [ '<STR_LIT>' ] = ( dates - decomposed [ '<STR_LIT>' ] ) * <NUM_LIT> <EOL> return decomposed <EOL> def plot_clocked_and_closed ( ax , orgnodes , days = <NUM_LIT:30> ) : <EOL> events = list ( nodes_to_events ( <EOL> orgnodes , <EOL> filters = [ within_ndays_before ( days ) ] , <EOL> eventclass = [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> closed = numpy . array ( <EOL> [ date2num ( e . date . start ) <EOL> for e in events if e . eventclass == '<STR_LIT>' ] ) <EOL> clock = numpy . array ( <EOL> [ ( date2num ( e . date . start ) , date2num ( e . date . end ) ) <EOL> for e in events if e . eventclass == '<STR_LIT>' ] , <EOL> dtype = [ ( '<STR_LIT:start>' , float ) , ( '<STR_LIT:end>' , float ) ] ) <EOL> dh_closed = decompose_in_day_and_hour ( closed ) <EOL> dh_clock_start = decompose_in_day_and_hour ( clock [ '<STR_LIT:start>' ] ) <EOL> dh_clock_end = decompose_in_day_and_hour ( clock [ '<STR_LIT:end>' ] ) <EOL> ax . plot ( dh_closed [ '<STR_LIT>' ] + <NUM_LIT:0.5> , dh_closed [ '<STR_LIT>' ] , '<STR_LIT:x>' ) <EOL> if len ( dh_clock_start ) > <NUM_LIT:0> : <EOL> ax . errorbar ( <EOL> dh_clock_start [ '<STR_LIT>' ] + <NUM_LIT:0.5> , <EOL> ( dh_clock_start [ '<STR_LIT>' ] + dh_clock_start [ '<STR_LIT>' ] ) / <NUM_LIT> , <EOL> yerr = ( dh_clock_end [ '<STR_LIT>' ] - dh_clock_start [ '<STR_LIT>' ] ) , <EOL> fmt = None ) <EOL> set_xaxis_format_date ( ax ) <EOL> ax . set_yticks ( [ <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> ax . set_ylim ( <NUM_LIT> , - <NUM_LIT:0.1> ) <EOL> def gene_clocked_and_closed ( orgnodes , done = '<STR_LIT>' , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> fig = pylab . figure ( figsize = FIGSIZE ) <EOL> fig . subplots_adjust ( bottom = <NUM_LIT> ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> plot_clocked_and_closed ( ax , orgnodes , ** kwds ) <EOL> return fig <EOL> def gene_overview ( orgnodes , done , days = <NUM_LIT:30> ) : <EOL> """<STR_LIT>""" <EOL> fig = pylab . figure ( figsize = FIGSIZE ) <EOL> fig . subplots_adjust ( bottom = <NUM_LIT> ) <EOL> ax1 = fig . add_subplot ( <NUM_LIT> ) <EOL> ax2 = fig . add_subplot ( <NUM_LIT> ) <EOL> plot_done_par_day ( ax1 , orgnodes , done , days , ylabel = '<STR_LIT>' ) <EOL> plot_clocked_per_day ( ax2 , orgnodes , days , ylabel = '<STR_LIT>' ) <EOL> set_xaxis_format_date ( ax1 ) <EOL> pylab . setp ( ax1 . get_xticklabels ( ) , visible = False ) <EOL> set_xaxis_format_date ( ax2 ) <EOL> ( xmin1 , xmax1 ) = ax1 . get_xlim ( ) <EOL> ( xmin2 , xmax2 ) = ax2 . get_xlim ( ) <EOL> xlim = ( min ( xmin1 , xmin2 ) , max ( xmax1 , xmax2 ) ) <EOL> ax1 . set_xlim ( xlim ) <EOL> ax2 . set_xlim ( xlim ) <EOL> ax1 . set_title ( '<STR_LIT>' ) <EOL> return fig <EOL> graph_func_map = { <EOL> '<STR_LIT>' : gene_done_par_day , <EOL> '<STR_LIT>' : gene_clocked_par_day , <EOL> '<STR_LIT>' : gene_tags_dist , <EOL> '<STR_LIT>' : gene_clocked_and_closed , <EOL> '<STR_LIT>' : gene_overview , <EOL> } <EOL> """<STR_LIT>""" </s>
