docs: def connect_mv_generators(network):
      """Connect MV generators to existing grids.
  
      This function searches for unconnected generators in MV grids and connects them.
  
      It connects
  
          * generators of voltage level 4
              * to HV-MV station
  
          * generators of voltage level 5
              * with a nom. capacity of <=30 kW to LV loads of type residential
              * with a nom. capacity of >30 kW and <=100 kW to LV loads of type
                  retail, industrial or agricultural
              * to the MV-LV station if no appropriate load is available (fallback)
  
      Parameters
      ----------
      network : :class:`~.grid.network.Network`
          The eDisGo container object
  
      Notes
      -----
      Adapted from `Ding0 <https://github.com/openego/ding0/blob/\
          21a52048f84ec341fe54e0204ac62228a9e8a32a/\
          ding0/grid/mv_grid/mv_connect.py#L820>`_.
      """
  
      # get params from config
      buffer_radius = int(network.config[
                              'grid_connection']['conn_buffer_radius'])
      buffer_radius_inc = int(network.config[
                                  'grid_connection']['conn_buffer_radius_inc'])
  
      # get standard equipment
      std_line_type = network.equipment_data['mv_cables'].loc[
          network.config['grid_expansion_standard_equipment']['mv_line']]
  
      for geno in sorted(network.mv_grid.graph.nodes_by_attribute('generator'),
                         key=lambda _: repr(_)):
          if nx.is_isolate(network.mv_grid.graph, geno):
  
              # ===== voltage level 4: generator has to be connected to MV station =====
              if geno.v_level == 4:
  
                  line_length = calc_geo_dist_vincenty(network=network,
                                                       node_source=geno,
                                                       node_target=network.mv_grid.station)
  
                  line = Line(id=random.randint(10**8, 10**9),
                              type=std_line_type,
                              kind='cable',
                              quantity=1,
                              length=line_length / 1e3,
                              grid=network.mv_grid)
  
                  network.mv_grid.graph.add_edge(network.mv_grid.station,
                                                 geno,
                                                 line=line,
                                                 type='line')
  
                  # add line to equipment changes to track costs
                  _add_cable_to_equipment_changes(network=network,
                                                  line=line)
  
              # ===== voltage level 5: generator has to be connected to MV grid (next-neighbor) =====
              elif geno.v_level == 5:
  
                  # get branches within a the predefined radius `generator_buffer_radius`
                  branches = calc_geo_lines_in_buffer(network=network,
                                                      node=geno,
                                                      grid=network.mv_grid,
                                                      radius=buffer_radius,
                                                      radius_inc=buffer_radius_inc)
  
                  # calc distance between generator and grid's lines -> find nearest line
                  conn_objects_min_stack = _find_nearest_conn_objects(network=network,
                                                                      node=geno,
                                                                      branches=branches)
  
                  # connect!
                  # go through the stack (from nearest to most far connection target object)
                  generator_connected = False
                  for dist_min_obj in conn_objects_min_stack:
                      target_obj_result = _connect_mv_node(network=network,
                                                           node=geno,
                                                           target_obj=dist_min_obj)
  
                      if target_obj_result is not None:
                          generator_connected = True
                          break
  
                  if not generator_connected:
                      logger.debug(
                          'Generator {0} could not be connected, try to '
                          'increase the parameter `conn_buffer_radius` in '
                          'config file `config_grid.cfg` to gain more possible '
                          'connection points.'.format(geno))