#NEWLINE# def fetch_stats( package ) : #NEWLINE# #INDENT# releases = list ( Release . objects . filter ( package = package ) . only ( 'version' , 'order' ) . order_by ( 'order' ) ) #NEWLINE# specific_releases = set ( [ x . version for x in releases [ ( - 8 ) : ] ] ) #NEWLINE# deltas = list ( DownloadDelta . objects . filter ( file__release__in = releases ) . only ( 'date' , 'delta' , 'file__release__version' ) . order_by ( 'date' ) . select_related ( 'file' , 'file__release' ) ) #NEWLINE# if ( not deltas ) : #NEWLINE# #INDENT# return [ { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ] #NEWLINE# #UNINDENT# data = ( [ { #NEWLINE# #INDENT# 'name' : 'Other' , #NEWLINE# 'data' : [ ] , #NEWLINE# #UNINDENT# } ] + [ { #NEWLINE# #INDENT# 'name' : release . version , #NEWLINE# 'data' : [ ] , #NEWLINE# #UNINDENT# } for release in releases if ( release . version in specific_releases ) ] ) #NEWLINE# start_week = isoweek . Week . withdate ( deltas [ 0 ] . date ) #NEWLINE# end_week = isoweek . Week . thisweek ( ) #NEWLINE# current = isoweek . Week ( start_week . year , start_week . week ) #NEWLINE# while ( ( current . year <= end_week . year ) and ( current . week < end_week . week ) ) : #NEWLINE# #INDENT# for x in data : #NEWLINE# #INDENT# x [ 'data' ] . append ( { #NEWLINE# #INDENT# 'x' : int ( time . mktime ( current . day ( 0 ) . timetuple ( ) ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# current = isoweek . Week ( current . year , ( end_week . week + 1 ) ) #NEWLINE# #UNINDENT# _data = collections . defaultdict ( dict ) #NEWLINE# for d in deltas : #NEWLINE# #INDENT# target = int ( time . mktime ( isoweek . Week . withdate ( d . date ) . day ( 0 ) . timetuple ( ) ) ) #NEWLINE# _data [ ( d . file . release . version if ( d . file . release . version in specific_releases ) else 'Other' ) ] [ target ] = d . delta #NEWLINE# #UNINDENT# for i in xrange ( 0 , len ( data ) ) : #NEWLINE# #INDENT# for j in xrange ( 0 , len ( data [ i ] [ 'data' ] ) ) : #NEWLINE# #INDENT# data [ i ] [ 'data' ] [ j ] [ 'y' ] = _data [ ( data [ i ] [ 'name' ] if ( data [ i ] [ 'name' ] in specific_releases ) else 'Other' ) ] . get ( data [ i ] [ 'data' ] [ j ] [ 'x' ] , 0 ) #NEWLINE# #UNINDENT# #UNINDENT# return data