Exemplo n.º 1
0
    def test_range_seconds(self):
        start, end = parse_range('last 3 seconds')
        self.assertTrue(end - start, timedelta(0, 3))
        self.close_to_now(end)

        start, end = parse_range('previous 3 seconds')
        self.assertTrue(end - start, timedelta(0, 3))
        self.within_unit(start, 'second')

        start, end = parse_range('this second')
        self.within_unit(start, 'second')
Exemplo n.º 2
0
    def test_range_seconds(self):
        start, end = parse_range('last 3 seconds')
        self.assertTrue(end - start, timedelta(0, 3))
        self.close_to_now(end)

        start, end = parse_range('previous 3 seconds')
        self.assertTrue(end - start, timedelta(0, 3))
        self.within_unit(start, 'second')

        start, end = parse_range('this second')
        self.within_unit(start, 'second')
Exemplo n.º 3
0
    def test_range_minutes(self):
        start, end = parse_range('last 3 minutes')
        self.assertTrue(end - start, timedelta(0, 3*60))

        start, end = parse_range('previous 3 minutes')
        self.assertTrue(end - start, timedelta(0, 3*60))
        self.on_boundary(end, 'minute')
        self.within_unit(end, 'minute')

        start, end = parse_range('this minute')
        self.on_boundary(start, 'minute')
        self.close_to_now(end)
        self.within_unit(start, 'minute')
Exemplo n.º 4
0
    def test_range_days(self):
        start, end = parse_range('last 3 days')
        self.assertTrue(end - start, parse_timedelta('3 days'))

        start, end = parse_range('yesterday')
        self.assertTrue(end - start, parse_timedelta('1 day'))
        self.on_boundary(end, 'day')
        self.within_unit(end, 'day')

        start, end = parse_range('today')
        self.on_boundary(start, 'day')
        self.close_to_now(end)
        self.within_unit(start, 'day')
Exemplo n.º 5
0
    def test_range_hours(self):
        start, end = parse_range('last 3 hours')
        self.assertTrue(end - start, timedelta(0, 60 * 60))

        start, end = parse_range('previous 3 hours')
        self.assertTrue(end - start, timedelta(0, 60 * 60))
        self.on_boundary(end, 'hour')
        self.within_unit(end, 'hour')

        start, end = parse_range('this hour')
        self.on_boundary(start, 'hour')
        self.close_to_now(end)
        self.within_unit(start, 'hour')
Exemplo n.º 6
0
    def test_range_minutes(self):
        start, end = parse_range('last 3 minutes')
        self.assertTrue(end - start, timedelta(0, 3 * 60))

        start, end = parse_range('previous 3 minutes')
        self.assertTrue(end - start, timedelta(0, 3 * 60))
        self.on_boundary(end, 'minute')
        self.within_unit(end, 'minute')

        start, end = parse_range('this minute')
        self.on_boundary(start, 'minute')
        self.close_to_now(end)
        self.within_unit(start, 'minute')
Exemplo n.º 7
0
    def test_range_hours(self):
        start, end = parse_range('last 3 hours')
        self.assertTrue(end - start, timedelta(0, 60*60))

        start, end = parse_range('previous 3 hours')
        self.assertTrue(end - start, timedelta(0, 60*60))
        self.on_boundary(end, 'hour')
        self.within_unit(end, 'hour')

        start, end = parse_range('this hour')
        self.on_boundary(start, 'hour')
        self.close_to_now(end)
        self.within_unit(start, 'hour')
Exemplo n.º 8
0
    def test_range_days(self):
        start, end = parse_range('last 3 days')
        self.assertTrue(end - start, parse_timedelta('3 days'))

        start, end = parse_range('yesterday')
        self.assertTrue(end - start, parse_timedelta('1 day'))
        self.on_boundary(end, 'day')
        self.within_unit(end, 'day')

        start, end = parse_range('today')
        self.on_boundary(start, 'day')
        self.close_to_now(end)
        self.within_unit(start, 'day')
Exemplo n.º 9
0
    def test_range_years(self):

        start, end = parse_range('last 3 years')
        self.assertTrue(end - start, parse_timedelta('3 years'))

        start, end = parse_range('previous 3 years')
        self.assertEquals(start, end - relativedelta(years=3))
        self.on_boundary(end, 'year')
        self.within_unit(end, 'year')

        start, end = parse_range('this year')
        self.on_boundary(start, 'year')
        self.close_to_now(end)
        self.within_unit(start, 'year')
Exemplo n.º 10
0
    def test_range_months(self):

        start, end = parse_range('last 3 months')
        self.assertTrue(end - start, parse_timedelta('3 months'))

        start, end = parse_range('previous 3 months')
        self.assertEquals(start, end - relativedelta(months=3))
        self.on_boundary(end, 'month')
        self.within_unit(end, 'month')

        start, end = parse_range('this month')
        self.on_boundary(start, 'month')
        self.close_to_now(end)
        self.within_unit(start, 'month')
Exemplo n.º 11
0
    def test_range_months(self):

        start, end = parse_range('last 3 months')
        self.assertTrue(end - start, parse_timedelta('3 months'))

        start, end = parse_range('previous 3 months')
        self.assertEqual(start, end - relativedelta(months=3))
        self.on_boundary(end, 'month')
        self.within_unit(end, 'month')

        start, end = parse_range('this month')
        self.on_boundary(start, 'month')
        self.close_to_now(end)
        self.within_unit(start, 'month')
Exemplo n.º 12
0
    def test_range_years(self):

        start, end = parse_range('last 3 years')
        self.assertTrue(end - start, parse_timedelta('3 years'))

        start, end = parse_range('previous 3 years')
        self.assertEqual(start, end - relativedelta(years=3))
        self.on_boundary(end, 'year')
        self.within_unit(end, 'year')

        start, end = parse_range('this year')
        self.on_boundary(start, 'year')
        self.close_to_now(end)
        self.within_unit(start, 'year')
Exemplo n.º 13
0
    def test_range_quarters(self):
        start, end = parse_range('last 3 q')
        self.assertTrue(end - start, parse_timedelta('3 q'))

        start, end = parse_range('previous 3 q')
        self.assertEquals(start, end - relativedelta(months=9))
        self.on_boundary(end, 'month')
        self.within_unit(end, 'quarter')
        self.assertTrue(end.month in [1, 4, 7, 10])

        start, end = parse_range('this q')
        self.on_boundary(start, 'month')
        self.close_to_now(end)
        self.within_unit(start, 'quarter')
        self.assertTrue(start.month in [1, 4, 7, 10])
Exemplo n.º 14
0
    def test_range_quarters(self):
        start, end = parse_range('last 3 q')
        self.assertTrue(end - start, parse_timedelta('3 q'))

        start, end = parse_range('previous 3 q')
        self.assertEqual(start, end - relativedelta(months=9))
        self.on_boundary(end, 'month')
        self.within_unit(end, 'quarter')
        self.assertTrue(end.month in [1, 4, 7, 10])

        start, end = parse_range('this q')
        self.on_boundary(start, 'month')
        self.close_to_now(end)
        self.within_unit(start, 'quarter')
        self.assertTrue(start.month in [1, 4, 7, 10])
Exemplo n.º 15
0
    def test_range_weeks(self):
        start, end = parse_range('last 3 weeks')
        self.assertTrue(end - start, parse_timedelta('3 weeks'))

        start, end = parse_range('previous 3 weeks')
        self.assertTrue(end - start, parse_timedelta('3 weeks'))
        self.on_boundary(end, 'day')
        self.within_unit(end, 'week')
        self.assertTrue(end.weekday() == 6)

        start, end = parse_range('this week')
        self.on_boundary(start, 'day')
        self.close_to_now(end)
        self.within_unit(start, 'week')
        self.assertTrue(start.weekday() == 6)

        start, end = parse_range('previous week', begin_monday=True)
        self.assertTrue(start.weekday() == 0)

        start, end = parse_range('this week', begin_monday=True)
        self.assertTrue(start.weekday() == 0)
Exemplo n.º 16
0
    def test_range_weeks(self):
        start, end = parse_range('last 3 weeks')
        self.assertTrue(end - start, parse_timedelta('3 weeks'))

        start, end = parse_range('previous 3 weeks')
        self.assertTrue(end - start, parse_timedelta('3 weeks'))
        self.on_boundary(end, 'day')
        self.within_unit(end, 'week')
        self.assertTrue(end.weekday() == 6)

        start, end = parse_range('this week')
        self.on_boundary(start, 'day')
        self.close_to_now(end)
        self.within_unit(start, 'week')
        self.assertTrue(start.weekday() == 6)

        start, end = parse_range('previous week', begin_monday=True)
        self.assertTrue(start.weekday() == 0)

        start, end = parse_range('this week', begin_monday=True)
        self.assertTrue(start.weekday() == 0)
Exemplo n.º 17
0
    def __init__(self, start=None, end=None, duration=None, time_range=None):
        """Initialize a TimeFilter object.

         :param start: integer, start time in epoch seconds
         :param end: integer, end time in epoch seconds
         :param duration: string, time duration, i.e. '1 hour'
         :param time_range: string, time range, i.e. 'last 1 hour'
            or '4/21/13 4:00 to 4/21/13 5:00'

        """
        invalid = False

        if not start and not end and not duration and not time_range:
            # when querying file or clip, usually no time filters are provided
            self.start = None
            self.end = None

        elif start and end:
            if duration or time_range:
                invalid = True
            else:
                self.start = str(start)
                self.end = str(end)

        elif time_range:
            if start or end or duration:
                invalid = True
            else:
                start, end = timeutils.parse_range(time_range)
                self.start = timeutils.datetime_to_seconds(start)
                self.end = timeutils.datetime_to_seconds(end)

        elif duration:
            if not start and not end:
                invalid = True
            else:
                td = timeutils.parse_timedelta(duration).total_seconds()
                if start:
                    self.start = str(start)
                    self.end = str(int(start + td))
                else:
                    self.start = str(int(end - td))
                    self.end = str(end)

        elif start or end:
            invalid = True

        if invalid:
            msg = ('Start/end timestamps can not be derived from start "{}" '
                   'end "{}" duration "{}" time_range "{}".'.format(
                       start, end, duration, time_range))
            raise AppResponseException(msg)
Exemplo n.º 18
0
    def parse_range(cls, string):
        """Creata a TimeFilter based on human readable string.

        :param str string: time string

        The ``string`` parameter can be any time range string
        such as:

        * ``12:00 PM to 1:00 PM``
        * ``last 2 weeks``

        """
        (start, end) = timeutils.parse_range(string)
        return cls(start, end)
Exemplo n.º 19
0
    def parse_range(cls, string):
        """Creata a TimeFilter based on human readable string.

        :param str string: time string

        The ``string`` parameter can be any time range string
        such as:

        * ``12:00 PM to 1:00 PM``
        * ``last 2 weeks``

        """
        (start, end) = timeutils.parse_range(string)
        return cls(start, end)
Exemplo n.º 20
0
 def parse_range(cls, s):
     """Take a range string `s` and return a TimeFilter object."""
     (start, end) = timeutils.parse_range(s)
     return cls(start, end)
Exemplo n.º 21
0
 def parse_range(cls, s):
     """Take a range string `s` and return a TimeFilter object."""
     (start, end) = timeutils.parse_range(s)
     return cls(start, end)