app/models/activities/accountability_report.rb
def inject_departments(force = false)
    load_results(:with_averages_added, force) if force || @results.empty?
    @log_step = :with_departments
    @overwrite_log = true
    puts "Injecting department identifiers into results", true
    # puts ". = Department was found in SDB     0 = Department was not found in SDB    E = Source is EXPO so sponsoring unit is used   R = Extra reporting department was specified and added"
    for system_key, quarter_hash in @results
      for quarter_abbrev, activities in quarter_hash
        for activity in activities          
          course_identifier = nil
          service_learning_department_identifier = nil
          
          klass, id = activity[:activity].split("_")
          a = klass.constantize.find(id) rescue nil
          print system_key.to_s.ljust(11)
          print "department: #{(a.department_name || a.department_id rescue nil).to_s[0..47]}".ljust(62, ".")          
          
          if a.is_a?(Activity) && !a.department_id.blank?
            department_identifier = "#{a.department_id.to_s}_#{a.department.try(:name)}"
            # print "."
          elsif a.is_a?(ServiceLearningPlacement)
              if a.course && !a.course.courses.blank?
                for c in a.course.courses                  
                   if c.course.enrolls?(Person.find(a.person_id)) # TODO new ruby version 1.8.7 head causes the SQL statement error on this query. Work around to rescue false. Neet to find a way for this.
                      department_identifier = "#{c.course.department.dept_code.to_s}_#{c.course.department.try(:name)}"
                      course_identifier = "#{c.course.short_title}"
                   end rescue false
                end                                                
              else
                department_identifier = "No registered course, Volunteer"
              end
              
              if a.unit_id == 4
                service_learning_department_identifier = "0_Pipeline Project"
              elsif a.unit_id == 9
                service_learning_department_identifier = "0_Bothell Service-Learning"
              else 
                service_learning_department_identifier = "0_Carlson Center"                                
              end              
                          
            # print "E"
          elsif a.respond_to?(:unit)
            department_identifier = "0_#{a.unit.name}"
            # print "E"
          else
            department_identifier = "0_#{a.department_name}"
            # print "0"
          end
          activity[:department] = department_identifier          
          puts department_identifier
          activity[:course] = course_identifier
          print "           course: ".ljust(73, ".")
          puts activity[:course] || "nil (not specified)"
          activity[:reporting_department] = service_learning_department_identifier
        end             
        
        if a.is_a?(ActivityCourse)
          print "           reporting_department: #{(a.reporting_department_name || a.reporting_department_id).to_s[0..37]}".ljust(73, ".")
          if !a.reporting_department_id.blank?
            reporting_department_identifier = "#{a.reporting_department_id.to_s}_#{a.reporting_department.try(:name)}"
          elsif !a.reporting_department_name.blank?
            reporting_department_identifier = "0_#{a.reporting_department_name}"
          else
            reporting_department_identifier = nil
          end
          if reporting_department_identifier && reporting_department_identifier != department_identifier
            activity[:reporting_department] = reporting_department_identifier
          end
          puts activity[:reporting_department] || "nil (same as department, or not specified)"
        end
      end
    end
    puts "\n#{@results.size} unique students."
    puts "Saved results output to #{dump_results!(:with_departments)}"
  end
# Inserts the department identifier into the activity hash in the form "<department ID or zero>_<department full name>" using
# the following rules:
# 
# * For activities with a department_id defined in the Activity record, we use that department
# * For ActivityCourse records, a separate "reporting department" can be specified, in which case we populate a
#   :reporting_department attribute in the hash (as long as the reporting department is not the same as the activity department).
# * For ServiceLearningPlacements, the department is set as "0_Carlson Center". In June, 2011, break down Carlson Center Placement to departments and inject courses.
# * For objects that have an associated Unit in EXPO (e.g., Scholarship offerings and symposium), the department is set
#   as "0_<unit name>"
# * For all others, the the department is set as "0_<department_name>"
Inserts the department identifier into the activity hash in the form "_" using
the following rules.

For activities with a department_id defined in the Activity record, we use that department
For ActivityCourse records, a separate "reporting department" can be specified, in which case we populate a
:reporting_department attribute in the hash (as long as the reporting department is not the same as the activity department).
For ServiceLearningPlacements, the department is set as "0_Carlson Center". In June, 2011, break down Carlson Center Placement to departments and inject courses.
For objects that have an associated Unit in EXPO , the department is set
as "0_"
For all others, the the department is set as "0_"
Inserts the department identifier into the activity hash in the form " _ " using the following rules . For activities with a department_id defined in the Activity record we use that department For ActivityCourse records a separate " reporting department " can be specified in which case we populate a : reporting_department attribute in the hash ( as long as the reporting department is not the same as the activity department ) . For ServiceLearningPlacements the department is set as " 0_Carlson Center " . In June 2011 break down Carlson Center Placement to departments and inject courses . For objects that have an associated Unit in EXPO the department is set as " 0_ " For all others the the department is set as " 0_ "
def inject_departments(force = false)
    load_results(:with_averages_added, force) if force || @results.empty?
    @log_step = :with_departments
    @overwrite_log = true
    puts "Injecting department identifiers into results", true
    for system_key, quarter_hash in @results
      for quarter_abbrev, activities in quarter_hash
        for activity in activities          
          course_identifier = nil
          service_learning_department_identifier = nil
          klass, id = activity[:activity].split("_")
          a = klass.constantize.find(id) rescue nil
          print system_key.to_s.ljust(11)
          print "department: #{(a.department_name || a.department_id rescue nil).to_s[0..47]}".ljust(62, ".")          
          if a.is_a?(Activity) && !a.department_id.blank?
            department_identifier = "#{a.department_id.to_s}_#{a.department.try(:name)}"
          elsif a.is_a?(ServiceLearningPlacement)
              if a.course && !a.course.courses.blank?
                for c in a.course.courses                  
                   if c.course.enrolls?(Person.find(a.person_id)) 
                      department_identifier = "#{c.course.department.dept_code.to_s}_#{c.course.department.try(:name)}"
                      course_identifier = "#{c.course.short_title}"
                   end rescue false
                end                                                
              else
                department_identifier = "No registered course, Volunteer"
              end
              if a.unit_id == 4
                service_learning_department_identifier = "0_Pipeline Project"
              elsif a.unit_id == 9
                service_learning_department_identifier = "0_Bothell Service-Learning"
              else 
                service_learning_department_identifier = "0_Carlson Center"                                
              end              
          elsif a.respond_to?(:unit)
            department_identifier = "0_#{a.unit.name}"
          else
            department_identifier = "0_#{a.department_name}"
          end
          activity[:department] = department_identifier          
          puts department_identifier
          activity[:course] = course_identifier
          print "           course: ".ljust(73, ".")
          puts activity[:course] || "nil (not specified)"
          activity[:reporting_department] = service_learning_department_identifier
        end             
        if a.is_a?(ActivityCourse)
          print "           reporting_department: #{(a.reporting_department_name || a.reporting_department_id).to_s[0..37]}".ljust(73, ".")
          if !a.reporting_department_id.blank?
            reporting_department_identifier = "#{a.reporting_department_id.to_s}_#{a.reporting_department.try(:name)}"
          elsif !a.reporting_department_name.blank?
            reporting_department_identifier = "0_#{a.reporting_department_name}"
          else
            reporting_department_identifier = nil
          end
          if reporting_department_identifier && reporting_department_identifier != department_identifier
            activity[:reporting_department] = reporting_department_identifier
          end
          puts activity[:reporting_department] || "nil (same as department, or not specified)"
        end
      end
    end
    puts "\n#{@results.size} unique students."
    puts "Saved results output to #{dump_results!(:with_departments)}"
  end
def inject_departments ( force = false ) load_results ( :with_averages_added , force ) if force || @results . empty? @log_step = :with_departments @overwrite_log = true puts "Injecting department identifiers into results" , true for system_key , quarter_hash in @results for quarter_abbrev , activities in quarter_hash for activity in activities course_identifier = nil service_learning_department_identifier = nil klass , id = activity [ :activity ] . split ( "_" ) a = klass . constantize . find ( id ) rescue nil print system_key . to_s . ljust ( 11 ) print "department: #{(a.department_name || a.department_id rescue nil).to_s[0..47]}" . ljust ( 62 , "." ) if a . is_a? ( Activity ) && ! a . department_id . blank? department_identifier = "#{a.department_id.to_s}_#{a.department.try(:name)}" elsif a . is_a? ( ServiceLearningPlacement ) if a . course && ! a . course . courses . blank? for c in a . course . courses if c . course . enrolls? ( Person . find ( a . person_id ) ) department_identifier = "#{c.course.department.dept_code.to_s}_#{c.course.department.try(:name)}" course_identifier = "#{c.course.short_title}" end rescue false end else department_identifier = "No registered course, Volunteer" end if a . unit_id == 4 service_learning_department_identifier = "0_Pipeline Project" elsif a . unit_id == 9 service_learning_department_identifier = "0_Bothell Service-Learning" else service_learning_department_identifier = "0_Carlson Center" end elsif a . respond_to? ( :unit ) department_identifier = "0_#{a.unit.name}" else department_identifier = "0_#{a.department_name}" end activity [ :department ] = department_identifier puts department_identifier activity [ :course ] = course_identifier print "           course: " . ljust ( 73 , "." ) puts activity [ :course ] || "nil (not specified)" activity [ :reporting_department ] = service_learning_department_identifier end if a . is_a? ( ActivityCourse ) print "           reporting_department: #{(a.reporting_department_name || a.reporting_department_id).to_s[0..37]}" . ljust ( 73 , "." ) if ! a . reporting_department_id . blank? reporting_department_identifier = "#{a.reporting_department_id.to_s}_#{a.reporting_department.try(:name)}" elsif ! a . reporting_department_name . blank? reporting_department_identifier = "0_#{a.reporting_department_name}" else reporting_department_identifier = nil end if reporting_department_identifier && reporting_department_identifier != department_identifier activity [ :reporting_department ] = reporting_department_identifier end puts activity [ :reporting_department ] || "nil (same as department, or not specified)" end end end puts "\n#{@results.size} unique students." puts "Saved results output to #{dump_results!(:with_departments)}" end
Inserts the department identifier into the activity hash in the form "<department ID or zero>_<department full name>" using
the following rules:
Inserts the department identifier into the activity hash in the form " <department ID or zero > _<department full name > " using the following rules :
# puts ". = Department was found in SDB     0 = Department was not found in SDB    E = Source is EXPO so sponsoring unit is used   R = Extra reporting department was specified and added" # print "." # TODO new ruby version 1.8.7 head causes the SQL statement error on this query. Work around to rescue false. Neet to find a way for this. # print "E" # print "E" # print "0"
force