code: def positions_binning(records):
      
      def get_key(d):
          return (d.year, d.day, d.hour, d.minute // 30)
  
      chunks = itertools.groupby(records, key=lambda r: get_key(r.datetime))
  
      for _, items in chunks:
          positions = [i.position for i in items]
          # Given the low number of positions per chunk of 30 minutes, and
          # the need for a deterministic value, we use max and not Counter
          yield max(positions, key=positions.count)
docs: Bin records by chunks of 30 minutes, returning the most prevalent position.
  
      If multiple positions have the same number of occurrences
      (during 30 minutes), we select the last one.