<commit_before>class PupsController < ApplicationController

  before_filter :breeder_exists, :only => :create
  before_filter :check_sign_in, :only => [:new, :dog_name, :dog_how_long, :dog_breed, :dog_breeder]

  # Devise. Methods not in the list below will require a user to be logged in.
  before_filter :authenticate_user!, except: [:index, :new, :main, :show, :breed]

  def add_breeder_first
    print params
  end

  def breeder_exists
    if params[:pup][:breeder_id].to_i == -1
      breeder = Breeder.find_or_create(params[:breeder][:name], params[:breeder][:city], params[:breeder][:state])
      params[:pup][:breeder_id] = breeder.id
    end
  end

  def index
    @pups = Pup.all
  end

  def new
    byebug
    breeder_name = params[:potato][:poops]
    if !session[:step1] || !session[:step2] || !session[:step3]
      redirect_to root_path and return
    end
    if breeder_name.nil? || breeder_name.empty?
      flash[:notice] = "Enter your breeder's name"
      session[:step4] = false
      redirect_to dog_breeder_path(:pup => {:breed_1 => session[:breed1], :breed2 => session[:breed2]}) and return
    else
      session[:breeder_name] = breeder_name
      session[:breeder_id] = params[:breeder_id]
      session[:step4] = true
    end
  end

  def main
    @all_breeds = Pup.all_breeds
    @all_breeds_none = Pup.all_breeds_none
    @all_breeders = Breeder.all.map {|breeder| breeder.name}
    @mission_statement_sections = Text.mission_statement_sections
  end

  def show
    @pup = Pup.find params[:id]
  end

  def create
    param = params[:pup]
    param[:pup_name] = session[:pup_name]
    param[:breed1] = session[:breed1]
    param[:breed2] = session[:breed2]
    param[:breeder_id] = session[:breeder_id]
    byebug
    @pup = Pup.new(param)
    if @pup.save
      flash[:notice] = "#{@pup.pup_name} was successfully added"
      redirect_to breed_path(:pup => {:breed_1 => @pup.breed_1, :breed_2 => @pup.breed_2})
    else 
      flash.keep[:notice] = "Please make sure all fields are complete!"
      redirect_to new_pup_path
    end
  end

  def breed
    breed_1, breed_2 = params[:pup][:breed_1], params[:pup][:breed_2]
    @pups = Pup.find_by_breeds(breed_1, breed_2)
    if @pups.length == 0
      flash[:message] = "Sorry, there are no dogs of the breed #{breed_1}"
      flash[:message] += " and #{breed_2}" if breed_2 != 'None'
      redirect_to root_path and return
    end
    @avg_ratings = Pup.avg_ratings_by_breeds(breed_1, breed_2)
  end

  def update
    @pup = Pup.find params[:id]
    @pup.update_attributes(params[:pup])
    redirect_to pups_path
  end

  def destroy
    @pup = Pup.find params[:id]
    @pup.destroy
    redirect_to pups_path
  end

  def dog_name

  end

  def dog_how_long
    pup_name = params[:pup][:pup_name]
    if pup_name.nil? || pup_name.empty?
      flash[:notice] = "Please enter a name for your dog"
      session[:step1] = false
      redirect_to dog_name_path and return
    else
      session[:pup_name] = pup_name
      session[:step1] = true
    end
  end

  def dog_breed
    @all_breeds = Pup.all_breeds
    @all_breeds_none = Pup.all_breeds_none
    years = params[:pup][:years]
    months = params[:pup][:months]
    if !session[:step1]
      redirect_to root_path and return
    end
    if years.nil? || months.nil? || (years.empty? && months.empty?)
      flash[:notice] = "Please enter how long you have owned your dog."
      session[:step2] = false
      redirect_to dog_how_long_path(:pup => {:pup_name => session[:pup_name]}) and return
    elsif is_valid_year_month?(years, months)
      session[:years] = years 
      session[:months] = months
      session[:step2] = true
    else
      session[:step2] = false
      flash[:notice] = "Sorry, to keep the information in our database as accurate as possible, we are collecting data only for dogs that have been in the current home for at least six months. Please come back and evaluate your dog later."
      redirect_to root_path and return
    end
  end

  def dog_breeder
    multiple_breeds = params[:multiple_breeds]
    breed1 = params[:pup][:breed1]
    breed2 = params[:pup][:breed2]
    if !session[:step1] || !session[:step2]
      redirect_to root_path and return
    end
    if multiple_breeds == "Purebred"
      session[:breed1] = breed1
      session[:breed2] = breed2
      session[:multiple_breeds] = multiple_breeds<commit_msg>finish general logic<commit_after>class PupsController < ApplicationController

  before_filter :breeder_exists, :only => :create
  before_filter :check_sign_in, :only => [:new, :dog_name, :dog_how_long, :dog_breed, :dog_breeder]

  # Devise. Methods not in the list below will require a user to be logged in.
  before_filter :authenticate_user!, except: [:index, :new, :main, :show, :breed]

  def add_breeder_first
    print params
  end

  def breeder_exists
    if params[:pup][:breeder_id].to_i == -1
      breeder = Breeder.find_or_create(params[:breeder][:name], params[:breeder][:city], params[:breeder][:state])
      params[:pup][:breeder_id] = breeder.id
    end
  end

  def index
    @pups = Pup.all
  end

  def new
    breeder_name = params[:potato][:poops]
    breeder = params[:breeder]
    if !session[:step1] || !session[:step2] || !session[:step3]
      redirect_to root_path and return
    end
    if breeder_name.nil? || breeder_name.empty?
      flash[:notice] = "Enter your breeder's name"
      session[:step4] = false
      redirect_to dog_breeder_path(:pup => {:breed_1 => session[:breed1], :breed2 => session[:breed2]}) and return
    else
      session[:breeder_name] = breeder_name
      session[:breeder_id] = params[:breeder_id]
      session[:step4] = true
    end
  end

  def main
    @all_breeds = Pup.all_breeds
    @all_breeds_none = Pup.all_breeds_none
    @all_breeders = Breeder.all.map {|breeder| breeder.name}
    @mission_statement_sections = Text.mission_statement_sections
  end

  def show
    @pup = Pup.find params[:id]
  end

  def create
    param = params[:pup]
    param[:pup_name] = session[:pup_name]
    param[:breed_1] = session[:breed1]
    param[:breed_2] = session[:breed2]
    param[:breeder_id] = session[:breeder_id]
    @pup = Pup.new(param)
    if @pup.save
      flash[:notice] = "#{@pup.pup_name} was successfully added"
      redirect_to breed_path(:pup => {:breed_1 => @pup.breed_1, :breed_2 => @pup.breed_2})
    else 
      flash.keep[:notice] = "Please make sure all fields are complete!"
      redirect_to new_pup_path
    end
  end

  def breed
    breed_1, breed_2 = params[:pup][:breed_1], params[:pup][:breed_2]
    @pups = Pup.find_by_breeds(breed_1, breed_2)
    if @pups.length == 0
      flash[:message] = "Sorry, there are no dogs of the breed #{breed_1}"
      flash[:message] += " and #{breed_2}" if breed_2 != 'None'
      redirect_to root_path and return
    end
    @avg_ratings = Pup.avg_ratings_by_breeds(breed_1, breed_2)
  end

  def update
    @pup = Pup.find params[:id]
    @pup.update_attributes(params[:pup])
    redirect_to pups_path
  end

  def destroy
    @pup = Pup.find params[:id]
    @pup.destroy
    redirect_to pups_path
  end

  def dog_name

  end

  def dog_how_long
    pup_name = params[:pup][:pup_name]
    if pup_name.nil? || pup_name.empty?
      flash[:notice] = "Please enter a name for your dog"
      session[:step1] = false
      redirect_to dog_name_path and return
    else
      session[:pup_name] = pup_name
      session[:step1] = true
    end
  end

  def dog_breed
    @all_breeds = Pup.all_breeds
    @all_breeds_none = Pup.all_breeds_none
    years = params[:pup][:years]
    months = params[:pup][:months]
    if !session[:step1]
      redirect_to root_path and return
    end
    if years.nil? || months.nil? || (years.empty? && months.empty?)
      flash[:notice] = "Please enter how long you have owned your dog."
      session[:step2] = false
      redirect_to dog_how_long_path(:pup => {:pup_name => session[:pup_name]}) and return
    elsif is_valid_year_month?(years, months)
      session[:years] = years 
      session[:months] = months
      session[:step2] = true
    else
      session[:step2] = false
      flash[:notice] = "Sorry, to keep the information in our database as accurate as possible, we are collecting data only for dogs that have been in the current home for at least six months. Please come back and evaluate your dog later."
      redirect_to root_path and return
    end
  end

  def dog_breeder
    multiple_breeds = params[:multiple_breeds]
    breed1 = params[:pup][:breed_1]
    breed2 = params[:pup][:breed_2]
    if !session[:step1] || !session[:step2]
      redirect_to root_path and return
    end
    if multiple_breeds == "Purebred"
      session[:breed1] = breed1
      session[:breed2] = breed2
      session[:multiple_breeds] = multiple_breeds
{'fraction_non_alphanumeric': 0.11600454029511918, 'fraction_numerical': 0.010442678774120319, 'mean_word_length': 3.3835820895522386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '5430193', 'n_tokens_mistral': 3135, 'n_tokens_neox': 3074, 'n_words': 743}