<commit_before>class ProjectsController < ApplicationController
  before_action :set_project, only: [:show, :edit, :update, :destroy]
  before_filter :authenticate_user!, only: [:new, :create, :edit, :update, :destroy]

  # GET /projects
  def index
    @title = 'Explore Projects'
    @projects = Project.paginate(page: params[:page], per_page: 10)
    
    if params.include?(:sort)
      if params[:sort] == 'popular'
        @projects = @projects.order('experiences_count desc, bookmarks_count desc')
      elsif params[:sort] == 'simple'
        @projects = @projects.order('average_simple asc')
      elsif params[:sort] == 'recent'
        @projects = @projects.order('created_at desc')
      end
    end   

    if params.include?(:sort2)
      if params[:sort2] == 'popular'
        @projects = @projects.order('experiences_count desc, bookmarks_count desc')
      elsif params[:sort2] == 'simple'
        @projects = @projects.order('average_simple asc')
      elsif params[:sort2] == 'recent'
        @projects = @projects.order('created_at desc')
      end
    end   

    @projects = @projects.order('experiences_count desc, bookmarks_count desc')

    if params.include?(:age)
      age = params[:age].to_i
      @projects = @projects.order("min_age > #{age + 2}, @ (#{age} - min_age) asc, min_age > #{age}") 
    end       
    
  end

  # GET /projects/1
  def show
    @title = @project.title
    @experience = Experience.new
    @new_bookmark = @project.bookmarks.new
    @bookmark = @project.bookmarks.where(user: current_user).first if current_user
    @current_experience = @project.experiences.where(user_id: current_user.id).last if user_signed_in?
  end<commit_msg>fixing ordering on projects page<commit_after>class ProjectsController < ApplicationController
  before_action :set_project, only: [:show, :edit, :update, :destroy]
  before_filter :authenticate_user!, only: [:new, :create, :edit, :update, :destroy]

  # GET /projects
  def index
    @title = 'Explore Projects'
    
    order = []

    if params.include?(:age)
      age = params[:age].to_i
      order << "min_age > #{age + 2}"
      order << "@ (#{age} - min_age) asc, min_age > #{age}"
    end       
    
    [:sort, :sort2].each do |param|
      if params.include?(param)
        if params[param] == 'popular'
          order << 'experiences_count desc'
          order << 'bookmarks_count desc'
        elsif params[param] == 'simple'
          order << 'average_simple asc'
        elsif params[param] == 'recent'
          order << 'created_at desc'
        end
      end   
    end
    
    unless params.include?(:sort) or params.include?(:sort2)
      order << 'experiences_count desc'
      order << 'bookmarks_count desc' 
    end
    
     @projects = Project.paginate(page: params[:page], per_page: 10).order(order.join(', '))
  end

  # GET /projects/1
  def show
    @title = @project.title
    @experience = Experience.new
    @new_bookmark = @project.bookmarks.new
    @bookmark = @project.bookmarks.where(user: current_user).first if current_user
    @current_experience = @project.experiences.where(user_id: current_user.id).last if user_signed_in?
  end
{'fraction_non_alphanumeric': 0.13392293114339862, 'fraction_numerical': 0.004421983575489577, 'mean_word_length': 3.097024579560155, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 7, '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': '1771808', 'n_tokens_mistral': 1021, 'n_tokens_neox': 982, 'n_words': 231}