Пример #1
0
    def test_add_signal_points_by_name(self):
        # with a signal
        signal = Signal.objects.create(name='a_signal',
                                       local_computer=self.local_computer)
        n1 = Signal.utc_to_millisec(datetime.datetime.now(tz=pytz.UTC))
        n1 = Signal.utc_to_millisec(datetime.datetime.now(tz=pytz.UTC))
        n2 = Signal.utc_to_millisec(
            datetime.datetime.now(tz=pytz.UTC) + datetime.timedelta(seconds=1))
        json_data = [[1, n1], [2, n2]]
        self.data_connection.add_signal_points_by_name(signal.name, json_data)

        # should find persisted data
        points = signal.get_data()
        self.assertEqual(2, len(points))
        self.assertEqual(1, points[0][0])
        self.assertEqual(2, points[1][0])
        self.assertAlmostEqual(n1, points[0][1], 2)
        self.assertAlmostEqual(n2, points[1][1], 2)

        # should download points by name
        downloaded_points = self.data_connection.get_signal_points_by_name(
            signal.name)
        self.assertEqual(2, len(downloaded_points))
        self.assertEqual(1, downloaded_points[0][0])
        self.assertEqual(2, downloaded_points[1][0])
        self.assertAlmostEqual(n1, downloaded_points[0][1], 2)
        self.assertAlmostEqual(n2, downloaded_points[1][1], 2)
Пример #2
0
    def test_add_get_points(self):
        signal = Signal.objects.create(system=self.system, name='a_signal')
        n1 = Signal.utc_to_millisec(tmz.now())
        n2 = Signal.utc_to_millisec(tmz.now() + tmz.timedelta(seconds=1))
        signal.add_points([[1, n1], [2, n2]])
        points = signal.get_data()

        self.assertEqual(2, len(points))
        self.assertEqual(1, points[0][0])
        self.assertEqual(2, points[1][0])
        self.assertAlmostEqual(n1, points[0][1], 2)
        self.assertAlmostEqual(n2, points[1][1], 2)
Пример #3
0
    def test_add_get_points(self):
        signal = Signal.objects.create(system=self.system,
                                       name='a_signal')
        n1 = Signal.utc_to_millisec(tmz.now())
        n2 = Signal.utc_to_millisec(tmz.now() + tmz.timedelta(seconds=1))
        signal.add_points([[1, n1], [2, n2]])
        points = signal.get_data()

        self.assertEqual(2, len(points))
        self.assertEqual(1,  points[0][0])
        self.assertEqual(2, points[1][0])
        self.assertAlmostEqual(n1, points[0][1],2)
        self.assertAlmostEqual(n2, points[1][1],2)
Пример #4
0
 def test_append_points(self):
     signal = Signal.objects.create(system=self.system, name='a_signal')
     n1 = Signal.utc_to_millisec(tmz.now())
     n2 = Signal.utc_to_millisec(tmz.now() + tmz.timedelta(seconds=1))
     a = reverse('signal_data', args=(signal.id,))
     json_data = json.dumps([[1, n1], [2, n2]])
     response = self.client.post(reverse('signal_data', args=(signal.id,)), data=json_data,
                                 content_type="application/json")
     points = signal.get_data()
     self.assertEqual(2, len(points))
     self.assertEqual(1,  points[0][0])
     self.assertEqual(2, points[1][0])
     self.assertAlmostEqual(n1, points[0][1], 2)
     self.assertAlmostEqual(n2, points[1][1], 2)
Пример #5
0
    def test_get_points(self):
        signal = Signal.objects.create(system=self.system, name='a_signal')
        n1 = Signal.utc_to_millisec(tmz.now())
        n2 = Signal.utc_to_millisec(tmz.now() + tmz.timedelta(seconds=1))
        signal.add_points([[1, n1], [2, n2]])

        a = reverse('signal_data', args=(signal.id,))
        response = self.client.get(reverse('signal_data', args=(signal.id,)))
        points = json.loads(response.content)

        self.assertEqual(2, len(points))
        self.assertEqual(1,  points[0][0])
        self.assertEqual(2, points[1][0])
        self.assertAlmostEqual(n1, points[0][1], 2)
        self.assertAlmostEqual(n2, points[1][1], 2)
Пример #6
0
    def test_add_multivalue_points(self):
        signal = Signal.objects.create(system=self.system, name='a_signal')
        n1 = Signal.utc_to_millisec(tmz.now())
        n2 = Signal.utc_to_millisec(tmz.now() + tmz.timedelta(seconds=1))

        signal.add_points([[1.0, 2.0, n1], [3.0, float('nan'), n2]])

        points = signal.get_data()
        self.assertEqual(2, len(points))

        self.assertEqual(3, len(points[0]))
        self.assertEqual(2.0, points[0][1])
        self.assertAlmostEqual(n1, points[0][2], 2)

        self.assertEqual(3, len(points[1]))
        self.assertTrue(math.isnan(points[1][1]))
        self.assertAlmostEqual(n2, points[1][2], 2)
Пример #7
0
    def test_add_multivalue_points(self):
        signal = Signal.objects.create(system=self.system,
                                       name='a_signal')
        n1 = Signal.utc_to_millisec(tmz.now())
        n2 = Signal.utc_to_millisec(tmz.now() + tmz.timedelta(seconds=1))

        signal.add_points([[1.0, 2.0, n1],[3.0, float('nan'), n2]])

        points = signal.get_data()
        self.assertEqual(2, len(points))

        self.assertEqual(3, len(points[0]))
        self.assertEqual(2.0, points[0][1])
        self.assertAlmostEqual(n1, points[0][2],2)

        self.assertEqual(3, len(points[1]))
        self.assertTrue(math.isnan(points[1][1]))
        self.assertAlmostEqual(n2, points[1][2], 2)
Пример #8
0
    def test_find_signals_with_data(self):

        experiment = Experiment.objects.create(local_computer=self.local_computer, name='an_experiment')
        signal = Signal.objects.create(local_computer=self.local_computer, name='a_signal', experiment=experiment)
        # with data
        n1 = Signal.utc_to_millisec(tmz.now())
        n2 = Signal.utc_to_millisec(tmz.now() + tmz.timedelta(seconds=1))
        signal.add_points([[1, n1], [2, n2]])

        # when requesting data
        response = self.client.get(reverse('FindSignals', args=(self.local_computer.id,)),
                                   data={INCLUDE_DATA:'true'})
        signals = json.loads(response.content)
        self.assertEqual(1, len(signals))

        # should see data
        points = signals[0]['data']
        self.assertEqual(2, len(points))
        self.assertEqual(1,  points[0][0])
        self.assertEqual(2, points[1][0])
        self.assertAlmostEqual(n1, points[0][1], 2)
        self.assertAlmostEqual(n2, points[1][1], 2)
Пример #9
0
    def test_add_signal_points(self):
        # with a signal and persisted data
        signal = Signal.objects.create(name='a_signal')
        n1 = Signal.utc_to_millisec(datetime.datetime.now(tz=pytz.UTC))
        n2 = Signal.utc_to_millisec(datetime.datetime.now(tz=pytz.UTC) + datetime.timedelta(seconds=1))
        json_data = [[1, n1], [2, n2]]
        self.data_connection.add_signal_points(signal.id, json_data)

        # should find persisted data
        points = signal.get_data()
        self.assertEqual(2, len(points))
        self.assertEqual(1,  points[0][0])
        self.assertEqual(2, points[1][0])
        self.assertAlmostEqual(n1, points[0][1], 2)
        self.assertAlmostEqual(n2, points[1][1], 2)

        # should download points by id
        downloaded_points = self.data_connection.get_signal_points(signal.id)
        self.assertEqual(2, len(downloaded_points))
        self.assertEqual(1,  downloaded_points[0][0])
        self.assertEqual(2, downloaded_points[1][0])
        self.assertAlmostEqual(n1, downloaded_points[0][1], 2)
        self.assertAlmostEqual(n2, downloaded_points[1][1], 2)
Пример #10
0
 def test_utc_time_functions(self):
     n1 = tmz.now()
     n1_ms = Signal.utc_to_millisec(n1)
     n1_back = Signal.millisec_to_utc(n1_ms)
     self.assertEqual(n1, n1_back)
Пример #11
0
 def test_utc_time_functions(self):
     n1 = tmz.now()
     n1_ms = Signal.utc_to_millisec(n1)
     n1_back = Signal.millisec_to_utc(n1_ms)
     self.assertEqual(n1, n1_back)