Changeset 14605 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 7 Mar 2017, 06:51:42 (8 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students/reports
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py
r14601 r14605 32 32 StudentStatisticsReportPDFView) 33 33 34 class ILevelReport(IReport):35 36 session = Attribute('Session to report')37 level = Attribute('Level to report')38 faccode = Attribute('Faculty to report')39 depcode = Attribute('Department to report')40 certcode = Attribute('Certificate to report')41 creation_dt_string = Attribute('Human readable report creation datetime')42 43 def excluded(level_obj):44 """Some universities may add further conditions to exclude45 students from reports. These conditions can be customized in46 this function.47 """48 return False49 50 def get_students(faccode, depcode, certcode, session, level):51 """Get students in a certain department, studying a certain programmen52 who registered courses in a certain session at a certain level.53 54 Returns a list of student data tuples.55 """56 site = grok.getSite()57 cat = queryUtility(ICatalog, name="students_catalog")58 if certcode == 'all':59 certcode = None60 result = cat.searchResults(61 depcode = (depcode, depcode), faccode = (faccode, faccode),62 certcode = (certcode, certcode)63 )64 table = []65 format_float = getUtility(IKofaUtils).format_float66 for stud in result:67 if not stud['studycourse'].has_key(str(level)):68 continue69 if stud.state == GRADUATED:70 continue71 level_obj = stud['studycourse'][str(level)]72 if level_obj.level_session != session:73 continue74 if excluded(level_obj):75 continue76 passed_params = level_obj.passed_params77 failed_courses = textwrap.fill(passed_params[4], 35)78 not_taken_courses = textwrap.fill(passed_params[5], 17)79 fullname = textwrap.fill(stud.display_fullname, 29)80 # This is a very special column requested by AAUE, Nigeria.81 # The 'remark' column remains empty in base package.82 remark = getattr(level_obj, 'remark', '')83 end_level = getattr(stud['studycourse'].certificate, 'end_level', None)84 credits_counted = level_obj.gpa_params[1]85 credits_passed = passed_params[2]86 level_gpa = format_float(level_obj.gpa_params[0], 3)87 cum_credits_taken = level_obj.cumulative_params[1]88 cum_credits_passed = level_obj.cumulative_params[4]89 if end_level and level >= end_level:90 cgpa = format_float(level_obj.cumulative_params[0], 2)91 else:92 cgpa = format_float(level_obj.cumulative_params[0], 3)93 if remark in ('FRNS', 'NER', 'NYV'):94 cgpa = ''95 if remark in ('NER', 'NYV'):96 # hide all data (requestd by AAUE, Nigeria)97 credits_counted = ''98 credits_passed = ''99 level_gpa = ''100 failed_courses = ''101 not_taken_courses = ''102 cum_credits_taken = ''103 cum_credits_passed = ''104 line = (105 stud.matric_number,106 fullname,107 credits_counted,108 credits_passed,109 level_gpa,110 failed_courses,111 not_taken_courses,112 cum_credits_taken,113 cum_credits_passed,114 cgpa,115 remark,116 )117 table.append(line)118 return sorted(table, key=lambda value:value[0])119 120 34 from reportlab.lib import colors 121 35 from reportlab.lib.styles import getSampleStyleSheet … … 194 108 ] 195 109 110 class ILevelReport(IReport): 111 112 session = Attribute('Session to report') 113 level = Attribute('Level to report') 114 faccode = Attribute('Faculty to report') 115 depcode = Attribute('Department to report') 116 certcode = Attribute('Certificate to report') 117 creation_dt_string = Attribute('Human readable report creation datetime') 118 196 119 @implementer(ILevelReport) 197 120 class LevelReport(Report): … … 207 130 note = None 208 131 signatures = None 132 133 def _excluded(self, level_obj): 134 """Some universities may add further conditions to exclude 135 students from reports. These conditions can be customized in 136 this function. 137 """ 138 return False 139 140 def _get_students(self, faccode, depcode, certcode, session, level): 141 """Get students in a certain department, studying a certain programmen 142 who registered courses in a certain session at a certain level. 143 144 Returns a list of student data tuples. 145 """ 146 site = grok.getSite() 147 cat = queryUtility(ICatalog, name="students_catalog") 148 if certcode == 'all': 149 certcode = None 150 result = cat.searchResults( 151 depcode = (depcode, depcode), faccode = (faccode, faccode), 152 certcode = (certcode, certcode) 153 ) 154 table = [] 155 format_float = getUtility(IKofaUtils).format_float 156 for stud in result: 157 if not stud['studycourse'].has_key(str(level)): 158 continue 159 if stud.state == GRADUATED: 160 continue 161 level_obj = stud['studycourse'][str(level)] 162 if level_obj.level_session != session: 163 continue 164 if self._excluded(level_obj): 165 continue 166 passed_params = level_obj.passed_params 167 failed_courses = textwrap.fill(passed_params[4], 35) 168 not_taken_courses = textwrap.fill(passed_params[5], 17) 169 fullname = textwrap.fill(stud.display_fullname, 29) 170 # This is a very special column requested by AAUE, Nigeria. 171 # The 'remark' column remains empty in base package. 172 remark = getattr(level_obj, 'remark', '') 173 end_level = getattr(stud['studycourse'].certificate, 'end_level', None) 174 credits_counted = level_obj.gpa_params[1] 175 credits_passed = passed_params[2] 176 level_gpa = format_float(level_obj.gpa_params[0], 3) 177 cum_credits_taken = level_obj.cumulative_params[1] 178 cum_credits_passed = level_obj.cumulative_params[4] 179 if end_level and level >= end_level: 180 cgpa = format_float(level_obj.cumulative_params[0], 2) 181 else: 182 cgpa = format_float(level_obj.cumulative_params[0], 3) 183 if remark in ('FRNS', 'NER', 'NYV'): 184 cgpa = '' 185 if remark in ('NER', 'NYV'): 186 # hide all data (requestd by AAUE, Nigeria) 187 credits_counted = '' 188 credits_passed = '' 189 level_gpa = '' 190 failed_courses = '' 191 not_taken_courses = '' 192 cum_credits_taken = '' 193 cum_credits_passed = '' 194 line = ( 195 stud.matric_number, 196 fullname, 197 credits_counted, 198 credits_passed, 199 level_gpa, 200 failed_courses, 201 not_taken_courses, 202 cum_credits_taken, 203 cum_credits_passed, 204 cgpa, 205 remark, 206 ) 207 table.append(line) 208 return sorted(table, key=lambda value:value[0]) 209 209 210 210 def __init__(self, faccode, depcode, certcode, session, level, … … 241 241 self.creation_dt_string = self.creation_dt.astimezone( 242 242 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 243 self.data = get_students(faccode, depcode, certcode, session, level)243 self.data = self._get_students(faccode, depcode, certcode, session, level) 244 244 245 245 def create_pdf(self, job_id): -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/raw_score_report.py
r14601 r14605 32 32 from waeup.kofa.students.reports.student_statistics import ( 33 33 StudentStatisticsReportPDFView) 34 35 class IRawScoreReport(IReport):36 37 session = Attribute('Session to report')38 level = Attribute('Level to report')39 faccode = Attribute('Faculty to report')40 depcode = Attribute('Department to report')41 certcode = Attribute('Certificate to report')42 creation_dt_string = Attribute('Human readable report creation datetime')43 44 def excluded(level_obj):45 """Some universities may add further conditions to exclude46 students from reports. These conditions can be customized in47 this function.48 """49 return False50 51 def get_courses(faccode, depcode, certcode, session, level):52 """Method 1: Get certificate courses of a53 certain department/certificate at a certain level.54 """55 site = grok.getSite()56 course_codes = []57 department = site['faculties'][faccode][depcode]58 if certcode == 'all':59 for cert in department.certificates.values():60 for certcourse in cert.values():61 if certcourse.level == level:62 course_codes.append(certcourse.getCourseCode())63 else:64 certificate = site['faculties'][faccode][depcode].certificates[certcode]65 for certcourse in certificate.values():66 if certcourse.level == level:67 course_codes.append(certcourse.getCourseCode())68 return course_codes69 70 def get_students(faccode, depcode, certcode, session, level, course_codes):71 """Get students in a certain department/certificate who registered courses72 in a certain session at a certain level.73 74 Returns a list of student data tuples.75 """76 cat = queryUtility(ICatalog, name="students_catalog")77 if certcode == 'all':78 certcode = None79 result = cat.searchResults(80 depcode = (depcode, depcode), faccode = (faccode, faccode),81 certcode = (certcode, certcode)82 )83 table = []84 for stud in result:85 if not stud['studycourse'].has_key(str(level)):86 continue87 if stud.state == GRADUATED:88 continue89 level_obj = stud['studycourse'][str(level)]90 if level_obj.level_session != session:91 continue92 if excluded(level_obj):93 continue94 scores = dict()95 for ticket in level_obj.values():96 if ticket.code in course_codes:97 if ticket.total_score is not None:98 scores[ticket.code] = (ticket.total_score, ticket.grade)99 else:100 scores[ticket.code] = ('Nil', '')101 fullname = textwrap.fill(stud.display_fullname, 26)102 line = (103 stud.matric_number,104 fullname,105 scores,106 )107 table.append(line)108 return sorted(table, key=lambda value:value[0])109 110 34 from reportlab.lib import colors 111 35 from reportlab.lib.styles import getSampleStyleSheet … … 172 96 ] 173 97 98 class IRawScoreReport(IReport): 99 100 session = Attribute('Session to report') 101 level = Attribute('Level to report') 102 faccode = Attribute('Faculty to report') 103 depcode = Attribute('Department to report') 104 certcode = Attribute('Certificate to report') 105 creation_dt_string = Attribute('Human readable report creation datetime') 106 174 107 @implementer(IRawScoreReport) 175 108 class RawScoreReport(Report): … … 183 116 note = "" 184 117 signatures = None 118 119 def _excluded(self, level_obj): 120 """Some universities may add further conditions to exclude 121 students from reports. These conditions can be customized in 122 this function. 123 """ 124 return False 125 126 def _get_courses(self, faccode, depcode, certcode, session, level): 127 """Method 1: Get certificate courses of a 128 certain department/certificate at a certain level. 129 """ 130 site = grok.getSite() 131 course_codes = [] 132 department = site['faculties'][faccode][depcode] 133 if certcode == 'all': 134 for cert in department.certificates.values(): 135 for certcourse in cert.values(): 136 if certcourse.level == level: 137 course_codes.append(certcourse.getCourseCode()) 138 else: 139 certificate = site['faculties'][faccode][depcode].certificates[certcode] 140 for certcourse in certificate.values(): 141 if certcourse.level == level: 142 course_codes.append(certcourse.getCourseCode()) 143 return course_codes 144 145 def _get_students(self, faccode, depcode, certcode, session, level, course_codes): 146 """Get students in a certain department/certificate who registered courses 147 in a certain session at a certain level. 148 149 Returns a list of student data tuples. 150 """ 151 cat = queryUtility(ICatalog, name="students_catalog") 152 if certcode == 'all': 153 certcode = None 154 result = cat.searchResults( 155 depcode = (depcode, depcode), faccode = (faccode, faccode), 156 certcode = (certcode, certcode) 157 ) 158 table = [] 159 for stud in result: 160 if not stud['studycourse'].has_key(str(level)): 161 continue 162 if stud.state == GRADUATED: 163 continue 164 level_obj = stud['studycourse'][str(level)] 165 if level_obj.level_session != session: 166 continue 167 if self._excluded(level_obj): 168 continue 169 scores = dict() 170 for ticket in level_obj.values(): 171 if ticket.code in course_codes: 172 if ticket.total_score is not None: 173 scores[ticket.code] = (ticket.total_score, ticket.grade) 174 else: 175 scores[ticket.code] = ('Nil', '') 176 fullname = textwrap.fill(stud.display_fullname, 26) 177 line = ( 178 stud.matric_number, 179 fullname, 180 scores, 181 ) 182 table.append(line) 183 return sorted(table, key=lambda value:value[0]) 185 184 186 185 def __init__(self, faccode, depcode, certcode, session, level, … … 221 220 self.data = dict() 222 221 for level in self.past_levels: 223 course_codes = get_courses(222 course_codes = self._get_courses( 224 223 faccode, depcode, certcode, session, level) 225 224 self.course_codes[level] = course_codes 226 self.data[level] = get_students(225 self.data[level] = self._get_students( 227 226 faccode, depcode, certcode, session, 228 227 self.levelcode, course_codes) -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/session_results_presentation.py
r14601 r14605 33 33 from waeup.kofa.students.reports.student_statistics import ( 34 34 StudentStatisticsReportPDFView) 35 36 37 class ISessionResultsPresentation(ILevelReport):38 39 """ Same interface as for level session results presentation.40 """41 42 def excluded(level_obj):43 """Some universities may add further conditions to exclude44 students from reports. These conditions can be customized in45 this function.46 """47 return False48 49 def get_students(faccode, depcode, certcode, session, level=None):50 """Get students in a certain department, studying a certain programmen51 who registered courses in a certain session at a certain level.52 53 Returns a list of lists of student data tuples.54 """55 site = grok.getSite()56 cat = queryUtility(ICatalog, name="students_catalog")57 if certcode == 'all':58 certcode = None59 result = cat.searchResults(60 depcode = (depcode, depcode), faccode = (faccode, faccode),61 certcode = (certcode, certcode)62 )63 students_utils = getUtility(IStudentsUtils)64 table = list()65 for i in range(len(students_utils.gpa_boundaries)+1):66 # The last list is reserved for students with more than one67 # level in the same session.68 table.append([])69 for stud in result:70 if stud.state == GRADUATED:71 continue72 line = (stud.student_id,73 stud.matric_number,74 stud.display_fullname,75 )76 if level != 0:77 if not stud['studycourse'].has_key(str(level)):78 continue79 level_obj = stud['studycourse'][str(level)]80 if level_obj.level_session != session:81 continue82 if excluded(level_obj):83 continue84 else:85 itemcount = 086 for item in stud['studycourse'].values():87 if item.level_session == session:88 level_obj = item89 itemcount += 190 if itemcount == 0:91 # No level registered in this session92 continue93 if itemcount > 1:94 # Error: more than one level registered in this session95 table[len(students_utils.gpa_boundaries)].append(line)96 continue97 gpaclass = students_utils.getDegreeClassNumber(level_obj)98 table[gpaclass].append(line)99 for i in range(len(students_utils.gpa_boundaries)+1):100 if len(table[i]):101 table[i] = sorted([value for value in table[i]],102 key=lambda value: value[2])103 return table104 105 35 from reportlab.lib import colors 106 36 from reportlab.lib.styles import getSampleStyleSheet … … 127 57 ('ALIGN', (3,1), (-1,-1), 'RIGHT'), 128 58 ] 59 60 class ISessionResultsPresentation(ILevelReport): 61 """ Same interface as for level session results presentation. 62 """ 129 63 130 64 @implementer(ISessionResultsPresentation) … … 141 75 142 76 note = None 77 78 def _excluded(self, level_obj): 79 """Some universities may add further conditions to exclude 80 students from reports. These conditions can be customized in 81 this function. 82 """ 83 return False 84 85 def _get_students(self, faccode, depcode, certcode, session, level=None): 86 """Get students in a certain department, studying a certain programmen 87 who registered courses in a certain session at a certain level. 88 89 Returns a list of lists of student data tuples. 90 """ 91 site = grok.getSite() 92 cat = queryUtility(ICatalog, name="students_catalog") 93 if certcode == 'all': 94 certcode = None 95 result = cat.searchResults( 96 depcode = (depcode, depcode), faccode = (faccode, faccode), 97 certcode = (certcode, certcode) 98 ) 99 students_utils = getUtility(IStudentsUtils) 100 table = list() 101 for i in range(len(students_utils.gpa_boundaries)+1): 102 # The last list is reserved for students with more than one 103 # level in the same session. 104 table.append([]) 105 for stud in result: 106 if stud.state == GRADUATED: 107 continue 108 line = (stud.student_id, 109 stud.matric_number, 110 stud.display_fullname, 111 ) 112 if level != 0: 113 if not stud['studycourse'].has_key(str(level)): 114 continue 115 level_obj = stud['studycourse'][str(level)] 116 if level_obj.level_session != session: 117 continue 118 if self._excluded(level_obj): 119 continue 120 else: 121 itemcount = 0 122 for item in stud['studycourse'].values(): 123 if item.level_session == session: 124 level_obj = item 125 itemcount += 1 126 if itemcount == 0: 127 # No level registered in this session 128 continue 129 if itemcount > 1: 130 # Error: more than one level registered in this session 131 table[len(students_utils.gpa_boundaries)].append(line) 132 continue 133 gpaclass = students_utils.getDegreeClassNumber(level_obj) 134 table[gpaclass].append(line) 135 for i in range(len(students_utils.gpa_boundaries)+1): 136 if len(table[i]): 137 table[i] = sorted([value for value in table[i]], 138 key=lambda value: value[2]) 139 return table 143 140 144 141 def __init__(self, faccode, depcode, certcode, session, level, … … 180 177 self.creation_dt_string = self.creation_dt.astimezone( 181 178 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 182 self.data = get_students(faccode, depcode, certcode, session, level)179 self.data = self._get_students(faccode, depcode, certcode, session, level) 183 180 184 181 def create_pdf(self, job_id): -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_level_report.py
r14529 r14605 5 5 from waeup.kofa.interfaces import IJobManager 6 6 from waeup.kofa.students.reports.level_report import ( 7 get_students,LevelReport, ILevelReport)7 LevelReport, ILevelReport) 8 8 from waeup.kofa.students.tests.test_catalog import CatalogTestSetup 9 9 from waeup.kofa.students.tests.test_browser import StudentsFullSetup … … 65 65 self._add_tickets() 66 66 # we can get a table with one student 67 result = get_students('fac1', 'dep1', 'CERT1', 2010, 100) 67 lr = LevelReport('fac1', 'dep1', 'CERT1', 2010, 100) 68 result = lr._get_students('fac1', 'dep1', 'CERT1', 2010, 100) 68 69 self.assertEqual(result, 69 70 [(u'1234', u'Bob Tester', 90, 30, '1.666', … … 71 72 90, 30, '1.666', '')]) 72 73 # same result when selecting all certificates 73 result = get_students('fac1', 'dep1', 'all', 2010, 100)74 result = lr._get_students('fac1', 'dep1', 'all', 2010, 100) 74 75 self.assertEqual(result, 75 76 [(u'1234', u'Bob Tester', 90, 30, '1.666', -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_raw_score_report.py
r14505 r14605 10 10 from waeup.kofa.browser.tests.test_pdf import samples_dir 11 11 from waeup.kofa.students.reports.raw_score_report import ( 12 get_students, RawScoreReport, IRawScoreReport, 13 get_courses) 12 RawScoreReport, IRawScoreReport) 14 13 15 14 … … 37 36 def test_get_courses(self): 38 37 # we can get a list with one course code 39 result = get_courses('fac1', 'dep1', 'CERT1', 2010, 100) 38 rsr = RawScoreReport('fac1', 'dep1', 'CERT1', 2010, 100) 39 result = rsr._get_courses('fac1', 'dep1', 'CERT1', 2010, 100) 40 40 self.assertEqual(result, [(u'Course1')]) 41 41 return … … 43 43 def test_get_students(self): 44 44 # we can get a table with one student 45 course_codes = get_courses('fac1', 'dep1', 'CERT1', 2010, 100) 46 result = get_students('fac1', 'dep1', 'CERT1', 2010, 100, course_codes) 45 rsr = RawScoreReport('fac1', 'dep1', 'CERT1', 2010, 100) 46 course_codes = rsr._get_courses('fac1', 'dep1', 'CERT1', 2010, 100) 47 result = rsr._get_students( 48 'fac1', 'dep1', 'CERT1', 2010, 100, course_codes) 47 49 self.assertEqual(result, 48 50 [(u'1234', u'Bob Tester', {'Course1': (70, 'A')})]) 49 51 self.student['studycourse']['100']['Course1'].score = None 50 result = get_students('fac1', 'dep1', 'CERT1', 2010, 100, course_codes) 52 result = rsr._get_students( 53 'fac1', 'dep1', 'CERT1', 2010, 100, course_codes) 51 54 self.assertEqual(result, 52 55 [(u'1234', u'Bob Tester', {'Course1': ('Nil', '')})]) -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_session_results_presentation.py
r14514 r14605 6 6 from waeup.kofa.interfaces import IJobManager 7 7 from waeup.kofa.students.reports.session_results_presentation import ( 8 get_students,SessionResultsPresentation, ISessionResultsPresentation)8 SessionResultsPresentation, ISessionResultsPresentation) 9 9 from waeup.kofa.students.tests.test_catalog import CatalogTestSetup 10 10 from waeup.kofa.students.tests.test_browser import StudentsFullSetup … … 26 26 27 27 def test_get_students(self): 28 result = get_students('fac1', 'dep1', 'CERT1', 2010, 100) 28 sr = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100) 29 result = sr._get_students('fac1', 'dep1', 'CERT1', 2010, 100) 29 30 self.assertEqual(result, 30 31 [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []]) … … 32 33 33 34 def test_get_students_at_all_levels(self): 34 result = get_students('fac1', 'dep1', 'CERT1', 2010, 0) 35 sr = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100) 36 result = sr._get_students('fac1', 'dep1', 'CERT1', 2010, 0) 35 37 self.assertEqual(result, 36 38 [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []]) … … 38 40 39 41 def test_get_students_all_certs(self): 40 result = get_students('fac1', 'dep1', 'all', 2010, 100) 42 sr = SessionResultsPresentation('fac1', 'dep1', 'all', 2010, 100) 43 result = sr._get_students('fac1', 'dep1', 'all', 2010, 100) 41 44 self.assertEqual(result, 42 45 [[], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')], []]) … … 49 52 studylevel.level_session = 2010 50 53 self.student['studycourse']['200'] = studylevel 51 result = get_students('fac1', 'dep1', 'CERT1', 2010, 0) 54 sr = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100) 55 result = sr._get_students('fac1', 'dep1', 'CERT1', 2010, 0) 52 56 self.assertEqual(result, 53 57 [[], [], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')]]) … … 56 60 def test_get_students_without_scores(self): 57 61 self.student['studycourse']['100']['Course1'].score = None 58 result = get_students('fac1', 'dep1', 'CERT1', 2010, 0) 62 sr = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100) 63 result = sr._get_students('fac1', 'dep1', 'CERT1', 2010, 0) 59 64 self.assertEqual(result, 60 65 [[], [], [], [], [], [], [(u'K1000000', u'1234', u'Bob Tester')]]) … … 62 67 def test_get_students_without_level_in_session(self): 63 68 self.student['studycourse']['100'].level_session = 2011 64 result = get_students('fac1', 'dep1', 'CERT1', 2010) 69 sr = SessionResultsPresentation('fac1', 'dep1', 'CERT1', 2010, 100) 70 result = sr._get_students('fac1', 'dep1', 'CERT1', 2010) 65 71 self.assertEqual(result, 66 72 [[], [], [], [], [], [], []])
Note: See TracChangeset for help on using the changeset viewer.