- Timestamp:
- 24 Jan 2015, 18:30:11 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/student_statistics.py
r11254 r12515 32 32 creation_dt_string = Attribute('Human readable report creation datetime') 33 33 34 def get_student_stats(session, mode ):34 def get_student_stats(session, mode, breakdown): 35 35 """Get students in a certain session and study mode. 36 36 37 Returns a table ordered by faculty code (one per row) and37 Returns a table ordered by code (faculty or department, one per row) and 38 38 registration state (cols). The result is a 3-tuple representing 39 ((< FACULTY_CODES>), (<STATES>), (<NUM_OF_STUDENTS>)). The39 ((<CODES>), (<STATES>), (<NUM_OF_STUDENTS>)). The 40 40 (<NUM_OF_STUDENTS>) is an n-tuple with each entry containing the 41 number of students found in that faculty and with the respective41 number of students found in that faculty/department and with the respective 42 42 state. 43 43 … … 54 54 states = tuple([x.value for x in registration_states_vocab]) 55 55 states = states + (u'Total',) 56 fac_codes = tuple(sorted([x for x in site['faculties'].keys()], 57 key=lambda x: x.lower())) 58 fac_codes = fac_codes + (u'Total',) 56 if breakdown == 'faccode': 57 codes = tuple(sorted([x for x in site['faculties'].keys()], 58 key=lambda x: x.lower())) 59 elif breakdown == 'depcode': 60 faculties = site['faculties'] 61 depcodes = [] 62 for fac in faculties.values(): 63 for dep in fac.values(): 64 depcodes.append(dep.code) 65 codes = tuple(sorted([x for x in depcodes], 66 key=lambda x: x.lower())) 67 codes = codes + (u'Total',) 59 68 # XXX: Here we do _one_ query and then examine the single 60 69 # students. One could also do multiple queries and just look for … … 63 72 cat = queryUtility(ICatalog, name="students_catalog") 64 73 result = cat.searchResults(current_session=(session, session)) 65 table = [[0 for x in xrange(len(states))] for y in xrange(len( fac_codes))]74 table = [[0 for x in xrange(len(states))] for y in xrange(len(codes))] 66 75 mode_groups = getUtility(IKofaUtils).MODE_GROUPS 67 76 for stud in result: 68 77 if mode != 'All' and stud.current_mode not in mode_groups[mode]: 69 78 continue 70 if stud.faccode not in fac_codes:79 if getattr(stud, breakdown) not in codes: 71 80 # studs can have a faccode ``None`` 72 81 continue 73 row = fac_codes.index(stud.faccode)82 row = codes.index(getattr(stud, breakdown)) 74 83 col = states.index(stud.state) 75 84 table[row][col] += 1 … … 79 88 # turn lists into tuples 80 89 table = tuple([tuple(row) for row in table]) 81 return ( fac_codes, states, table)90 return (codes, states, table) 82 91 83 92 from reportlab.lib import colors … … 124 133 mode = None 125 134 126 def __init__(self, session, mode, author='System'):135 def __init__(self, session, mode, breakdown, author='System'): 127 136 super(StudentStatisticsReport, self).__init__( 128 args=[session, mode ], kwargs={'author':author})137 args=[session, mode, breakdown], kwargs={'author':author}) 129 138 self.session = academic_sessions_vocab.getTerm(session).title 130 139 self.mode = mode 140 self.breakdown = breakdown 131 141 self.author = author 132 142 self.creation_dt_string = self.creation_dt.astimezone( 133 143 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 134 self.data = get_student_stats(session, mode )144 self.data = get_student_stats(session, mode, breakdown) 135 145 136 146 def create_pdf(self): … … 156 166 grok.name('student_stats') 157 167 158 def generate(self, site, session=None, mode=None, author=None): 159 result = StudentStatisticsReport(session=session, mode=mode, author=author) 168 def generate(self, site, session=None, mode=None, breakdown=None, author=None): 169 result = StudentStatisticsReport( 170 session=session, mode=mode, breakdown=breakdown, author=author) 160 171 return result 161 172 … … 185 196 return None 186 197 187 def update(self, CREATE=None, session=None, mode=None ):198 def update(self, CREATE=None, session=None, mode=None, breakdown=None): 188 199 self.parent_url = self.url(self.context.__parent__) 189 200 self._set_session_values() 190 201 self._set_mode_values() 202 self._set_breakdown_values() 191 203 if CREATE and session: 192 204 # create a new report job for students by session … … 195 207 kw = dict( 196 208 session=int(session), 197 mode=mode) 209 mode=mode, 210 breakdown=breakdown) 198 211 self.flash(_('New report is being created in background')) 199 212 job_id = container.start_report_job( … … 201 214 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 202 215 grok.getSite().logger.info( 203 '%s - report %s created: %s (session=%s, mode=%s )' % (204 ob_class, job_id, self.context.title, session, mode ))216 '%s - report %s created: %s (session=%s, mode=%s, breakdown=%s)' % ( 217 ob_class, job_id, self.context.title, session, mode, breakdown)) 205 218 self.redirect(self.parent_url) 206 219 return … … 215 228 mode_groups = getUtility(IKofaUtils).MODE_GROUPS 216 229 self.modes = sorted([(key, key) for key in mode_groups.keys()]) 230 return 231 232 def _set_breakdown_values(self): 233 self.breakdowns = [('Faculties', 'faccode'), ('Departments', 'depcode')] 217 234 return 218 235
Note: See TracChangeset for help on using the changeset viewer.