<commit_before># -*- coding: utf-8 -*-
class RestaurantsController < ApplicationController
  
  before_action :set_restaurants, only: [:report, :deliver]
  
  def index
    @restaurants = Restaurant.all
    @per_array = Array.new
    
    @restaurants.each do |restaurant|
      #perは占有率
      per = ((restaurant.num_people.to_f/restaurant.num_seats.to_f)*100).round
      #モデルのseats_occに占有率を更新
      restaurant.seats_occ = per
      restaurant.save
    end
    #占有率が低い順に並び替える
    @rank=Restaurant.order('crowdedness')
    @how_crowded = ["記録なし","空いてる","やや混んでる","混んでる","外にも人がいる","外にたくさん人がいる"]
    @icon = []
    @len_num = @rank.count
  end
  
  def search
    escaped = params[:name].gsub('\\', '\\\\\\\\').gsub('%', '\%').gsub('_', '\_')    
    
    if escaped.blank?
      flash[:warning] = '店名を入力してください'
      redirect_to :root
    end
    
    @searched = Restaurant.where("name like ? or hurigana like ?", "%#{escaped}%", "%#{escaped}%")
    @how_crowded = ["記録なし","空いてる","やや混んでる","混んでる","外にも人がいる","外にたくさん人がいる"]
    
    if @searched.empty?
      @error = "検索ワードがヒットしませんでした。もう一度入れなおして下さい。"
    end
    
  end
  
  def report
    #resnameはトップからlink_toで飛んできた値
    @restaurant_id = Restaurant.find_by(name: params[:resname])
    #restaurantidがnilだった場合は指定なし、そうでない場合は指定ありで初期値が設定される
    if @restaurant_id.nil? then
      @restaurant = Restaurant.new()
    else
      @restaurant = Restaurant.new(:id => @restaurant_id.id)
    end
  end
  
  def deliver
    id = params[:restaurant][:id]

    if id.blank?
      flash[:warning] = '店名を選択して下さい'
      redirect_to :report_restaurants and return
    end

    if params[:restaurant][:crowdedness].blank?
      flash[:warning] = '混雑度を選択して下さい'
      redirect_to :report_restaurants and return
    end

    restaurant = Restaurant.find(id)
    crowd = params[:restaurant][:crowdedness]
    if crowd.blank?
      flash[:warning] = '店の混雑度を選択して下さい'
      redirect_to :report_restaurants and return
    end
    restaurant.crowdedness = crowd
    Restaurant.transaction do
      restaurant.save!
      restaurant.touch
    end
    redirect_to :root
  end

  private

  def set_restaurants
    @restaurant_names = Restaurant.all.order("hurigana").pluck(:name, :id, :hurigana)
  end
end<commit_msg>sort name<commit_after># -*- coding: utf-8 -*-
class RestaurantsController < ApplicationController
  
  before_action :set_restaurants, only: [:report, :deliver]
  
  def index
    @restaurants = Restaurant.all
    @per_array = Array.new
    
    @restaurants.each do |restaurant|
      #perは占有率
      per = ((restaurant.num_people.to_f/restaurant.num_seats.to_f)*100).round
      #モデルのseats_occに占有率を更新
      restaurant.seats_occ = per
      restaurant.save
    end
    #占有率が低い順に並び替える
    @rank=Restaurant.order('crowdedness')
    @how_crowded = ["記録なし","空いてる","やや混んでる","混んでる","外にも人がいる","外にたくさん人がいる"]
    @icon = []
    @len_num = @rank.count
  end
  
  def search
    escaped = params[:name].gsub('\\', '\\\\\\\\').gsub('%', '\%').gsub('_', '\_')    
    
    if escaped.blank?
      flash[:warning] = '店名を入力してください'
      redirect_to :root
    end
    
    @searched = Restaurant.where("name like ? or hurigana like ?", "%#{escaped}%", "%#{escaped}%")
    @how_crowded = ["記録なし","空いてる","やや混んでる","混んでる","外にも人がいる","外にたくさん人がいる"]
    
    if @searched.empty?
      @error = "検索ワードがヒットしませんでした。もう一度入れなおして下さい。"
    end
    
  end
  
  def report
    #resnameはトップからlink_toで飛んできた値
    @restaurant_id = Restaurant.find_by(name: params[:resname])
    #restaurantidがnilだった場合は指定なし、そうでない場合は指定ありで初期値が設定される
    if @restaurant_id.nil? then
      @restaurant = Restaurant.new()
    else
      @restaurant = Restaurant.new(:id => @restaurant_id.id)
    end
  end
  
  def deliver
    id = params[:restaurant][:id]
    
    if id.blank?
      flash[:warning] = '店名を選択して下さい'
      redirect_to :report_restaurants and return
    end
    
    if params[:restaurant][:crowdedness].blank?
      flash[:warning] = '混雑度を選択して下さい'
      redirect_to :report_restaurants and return
    end
    
    restaurant = Restaurant.find(id)
    crowd = params[:restaurant][:crowdedness]
    if crowd.blank?
      flash[:warning] = '店の混雑度を選択して下さい'
      redirect_to :report_restaurants and return
    end
    restaurant.crowdedness = crowd
    Restaurant.transaction do
      restaurant.save!
      restaurant.touch
    end
    redirect_to :root
  end

  private
  
  def set_restaurants
    #五十音順で並び替えてnameとidを渡す
    @restaurant_names = Restaurant.all.order("hurigana").pluck(:name, :id)
  end
end
{'fraction_non_alphanumeric': 0.13115119127143177, 'fraction_numerical': 0.0017813404586951682, 'mean_word_length': 3.0541516245487363, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2126884', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1875, 'n_words': 274}