<commit_before>class LoadProfilesController < ResourceController
  RESOURCE_ACTIONS = %i(show edit update destroy)

  before_filter :fetch_profile, only: RESOURCE_ACTIONS
  before_filter :authorize_generic, except: RESOURCE_ACTIONS
  before_filter :fetch_technologies, only: %i(new create edit update)

  respond_to :html
  respond_to :json, only: :show

  def index
    skip_policy_scope
    @load_profile_categories = LoadProfileCategory.where(parent_id: nil)
    @price_curves = PriceCurve.all
  end

  # GET /load_profiles
  def show
    respond_with(@profile)
  end

  # GET /load_profiles/new
  def new
    @profile = LoadProfile.new
    build_load_profile_components
  end

  def edit
    build_load_profile_components
  end

  def update
    @profile.update_attributes(profile_params)
    respond_with(@profile)
  end

  def create
    @profile = current_user.load_profiles.create(profile_params)
    respond_with(@profile)
  end

  # DELETE /profiles/:id
  def destroy
    @profile.destroy
    redirect_to(load_profiles_url)
  end

  private

  def build_load_profile_components
    LoadProfileComponent::CURVE_TYPES.values.flatten.each do |curve_type|
      @profile.load_profile_components.build(curve_type: curve_type)
    end
  end

  def fetch_profile
    @profile = LoadProfile.find(params[:id])
    authorize @profile
  end<commit_msg>Don't build an extra load profile component if it already exists<commit_after>class LoadProfilesController < ResourceController
  RESOURCE_ACTIONS = %i(show edit update destroy)

  before_filter :fetch_profile, only: RESOURCE_ACTIONS
  before_filter :authorize_generic, except: RESOURCE_ACTIONS
  before_filter :fetch_technologies, only: %i(new create edit update)

  respond_to :html
  respond_to :json, only: :show

  def index
    skip_policy_scope
    @load_profile_categories = LoadProfileCategory.where(parent_id: nil)
    @price_curves = PriceCurve.all
  end

  # GET /load_profiles
  def show
    respond_with(@profile)
  end

  # GET /load_profiles/new
  def new
    @profile = LoadProfile.new
    build_load_profile_components
  end

  def edit
    build_load_profile_components
  end

  def update
    @profile.update_attributes(profile_params)
    respond_with(@profile)
  end

  def create
    @profile = current_user.load_profiles.create(profile_params)
    respond_with(@profile)
  end

  # DELETE /profiles/:id
  def destroy
    @profile.destroy
    redirect_to(load_profiles_url)
  end

  private

  def build_load_profile_components
    LoadProfileComponent::CURVE_TYPES.values.flatten.each do |curve_type|
      unless @profile.load_profile_components.map(&:curve_type).include?(curve_type)
        @profile.load_profile_components.build(curve_type: curve_type)
      end
    end
  end

  def fetch_profile
    @profile = LoadProfile.find(params[:id])
    authorize @profile
  end
{'fraction_non_alphanumeric': 0.06807017543859649, 'fraction_numerical': 0.0, 'mean_word_length': 4.174228675136116, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1679517', 'n_tokens_mistral': 921, 'n_tokens_neox': 890, 'n_words': 194}