<commit_before>class BatsController < ApplicationController
  require "gruff"
  def index
    redirect_to :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
    :redirect_to => { :action => :list }

	#Only list the active bats
  def list
    if params[:bats]
      @bats = Bat.find(params[:bats])
    else
      @bats = Bat.active
    end
  end
  
  def list_all
    @bats = Bat.find(:all, :order => 'band')
    @show_leave_date_and_reason = true
    render :action => 'list'
  end

	def list_deactivated
		@bats = Bat.not_active
		@show_leave_date_and_reason = true
		render :action => 'list'
	end

  def change_bats_list
    if params[:cage] && params[:cage][:id] != ""
      bats = Cage.find(params[:cage][:id]).bats
    elsif params[:protocol] && params[:protocol][:id] != ""
      bats = Protocol.find(params[:protocol][:id]).bats
    elsif params[:room] && params[:room][:id] != ""
      bats = Room.find(params[:room][:id]).bats
    elsif params[:species] && params[:species][:id] != ""
      bats = Species.find(params[:species][:id]).bats.active
    elsif params[:user] && params[:user][:id] != ""
      bats = User.find(params[:user][:id]).bats
    elsif params[:option]
      if params[:option]=='med'
        bats = Bat.sick
      elsif params[:option]=='flight_exempt'
        bats = Bat.exempt_from_flight
      elsif params[:option]=='non_flight_exempt'
        bats = Bat.not_exempt_from_flight
      elsif params[:option]=='not_weighed'
        bats = Bat.not_weighed(Bat.active,Date.today)
      elsif params[:option]=='not_flown'
        bats = Bat.not_flown(Bat.active,3)
      elsif params[:option]=='current'
        bats = Bat.active
      elsif params[:option]=='deactivated'
        bats = Bat.not_active
      elsif params[:option]=='all'
        bats = Bat.all
      elsif params[:option]=='my'
        bats = User.find(session[:person]).bats
      end
    end
    render_bat_list(bats)
  end

	def sort_by_species
		bat_list = Bat.find(params[:ids])
		bat_list = bat_list.sort_by{|bat| [bat.species.name, bat.band.downcase]}
    render_bat_list(bat_list)
	end

  def sort_by_deactivation_date
		bat_list = Bat.find(params[:ids], :order => 'leave_date')
    render_bat_list(bat_list)
	end
	
	def sort_by_gender
		bat_list = Bat.find(params[:ids], :order => 'gender, band')
    render_bat_list(bat_list)
	end
	
	def sort_by_weight
		bat_list = Bat.find(params[:ids])
		bat_list = bat_list.sort_by{|bat| [bat.weights.recent_never_nil.weight, bat.band.downcase]}
		render_bat_list(bat_list)
	end

	def sort_by_weigh_date
		bat_list = Bat.find(params[:ids])
		bat_list = bat_list.sort_by{|bat| [bat.weights.recent_never_nil.date.to_f, bat.band.downcase]}
		render_bat_list(bat_list)
	end
  
  def sort_by_last_flown
		bat_list = Bat.find(params[:ids])
		bat_list = bat_list.sort_by{|bat| [bat.flights[-1].date, bat.band.downcase]}
		render_bat_list(bat_list)
	end

  def sort_by_sx
		bat_list = Bat.find(params[:ids], :order => 'band')<commit_msg>Fixed sorting bat list bug on flights<commit_after>class BatsController < ApplicationController
  require "gruff"
  def index
    redirect_to :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
    :redirect_to => { :action => :list }

	#Only list the active bats
  def list
    if params[:bats]
      @bats = Bat.find(params[:bats])
    else
      @bats = Bat.active
    end
  end
  
  def list_all
    @bats = Bat.find(:all, :order => 'band')
    @show_leave_date_and_reason = true
    render :action => 'list'
  end

	def list_deactivated
		@bats = Bat.not_active
		@show_leave_date_and_reason = true
		render :action => 'list'
	end

  def change_bats_list
    if params[:cage] && params[:cage][:id] != ""
      bats = Cage.find(params[:cage][:id]).bats
    elsif params[:protocol] && params[:protocol][:id] != ""
      bats = Protocol.find(params[:protocol][:id]).bats
    elsif params[:room] && params[:room][:id] != ""
      bats = Room.find(params[:room][:id]).bats
    elsif params[:species] && params[:species][:id] != ""
      bats = Species.find(params[:species][:id]).bats.active
    elsif params[:user] && params[:user][:id] != ""
      bats = User.find(params[:user][:id]).bats
    elsif params[:option]
      if params[:option]=='med'
        bats = Bat.sick
      elsif params[:option]=='flight_exempt'
        bats = Bat.exempt_from_flight
      elsif params[:option]=='non_flight_exempt'
        bats = Bat.not_exempt_from_flight
      elsif params[:option]=='not_weighed'
        bats = Bat.not_weighed(Bat.active,Date.today)
      elsif params[:option]=='not_flown'
        bats = Bat.not_flown(Bat.active,3)
      elsif params[:option]=='current'
        bats = Bat.active
      elsif params[:option]=='deactivated'
        bats = Bat.not_active
      elsif params[:option]=='all'
        bats = Bat.all
      elsif params[:option]=='my'
        bats = User.find(session[:person]).bats
      end
    end
    render_bat_list(bats)
  end

	def sort_by_species
		bat_list = Bat.find(params[:ids])
		bat_list = bat_list.sort_by{|bat| [bat.species.name, bat.band.downcase]}
    render_bat_list(bat_list)
	end

  def sort_by_deactivation_date
		bat_list = Bat.find(params[:ids], :order => 'leave_date')
    render_bat_list(bat_list)
	end
	
	def sort_by_gender
		bat_list = Bat.find(params[:ids], :order => 'gender, band')
    render_bat_list(bat_list)
	end
	
	def sort_by_weight
		bat_list = Bat.find(params[:ids])
		bat_list = bat_list.sort_by{|bat| [bat.weights.recent_never_nil.weight, bat.band.downcase]}
		render_bat_list(bat_list)
	end

	def sort_by_weigh_date
		bat_list = Bat.find(params[:ids])
		bat_list = bat_list.sort_by{|bat| [bat.weights.recent_never_nil.date.to_f, bat.band.downcase]}
		render_bat_list(bat_list)
	end
  
  def sort_by_last_flown
		bat_list = Bat.find(params[:ids])
		bat_list = bat_list.sort_by{|bat| [bat.flights.empty? ? Date.new : bat.flights[-1].date, bat.band.downcase]}
		render_bat_list(bat_list)
	end

  def sort_by_sx
		bat_list = Bat.find(params[:ids], :order => 'band')
{'fraction_non_alphanumeric': 0.14940686117345303, 'fraction_numerical': 0.0022443090734209684, 'mean_word_length': 3.6078286558345645, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4420552', 'n_tokens_mistral': 2398, 'n_tokens_neox': 2266, 'n_words': 401}