<commit_before>require 'importers/base_importer'

module Importers
  class SubventionsImporter < BaseImporter
    def import!
      each_row do |row|
        recipient = row[:ong].capitalize
        project = row[:titulo_proyecto].try(:capitalize)
        kind = row[:tipologia]
        location = row[:pais].capitalize
        year = row[:ano_de_ejecucion].to_i
        amount = row[:subvencion_]
        euros, cents = amount.split(',')
        cents ||= "00"
        amount_euro_cents = "#{euros}#{cents}".gsub(/[^0-9]/,'').to_i

        puts "Importing #{year} subvention to: #{recipient} - #{project}"

        subvention = Subvention.find_or_initialize_by(project: project, recipient: recipient)
        subvention.attributes = { recipient: recipient, project: project, kind: kind, location: location, year: year, amount_euro_cents: amount_euro_cents }
        subvention.save!
      end
    end
  end
end<commit_msg>updates subventions_importer to find also by year<commit_after>require 'importers/base_importer'

module Importers
  class SubventionsImporter < BaseImporter
    def import!
      each_row do |row|
        recipient = row[:ong].capitalize
        project = row[:titulo_proyecto].try(:capitalize)
        kind = row[:tipologia]
        location = row[:pais].capitalize
        year = row[:ano_de_ejecucion].to_i
        amount = row[:subvencion_]
        euros, cents = amount.split(',')
        cents ||= "00"
        amount_euro_cents = "#{euros}#{cents}".gsub(/[^0-9]/,'').to_i

        puts "Importing #{year} subvention to: #{recipient} - #{project}"

        subvention = Subvention.find_or_initialize_by(project: project, recipient: recipient, year: year)
        subvention.attributes = { recipient: recipient, project: project, kind: kind, location: location, year: year, amount_euro_cents: amount_euro_cents }
        subvention.save!
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12038014783526928, 'fraction_numerical': 0.004223864836325237, 'mean_word_length': 3.2017738359201773, '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': '3208048', 'n_tokens_mistral': 608, 'n_tokens_neox': 591, 'n_words': 129}