#NEWLINE# def base_timeseries( cat_id = None ) : #NEWLINE# #INDENT# get_all = request . args . get ( 'all' ) #NEWLINE# start = request . args . get ( 'start' ) #NEWLINE# end = request . args . get ( 'end' ) #NEWLINE# slice = request . args . get ( 'time_slice' , None ) #NEWLINE# if get_all : #NEWLINE# #INDENT# if cat_id : #NEWLINE# #INDENT# return category . Category ( REDIS , cat_id = cat_id ) . timeseries . all ( time_slice = slice ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# time_series = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for cat in category . Category . get_all_categories ( REDIS ) : #NEWLINE# #INDENT# time_series [ cat . cat_id ] = cat . timeseries . all ( time_slice = slice ) #NEWLINE# #UNINDENT# return time_series #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( start and end ) : #NEWLINE# #INDENT# start = calendar . timegm ( parser . parse ( start ) . timetuple ( ) ) #NEWLINE# end = calendar . timegm ( parser . parse ( end ) . timetuple ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# end = time . time ( ) #NEWLINE# start = ( end - DEFAULT_TIME_SLICE ) #NEWLINE# #UNINDENT# if cat_id : #NEWLINE# #INDENT# return [ [ ( x . timestamp * 1000 ) , x . count ] for x in category . Category ( REDIS , cat_id = cat_id ) . timeseries . range ( start , end , time_slice = slice ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# time_series = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for cat in category . Category . get_all_categories ( REDIS ) : #NEWLINE# #INDENT# data = [ ( ( x . timestamp * 1000 ) , x . count ) for x in cat . timeseries . range ( start , end , time_slice = slice ) ] #NEWLINE# if data : #NEWLINE# #INDENT# time_series [ cat . cat_id ] = data #NEWLINE# #UNINDENT# #UNINDENT# return time_series