Skip to content

Commit

Permalink
support additional enrollment and major attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fanglinfang committed May 1, 2017
1 parent 9666e27 commit 1112254
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 30 deletions.
14 changes: 14 additions & 0 deletions uw_sws/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def _json_to_enrollment(json_data, term):
enrollment.regid = json_data['RegID']
enrollment.class_level = json_data['ClassLevel']
enrollment.is_honors = json_data['HonorsProgram']

value = json_data['PendingMajorChange']
enrollment.has_pending_major_change = value

enrollment.is_enroll_src_pce = is_src_location_pce(json_data,
ENROLLMENT_SOURCE_PCE)
enrollment.off_term_sections = {}
Expand Down Expand Up @@ -146,7 +150,17 @@ def _json_to_off_term_section(json_data, aterm):
def _json_to_major(json_data):
major = Major()
major.degree_abbr = json_data['Abbreviation']
try:
major.college_abbr = json_data['CollegeAbbreviation']
except KeyError:
major.college_abbr = ""
try:
major.college_full_name = json_data['CollegeFullName']
except KeyError:
major.college_full_name = ""

major.degree_name = json_data['DegreeName']
major.degree_level = int(json_data['DegreeLevel'])
major.full_name = json_data['FullName']
major.major_name = json_data['MajorName']
major.short_name = json_data['ShortName']
Expand Down
25 changes: 24 additions & 1 deletion uw_sws/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ class Enrollment(models.Model):
db_index=True,
unique=True)
is_enroll_src_pce = models.NullBooleanField()
has_pending_major_change = models.NullBooleanField()

def is_non_matric(self):
return self.class_level.lower() == Enrollment.CLASS_LEVEL_NON_MATRIC
Expand All @@ -994,15 +995,29 @@ def has_off_term_course(self):


class Major(models.Model):
degree_abbr = models.CharField(max_length=50)
college_abbr = models.CharField(max_length=50)
college_full_name = models.CharField(max_length=100)
degree_name = models.CharField(max_length=100)
degree_abbr = models.CharField(max_length=100)
degree_level = models.IntegerField()
full_name = models.CharField(max_length=100)
major_name = models.CharField(max_length=100)
short_name = models.CharField(max_length=50)
campus = models.CharField(max_length=8)

def __eq__(self, other):
return (other is not None and
type(self) == type(other) and
self.__key() == other.__key())

def __key(self):
return (self.campus, self.college_abbr, self.major_name)

def json_data(self):
return {'degree_abbr': self.degree_abbr,
'college_abbr': self.college_abbr,
'college_full_name': self.college_abbr,
'degree_level': self.degree_level,
'degree_name': self.degree_name,
'campus': self.campus,
'name': self.major_name,
Expand All @@ -1018,6 +1033,14 @@ class Minor(models.Model):
full_name = models.CharField(max_length=100)
short_name = models.CharField(max_length=50)

def __eq__(self, other):
return (other is not None and
type(self) == type(other) and
self.__key() == other.__key())

def __key(self):
return (self.campus, self.full_name)

def json_data(self):
return {'abbr': self.abbr,
'campus': self.campus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,11 @@
"RegID": "9136CCB8F66711D5BE060004AC494FFE"
},
"QtrGradePoints": 30,
"QtrGradedAttmp": 10,
"QtrNonGrdEarned": 2,
"RegID": "9136CCB8F66711D5BE060004AC494FFE",
"Registrations": [
{
"QtrGradedAttmp": 10,
"QtrNonGrdEarned": 2,
"RegID": "9136CCB8F66711D5BE060004AC494FFE",
"Registrations": [
{
"AddAccessCode": "",
"Auditor": false,
"Credits": " 2.0",
Expand Down Expand Up @@ -943,8 +943,8 @@
},
"VariableCredit": false,
"WritingCourse": false
},
{
},
{
"AddAccessCode": "",
"Auditor": false,
"Credits": " 5.0",
Expand Down Expand Up @@ -975,8 +975,8 @@
},
"VariableCredit": false,
"WritingCourse": false
},
{
},
{
"AddAccessCode": "",
"Auditor": false,
"Credits": " 3.0",
Expand Down Expand Up @@ -1007,8 +1007,8 @@
},
"VariableCredit": false,
"WritingCourse": true
},
{
},
{
"AddAccessCode": "",
"Auditor": false,
"Credits": " 1.0",
Expand Down Expand Up @@ -1039,8 +1039,8 @@
},
"VariableCredit": false,
"WritingCourse": true
},
{
},
{
"AddAccessCode": "",
"Auditor": false,
"Credits": " 1.0",
Expand Down Expand Up @@ -1088,20 +1088,24 @@
"LeaveEndYear": 0,
"Majors": [
{
"Abbreviation": "ACMS",
"Campus": "Seattle",
"DegreeLevel": 1,
"DegreeName": "BACHELOR OF SCIENCE (APPLIED & COMPUTATIONAL MATH SCIENCES)",
"DegreeType": 5,
"FullName": "App & Comp Math Sci (Social & Behav Sci)",
"MajorName": "ACMS (SOC & BEH SCI)",
"Pathway": 80,
"ShortName": "ACMS (SBS)"
"Abbreviation":"ENGL",
"Campus":"Seattle",
"CollegeAbbreviation":"A & S",
"CollegeFullName":"COLLEGE OF ARTS & SCIENCES",
"DegreeLevel":1,
"DegreeName":"BACHELOR OF ARTS (ENGLISH)",
"DegreeType":1,
"FullName":"English",
"MajorName":"ENGLISH",
"Pathway":0,
"ShortName":"ENGLISH"
}
],
"Metadata":"EnrollmentSourceLocation=SDB;",
"Minors":[],
"PendingClassChange": false,
"PendingHonorsChange": false,
"PendingMajorChange": false,
"PendingMajorChange": true,
"PendingResidentChange": false,
"PendingSpecialProgramChange": false,
"Person": {
Expand Down
38 changes: 32 additions & 6 deletions uw_sws/tests/test_enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from uw_pws.util import fdao_pws_override
from uw_sws.models import Term
from uw_sws.term import get_current_term, get_next_term,\
get_term_by_year_and_quarter, get_term_after
get_term_by_year_and_quarter, get_term_after, get_term_before
from uw_sws.enrollment import get_grades_by_regid_and_term,\
is_src_location_pce, ENROLLMENT_SOURCE_PCE, has_start_end_dates,\
get_enrollment_by_regid_and_term, enrollment_search_by_regid
Expand Down Expand Up @@ -46,6 +46,7 @@ def test_javerage_major(self):
self.assertFalse(enrollment.is_non_matric())
self.assertFalse(enrollment.has_off_term_course())
self.assertFalse(enrollment.is_enroll_src_pce)
self.assertFalse(enrollment.has_pending_major_change)

def test_is_src_location_pce(self):
self.assertFalse(is_src_location_pce(
Expand Down Expand Up @@ -115,14 +116,19 @@ def test_offterm_enrolled_courses(self):
enrollment.off_term_sections.get("2014,winter,PSYCH,203/A"))

def test_enrollment_search(self):
# off term course sections
# pce course enrollments
result_dict = enrollment_search_by_regid(
'AABBCCDDEEFFAABBCCDDEEFFAABBCCDC')
self.assertEqual(len(result_dict), 2)

term = get_current_term()
self.assertTrue(term in result_dict)
enrollment = result_dict.get(term)
self.assertTrue(enrollment.is_non_matric())
self.assertEquals(enrollment.majors[0].college_abbr, "INDUG")
self.assertEquals(enrollment.majors[0].college_full_name,
"INTERDISCIPLINARY UNDERGRADUATE PROGRAMS")
self.assertEquals(enrollment.majors[0].degree_level, 0)
self.assertEqual(len(enrollment.off_term_sections), 3)
self.assertTrue(
"2013,spring,AAES,150/A" in enrollment.off_term_sections)
Expand All @@ -134,6 +140,12 @@ def test_enrollment_search(self):
self.assertEqual(str(section1.end_date), '2013-06-19 00:00:00')
self.assertEqual(str(section1.start_date), '2013-04-01 00:00:00')
self.assertTrue(section1.is_reg_src_pce)

term0 = get_term_before(term)
self.assertTrue(term0 in result_dict)
enrollment0 = result_dict.get(term0)
self.assertEquals(enrollment.majors[0], enrollment0.majors[0])
self.assertEqual(len(enrollment0.off_term_sections), 2)

# regular course
result_dict = enrollment_search_by_regid(
Expand All @@ -146,17 +158,31 @@ def test_enrollment_search(self):
self.assertEquals(enrollment.class_level, "SENIOR")
self.assertEquals(len(enrollment.majors), 1)
self.assertEquals(len(enrollment.minors), 1)
enroll_major = enrollment.majors[0]
self.assertEquals(enroll_major.college_abbr, "")
self.assertEquals(enroll_major.college_full_name, "")
self.assertEquals(enroll_major.degree_level, 1)
self.assertEquals(len(enrollment.minors), 1)
enroll_minor = enrollment.minors[0]

term1 = get_term_by_year_and_quarter(2013, 'summer')
self.assertTrue(term1 in result_dict)
enroll1 = result_dict.get(term1)
self.assertIsNotNone(enroll1)
self.assertTrue(enroll1.has_pending_major_change)
enroll1_major = enroll1.majors[0]
self.assertFalse(enroll_major == enroll1_major)

term2 = get_term_by_year_and_quarter(2013, 'autumn')
self.assertIsNone(result_dict.get(term2))

term3 = get_term_by_year_and_quarter(2012, 'spring')
self.assertTrue(term3 in result_dict)
self.assertIsNotNone(result_dict.get(term3))

term1 = get_term_by_year_and_quarter(2013, 'summer')
self.assertTrue(term1 in result_dict)
self.assertIsNotNone(result_dict.get(term1))
enroll3 = result_dict.get(term3)
self.assertEquals(len(enroll3.minors), 1)
enroll3_minor = enroll3.minors[0]
self.assertTrue(enroll3_minor != enroll_minor)

term4 = Term(year=1996, quarter='autumn')
self.assertTrue(term4 in result_dict)
Expand Down

0 comments on commit 1112254

Please sign in to comment.