def poll_and_enqueue_data(self): ''' START 'DATA MANAGEMENT' ''' # pick up new data from mmap or other system (i.e. generated) new_data, new_data_is_empty, nbr_buffers_per_mmap_file = request_new_data(self.USE_MMAP, self.RANDOM_DATA, self.MMAP) # don't add empty data to the queue # don't use 'NBR_INDEPENDENT_CHANNELS' here, because we might be skipping this channel if sum(new_data_is_empty) != len(new_data): #print len(new_data[0][0]) #print new_data[1][0] append_data_to_plot_queue(self.plot_queue, new_data, nbr_buffers_per_mmap_file) ''' END 'DATA MANAGEMENT' ''' ''' debugging if new_data_is_empty[0] == 1: print 'new data is empty!' else: print ' NOT EMPTY!' ''' ''' auto-purge plot queue if feature is activated and limit is reached. '''
def update(self, dt): # update nPointsToUpdate points per `update()` call # TODO: handle cases where 'nPoints' is not a multiple of 'nPointsToUpdate' # (need to wrap around at the end of the list) ''' START 'DATA MANAGEMENT' ''' # pick up new data from mmap or other system (i.e. generated) new_data, new_data_is_empty, nbr_buffers_per_mmap_file = request_new_data( self.USE_MMAP, self.DATA, self.MMAP) # don't add empty data to the queue # don't use 'NBR_INDEPENDENT_CHANNELS' here, because we might be skipping this channel if sum(new_data_is_empty) != len(new_data): #print len(new_data[0][0]) #print new_data[1][0] append_data_to_plot_queue(self.plot_queue, new_data, nbr_buffers_per_mmap_file) ''' END 'DATA MANAGEMENT' ''' ''' debugging if new_data_is_empty[0] == 1: print 'new data is empty!' else: print ' NOT EMPTY!' ''' # Quit here if we are not supposed to draw anything new. This way the queue # keeps growing and we don't miss anything. if not self.DO_DRAW: return # don't purge entire queue - keep at least 'MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE' elements in queue. # this will give us a smoother plotting experience. queue_length = len(self.plot_queue) if queue_length < MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE: return ''' START 'dequeue buffers and prepare them for plotting' ''' # plot ALL buffers currently in queue. for j in xrange(queue_length): # dequeue buffers and update VBOs # raw_data is an array of channels containing the data per channel. raw_data = get_data_from_plot_queue(self.plot_queue) #print raw_data # update y values in main VBO - do this for each channel! current_pos_in_memory = gl_update_two_coordinates_in_VBO_static_view( raw_data, self.vbo_data, self.c, self.nPoints, self.nPointsToUpdate, BYTES_PER_POINT, BYTES_PER_COORDINATE, self.NBR_CHANNELS, self.x_coords) # Update position of vertical line - move it one 'nPointsToUpdate' # buffer ahead of currently updated position. calc modulo 'nPoints', # so that the position is in the range from 0 to nPoints. self.line_ver.curr_pos = (current_pos_in_memory + self.nPointsToUpdate) % self.nPoints # increase counter and modulo 'nPoints', so that 'c' doesn't grow out of bounds. self.c = (self.c + 1) % self.nPoints ''' END 'dequeue buffers and prepare them for plotting' ''' # set the resulting vertical line position. if self.SHOW_VERTICAL_LINE: self.line_ver.gl_update_line_x_value(self.line_ver.curr_pos) # auto-purge plot queue if feature is activated and limit is reached. if self.plot_queue_purge_if_size_limit_reached and len( self.plot_queue) > self.plot_queue_size_limit: self.plot_queue = setup_plotting_queue()
def update(self, dt): # update nPointsToUpdate points per `update()` call # TODO: handle cases where 'nPoints' is not a multiple of 'nPointsToUpdate' # (need to wrap around at the end of the list) """ START 'DATA MANAGEMENT' """ # pick up new data from mmap or other system (i.e. generated) new_data, new_data_is_empty, nbr_buffers_per_mmap_file = request_new_data(self.USE_MMAP, self.DATA, self.MMAP) # don't add empty data to the queue # don't use 'NBR_INDEPENDENT_CHANNELS' here, because we might be skipping this channel if sum(new_data_is_empty) != len(new_data): # print len(new_data[0][0]) # print new_data[1][0] append_data_to_plot_queue(self.plot_queue, new_data, nbr_buffers_per_mmap_file) """ END 'DATA MANAGEMENT' """ """ debugging if new_data_is_empty[0] == 1: print 'new data is empty!' else: print ' NOT EMPTY!' """ # Quit here if we are not supposed to draw anything new. This way the queue # keeps growing and we don't miss anything. if not self.DO_DRAW: return # don't purge entire queue - keep at least 'MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE' elements in queue. # this will give us a smoother plotting experience. queue_length = len(self.plot_queue) if queue_length < MIN_NBR_BUFFERS_NECESSARY_FOR_UPDATE: return """ START 'dequeue buffers and prepare them for plotting' """ # plot ALL buffers currently in queue. for j in xrange(queue_length): # dequeue buffers and update VBOs # raw_data is an array of channels containing the data per channel. raw_data = get_data_from_plot_queue(self.plot_queue) # print raw_data # update y values in main VBO - do this for each channel! current_pos_in_memory = gl_update_two_coordinates_in_VBO_static_view( raw_data, self.vbo_data, self.c, self.nPoints, self.nPointsToUpdate, BYTES_PER_POINT, BYTES_PER_COORDINATE, self.NBR_CHANNELS, self.x_coords, ) # Update position of vertical line - move it one 'nPointsToUpdate' # buffer ahead of currently updated position. calc modulo 'nPoints', # so that the position is in the range from 0 to nPoints. self.line_ver.curr_pos = (current_pos_in_memory + self.nPointsToUpdate) % self.nPoints # increase counter and modulo 'nPoints', so that 'c' doesn't grow out of bounds. self.c = (self.c + 1) % self.nPoints """ END 'dequeue buffers and prepare them for plotting' """ # set the resulting vertical line position. if self.SHOW_VERTICAL_LINE: self.line_ver.gl_update_line_x_value(self.line_ver.curr_pos) # auto-purge plot queue if feature is activated and limit is reached. if self.plot_queue_purge_if_size_limit_reached and len(self.plot_queue) > self.plot_queue_size_limit: self.plot_queue = setup_plotting_queue()