'Test automatic determination of reasonable aggregation time slot'

def testAutomaticSlotLength(self):

    assertEqual = self.assertEqual
    s3db = current.s3db
    query = (FS('event_type') == 'STARTEND')
    resource = s3db.resource('tp_test_events', filter=query)
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', end='2011-03-01')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2011, 1, 3, 0, 0, 0))
    assertEqual(ef.end, tp_datetime(2011, 3, 1, 0, 0, 0))
    assertEqual(ef.slots, 'weeks')
    query = (FS('event_type') == 'NOSTART')
    resource = s3db.resource('tp_test_events', filter=query)
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', end='2013-01-01')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2012, 2, 12, 0, 0, 0))
    assertEqual(ef.end, tp_datetime(2013, 1, 1, 0, 0))
    assertEqual(ef.slots, 'months')
    query = (FS('event_type') == 'NOEND')
    resource = s3db.resource('tp_test_events', filter=query)
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', end='2016-06-01')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2012, 7, 21, 0, 0, 0))
    assertEqual(ef.end, tp_datetime(2016, 6, 1, 0, 0))
    assertEqual(ef.slots, '3    months')
    resource = s3db.resource('tp_test_events')
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', end='2011-01-15')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2011, 1, 3, 0, 0, 0))
    assertEqual(ef.end, tp_datetime(2011, 1, 15, 0, 0))
    assertEqual(ef.slots, 'days')
    query = (FS('event_type') == 'NOEND')
    resource = s3db.resource('tp_test_events', filter=query)
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', end='2016-06-01', slots='years')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2012, 7, 21, 0, 0, 0))
    assertEqual(ef.end, tp_datetime(2016, 6, 1, 0, 0))
    assertEqual(ef.slots, 'years')
    query = (FS('event_type') == 'STARTEND')
    resource = s3db.resource('tp_test_events', filter=query)
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', start='2011-02-15', end='2011-03-01')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2011, 2, 15, 0, 0, 0))
    assertEqual(ef.end, tp_datetime(2011, 3, 1, 0, 0, 0))
    assertEqual(ef.slots, 'days')
    query = (FS('event_type') == 'STARTEND')
    resource = s3db.resource('tp_test_events', filter=query)
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', start='2011-02-15', end=tp_datetime(2011, 2, 28, 12, 53, 0))
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2011, 2, 15, 0, 0, 0))
    assertEqual(ef.end, tp_datetime(2011, 2, 28, 12, 53, 0))
    assertEqual(ef.slots, 'days')
