<commit_before>class DashboardGrid
  DEFAULT_LOCATION_GRID_SIZE = 63

  class << self
    def generate(request_params={})
      new(request_params).generate
    end
  end

  def initialize(request_params)
    @request_params = request_params
    @tags = request_params[:tags]
    @locations = request_params[:view]
    @projects = find_projects.sort_by { |p| p.name.to_s.downcase }
  end

  def generate
    if @locations
      generate_with_locations
    else
      generate_without_locations
    end
  end

  private

  def generate_with_locations
    locations = []
    @projects.group_by(&:location).keys.sort{ |l1,l2| group_sort(l1,l2) }.each do |location|
      location_projects = location_groups[location]
      locations << SubGridCollection.new([Location.new(location(location_projects))] + location_projects)
    end
    GridCollection.new(locations.flatten, DEFAULT_LOCATION_GRID_SIZE).each_slice(9).to_a.transpose.flatten
  end

  def generate_without_locations
    GridCollection.new @projects, @request_params[:tiles_count].try(:to_i)
  end

  def find_projects
    if @tags
      generate_with_tags
    else
      generate_projects
    end
  end

  def generate_projects
    Project.standalone + AggregateProject.all
  end

  def generate_with_tags
    Project.standalone_with_tags(@tags) + AggregateProject.all_with_tags(@tags)
  end

  def group_sort(l1, l2)
    return -1 if l1 == "San Francisco"
    return 1 if l2 == "San Francisco"
    return 1 if l1.nil?
    return -1 if l2.nil?
    l1 <=> l2
  end


  def location(location_projects)
    location = location_projects.first.try(:location)
    return location if location_projects.all? { |e| e.nil? || e.location == location }
  end

  def location_groups
    @projects.group_by(&:location)
  end

  def sort(projects)
    projects.sort_by(&:name)
  end
end<commit_msg>Allow a 'SF' location to show up first if that is used instead of "San Francisco"<commit_after>class DashboardGrid
  DEFAULT_LOCATION_GRID_SIZE = 63

  class << self
    def generate(request_params={})
      new(request_params).generate
    end
  end

  def initialize(request_params)
    @request_params = request_params
    @tags = request_params[:tags]
    @locations = request_params[:view]
    @projects = find_projects.sort_by { |p| p.name.to_s.downcase }
  end

  def generate
    if @locations
      generate_with_locations
    else
      generate_without_locations
    end
  end

  private

  def generate_with_locations
    locations = []
    @projects.group_by(&:location).keys.sort{ |l1,l2| group_sort(l1,l2) }.each do |location|
      location_projects = location_groups[location]
      locations << SubGridCollection.new([Location.new(location(location_projects))] + location_projects)
    end
    GridCollection.new(locations.flatten, DEFAULT_LOCATION_GRID_SIZE).each_slice(9).to_a.transpose.flatten
  end

  def generate_without_locations
    GridCollection.new @projects, @request_params[:tiles_count].try(:to_i)
  end

  def find_projects
    if @tags
      generate_with_tags
    else
      generate_projects
    end
  end

  def generate_projects
    Project.standalone + AggregateProject.all
  end

  def generate_with_tags
    Project.standalone_with_tags(@tags) + AggregateProject.all_with_tags(@tags)
  end

  def group_sort(l1, l2)
    return -1 if ["San Francisco", "SF"].include?(l1)
    return 1 if ["San Francisco", "SF"].include?(l2)
    return 1 if l1.nil?
    return -1 if l2.nil?
    l1 <=> l2
  end


  def location(location_projects)
    location = location_projects.first.try(:location)
    return location if location_projects.all? { |e| e.nil? || e.location == location }
  end

  def location_groups
    @projects.group_by(&:location)
  end

  def sort(projects)
    projects.sort_by(&:name)
  end
end
{'fraction_non_alphanumeric': 0.09254362771020624, 'fraction_numerical': 0.010047593865679535, 'mean_word_length': 3.6246943765281174, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '2857007', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1209, 'n_words': 264}