<commit_before>class MetricConfigurationsController < ApplicationController
  def save
    params[:metric_configuration][:metric].delete(:code)
    metric_configuration = KalibroGem::Entities::MetricConfiguration.new(params[:metric_configuration])
    metric_configuration.configuration_id = params[:configuration_id]
    metric_configuration.id = nil

    respond_to do |format|
      if metric_configuration.save
        format.json { render json: metric_configuration.to_hash }
      else
        format.json { render json: metric_configuration.to_hash, status: :unprocessable_entity }
      end
    end
  end

  def get
    begin
      metric_configuration = KalibroGem::Entities::MetricConfiguration.find(params[:id])
    rescue KalibroGem::Errors::RecordNotFound
      metric_configuration = {error: 'RecordNotFound'}
    end

    respond_to do |format|
      if metric_configuration.is_a?(KalibroGem::Entities::MetricConfiguration)
        format.json { render json: metric_configuration.to_hash }
      else
        format.json { render json: metric_configuration, status: :unprocessable_entity }
      end
    end<commit_msg>Setting aggregation form for coumpund metric configuration.<commit_after>class MetricConfigurationsController < ApplicationController
  def save
    params[:metric_configuration][:metric].delete(:code)
    metric_configuration = KalibroGem::Entities::MetricConfiguration.new(params[:metric_configuration])
    metric_configuration.configuration_id = params[:configuration_id]
    metric_configuration.id = nil

    #Sending this garbage just because KalibroJava is waiting Prezento to send an aggregation form
    if metric_configuration.metric.compound == "true"
      metric_configuration.aggregation_form = "AVERAGE"
    end

    respond_to do |format|
      if metric_configuration.save
        format.json { render json: metric_configuration.to_hash }
      else
        format.json { render json: metric_configuration.to_hash, status: :unprocessable_entity }
      end
    end
  end

  def get
    begin
      metric_configuration = KalibroGem::Entities::MetricConfiguration.find(params[:id])
    rescue KalibroGem::Errors::RecordNotFound
      metric_configuration = {error: 'RecordNotFound'}
    end

    respond_to do |format|
      if metric_configuration.is_a?(KalibroGem::Entities::MetricConfiguration)
        format.json { render json: metric_configuration.to_hash }
      else
        format.json { render json: metric_configuration, status: :unprocessable_entity }
      end
    end
{'fraction_non_alphanumeric': 0.07661927330173776, 'fraction_numerical': 0.0, 'mean_word_length': 4.1483739837398375, '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': '3828077', 'n_tokens_mistral': 669, 'n_tokens_neox': 667, 'n_words': 145}