app/models/offerings/offering.rb
def majors_mapping(status = :confirmed, reference_quarter = nil)
    reference_quarter ||= Quarter.find_by_date(deadline)
    OFFERINGS_CACHE.fetch("majors_mapping_#{id}_#{status.to_s.underscore}_#{reference_quarter.abbrev}", :expires_in => 24.hours) do
      @apps = application_for_offerings.with_status(status)
      majors ||= {}
      all_apps ||= (@apps + @apps.collect(&:group_members)).flatten.compact
      applicants ||= all_apps.collect(&:person).flatten.compact.uniq
      major_extras ||= MajorExtra.all
      major_abbrs ||= {}
      for major_extra in major_extras
        major_abbrs[major_extra.major_abbr.strip] = [] unless major_abbrs[major_extra.major_abbr.strip]
        major_abbrs[major_extra.major_abbr.strip] << major_extra
      end
      for a in all_apps
        if a.person
          # print a.person.id.to_s.ljust(10)
          if a.person.is_a?(Student) && (Quarter.current_quarter != Quarter.find_by_date(confirmation_deadline))
            sk = a.person.system_key
            rq = reference_quarter            
            t = StudentTranscript.find(sk, rq.year, rq.quarter_code_id) rescue nil
            t = (StudentTranscript.find(sk, rq.prev.year, rq.prev.quarter_code_id) rescue nil) if t.nil?
            ref_majors = t.nil? ? [] : t.majors
            # puts ref_majors.size
          else
            ref_majors = a.person.majors
          end
          major_extra = nil
          for major in ref_majors
            major_name = major
            if major.is_a?(StudentMajor) || major.is_a?(StudentTranscriptMajor)
              # major_extra_field = @major_extras.select{|m| major.major_abbr.strip == m.major_abbr.strip }
              # major_extra = major_extra_field.select{|m| major.branch == m.major_branch && major.pathway == m.major_pathway }
              if major_abbrs[major.major_abbr.strip]
                major_extra = major_abbrs[major.major_abbr.strip].find{|m| major.branch == m.major_branch && major.pathway == m.major_pathway }
              end
              major_name = major_extra.nil? ? major.full_name : major_extra.fixed_name
            end
            majors[major_name] = (majors[major_name].nil? ? [a.app.id] : majors[major_name] << a.app.id) unless major_name.blank?
          end
        end
      end
      majors
    end
  end
# Creates (or restores from cache) a hash with keys of major names and values of arrays of application ID numbers.
# Default cache is 24 hours.
Creates (or restores from cache) a hash with keys of major names and values of arrays of application ID numbers.
Default cache is 24 hours.
Creates ( or restores from cache ) a hash with keys of major names and values of arrays of application ID numbers . Default cache is 24 hours .
def majors_mapping(status = :confirmed, reference_quarter = nil)
    reference_quarter ||= Quarter.find_by_date(deadline)
    OFFERINGS_CACHE.fetch("majors_mapping_#{id}_#{status.to_s.underscore}_#{reference_quarter.abbrev}", :expires_in => 24.hours) do
      @apps = application_for_offerings.with_status(status)
      majors ||= {}
      all_apps ||= (@apps + @apps.collect(&:group_members)).flatten.compact
      applicants ||= all_apps.collect(&:person).flatten.compact.uniq
      major_extras ||= MajorExtra.all
      major_abbrs ||= {}
      for major_extra in major_extras
        major_abbrs[major_extra.major_abbr.strip] = [] unless major_abbrs[major_extra.major_abbr.strip]
        major_abbrs[major_extra.major_abbr.strip] << major_extra
      end
      for a in all_apps
        if a.person
          if a.person.is_a?(Student) && (Quarter.current_quarter != Quarter.find_by_date(confirmation_deadline))
            sk = a.person.system_key
            rq = reference_quarter            
            t = StudentTranscript.find(sk, rq.year, rq.quarter_code_id) rescue nil
            t = (StudentTranscript.find(sk, rq.prev.year, rq.prev.quarter_code_id) rescue nil) if t.nil?
            ref_majors = t.nil? ? [] : t.majors
          else
            ref_majors = a.person.majors
          end
          major_extra = nil
          for major in ref_majors
            major_name = major
            if major.is_a?(StudentMajor) || major.is_a?(StudentTranscriptMajor)
              if major_abbrs[major.major_abbr.strip]
                major_extra = major_abbrs[major.major_abbr.strip].find{|m| major.branch == m.major_branch && major.pathway == m.major_pathway }
              end
              major_name = major_extra.nil? ? major.full_name : major_extra.fixed_name
            end
            majors[major_name] = (majors[major_name].nil? ? [a.app.id] : majors[major_name] << a.app.id) unless major_name.blank?
          end
        end
      end
      majors
    end
  end
def majors_mapping ( status = :confirmed , reference_quarter = nil ) reference_quarter ||= Quarter . find_by_date ( deadline ) OFFERINGS_CACHE . fetch ( "majors_mapping_#{id}_#{status.to_s.underscore}_#{reference_quarter.abbrev}" , :expires_in => 24 . hours ) do @apps = application_for_offerings . with_status ( status ) majors ||= { } all_apps ||= ( @apps + @apps . collect ( & :group_members ) ) . flatten . compact applicants ||= all_apps . collect ( & :person ) . flatten . compact . uniq major_extras ||= MajorExtra . all major_abbrs ||= { } for major_extra in major_extras major_abbrs [ major_extra . major_abbr . strip ] = [ ] unless major_abbrs [ major_extra . major_abbr . strip ] major_abbrs [ major_extra . major_abbr . strip ] << major_extra end for a in all_apps if a . person if a . person . is_a? ( Student ) && ( Quarter . current_quarter != Quarter . find_by_date ( confirmation_deadline ) ) sk = a . person . system_key rq = reference_quarter t = StudentTranscript . find ( sk , rq . year , rq . quarter_code_id ) rescue nil t = ( StudentTranscript . find ( sk , rq . prev . year , rq . prev . quarter_code_id ) rescue nil ) if t . nil? ref_majors = t . nil? ? [ ] : t . majors else ref_majors = a . person . majors end major_extra = nil for major in ref_majors major_name = major if major . is_a? ( StudentMajor ) || major . is_a? ( StudentTranscriptMajor ) if major_abbrs [ major . major_abbr . strip ] major_extra = major_abbrs [ major . major_abbr . strip ] . find { | m | major . branch == m . major_branch && major . pathway == m . major_pathway } end major_name = major_extra . nil? ? major . full_name : major_extra . fixed_name end majors [ major_name ] = ( majors [ major_name ] . nil? ? [ a . app . id ] : majors [ major_name ] << a . app . id ) unless major_name . blank? end end end majors end end
Creates (or restores from cache) a hash with keys of major names and values of arrays of application ID numbers.
Creates ( or restores from cache ) a hash with keys of major names and values of arrays of application ID numbers .
# print a.person.id.to_s.ljust(10) # puts ref_majors.size # major_extra_field = @major_extras.select{|m| major.major_abbr.strip == m.major_abbr.strip } # major_extra = major_extra_field.select{|m| major.branch == m.major_branch && major.pathway == m.major_pathway }
status
reference_quarter