def _test_set_data_and_playback_states(self):
     bb = Blackboard()
     sim = DataSimulator( bb )
     
     reader = HDFReader();
      
     filename = filenames[5][0]
      
     # Reading two datafiles
     [ mat, frequencies, _ ] = reader.read(filename)       # Read data from first data file
     data = [ np.asarray( mat[i-1][ 1 ] ) for i in range(1,9) ]       # get data from selected channels
     patterns = ['/EEG/channel_%d' % (i) for i in range(1,9) ]
     
     interval = 1. / frequencies[ 1 ]  
     
     sim.set_simulation_data(data)
     sim.set_simulation_interval(interval)
     sim.set_patterns(patterns)
     
     self.assertEqual(sim.get_simulation_state(), DataSimulator.IDLE, "Simulator should be idle now")
     sim.start()
     time.sleep(.1)
     self.assertEqual(sim.get_simulation_state(), DataSimulator.PLAYING, "Simulator should be playing now")
     sim.pause()
     time.sleep(.1)
     self.assertEqual(sim.get_simulation_state(), DataSimulator.PAUSED, "Simulator should be paused now")
     sim.start()
     time.sleep(.1)
     self.assertEqual(sim.get_simulation_state(), DataSimulator.PLAYING, "Simulator should be playing now")
     sim.stop()
     time.sleep(.1)
     self.assertEqual(sim.get_simulation_state(), DataSimulator.IDLE, "Simulator should be stopped now")
 
     self.assertTrue(bb.get_count(patterns[0]) > 0, "Samples should be received on blackboard")
Пример #2
0
    def test_play_stop(self):
        blackboard = Blackboard()
        simulator = DataSimulator(blackboard)

        # Prepare the simulator preconditions
        simulator.set_simulation_data("test")
        simulator.set_patterns("test")
        simulator.set_simulation_interval(1)

        simulator.start()
        simulator.stop()

        simulator.set_state(self.states.get('PAUSED'))
        simulator.start()
        simulator.stop()
 def test_play_stop(self):
     blackboard = Blackboard()
     simulator  = DataSimulator( blackboard )             
     
     # Prepare the simulator preconditions
     simulator.set_simulation_data("test")
     simulator.set_patterns("test")
     simulator.set_simulation_interval(1)
     
     simulator.start()
     simulator.stop()
     
     simulator.set_state(self.states.get('PAUSED'))
     simulator.start()
     simulator.stop()
Пример #4
0
    def _test_get_time(self):
        bb = Blackboard()
        sim = DataSimulator(bb)

        reader = HDFReader()

        filename = filenames[5][0]

        # Reading two datafiles
        [mat, frequencies,
         _] = reader.read(filename)  # Read data from first data file
        data = [np.asarray(mat[i - 1][1])
                for i in range(1, 9)]  # get data from selected channels
        patterns = ['/EEG/channel_%d' % (i) for i in range(1, 9)]

        interval = 1. / frequencies[1]

        sim.set_simulation_data(data)
        sim.set_simulation_interval(interval)
        sim.set_patterns(patterns)

        total_time = sim.get_total_time()

        start_time = sim.get_current_time()
        self.assertEquals(start_time, 0, 'Time should be zero before playback')

        sim.start()

        time.sleep(3)

        now_time = sim.get_current_time()
        self.assertAlmostEquals(
            now_time,
            3,
            msg='Time should be close to 3 after 3 seconds playback. Is %f' %
            now_time,
            delta=.05)

        sim.set_time(total_time - 2)
        self.assertTrue(sim.get_simulation_state() is DataSimulator.PLAYING,
                        'Should be playing after setting time')

        time.sleep(3)

        self.assertTrue(sim.get_simulation_state() is DataSimulator.IDLE,
                        'Should be done playing')

        sim.stop()
Пример #5
0
    def _test_set_data_and_playback_states(self):
        bb = Blackboard()
        sim = DataSimulator(bb)

        reader = HDFReader()

        filename = filenames[5][0]

        # Reading two datafiles
        [mat, frequencies,
         _] = reader.read(filename)  # Read data from first data file
        data = [np.asarray(mat[i - 1][1])
                for i in range(1, 9)]  # get data from selected channels
        patterns = ['/EEG/channel_%d' % (i) for i in range(1, 9)]

        interval = 1. / frequencies[1]

        sim.set_simulation_data(data)
        sim.set_simulation_interval(interval)
        sim.set_patterns(patterns)

        self.assertEqual(sim.get_simulation_state(), DataSimulator.IDLE,
                         "Simulator should be idle now")
        sim.start()
        time.sleep(.1)
        self.assertEqual(sim.get_simulation_state(), DataSimulator.PLAYING,
                         "Simulator should be playing now")
        sim.pause()
        time.sleep(.1)
        self.assertEqual(sim.get_simulation_state(), DataSimulator.PAUSED,
                         "Simulator should be paused now")
        sim.start()
        time.sleep(.1)
        self.assertEqual(sim.get_simulation_state(), DataSimulator.PLAYING,
                         "Simulator should be playing now")
        sim.stop()
        time.sleep(.1)
        self.assertEqual(sim.get_simulation_state(), DataSimulator.IDLE,
                         "Simulator should be stopped now")

        self.assertTrue(
            bb.get_count(patterns[0]) > 0,
            "Samples should be received on blackboard")
 def _test_get_time(self):
     bb = Blackboard()
     sim = DataSimulator( bb )
     
     reader = HDFReader();
      
     filename = filenames[5][0]
      
     # Reading two datafiles
     [ mat, frequencies, _ ] = reader.read(filename)       # Read data from first data file
     data = [ np.asarray( mat[i-1][ 1 ] ) for i in range(1,9) ]       # get data from selected channels
     patterns = ['/EEG/channel_%d' % (i) for i in range(1,9) ]
     
     interval = 1. / frequencies[ 1 ]  
     
     sim.set_simulation_data(data)
     sim.set_simulation_interval(interval)
     sim.set_patterns(patterns)
     
     total_time = sim.get_total_time()
     
     start_time = sim.get_current_time()
     self.assertEquals(start_time, 0, 'Time should be zero before playback')
     
     sim.start()
     
     time.sleep( 3 )
     
     now_time = sim.get_current_time()
     self.assertAlmostEquals(now_time, 3, msg='Time should be close to 3 after 3 seconds playback. Is %f'%now_time, delta=.05)
  
     sim.set_time( total_time - 2 )
     self.assertTrue( sim.get_simulation_state() is DataSimulator.PLAYING, 'Should be playing after setting time')
     
     time.sleep(3)
     
     self.assertTrue( sim.get_simulation_state() is DataSimulator.IDLE, 'Should be done playing')
     
     sim.stop()