<commit_before>module MisPerson

  def self.included receiver
    receiver.extend ClassMethods
    receiver.belongs_to :mis_person, :class_name => "Ebs::Person", :foreign_key => :mis_id
  end

  module ClassMethods

    def connector
      "EBS connector"
    end

    def import(uln, options = {})
      uln = uln.unique_learn_no if uln.kind_of? Ebs::Person
      options.reverse_merge! :save => true, :courses => true
      logger.info "Importing user #{uln}"
      if (ep = Ebs::Person.find_by_unique_learn_no(uln))
        @person = Person.find_or_create_by_uln(uln)
        @person.update_attributes(
          :forename      => ep.forename,
          :surname       => ep.surname,
          :middle_names  => ep.middle_names && ep.middle_names.split,
          :address       => [ep.address.address_line_1,ep.address.address_line_2,
                             ep.address.address_line_3,ep.address.address_line_4].reject{|a| a.blank?},
          :town          => ep.address.town,
          :postcode      => [ep.address.uk_post_code_pt1,ep.address.uk_post_code_pt2].join(" "),
          :mobile_number => ep.mobile_phone_number,
          :next_of_kin   => ep.fes_nok_contact_no,
          :date_of_birth => ep.date_of_birth,
          :uln           => uln,
          :mis_id        => ep.id
        )
        @person.save if options[:save] 
        @person.import_courses if options[:courses]
        return @person
      else
        return false
      end
    end

  end

  # Instance methods

  def timetable_events(options = {})
    logger.warn(options)
    from = options[:from] || Date.today.beginning_of_week
    to   = options[:to  ] || from.end_of_week
    Ebs::RegisterEventDetailsSlot.where(:object_id => mis_id, :object_type => ['L','T'], :planned_start_date => from..to).map do |s| 
      TimetableEvent.create(
        :title => s.description,
        :start => s.actual_start_date || s.planned_start_date,
        :end   => s.actual_end_date   || s.planned_end_date,
        :mark  => s.usage_code
      )
    end
  end
 
  def mis_search_for(query)
    Ebs::Person.search_for(query).limit(10).map{|p| import(p,:save => false, :courses => false)}
  end

  def photo_path
    return Ilp2::Application.config.mis_photo_path + "/" + mis_id.to_s + ".jpg"
  end

  def import_courses
    mis_person.people_units.each do |pu|
      course = Course.get(pu.uio_id)
      pc= PersonCourse.find_or_create_by_person_id_and_course_id(id,course.id)
      if pu.unit_type == "A" 
        pc.update_attributes(:status => :not_started,
                             :application_date => pu.created_date
                            )
      elsif pu.unit_type == "R"
        pc.update_attributes(:enrolment_date => pu.created_date,
                             :status => Ilp2::Application.config.mis_progress_codes[pu.progress_code],
                             :end_date => pu.progress_date) unless pc.status == :not_started
      end
    end
  end

end

module MisCourse

  def self.included receiver<commit_msg>Person#mis_search_for should be a class method<commit_after>module MisPerson

  def self.included receiver
    receiver.extend ClassMethods
    receiver.belongs_to :mis_person, :class_name => "Ebs::Person", :foreign_key => :mis_id
  end

  module ClassMethods

    def connector
      "EBS connector"
    end

    def import(uln, options = {})
      uln = uln.unique_learn_no if uln.kind_of? Ebs::Person
      options.reverse_merge! :save => true, :courses => true
      logger.info "Importing user #{uln}"
      if (ep = Ebs::Person.find_by_unique_learn_no(uln))
        @person = Person.find_or_create_by_uln(uln)
        @person.update_attributes(
          :forename      => ep.forename,
          :surname       => ep.surname,
          :middle_names  => ep.middle_names && ep.middle_names.split,
          :address       => [ep.address.address_line_1,ep.address.address_line_2,
                             ep.address.address_line_3,ep.address.address_line_4].reject{|a| a.blank?},
          :town          => ep.address.town,
          :postcode      => [ep.address.uk_post_code_pt1,ep.address.uk_post_code_pt2].join(" "),
          :mobile_number => ep.mobile_phone_number,
          :next_of_kin   => ep.fes_nok_contact_no,
          :date_of_birth => ep.date_of_birth,
          :uln           => uln,
          :mis_id        => ep.id
        )
        @person.save if options[:save] 
        @person.import_courses if options[:courses]
        return @person
      else
        return false
      end
    end

  def mis_search_for(query)
    Ebs::Person.search_for(query).limit(10).map{|p| import(p,:save => false, :courses => false)}
  end

  end

  # Instance methods

  def timetable_events(options = {})
    logger.warn(options)
    from = options[:from] || Date.today.beginning_of_week
    to   = options[:to  ] || from.end_of_week
    Ebs::RegisterEventDetailsSlot.where(:object_id => mis_id, :object_type => ['L','T'], :planned_start_date => from..to).map do |s| 
      TimetableEvent.create(
        :title => s.description,
        :start => s.actual_start_date || s.planned_start_date,
        :end   => s.actual_end_date   || s.planned_end_date,
        :mark  => s.usage_code
      )
    end
  end
 
  def photo_path
    return Ilp2::Application.config.mis_photo_path + "/" + mis_id.to_s + ".jpg"
  end

  def import_courses
    mis_person.people_units.each do |pu|
      course = Course.get(pu.uio_id)
      pc= PersonCourse.find_or_create_by_person_id_and_course_id(id,course.id)
      if pu.unit_type == "A" 
        pc.update_attributes(:status => :not_started,
                             :application_date => pu.created_date
                            )
      elsif pu.unit_type == "R"
        pc.update_attributes(:enrolment_date => pu.created_date,
                             :status => Ilp2::Application.config.mis_progress_codes[pu.progress_code],
                             :end_date => pu.progress_date) unless pc.status == :not_started
      end
    end
  end

end

module MisCourse

  def self.included receiver
{'fraction_non_alphanumeric': 0.11502386045746256, 'fraction_numerical': 0.003291097581043278, 'mean_word_length': 2.33589462129528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 61, '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': '5813130', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1975, 'n_words': 338}