<commit_before>module Blackbeard
  module DashboardRoutes
    class Metrics < Base
      get '/metrics' do
        @metrics = Metric.all
        erb 'metrics/index'.to_sym
      end

      get "/metrics/:type/:type_id" do
        @metric = Metric.find(params[:type], params[:type_id]) or pass
        @group = Group.find(params[:group_id]) if params[:group_id]
        @cohort = Cohort.find(params[:cohort_id]) if params[:cohort_id]
        erb 'metrics/show'.to_sym
      end

      post "/metrics/:type/:type_id" do
        @metric = Metric.find(params[:type], params[:type_id]) or pass
        @metric.update_attributes(params)
        "OK"
      end

      post "/metrics/:type/:type_id/groups" do
        @metric = Metric.find(params[:type], params[:type_id]) or pass
        @group = Group.find(params[:group_id])
        @metric.add_group(@group) if @group
        redirect url("metrics/#{@metric.type}/#{@metric.type_id}?group_id=#{@group.id}")
      end

      post "/metrics/:type/:type_id/cohorts" do
        @metric = Metric.find(params[:type], params[:type_id]) or pass
        @cohort = Cohort.find(params[:cohort_id])
        @metric.add_cohort(@cohort) if @cohort
        redirect url("metrics/#{@metric.type}/#{@metric.type_id}?cohort_id=#{@cohort.id}")
      end

    end
  end
end<commit_msg>juking codeclimate<commit_after>module Blackbeard
  module DashboardRoutes
    class Metrics < Base
      get '/metrics' do
        @metrics = Metric.all
        erb 'metrics/index'.to_sym
      end

      get "/metrics/:type/:type_id" do
        ensure_metric; find_group; find_cohort
        erb 'metrics/show'.to_sym
      end

      post "/metrics/:type/:type_id" do
        ensure_metric
        @metric.update_attributes(params)
        "OK"
      end

      post "/metrics/:type/:type_id/groups" do
        ensure_metric; find_group
        @metric.add_group(@group) if @group
        redirect url("metrics/#{@metric.type}/#{@metric.type_id}?group_id=#{@group.id}")
      end

      post "/metrics/:type/:type_id/cohorts" do
        ensure_metric; find_cohort
        @metric.add_cohort(@cohort) if @cohort
        redirect url("metrics/#{@metric.type}/#{@metric.type_id}?cohort_id=#{@cohort.id}")
      end

      def ensure_metric
        @metric = Metric.find(params[:type], params[:type_id]) or pass
      end

      def find_group
        @group = Group.find(params[:group_id]) if params[:group_id]
      end

      def find_cohort
        @cohort = Cohort.find(params[:cohort_id]) if params[:cohort_id]
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.13620352250489237, 'fraction_numerical': 0.0, 'mean_word_length': 2.6152758132956153, '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': '7191421', 'n_tokens_mistral': 868, 'n_tokens_neox': 848, 'n_words': 158}