<commit_before># == Schema Information
#
# Table name: donors
#
#  id                        :integer          not null, primary key
#  name                      :string(2000)
#  description               :text
#  website                   :string(255)
#  twitter                   :string(255)
#  facebook                  :string(255)
#  contact_person_name       :string(255)
#  contact_company           :string(255)
#  contact_person_position   :string(255)
#  contact_email             :string(255)
#  contact_phone_number      :string(255)
#  logo_file_name            :string(255)
#  logo_content_type         :string(255)
#  logo_file_size            :integer
#  logo_updated_at           :datetime
#  site_specific_information :text
#  created_at                :datetime
#  updated_at                :datetime
#  iati_organizationid       :string(255)
#  organization_type         :string(255)
#  organization_type_code    :integer
#

class Donor < ActiveRecord::Base

  #has_many :resources, :conditions => 'resources.element_type = #{Iom::ActsAsResource::DONOR_TYPE}', :foreign_key => :element_id, :dependent => :destroy
  #has_many :media_resources, :conditions => 'media_resources.element_type = #{Iom::ActsAsResource::DONOR_TYPE}', :foreign_key => :element_id, :dependent => :destroy, :order => 'position ASC'
  has_many :donations, dependent: :destroy
  has_many :donated_projects, -> {where("(projects.end_date is null or projects.end_date > now())")}, through: :donations, source: :project
  has_many :all_donated_projects, through: :donations, source: :project
  has_many :offices, dependent: :destroy

  has_attached_file :logo, styles: {
      small: {
        geometry: "80x46>",
        format: 'jpg'
      },
      medium: {
        geometry: "200x150>",
        format: 'jpg'
      }
    },
    url: "/system/:attachment/:id/:style.:extension"
  scope :active, -> {joins([donations: :project]).where("projects.end_date is null or (projects.end_date > ? AND projects.start_date < ?)", Date.today.to_s(:db), Date.today.to_s(:db))}
  scope :sectors, -> (sectors) {joins([donations: [project: :sectors]]).where(sectors: {id: sectors})}
  scope :site, -> (site) {joins([donations: [project: :sites]]).where(sites: {id: site})}
  scope :geolocation, -> (geolocation,level=0){joins(projects: :geolocations).where("g#{level}=?", geolocation).where('adm_level >= ?', level)}
  scope :projects, -> (projects){joins(:projects).where(projects: {id: projects})}
  scope :countries, -> (countries){joins(projects: :geolocations).where(geolocations: {country_uid: countries})}
  scope :organizations, -> (orgs){joins(:projects).joins('join organizations on projects.primary_organization_id = organizations.id').where(organizations: {id: orgs})}
  def self.fetch_all(options={})
    level = Geolocation.find_by(uid: options[:geolocation]).adm_level if options[:geolocation]
    donors = Donor.all
    donors = donors.active                                                    if options[:status] && options[:status] == 'active'
    donors = donors.site(options[:site])                                      if options[:site]<commit_msg>fixes donor query<commit_after># == Schema Information
#
# Table name: donors
#
#  id                        :integer          not null, primary key
#  name                      :string(2000)
#  description               :text
#  website                   :string(255)
#  twitter                   :string(255)
#  facebook                  :string(255)
#  contact_person_name       :string(255)
#  contact_company           :string(255)
#  contact_person_position   :string(255)
#  contact_email             :string(255)
#  contact_phone_number      :string(255)
#  logo_file_name            :string(255)
#  logo_content_type         :string(255)
#  logo_file_size            :integer
#  logo_updated_at           :datetime
#  site_specific_information :text
#  created_at                :datetime
#  updated_at                :datetime
#  iati_organizationid       :string(255)
#  organization_type         :string(255)
#  organization_type_code    :integer
#

class Donor < ActiveRecord::Base

  #has_many :resources, :conditions => 'resources.element_type = #{Iom::ActsAsResource::DONOR_TYPE}', :foreign_key => :element_id, :dependent => :destroy
  #has_many :media_resources, :conditions => 'media_resources.element_type = #{Iom::ActsAsResource::DONOR_TYPE}', :foreign_key => :element_id, :dependent => :destroy, :order => 'position ASC'
  has_many :donations, dependent: :destroy
  #has_many :donated_projects, -> {where("(projects.end_date is null or projects.end_date > now())")}, through: :donations, source: :project
  #has_many :all_donated_projects, through: :donations, source: :project
  has_many :projects, through: :donations, source: :project
  has_many :offices, dependent: :destroy

  has_attached_file :logo, styles: {
      small: {
        geometry: "80x46>",
        format: 'jpg'
      },
      medium: {
        geometry: "200x150>",
        format: 'jpg'
      }
    },
    url: "/system/:attachment/:id/:style.:extension"
  scope :active, -> {joins([donations: :project]).where("projects.end_date is null or (projects.end_date > ? AND projects.start_date < ?)", Date.today.to_s(:db), Date.today.to_s(:db))}
  scope :sectors, -> (sectors) {joins([donations: [project: :sectors]]).where(sectors: {id: sectors})}
  scope :site, -> (site) {joins([donations: [project: :sites]]).where(sites: {id: site})}
  scope :geolocation, -> (geolocation,level=0){joins(donations: [project: :geolocations]).where("g#{level}=?", geolocation).where('adm_level >= ?', level)}
  scope :projects, -> (projects){joins(donations: :project).where(projects: {id: projects})}
  scope :countries, -> (countries){joins(donations: [project: :geolocations]).where(geolocations: {country_uid: countries})}
  scope :organizations, -> (orgs){joins(donations: :project).joins('join organizations on projects.primary_organization_id = organizations.id').where(organizations: {id: orgs})}
  def self.fetch_all(options={})
    level = Geolocation.find_by(uid: options[:geolocation]).adm_level if options[:geolocation]
    donors = Donor.all
    donors = donors.active                                                    if options[:status] && options[:status] == 'active'
    donors = donors.site(options[:site])                                      if options[:site]
{'fraction_non_alphanumeric': 0.14301344170053143, 'fraction_numerical': 0.01594248202563301, 'mean_word_length': 3.179621162638798, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6300734', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1926, 'n_words': 391}