Module: HUBClassRosterHandler

Extended by:
ActionView::Helpers::TextHelper
Defined in:
lib/HUB_class_roster_handler.rb

Class Method Summary collapse

Class Method Details

.email_help_about_missing_student(webiso_account, course) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/HUB_class_roster_handler.rb', line 82

def self.email_help_about_missing_student , course
  options = {:to => "[email protected]", :subject => "Need to add this user #{}@andrew.cmu.edu",
             :message => "We were adding registered HUB users to the course #{course.name}, but they are not in the system.",
             :url => "http://whiteboard.sv.cmu.edu/people/new?webiso_account=#{}@andrew.cmu.edu&is_student=true",
             :url_label => "Add person"}
  GenericMailer.email(options).deliver
end

.email_professors_about_added_and_dropped_students(course, info) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/HUB_class_roster_handler.rb', line 98

def self.email_professors_about_added_and_dropped_students course, info
  faculty_emails = course.faculty.collect(&:email)
  if faculty_emails.any?
    options = {:to => faculty_emails, :subject => "Roster change for your course #{course.name}",
               :message => self.roster_change_message(course, info[:added], info[:dropped], info[:not_in_system])}
# The message handles this well...
#                 :url_label => "Your course: " + course.number + " " + course.short_or_full_name,
#                 :url => "http://whiteboard.sv.cmu.edu/courses/#{course.id}" }
  else
    options = {:to => "[email protected]", :subject => "Please add faculty to this course",
               :message => "The HUB importer code was just run, however this course has no faculty assigned to it. Thus, I could not email them.",
               :url_label => "The course: " + course.number + " " + course.short_or_full_name,
               :url => "http://whiteboard.sv.cmu.edu/courses/#{course.id}" }
  end

  GenericMailer.email(options).deliver
end

.handle(roster_text) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/HUB_class_roster_handler.rb', line 4

def self.handle roster_text
  raise ArgumentError if roster_text.blank?
  roster_text = roster_text.gsub("\n", ' ').gsub("\r", ' ')
  parsed_courses = roster_text.split('CLASS ROSTER')

  unless parsed_courses.any?
    raise "Could not read your file, please check format."
  end

  users = User.all

  students_for_course = {}
  students_not_in_system_hash = {}
  no_courses_parsed = true

  parsed_courses.each do |parsed_course|
    if /Run Date: (.*) Course: (.*) Sect:\s*(\w+).*Semester: (.*)College:(.*)Department:(.*)Instructor\(s\): (.*)Name.*?_+(.*)/.match(parsed_course)
      no_courses_parsed = false
      course_number = $2.strip
      (semester, year) = AcademicCalendar.parse_HUB_semester($4.strip)

      student_webiso_accounts = $8.scan(/\d+\.\d.*?(\w+)/)

      course = Course.where(:semester => semester, :year => year, :number => course_number[0..1] + '-' + course_number[2..4]).first :include => [:registered_students]
      next unless course
      students_for_course[course] = students_for_course[course] || Set.new
      students_not_in_system_hash[course] = students_not_in_system_hash[course] || Set.new

      student_webiso_accounts.each do ||
        student = users.select { |u| u. == ("#{[0]}@andrew.cmu.edu") }.first
        #next
        unless student
          self.email_help_about_missing_student([0], course)
          students_not_in_system_hash[course] << [0]
          next
        end
        students_for_course[course] << student
      end
    end
  end

  if no_courses_parsed
    raise "Could not read your file, please check format."
  end

  Rails.logger.debug "Students_for_course::: #{students_for_course}"
  return self.handle_roster_changes students_for_course, students_not_in_system_hash
#    return self.handle_roster_changes students_for_course
end

.handle_roster_changes(students_for_course, students_not_in_system_hash) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/HUB_class_roster_handler.rb', line 54

def self.handle_roster_changes students_for_course, students_not_in_system_hash
#  def self.handle_roster_changes students_for_course
  roster_changes = {}
  changes = false
  students_for_course.each do |course, students|
    roster_changes[course] = {}
    roster_changes[course][:added] = students.to_a - course.registered_students
    roster_changes[course][:dropped] = course.registered_students - students.to_a
    roster_changes[course][:not_in_system] = students_not_in_system_hash[course]

    Rails.logger.debug "Added: #{roster_changes[course][:added]}"
    Rails.logger.debug "Dropped: #{roster_changes[course][:dropped]}"

    course.registered_students = course.registered_students - roster_changes[course][:dropped]
    course.registered_students = course.registered_students + roster_changes[course][:added]

    if roster_changes[course][:added].any? || roster_changes[course][:dropped].any?
      course.invalidate_distribution_list
      changes = true
    end
    course.save
  end
  Rails.logger.debug roster_changes
#    Disable emailing professors about roster changes
#    self.send_emails roster_changes
  return changes
end

.roster_change_message(course, added, dropped, not_in_system) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/HUB_class_roster_handler.rb', line 116

def self.roster_change_message course, added, dropped, not_in_system

  unless course
    message = "This email is supposed to contain information about course roster changes, but an error occurred while"
    message += "generating its contents.  Please contact <a href='mailto:[email protected]?subject=Roster%20Email%20Error'>Todd Sedano</a>"
    return message += "to resolve any issues."
  end

  message = "** This is an experimental feature. ** "
  message += "The official registration list for your course can be <a href='https://acis.as.cmu.edu/grades/'>found here</a>.<br/><br/>"
  message += "By loading in HUB data we can auto create class email distribution lists. Also, if you create teams with the rails system, then you can see who has not been assigned to a team. This does not currently track students on wait-lists. We only have access to students registered in 96-xxx courses.<br/><br/>"
  message += "The HUB does not provide us with registration information on a daily basis. Periodically, we manually upload HUB registrations. This is a summary of changes since the last time we updated information from the HUB.<br/><br/>"

  unless not_in_system.blank?
    message += "#{pluralize(not_in_system.count, "registered student")} #{not_in_system.count > 1 ? "are" : "is"} not in any of our SV systems:<br/>"
    not_in_system.each { |student|
      escaped_student = ERB::Util.html_escape(student)
      message += "&nbsp;&nbsp;&nbsp;#{escaped_student}@andrew.cmu.edu<br/>"
    }
    message += "We can easily create accounts for #{not_in_system.count > 1 ? "these" : "this"} #{pluralize(not_in_system.count, "student")}. Please forward this email to [email protected] indicating which students you want added. (The rails system will create google and twiki accounts.)<br/><br/>"
  end

  unless added.blank?
    message += "#{pluralize(added.count, "student")} #{added.count > 1 ? "were" : "was"} added to the course:<br/>"
    added.each { |student|
      escaped_first_name = ERB::Util.html_escape(student.first_name)
      escaped_last_name = ERB::Util.html_escape(student.last_name)
      message += "&nbsp;&nbsp;&nbsp;#{escaped_first_name} #{escaped_last_name}<br/>"
    }
  end

  unless dropped.blank?
    message += "#{pluralize(dropped.count, "student")} #{dropped.count > 1 ? "were" : "was"} dropped from the course:<br/>"
    dropped.each { |student|
      escaped_first_name = ERB::Util.html_escape(student.first_name)
      escaped_last_name = ERB::Util.html_escape(student.last_name)
      message += "&nbsp;&nbsp;&nbsp;#{escaped_first_name} #{escaped_last_name}<br/>"
    }
  end

  escaped_course_email = ERB::Util.html_escape(course.email)
  message += "<br/>The system will be updating your course mailing list (#{escaped_course_email}) For more information, see your <a href='http://whiteboard.sv.cmu.edu/courses/#{course.id}'>course tools</a><br/><br/>"

  message
end

.send_emails(roster_changes) ⇒ Object



91
92
93
94
95
96
# File 'lib/HUB_class_roster_handler.rb', line 91

def self.send_emails roster_changes
  roster_changes.each do |course, info|
    next if info[:added].blank? && info[:dropped].blank? && info[:not_in_system].blank?
    email_professors_about_added_and_dropped_students(course, info)
  end
end