<commit_before>module GobiertoBudgets
  module Api
    class CategoriesController < ApplicationController
      caches_action :index

      def index
        kind = params[:kind]
        area = params[:area]
        render_404 and return if area == 'functional' and kind == 'I'

        if kind.nil? && area.nil?
          categories = {}
          BudgetArea.all_areas.each do |klass|
            area_name = klass.area_name
            BudgetLine.all_kinds.each do |kind|
              next if kind == GobiertoBudgets::BudgetLine::INCOME and klass == GobiertoBudgets::FunctionalArea

              categories[area_name] ||= {}
              categories[area_name][kind] = Hash[klass.all_items[kind].sort_by{ |k,v| k.to_f }]
            end
          end
        else
          klass = BudgetArea.klass_for(area)
          categories = Hash[klass.all_items[kind].sort_by{ |k,v| k.to_f }]
        end<commit_msg>Budget lines categories breadcrumb, quick-fix<commit_after>module GobiertoBudgets
  module Api
    class CategoriesController < ApplicationController
      caches_action :index

      def index
        kind = params[:kind]
        area = params[:area]
        render_404 and return if area == 'functional' and kind == 'I'

        if kind.nil? && area.nil?
          categories = {}
          BudgetArea.all_areas.each do |klass|
            area_name = klass.area_name
            BudgetLine.all_kinds.each do |kind|
              next if kind == GobiertoBudgets::BudgetLine::INCOME and klass == GobiertoBudgets::FunctionalArea

              categories[area_name] ||= {}
              categories[area_name][kind] = Hash[klass.all_items[kind].sort_by{ |k,v| k.to_f }]
            end
          end

          categories['custom'] = { 'I' => {}, 'G' => {} }

          custom_categories = GobiertoBudgets::Category.where(site: current_site)

          custom_categories.each do |category|
            if category.kind == GobiertoBudgets::BudgetLine::INCOME
              categories['custom']['I'][category.code] = category.name
            elsif category.kind == GobiertoBudgets::BudgetLine::EXPENSE
              categories['custom']['G'][category.code] = category.name
            end
          end
          
        else
          klass = BudgetArea.klass_for(area)
          categories = Hash[klass.all_items[kind].sort_by{ |k,v| k.to_f }]
        end
{'fraction_non_alphanumeric': 0.10730882974228982, 'fraction_numerical': 0.0025348542458808617, 'mean_word_length': 2.2130257801899593, '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': '6959301', 'n_tokens_mistral': 710, 'n_tokens_neox': 696, 'n_words': 140}