def streamData(sample):
  
  global last_values
  
  global tick
      
  # check packet skipped
  global last_id
  # TODO: duplicate packet if skipped to stay sync
  if sample.id != last_id + 1:
    print "time", tick, ": paquet skipped!"
  if sample.id == 255:
    last_id = -1
  else:
    last_id = sample.id
  
  # update counters
  global nb_samples_in, nb_samples_out
  nb_samples_in = nb_samples_in + 1
  
  # check for duplication, by default 1 (...which is *no* duplication of the one current sample)
  global leftover_duplications
  
  # first method with sampling rate and elapsed time (depends on system clock accuracy)
  if (0 > SAMPLING_RATE):
    # elapsed time since last call, update tick
    now = timeit.default_timer()
    elapsed_time = now - tick;
    # now we have to compute how many times we should send data to keep up with sample rate (oversampling)
    leftover_duplications = SAMPLING_RATE * elapsed_time + leftover_duplications - 1
    tick = now
  # second method with a samplin factor (depends on openbci accuracy)
  elif SAMPLING_FACTOR > 0:
    leftover_duplications = SAMPLING_FACTOR + leftover_duplications - 1
  #print "needed_duplications: ", needed_duplications, "leftover_duplications: ", leftover_duplications
  # If we need to insert values, will interpolate between current packet and last one
  # FIXME: ok, at the moment because we do packet per packet treatment, only handles nb_duplications == 1 for more interpolation is bad and sends nothing
  if (leftover_duplications > 1):
    leftover_duplications = leftover_duplications - 1
    interpol_values = list(last_values)
    for i in range(0,len(interpol_values)):
      # OK, it's a very rough interpolation
      interpol_values[i] = (last_values[i] + sample.channel_data[i]) / 2
    if DEBUG:
      print "  --"
      print "  last values: ", last_values
      print "  interpolation: ", interpol_values
      print "  current sample: ", sample.channel_data
    # send to clients interpolated sample
    #leftover_duplications = 0
    server.broadcast_values(interpol_values)
    nb_samples_out = nb_samples_out + 1
    
  # send to clients current sample
  server.broadcast_values(sample.channel_data)
  nb_samples_out = nb_samples_out + 1
  
  # save current values for possible interpolation
  last_values = list(sample.channel_data)
dataset/ETHPy150Open OpenBCI/OpenBCI_Python/scripts/stream_data.py/streamData/swapped operands of `>`