code: def cluster_and_update(records, group_dist=50, eps=100):
      
      # Run the DBSCAN algorithm with all stop locations and 1 minimal point.
      stops = get_stops(records, group_dist)
      labels = dbscan([s['location'] for s in stops], eps, 1)
  
      # Associate all records with their new antenna
      antennas = {}
      for i, stop in enumerate(stops):
          antenna_id = labels[i]
          for record in stop['records']:
              record.position.antenna = antenna_id
  
          antennas[antenna_id] = stop['location']
  
      all_records = sum(len(stop['records']) for stop in stops)
      if all_records != len(records):
          raise ValueError("get_antennas has {} records instead of {} "
                           "initially.".format(all_records, len(records)))
  
      return antennas
docs: Update records, by clustering their positions using the DBSCAN algorithm.
      Returns a dictionnary associating new antenna identifiers to (lat, lon)
      location tuples.
  
      .. note:: Use this function to cluster fine-grained GPS records.
  
      Parameters
      ----------
      records : list
          A list of Record objects ordered by non-decreasing datetime
      group_dist : float, default: 50
          Minimum distance (in meters) to switch to a new stop.
      eps : float, default: 100
          The eps parameter for the DBSCAN algorithm.