#NEWLINE# def sum_data( data , metric , collapse_key , dates , floor ) : #NEWLINE# #INDENT# collapsed = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for row in data : #NEWLINE# #INDENT# dimensions = row [ 'dimensions' ] #NEWLINE# k = dimensions [ collapse_key ] #NEWLINE# if ( k not in collapsed ) : #NEWLINE# #INDENT# d = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for dim in dimensions : #NEWLINE# #INDENT# if ( dim not in ga_date_keys ) : #NEWLINE# #INDENT# d [ dim ] = dimensions [ dim ] #NEWLINE# #UNINDENT# #UNINDENT# d [ 'week1' ] = 0 #NEWLINE# d [ 'week2' ] = 0 #NEWLINE# d [ '_timestamp' ] = to_datetime ( dates [ 0 ] ) #NEWLINE# collapsed [ k ] = d #NEWLINE# #UNINDENT# date_list = [ dimensions [ 'day' ] , dimensions [ 'month' ] , dimensions [ 'year' ] ] #NEWLINE# if ( '(other)' in date_list ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# week = ( 'week%d' % assign_day_to_week ( dimensions [ 'day' ] , dimensions [ 'month' ] , dimensions [ 'year' ] , dates ) ) #NEWLINE# if ( dimensions [ 'pagePath' ] in collapsed [ k ] [ 'pagePath' ] ) : #NEWLINE# #INDENT# collapsed [ k ] [ 'pagePath' ] = dimensions [ 'pagePath' ] #NEWLINE# #UNINDENT# collapsed [ k ] [ week ] += int ( key [ 'metrics' ] [ metric ] ) #NEWLINE# #UNINDENT# for key in collapsed : #NEWLINE# #INDENT# for week in [ 'week1' , 'week2' ] : #NEWLINE# #INDENT# if ( collapsed [ key ] [ week ] < floor ) : #NEWLINE# #INDENT# collapsed [ key ] [ week ] = floor #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return collapsed