def test_set_time(self): ''' Call the set_time function to improve (functional) code coverage ''' blackboard = Blackboard() simulator = DataSimulator( blackboard ) simulator.set_time(5)
def test_reset(self): ''' Call the reset function to improve (functional) code coverage ''' blackboard = Blackboard() simulator = DataSimulator(blackboard) simulator.reset()
def test_get_current_time(self): ''' Call the get_current_time function to improve (functional) code coverage ''' blackboard = Blackboard() simulator = DataSimulator(blackboard) self.assertEqual(simulator.get_current_time(), -1)
def test_get_current_time(self): ''' Call the get_current_time function to improve (functional) code coverage ''' blackboard = Blackboard() simulator = DataSimulator( blackboard ) self.assertEqual(simulator.get_current_time(), -1)
def test_set_time(self): ''' Call the set_time function to improve (functional) code coverage ''' blackboard = Blackboard() simulator = DataSimulator(blackboard) simulator.set_time(5)
def test_reset(self): ''' Call the reset function to improve (functional) code coverage ''' blackboard = Blackboard() simulator = DataSimulator( blackboard ) simulator.reset()
def test_set_simulation_data(self): ''' Verify if the simulation data can be set Only function is called to improve (functional) code coverage, so no verification yet ''' blackboard = Blackboard() simulator = DataSimulator( blackboard ) sim_data = self.create_simulation_data() simulator.set_simulation_data(sim_data)
def test_set_simulation_data(self): ''' Verify if the simulation data can be set Only function is called to improve (functional) code coverage, so no verification yet ''' blackboard = Blackboard() simulator = DataSimulator(blackboard) sim_data = self.create_simulation_data() simulator.set_simulation_data(sim_data)
def test_get_set_simulation_state(self): ''' Verify if the getting and setting of simulation states works correctly ''' blackboard = Blackboard() simulator = DataSimulator(blackboard) # Set all the states and verify if the state is set correctly for _, value in self.states.iteritems(): simulator.set_state(value) self.assertEqual(simulator.get_simulation_state(), value)
def test_get_set_simulation_state(self): ''' Verify if the getting and setting of simulation states works correctly ''' blackboard = Blackboard() simulator = DataSimulator( blackboard ) # Set all the states and verify if the state is set correctly for _, value in self.states.iteritems(): simulator.set_state(value) self.assertEqual(simulator.get_simulation_state(), value)
def __init__(self, arg0, marker_pattern=None ): self._counters = [] self._done = [] self._marker_pattern = marker_pattern self._current_time = 0 self.logger = logging.getLogger() if isinstance(arg0, DataSimulator): DataSimulator.__init__( self, arg0.blackboard ) self._observers = arg0._observers else: DataSimulator.__init__( self, arg0 ) Subject.__init__( self )
def __init__(self, arg0, marker_pattern=None): self._counters = [] self._done = [] self._marker_pattern = marker_pattern self._current_time = 0 self.logger = logging.getLogger() if isinstance(arg0, DataSimulator): DataSimulator.__init__(self, arg0.blackboard) self._observers = arg0._observers else: DataSimulator.__init__(self, arg0) Subject.__init__(self)
def test_pause(self): ''' Call the pause function to improve (functional) code coverage ''' blackboard = Blackboard() simulator = DataSimulator(blackboard) simulator.set_state(self.states.get('PLAYING')) simulator.pause() self.assertEqual(simulator.get_simulation_state(), self.states.get('PAUSED'))
def test_pause(self): ''' Call the pause function to improve (functional) code coverage ''' blackboard = Blackboard() simulator = DataSimulator( blackboard ) simulator.set_state(self.states.get('PLAYING')) simulator.pause() self.assertEqual(simulator.get_simulation_state(), self.states.get('PAUSED'))
def file_open(self, index=0): """ Open the selected file (load filename for processing) """ _eeg_type = 1 # Gefilterde data ( notch + lpf ) _eega_type = 2 # Ongefilterde data # Options for opening or saving a file root_dir = os.path.relpath('..\\..\\data\\') file_opt = options = {} options['defaultextension'] = '.h5' options['filetypes'] = [('HDF5 files', '.hdf5'), ('All files', '*.*')] options['initialdir'] = root_dir options['title'] = 'Select a recorded EEG file' _file_path_string = tkFileDialog.askopenfilename(**file_opt) # return if no file was selected (Cancel or Esc pressed) if len(_file_path_string) <= 0: return self.view._simulate_filenames[index] = _file_path_string # Initialize data reader reader = HDFReader() # Reading two datafiles try: # Read data from selected file [mat, frequencies, markers] = reader.read(_file_path_string) _data = [] # Get data from 4 channels and create simulator for given index for i in self.model.channels: try: # Files with timestamps chan_data = [v[:2] for v in mat[i - 1][_eega_type]] self.model.simulators[index] = TimedSimulator( self.model.simulators[index], marker_pattern=PatternStrings.MARKERS) except Exception as e: # Files without timestamps chan_data = [v for v in mat[i - 1][_eega_type]] self.model.simulators[index] = DataSimulator( self.model.simulators[index]) _data.append(chan_data) # if markers.any(): if markers != None: _data.append(markers) # Get simulator patterns _eeg_chans = [(PatternStrings.SIGNAL_EEG + '%d' % (index) + PatternStrings.CHANNEL + '%d' % (i)) for i in self.model.channels] # if markers.any(): if markers != None: # TODO: Check why .any is not working, because now a 'FutureWarning' is raised. _eeg_chans.append(PatternStrings.MARKERS) _interval = 1. / frequencies[_eeg_type] self.model.simulators[index].set_simulation_data(_data) self.model.simulators[index].set_simulation_interval(_interval) self.model.simulators[index].set_patterns(_eeg_chans) except IOError as e: self.logger.log(logging.ERROR, (__file__, ": IOError = ", e)) except ValueError as e: self.logger.log(logging.ERROR, (__file__, ": ValueError = ", e)) except TypeError as e: self.logger.log(logging.ERROR, (__file__, ": TypeError = ", e)) self.clear_filename(index) self.notify()
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()
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_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()
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()