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
        # falls back to first start date
        assertEqual(ef.start, tp_datetime(2011, 1, 3, 0, 0, 0))
        assertEqual(ef.end, tp_datetime(2011, 3, 1, 0, 0, 0))
        # ~8 weeks => reasonable intervall length: weeks
        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
        # falls back to first end date minus 1 day
        assertEqual(ef.start, tp_datetime(2012, 2, 12, 0, 0, 0))
        assertEqual(ef.end, tp_datetime(2013, 1, 1, 0, 0))
        # ~11 months => reasonable intervall length: months
        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
        # falls back to first start date
        assertEqual(ef.start, tp_datetime(2012, 7, 21, 0, 0, 0))
        assertEqual(ef.end, tp_datetime(2016, 6, 1, 0, 0))
        # ~4 years => reasonable intervall length: 3 months
        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
        # falls back to first start date
        assertEqual(ef.start, tp_datetime(2011, 1, 3, 0, 0, 0))
        assertEqual(ef.end, tp_datetime(2011, 1, 15, 0, 0))
        # ~12 days => reasonable intervall length: days
        assertEqual(ef.slots, "days")

        # Check with manual slot length
        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
        # falls back to first start date
        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")

        # Check with manual start date
        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
        # falls back to first start date
        assertEqual(ef.start, tp_datetime(2011, 2, 15, 0, 0, 0))
        assertEqual(ef.end, tp_datetime(2011, 3, 1, 0, 0, 0))
        # ~14 days => reasonable intervall length: days
        assertEqual(ef.slots, "days")

    # -------------------------------------------------------------------------
Test automatic determination of reasonable aggregation time slot
dataset/ETHPy150Open sahana/eden/modules/unit_tests/s3/s3timeplot.py/TimeSeriesTests.testAutomaticSlotLength