#NEWLINE# def update( self , current , values = [ ] ) : #NEWLINE# #INDENT# '\n            @param current: index of current step\n            @param values: list of tuples (name, value_for_last_step).\n            The progress bar will display averages for these values.\n        ' #NEWLINE# for ( k , v ) in values : #NEWLINE# #INDENT# if ( k not in self . sum_values ) : #NEWLINE# #INDENT# self . sum_values [ k ] = [ ( v * ( current - self . seen_so_far ) ) , ( current - self . seen_so_far ) ] #NEWLINE# self . unique_values . append ( k ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . sum_values [ k ] [ 0 ] += ( v * ( current - self . seen_so_far ) ) #NEWLINE# self . sum_values [ k ] [ 1 ] += ( current - self . seen_so_far ) #NEWLINE# #UNINDENT# #UNINDENT# self . seen_so_far = current #NEWLINE# now = time . time ( ) #NEWLINE# if ( self . verbose == 1 ) : #NEWLINE# #INDENT# prev_total_width = self . total_width #NEWLINE# sys . stdout . write ( ( '\x08' * prev_total_width ) ) #NEWLINE# sys . stdout . write ( '\r' ) #NEWLINE# numdigits = ( int ( np . floor ( np . log10 ( self . target ) ) ) + 1 ) #NEWLINE# barstr = ( '%%%dd/%%%dd [' % ( numdigits , numdigits ) ) #NEWLINE# bar = ( barstr % ( current , self . target ) ) #NEWLINE# prog = ( float ( current ) / self . target ) #NEWLINE# if ( current > self . target ) : #NEWLINE# #INDENT# prog = 1 #NEWLINE# #UNINDENT# prog_width = int ( ( self . width * prog ) ) #NEWLINE# if ( prog_width > 0 ) : #NEWLINE# #INDENT# bar += ( '=' * ( prog_width - 1 ) ) #NEWLINE# if ( current < self . target ) : #NEWLINE# #INDENT# bar += '>' #NEWLINE# #UNINDENT# #UNINDENT# bar += ( '.' * ( self . width - prog_width ) ) #NEWLINE# bar += ']' #NEWLINE# sys . stdout . write ( bar ) #NEWLINE# self . total_width = len ( bar ) #NEWLINE# if current : #NEWLINE# #INDENT# time_per_unit = ( ( now - self . start ) / current ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# time_per_unit = 0 #NEWLINE# #UNINDENT# eta = ( time_per_unit * ( self . target - current ) ) #NEWLINE# info = '' #NEWLINE# if ( current < self . target ) : #NEWLINE# #INDENT# info += ( ' - ETA: %ds' % eta ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# info += ( ' - %ds' % ( now - self . start ) ) #NEWLINE# #UNINDENT# for k in self . unique_values : #NEWLINE# #INDENT# info += ( ' - %s: %.4f' % ( k , ( self . sum_values [ k ] [ 0 ] / max ( 1 , self . sum_values [ k ] [ 1 ] ) ) ) ) #NEWLINE# #UNINDENT# self . total_width += len ( info ) #NEWLINE# if ( prev_total_width > self . total_width ) : #NEWLINE# #INDENT# info += ( ( prev_total_width - self . total_width ) * ' ' ) #NEWLINE# #UNINDENT# sys . stdout . write ( info ) #NEWLINE# sys . stdout . flush ( ) #NEWLINE# #UNINDENT# if ( self . verbose == 2 ) : #NEWLINE# #INDENT# if ( current >= self . target ) : #NEWLINE# #INDENT# info = ( '%ds' % ( now - self . start ) ) #NEWLINE# for k in self . unique_values : #NEWLINE# #INDENT# info += ( ' - %s: %.4f' % ( k , ( self . sum_values [ k ] [ 0 ] / max ( 1 , self . sum_values [ k ] [ 1 ] ) ) ) ) #NEWLINE# #UNINDENT# sys . stdout . write ( ( info + '\n' ) )