<commit_before>class ServerFinder

  attr_reader :user, :starts_at, :ends_at

  def initialize(user, starts_at, ends_at)
    @user                       = user
    @starts_at                  = starts_at
    @ends_at                    = ends_at
  end

  def servers
    Server.active.reservable_by_user(user).select do |server|
      CollisionFinder.new(server, reservation).colliding_reservations.none?
    end
  end

  def user_already_reserved_a_server_in_range?
    CollisionFinder.new(user, reservation).colliding_reservations.any?
  end

  def self.available_for_user(user)
    servers = []
    user.groups.each do |group|
      servers << {:name => group.name, :servers => Server.active.reservable_by_user(user).in_groups([group])}
    end

    free_servers = Server.active.reservable_by_user(user).without_group.ordered
    servers << {:name => "Everyone", :servers => free_servers}
  end

  private

  def reservation
    @reservation ||= Reservation.new(:starts_at => starts_at, :ends_at => ends_at, :user_id => user.id)
  end

end<commit_msg>order found group servers by their position,name<commit_after>class ServerFinder

  attr_reader :user, :starts_at, :ends_at

  def initialize(user, starts_at, ends_at)
    @user                       = user
    @starts_at                  = starts_at
    @ends_at                    = ends_at
  end

  def servers
    Server.active.reservable_by_user(user).select do |server|
      CollisionFinder.new(server, reservation).colliding_reservations.none?
    end
  end

  def user_already_reserved_a_server_in_range?
    CollisionFinder.new(user, reservation).colliding_reservations.any?
  end

  def self.available_for_user(user)
    servers = []
    user.groups.each do |group|
      servers << {:name => group.name, :servers => Server.active.reservable_by_user(user).in_groups([group]).ordered}
    end

    free_servers = Server.active.reservable_by_user(user).without_group.ordered
    servers << {:name => "Everyone", :servers => free_servers}
  end

  private

  def reservation
    @reservation ||= Reservation.new(:starts_at => starts_at, :ends_at => ends_at, :user_id => user.id)
  end

end
{'fraction_non_alphanumeric': 0.10320781032078104, 'fraction_numerical': 0.0, 'mean_word_length': 3.219607843137255, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5498690', 'n_tokens_mistral': 716, 'n_tokens_neox': 697, 'n_words': 131}