Beispiel #1
0
    def test_get_instantaneous_filtered(self):
        from datetime import datetime
        now = datetime(2010, 5, 13, 2, 42, 30)
        queue = self._make_one()
        fut = queue.get_instantaneous_frequency
        self.assertAlmostEqual(fut('Harry', now), 0.0)

        message = DummyMessage('one')
        message['Date'] = 'Wed, 13 May 2010 02:42:00'
        message['A'] = 'foo'
        message['B'] = 'bar'
        queue.collect_frequency_data(message, headers=('A','B'))

        message = DummyMessage('two')
        message['Date'] = 'Wed, 13 May 2010 02:42:15'
        message['A'] = 'foo'
        message['B'] = 'baz'
        queue.collect_frequency_data(message, headers=('A', 'B'))

        self.assertAlmostEqual(fut('Harry', now), 4.0)
        self.assertAlmostEqual(fut('Harry', now,
                                   headers={'A': 'foo', 'B': 'baz'}), 4.0)
        self.assertAlmostEqual(fut('Harry', now,
                                   headers={'A': 'foo', 'B': 'bar'}), 2.0)
        self.assertAlmostEqual(fut('Harry', now, {'A': 'mickey'}), 0.0)
Beispiel #2
0
    def test_get_instantaneous_filtered(self):
        from datetime import datetime
        now = datetime(2010, 5, 13, 2, 42, 30)
        queue = self._make_one()
        fut = queue.get_instantaneous_frequency
        self.assertAlmostEqual(fut('Harry', now), 0.0)

        message = DummyMessage('one')
        message['Date'] = 'Wed, 13 May 2010 02:42:00'
        message['A'] = 'foo'
        message['B'] = 'bar'
        queue.collect_frequency_data(message, headers=('A', 'B'))

        message = DummyMessage('two')
        message['Date'] = 'Wed, 13 May 2010 02:42:15'
        message['A'] = 'foo'
        message['B'] = 'baz'
        queue.collect_frequency_data(message, headers=('A', 'B'))

        self.assertAlmostEqual(fut('Harry', now), 4.0)
        self.assertAlmostEqual(
            fut('Harry', now, headers={
                'A': 'foo',
                'B': 'baz'
            }), 4.0)
        self.assertAlmostEqual(
            fut('Harry', now, headers={
                'A': 'foo',
                'B': 'bar'
            }), 2.0)
        self.assertAlmostEqual(fut('Harry', now, {'A': 'mickey'}), 0.0)
Beispiel #3
0
 def test_get_instantaneous_frequency_infinite(self):
     from datetime import datetime
     now = datetime(2010, 5, 13, 2, 42, 00)
     queue = self._make_one()
     fut = queue.get_instantaneous_frequency
     self.assertAlmostEqual(fut('Harry', now), 0.0)
     message = DummyMessage('one')
     message['Date'] = 'Wed, 13 May 2010 02:42:00'
     queue.collect_frequency_data(message)
     self.assertEqual(fut('Harry', now), float('inf'))
Beispiel #4
0
 def test_get_instantaneous_frequency_infinite(self):
     from datetime import datetime
     now = datetime(2010, 5, 13, 2, 42, 00)
     queue = self._make_one()
     fut = queue.get_instantaneous_frequency
     self.assertAlmostEqual(fut('Harry', now), 0.0)
     message = DummyMessage('one')
     message['Date'] = 'Wed, 13 May 2010 02:42:00'
     queue.collect_frequency_data(message)
     self.assertEqual(fut('Harry', now), float('inf'))
Beispiel #5
0
 def test_get_average_frequency(self):
     from datetime import datetime
     from datetime import timedelta
     now = datetime(2010, 5, 12, 2, 43)
     interval = timedelta(minutes=1)
     queue = self._make_one()
     fut = queue.get_average_frequency
     self.assertAlmostEqual(fut('Harry', now, interval), 0.0)
     queue.collect_frequency_data(DummyMessage('one'))
     self.assertAlmostEqual(fut('Harry', now, interval), 1.0)
     queue.collect_frequency_data(DummyMessage('two'))
     self._set_now(now)
     now += timedelta(minutes=1)
     interval = timedelta(minutes=2)
     queue.collect_frequency_data(DummyMessage('three'))
     queue.collect_frequency_data(DummyMessage('four'))
     self.assertAlmostEqual(fut('Harry', now, interval), 2.0)
     now += timedelta(minutes=1)
     self.assertAlmostEqual(fut('Harry', now, interval), 1.0)
     now += timedelta(minutes=1)
     self.assertAlmostEqual(fut('Harry', now, interval), 0.0)
Beispiel #6
0
 def test_get_average_frequency(self):
     from datetime import datetime
     from datetime import timedelta
     now = datetime(2010, 5, 12, 2, 43)
     interval = timedelta(minutes=1)
     queue = self._make_one()
     fut = queue.get_average_frequency
     self.assertAlmostEqual(fut('Harry', now, interval), 0.0)
     queue.collect_frequency_data(DummyMessage('one'))
     self.assertAlmostEqual(fut('Harry', now, interval), 1.0)
     queue.collect_frequency_data(DummyMessage('two'))
     self._set_now(now)
     now += timedelta(minutes=1)
     interval = timedelta(minutes=2)
     queue.collect_frequency_data(DummyMessage('three'))
     queue.collect_frequency_data(DummyMessage('four'))
     self.assertAlmostEqual(fut('Harry', now, interval), 2.0)
     now += timedelta(minutes=1)
     self.assertAlmostEqual(fut('Harry', now, interval), 1.0)
     now += timedelta(minutes=1)
     self.assertAlmostEqual(fut('Harry', now, interval), 0.0)