Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defect basili academiccalendar #268

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 65 additions & 189 deletions app/services/academic_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@ class AcademicCalendar
# Fall starts 1 week before and goes to roughly around Christmas
#
# In reality, this should be based upon when grades are due.

TERM_LENGTH = { "Fall" => { "A" => 7, "B" => 7, "Both" => 15 },
"Spring" => { "A" => 7, "B" => 7, "Both" => 16 },
"Summer" => { "A" => 6, "B" => 6, "Both" => 12 } }

SPRING_BREAK = { 2014 => 10..11, 2013 => 10..11, 2012 => 10..11, 2011 => 9..10, 2010 => 9..10 }

SEMESTER_START = { 2015 => { "Spring" => 3, "Summer" => 21, "Fall" => 35 },
2014 => { "Spring" => 3, "Summer" => 21, "Fall" => 35 },
2013 => { "Spring" => 3, "Summer" => 21, "Fall" => 35 },
2012 => { "Spring" => 3, "Summer" => 21, "Fall" => 35 },
2011 => { "Spring" => 2, "Summer" => 20, "Fall" => 35 },
2010 => { "Spring" => 2, "Summer" => 20, "Fall" => 34 },
2009 => { "Spring" => 3, "Summer" => 21, "Fall" => 34 },
2008 => { "Spring" => 2, "Summer" => 16, "Fall" => 35 } }

GRADES_DUE_FOR = { 2014 => { "Spring" => Date.new(2014, 5, 21),
"Summer" => Date.new(2014, 8, 12),
"Fall" => Date.new(2014, 12, 18) },
2013 => { "Spring" => Date.new(2013, 5, 22),
"Summer" => Date.new(2013, 8, 13),
"Fall" => Date.new(2013, 12, 18) },
2012 => { "Spring" => Date.new(2012, 5, 22),
"Summer" => Date.new(2012, 8, 14),
"Fall" => Date.new(2012, 12, 20) },
2011 => { "Spring" => Date.new(2011, 5, 17),
"Summer" => Date.new(2011, 8, 9),
"Fall" => Date.new(2011, 12, 22) },
2010 => { "Spring" => Date.new(2010, 5, 18),
"Summer" => Date.new(2010, 8, 10),
"Fall" => Date.new(2010, 12, 16) } }


def self.current_semester_old
cweek = Date.today.cweek()
return "Spring" if cweek < AcademicCalendar.semester_start("Summer", Date.today.cwyear) - 1 || cweek > 51
Expand Down Expand Up @@ -108,60 +141,22 @@ def self.week_during_semester?(year, week_number)
end

def self.spring_break(year)
case year
when 2014
return 10..11
when 2013
return 10..11
when 2012
return 10..11
when 2011
return 9..10
when 2010
return 9..10
else
options = {:to => "[email protected]",
:subject => "Academic Calendar needs updating: spring_break",
:message => "Please modify app/services/AcademicCalendar.rb spring_break(#{year})",
:url_label => "",
:url => ""
}
GenericMailer.email(options).deliver
return nil
if SPRING_BREAK[year].nil?
options = {:to => "[email protected]",
:subject => "Academic Calendar needs updating: spring_break",
:message => "Please modify app/services/AcademicCalendar.rb spring_break(#{year})",
:url_label => "",
:url => ""
}
GenericMailer.email(options).deliver
return nil
else
return SPRING_BREAK[year]
end
end


def self.term_length(semester, mini)
case semester
when "Fall"
case mini
when "A"
7
when "B"
7
when "Both"
15
end
when "Spring"
case mini
when "A"
7
when "B"
7
when "Both"
16
end
when "Summer"
case mini
when "A"
6
when "B"
6
when "Both"
12
end
end
TERM_LENGTH[semester][mini]
end

def self.break_length_between_minis(semester)
Expand All @@ -176,69 +171,22 @@ def self.break_length_between_minis(semester)
end

def self.grades_due_for(semester, year)
case year
when 2014
case semester
when "Spring"
return Date.new(2014, 5, 21) #Academic calendar doesn't exaclty say?
when "Summer"
return Date.new(2014, 8, 12)
when "Fall"
return Date.new(2014, 12, 18)
end
when 2013
case semester
when "Spring"
return Date.new(2013, 5, 22)
when "Summer"
return Date.new(2013, 8, 13)
when "Fall"
return Date.new(2013, 12, 18)
end
when 2012
case semester
when "Spring"
return Date.new(2012, 5, 22)
when "Summer"
return Date.new(2012, 8, 14)
when "Fall"
return Date.new(2012, 12, 20)
end
when 2011
case semester
when "Spring"
return Date.new(2011, 5, 17)
when "Summer"
return Date.new(2011, 8, 9)
when "Fall"
return Date.new(2011, 12, 22)
end
when 2010
case semester
when "Spring"
return Date.new(2010, 5, 18)
when "Summer"
return Date.new(2010, 8, 10)
when "Fall"
return Date.new(2010, 12, 16)
end
else
options = {:to => "[email protected]",
:subject => "Academic Calendar needs updating: grades_due_for",
:message => "Please modify app/services/AcademicCalendar.rb grades_due_for(#{semester}, #{year})",
:url_label => "",
:url => ""
}
GenericMailer.email(options).deliver
if GRADES_DUE_FOR[year].nil?
options = {:to => "[email protected]",
:subject => "Academic Calendar needs updating: grades_due_for",
:message => "Please modify app/services/AcademicCalendar.rb grades_due_for(#{semester}, #{year})",
:url_label => "",
:url => ""
}
GenericMailer.email(options).deliver
else
GRADES_DUE_FOR[year][semester]
end


end

#Historically we have used semester start to determine what is the current semester, moving forward, lets do this
#around the grades due deadline


# First day of class
# August 26, 2013
# January 13, 2014
Expand All @@ -250,89 +198,17 @@ def self.grades_due_for(semester, year)
# August 7, 2014

def self.semester_start(semester, year)
case year
when 2015
case semester
when "Spring" #Not official yet (4/1/2014)
return 3
when "Summer" #Not official yet (4/1/2014)
return 21
when "Fall" #Not official yet (4/1/2014)
return 35
end
when 2014
case semester
when "Spring"
return 3
when "Summer"
return 21
when "Fall" #Not official yet (1/2/2012)
return 35
end
when 2013
case semester
when "Spring"
return 3
when "Summer"
return 21
when "Fall"
return 35
end
when 2012
case semester
when "Spring"
return 3
when "Summer"
return 21
when "Fall"
return 35
end
when 2011
case semester
when "Spring"
return 2
when "Summer"
return 20
when "Fall"
return 35
end
when 2010
case semester
when "Spring"
return 2
when "Summer"
return 20
when "Fall"
return 34
end
when 2009
case semester
when "Spring"
return 3
when "Summer"
return 21
when "Fall"
return 34
end
when 2008 #This calendar is not aligned to the CMU Pittsburgh calendar
case semester
when "Spring"
return 2
when "Summer"
return 16
when "Fall"
return 35
end
else
options = {:to => "[email protected]",
:subject => "Academic Calendar needs updating: semester_start",
:message => "Please modify app/models/AcademicCalendar.rb semester_start(#{semester}, #{year})",
:url_label => "",
:url => ""
}
GenericMailer.email(options).deliver
if SEMESTER_START[year][semester].nil?
options = {:to => "[email protected]",
:subject => "Academic Calendar needs updating: semester_start",
:message => "Please modify app/models/AcademicCalendar.rb semester_start(#{semester}, #{year})",
:url_label => "",
:url => ""
}
GenericMailer.email(options).deliver
else
SEMESTER_START[year][semester]
end

end

def self.date_for_semester_start(semester, year)
Expand Down
32 changes: 32 additions & 0 deletions spec/services/academic_calendar_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'
require_relative '../../app/services/academic_calendar.rb'

describe AcademicCalendar do

context "Academic Calendar" do

it 'should return spring break range' do
AcademicCalendar.spring_break(2014).should eq(10..11)
end

it 'should return term lengths' do
AcademicCalendar.term_length("Fall", "A").should eq(7)
AcademicCalendar.term_length("Fall", "B").should eq(7)
AcademicCalendar.term_length("Fall", "Both").should eq(15)

AcademicCalendar.term_length("Spring", "A").should eq(7)
AcademicCalendar.term_length("Spring", "B").should eq(7)
AcademicCalendar.term_length("Spring", "Both").should eq(16)

AcademicCalendar.term_length("Summer", "A").should eq(6)
AcademicCalendar.term_length("Summer", "B").should eq(6)
AcademicCalendar.term_length("Summer", "Both").should eq(12)
end

it 'should return due date for grades' do
AcademicCalendar.grades_due_for("Spring", 2014).should eq(Date.new(2014, 5, 21))
end

end

end