#NEWLINE# def testEventDataAggregation( self ) : #NEWLINE# #INDENT# ' Test aggregation of event data ' #NEWLINE# s3db = current . s3db #NEWLINE# assertEqual = self . assertEqual #NEWLINE# assertTrue = self . assertTrue #NEWLINE# PERIODS = 'p' #NEWLINE# TIMES = 't' #NEWLINE# VALUE = 'v' #NEWLINE# resource = s3db . resource ( 'tp_test_events' ) #NEWLINE# ts = S3TimeSeries ( resource , event_start = 'event_start' , event_end = 'event_end' , end = '2013-01-01' , slots = 'months' , facts = [ S3TimeSeriesFact ( 'sum' , 'parameter1' ) ] ) #NEWLINE# assertEqual ( ts . event_frame . slots , 'months' ) #NEWLINE# expected = [ ( ( 2011 , 1 , 3 ) , ( 2011 , 2 , 3 ) , [ 15 ] ) , ( ( 2011 , 2 , 3 ) , ( 2011 , 3 , 3 ) , [ 15 ] ) , ( ( 2011 , 3 , 3 ) , ( 2011 , 4 , 3 ) , [ 15 ] ) , ( ( 2011 , 4 , 3 ) , ( 2011 , 5 , 3 ) , [ 18 ] ) , ( ( 2011 , 5 , 3 ) , ( 2011 , 6 , 3 ) , [ 18 ] ) , ( ( 2011 , 6 , 3 ) , ( 2011 , 7 , 3 ) , [ 15 ] ) , ( ( 2011 , 7 , 3 ) , ( 2011 , 8 , 3 ) , [ 18 ] ) , ( ( 2011 , 8 , 3 ) , ( 2011 , 9 , 3 ) , [ 18 ] ) , ( ( 2011 , 9 , 3 ) , ( 2011 , 10 , 3 ) , [ 15 ] ) , ( ( 2011 , 10 , 3 ) , ( 2011 , 11 , 3 ) , [ 15 ] ) , ( ( 2011 , 11 , 3 ) , ( 2011 , 12 , 3 ) , [ 15 ] ) , ( ( 2011 , 12 , 3 ) , ( 2012 , 1 , 3 ) , [ 12 ] ) , ( ( 2012 , 1 , 3 ) , ( 2012 , 2 , 3 ) , [ 12 ] ) , ( ( 2012 , 2 , 3 ) , ( 2012 , 3 , 3 ) , [ 12 ] ) , ( ( 2012 , 3 , 3 ) , ( 2012 , 4 , 3 ) , [ 9 ] ) , ( ( 2012 , 4 , 3 ) , ( 2012 , 5 , 3 ) , [ 9 ] ) , ( ( 2012 , 5 , 3 ) , ( 2012 , 6 , 3 ) , [ 9 ] ) , ( ( 2012 , 6 , 3 ) , ( 2012 , 7 , 3 ) , [ 6 ] ) , ( ( 2012 , 7 , 3 ) , ( 2012 , 8 , 3 ) , [ 9 ] ) , ( ( 2012 , 8 , 3 ) , ( 2012 , 9 , 3 ) , [ 9 ] ) , ( ( 2012 , 9 , 3 ) , ( 2012 , 10 , 3 ) , [ 6 ] ) , ( ( 2012 , 10 , 3 ) , ( 2012 , 11 , 3 ) , [ 9 ] ) , ( ( 2012 , 11 , 3 ) , ( 2012 , 12 , 3 ) , [ 9 ] ) , ( ( 2012 , 12 , 3 ) , ( 2013 , 1 , 1 ) , [ 9 ] ) ] #NEWLINE# result = ts . as_dict ( ) #NEWLINE# periods = result [ PERIODS ] #NEWLINE# for ( i , period ) in enumerate ( periods ) : #NEWLINE# #INDENT# ( expected_start , expected_end , expected_value ) = expected [ i ] #NEWLINE# expected_start = tp_datetime ( * expected_start ) . isoformat ( ) #NEWLINE# expected_end = tp_datetime ( * expected_end ) . isoformat ( ) #NEWLINE# dates = period . get ( TIMES ) #NEWLINE# assertTrue ( isinstance ( dates , tuple ) ) #NEWLINE# ( start , end ) = dates #NEWLINE# assertEqual ( start , expected_start , msg = ( 'Period %s start should be %s, but is %s' % ( i , expected_start , start ) ) ) #NEWLINE# assertEqual ( end , expected_end , msg = ( 'Period %s end should be %s, but is %s' % ( i , expected_end , end ) ) ) #NEWLINE# value = period . get ( VALUE ) #NEWLINE# assertEqual ( value , expected_value , msg = ( 'Period %s sum should be %s, but is %s' % ( i , expected_value , value ) ) )