#NEWLINE# def graphite_func_aggregate( targets , agg_by_tags , aggfunc ) : #NEWLINE# #INDENT# aggfunc_abbrev = { #NEWLINE# #INDENT# 'averageSeries' : 'avg' , #NEWLINE# 'sumSeries' : 'sum' , #NEWLINE# #UNINDENT# } #NEWLINE# agg = Target ( { #NEWLINE# #INDENT# 'target' : ( '%s(%s)' % ( aggfunc , ',' . join ( [ t [ 'target' ] for t in targets ] ) ) ) , #NEWLINE# 'id' : [ t [ 'id' ] for t in targets ] , #NEWLINE# 'variables' : targets [ 0 ] [ 'variables' ] , #NEWLINE# 'tags' : targets [ 0 ] [ 'tags' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# differentiators = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# bucket_id = '<none>' #NEWLINE# for agg_by_tag in agg_by_tags . keys ( ) : #NEWLINE# #INDENT# for t in targets : #NEWLINE# #INDENT# if ( agg_by_tag in t [ 'match_buckets' ] ) : #NEWLINE# #INDENT# bucket_id = t [ 'match_buckets' ] [ agg_by_tag ] #NEWLINE# #UNINDENT# differentiators [ agg_by_tag ] = differentiators . get ( agg_by_tag , [ ] ) #NEWLINE# differentiators [ agg_by_tag ] . append ( t [ 'variables' ] . get ( agg_by_tag , '<missing>' ) ) #NEWLINE# #UNINDENT# differentiators [ agg_by_tag ] . sort ( ) #NEWLINE# bucket_id_str = '' #NEWLINE# if bucket_id : #NEWLINE# #INDENT# bucket_id_str = ( "'%s' " % bucket_id ) #NEWLINE# #UNINDENT# tag_val = ( ( '%s%s (%d vals, %d uniqs)' % ( bucket_id_str , aggfunc_abbrev . get ( aggfunc , t ) , len ( differentiators [ agg_by_tag ] ) , len ( set ( differentiators [ agg_by_tag ] ) ) ) ) , differentiators [ agg_by_tag ] ) #NEWLINE# agg [ 'variables' ] [ agg_by_tag ] = tag_val #NEWLINE# agg [ 'tags' ] [ agg_by_tag ] = tag_val #NEWLINE# #UNINDENT# return agg