<commit_before># frozen_string_literal: true

module GobiertoBudgets
  class BudgetLinesImporter
    def initialize(site, year)
      @site = site
      @year = year
    end

    def import!
      calculate_totals
      calculate_bubbles
      reset_cache
      publish_event
    end

    private

    attr_reader :site, :year

    def calculate_totals
      GobiertoBudgets::BudgetTotalCalculator.new(site, year).calculate!
    end

    def calculate_bubbles
      GobiertoBudgets::Data::Bubbles.dump(site.place)
    end

    def reset_cache
      Rails.cache.clear
    end

    def publish_event
      action = 'budgets_updated'

      Publishers::GobiertoBudgetsBudgetLineActivity.broadcast_event(action, {
        action: action,
        site_id: site.id
      })
    end
  end
end
<commit_msg>#1368: Include annual_data files generation in BudgetLines import<commit_after># frozen_string_literal: true

module GobiertoBudgets
  class BudgetLinesImporter
    def initialize(site, year)
      @site = site
      @year = year
    end

    def import!
      calculate_totals
      calculate_bubbles
      calculate_annual_data
      reset_cache
      publish_event
    end

    private

    attr_reader :site, :year

    def calculate_totals
      GobiertoBudgets::BudgetTotalCalculator.new(site, year).calculate!
    end

    def calculate_bubbles
      GobiertoBudgets::Data::Bubbles.dump(site.place)
    end

    def calculate_annual_data
      GobiertoBudgets::Data::Annual.new(site: site, year: year).generate_files
    end

    def reset_cache
      Rails.cache.clear
    end

    def publish_event
      action = 'budgets_updated'

      Publishers::GobiertoBudgetsBudgetLineActivity.broadcast_event(action, {
        action: action,
        site_id: site.id
      })
    end
  end
end

{'fraction_non_alphanumeric': 0.061872909698996656, 'fraction_numerical': 0.002229654403567447, 'mean_word_length': 2.731808731808732, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6739690', 'n_tokens_mistral': 590, 'n_tokens_neox': 556, 'n_words': 117}