def run(self): AcceptedStudentsQuery = AcceptedQuery({'strm': Semester.current().offset_name(1), 'acad_plans': ['CMPTMAJ', 'DCMPT', 'CMPTMIN', 'CMPTHON', 'CMPTJMA', 'CMPTJHO', 'SOSYMAJ', 'ZUSFU']}) AcceptedStudents = AcceptedStudentsQuery.result() EnrolledStudentsQuery = EnrolledQuery({'strm': Semester.current().offset_name(1), 'acad_progs': ['CMPT', 'CMPT2']}) EnrolledStudents = EnrolledStudentsQuery.result() # Let's calculate our totals so we can display those numbers as well. accepted_list = AcceptedStudents.column_as_list("SEX") accepted_total = len(accepted_list) accepted_m_count = len([i for i in accepted_list if i=='M']) accepted_f_count = len([i for i in accepted_list if i=='F']) accepted_u_count = len([i for i in accepted_list if i=='U']) enrolled_list = EnrolledStudents.column_as_list("SEX") enrolled_total = len(enrolled_list) enrolled_m_count = len([i for i in enrolled_list if i == 'M']) enrolled_f_count = len([i for i in enrolled_list if i == 'F']) enrolled_u_count = len([i for i in enrolled_list if i == 'U']) # Let's create two new tables to display these results. accepted_totals = Table() accepted_totals.append_column('TOTAL_COUNT') accepted_totals.append_column('M_COUNT') accepted_totals.append_column('M_PERCENT') accepted_totals.append_column('F_TOTAL') accepted_totals.append_column('F_PERCENT') accepted_totals.append_column('U_COUNT') accepted_totals.append_column('U_PERCENT') accepted_totals.append_row([accepted_total, accepted_m_count, 100.0 * accepted_m_count/accepted_total, accepted_f_count, 100.0 * accepted_f_count/accepted_total, accepted_u_count, 100.0 * accepted_u_count/accepted_total]) enrolled_totals = Table() enrolled_totals.append_column('TOTAL_COUNT') enrolled_totals.append_column('M_COUNT') enrolled_totals.append_column('M_PERCENT') enrolled_totals.append_column('F_TOTAL') enrolled_totals.append_column('F_PERCENT') enrolled_totals.append_column('U_COUNT') enrolled_totals.append_column('U_PERCENT') enrolled_totals.append_row([enrolled_total, enrolled_m_count, 100.0 * enrolled_m_count / enrolled_total, enrolled_f_count, 100.0 * enrolled_f_count / enrolled_total, enrolled_u_count, 100.0 * enrolled_u_count / enrolled_total]) self.artifacts.append(AcceptedStudents) self.artifacts.append(accepted_totals) self.artifacts.append(EnrolledStudents) self.artifacts.append(enrolled_totals)
def run(self): sems = Semester.objects.filter(name__gte='1001', name__lte=Semester.next_starting().name) u = Unit.objects.filter(label__in=['CMPT', 'ENSC', 'MSE']) courses = CourseOffering.objects.prefetch_related('meeting_time').filter(semester__in=sems, owner__in=u, graded=True).exclude( flags=CourseOffering.flags.combined).exclude(subject='DDP').exclude(component='CAN').order_by( 'semester', 'subject', 'number') course_history = Table() course_history.append_column('Semester') course_history.append_column('Course') course_history.append_column('Units') course_history.append_column('Instructor') course_history.append_column('Enrolment') course_history.append_column('Campus') course_history.append_column('Joint With') course_history.append_column('Lecture Times') course_history.append_column('Instructor(s) Rank(s)') for course in courses: semester = course.semester.label() label = course.name() units = course.units instr = course.instructors_printing_str() enrl = '%i/%i' % (course.enrl_tot, course.enrl_cap) if course.campus in CAMPUSES_SHORT: campus = CAMPUSES_SHORT[course.campus] else: campus = 'Unknown' if course.config.get('joint_with'): joint = str(', '.join(course.config.get('joint_with'))) else: joint = '' meeting_times = '' mt = [t for t in course.meeting_time.all() if t.meeting_type == 'LEC'] if mt: meeting_times = ', '.join(str("%s %s-%s" % (WEEKDAYS[t.weekday], t.start_time, t.end_time)) for t in mt) ranks = "; ".join(CareerEvent.ranks_as_of_semester(p.id, course.semester) for p in course.instructors()) course_history.append_row([semester, label, units, instr, enrl, campus, joint, meeting_times, ranks]) self.artifacts.append(course_history)
def run(self): semester = current_semester() # Get the full list of plans in each offering plans_query = PlansInCoursesQuery({'strm': semester}) plans = plans_query.result() # create a table with the counts of plans, not individual student info programs = Table() programs.append_column('SEMESTER') programs.append_column('SUBJECT') programs.append_column('CATALOG_NBR') programs.append_column('CLASS_SECTION') programs.append_column('CAMPUS') programs.append_column('ENRL_TOTAL') programs.append_column('ENRL_CAP') programs.append_column('PLANS') # group plans by offering offering_plans = ( (offering, (r['ACAD_PLAN'] for r in rows)) for offering, rows in itertools.groupby(plans.row_maps(), _rowkey)) # count for each offering found_plans = set() for (subj, nbr, sect, campus, tot, cap), plans in offering_plans: plans = list(plans) found_plans |= set(plans) count = counter(plans) count = [(n, plan) for plan, n in count.iteritems()] count.sort() count.reverse() count_str = ', '.join("%i*%s" % (n, plan) for n, plan in count) programs.append_row(("%04i" % (semester), subj, nbr, sect, campus, tot, cap, count_str)) self.artifacts.append(programs) # get a cheat-sheet of the plan codes found_plans = list(found_plans) found_plans.sort() descr = PlansDescriptionQuery({'plans': found_plans}).result() self.artifacts.append(descr)
def run(self): sems = Semester.objects.filter(name__gte='1094', name__lte=Semester.current().offset(2).name) u = Unit.objects.filter(label__in=['CMPT', 'MSE', 'ENSC']) courses = CourseOffering.objects.prefetch_related('meeting_time').filter(semester__in=sems, owner__in=u, graded=True).exclude( flags=CourseOffering.flags.combined).exclude(subject='DDP').order_by('semester', 'subject', 'number') courses = list(courses) courses.sort(key=lambda x: (x.instructors_printing_str(), x.semester)) course_history = Table() course_history.append_column('Instructor') course_history.append_column('Instructor(s) Rank(s)') course_history.append_column('School') course_history.append_column('Grad Students') course_history.append_column('Semester') course_history.append_column('Course') course_history.append_column('Enrolment') course_history.append_column('Campus') course_history.append_column('Joint With') course_history.append_column('Lecture Times') course_history.append_column('Credits') for course in courses: semester = course.semester.label() label = course.name() instr = course.instructors_printing_str() enrl = '%i/%i' % (course.enrl_tot, course.enrl_cap) unit = course.owner credits = course.units if course.campus in CAMPUSES_SHORT: campus = CAMPUSES_SHORT[course.campus] else: campus = 'Unknown' if course.config.get('joint_with'): joint = str(', '.join(course.config.get('joint_with'))) else: joint = '' meeting_times = '' mt = [t for t in course.meeting_time.all() if t.meeting_type == 'LEC'] if mt: meeting_times = ', '.join(str("%s %s-%s" % (WEEKDAYS[t.weekday], t.start_time, t.end_time)) for t in mt) grads = "; ".join(str(Supervisor.objects.filter(supervisor__userid=p.userid, supervisor_type='SEN', removed=False).count()) for p in course.instructors()) ranks = "; ".join(CareerEvent.ranks_as_of_semester(p.id, course.semester) for p in course.instructors()) course_history.append_row([instr, ranks, unit, grads, semester, label, enrl, campus, joint, meeting_times, credits]) self.artifacts.append(course_history)
def run(self): sems = Semester.objects.filter(name__gte='1001', name__lte=Semester.next_starting().name) u = Unit.objects.filter(label__in=['CMPT', 'ENSC', 'MSE']) courses = CourseOffering.objects.prefetch_related( 'meeting_time').filter( semester__in=sems, owner__in=u, graded=True).exclude( flags=CourseOffering.flags.combined).exclude( subject='DDP').exclude(component='CAN').order_by( 'semester', 'subject', 'number') course_history = Table() course_history.append_column('Semester') course_history.append_column('Course') course_history.append_column('Units') course_history.append_column('Instructor') course_history.append_column('Enrolment') course_history.append_column('Campus') course_history.append_column('Joint With') course_history.append_column('Lecture Times') course_history.append_column('Instructor(s) Rank(s)') for course in courses: semester = course.semester.label() label = course.name() units = course.units instr = course.instructors_printing_str() enrl = '%i/%i' % (course.enrl_tot, course.enrl_cap) if course.campus in CAMPUSES_SHORT: campus = CAMPUSES_SHORT[course.campus] else: campus = 'Unknown' if course.config.get('joint_with'): joint = str(', '.join(course.config.get('joint_with'))) else: joint = '' meeting_times = '' mt = [ t for t in course.meeting_time.all() if t.meeting_type == 'LEC' ] if mt: meeting_times = ', '.join( str("%s %s-%s" % (WEEKDAYS[t.weekday], t.start_time, t.end_time)) for t in mt) ranks = "; ".join( CareerEvent.ranks_as_of_semester(p.id, course.semester) for p in course.instructors()) course_history.append_row([ semester, label, units, instr, enrl, campus, joint, meeting_times, ranks ]) self.artifacts.append(course_history)
def run(self): current_semester = Semester.current() # Get all active CMPT PhD students, since that's all we care about. program = GradProgram.objects.get(label="PhD", unit__label='CMPT') all_students = GradStudent.objects.filter(program=program, current_status='ACTI') senior_supervisors = Supervisor.objects.filter(student__in=all_students, supervisor_type='SEN', removed=False) potential_supervisors = Supervisor.objects.filter(student__in=all_students, supervisor_type='POT', removed=False) # Split them up between the 3 tables we want: table1_students = all_students.filter(start_semester__lte=current_semester.offset(-2)) table2_students = all_students.filter(start_semester__lte=current_semester.offset(-5)) table3_students = all_students.filter(start_semester__lte=current_semester.offset(-8)) # The GradRequirements we care about: requirement1 = GradRequirement.objects.get(program=program, description='Supervisory Committee') requirement2 = GradRequirement.objects.get(program=program, description='Depth Exam') requirement3 = GradRequirement.objects.get(program=program, description='Breadth Requirements Approved') requirement4 = GradRequirement.objects.get(program=program, description='Thesis Proposal') # All three tables will have the same columns, might as well create them quickly. table1 = Table() table2 = Table() table3 = Table() for table in [table1, table2, table3]: table.append_column("Name") table.append_column("Student ID") table.append_column("Email") table.append_column("Semester Count") table.append_column("Senior Supervisor") table3.append_column("Missing Requirement(s)") # A quick helper method to build the string to display for the Senior Supervisor, given a student def get_supervisor_string(student): supervisor = senior_supervisors.filter(student=student).first() if supervisor: return '%s <%s>' % (supervisor.supervisor.name(), supervisor.supervisor.email()) else: supervisor = potential_supervisors.filter(student=student).first() if supervisor: return '%s (potential) <%s>' % (supervisor.supervisor.name(), supervisor.supervisor.email()) else: return 'None' # Get the lists of students from the master list who have completed the various requirements. students1_completed = CompletedRequirement.objects.values_list('student', flat=True)\ .filter(requirement=requirement1, student__in=all_students, removed=False) students2_completed = CompletedRequirement.objects.values_list('student', flat=True) \ .filter(requirement=requirement2, student__in=all_students, removed=False) students3_completed = CompletedRequirement.objects.values_list('student', flat=True) \ .filter(requirement=requirement3, student__in=all_students, removed=False) # The 4th requirement only really applies to the third list, so might as well limit it: students4_completed = CompletedRequirement.objects.values_list('student', flat=True) \ .filter(requirement=requirement4, student__in=table3_students, removed=False) # First table, simply everyone in table1_students who doesn't have a completed requirement 1 for student in [s for s in table1_students if s.id not in students1_completed]: supervisor_string = get_supervisor_string(student) table1.append_row([student.person.name(), student.person.emplid, student.person.email(), current_semester - student.start_semester + 1, supervisor_string]) # Table 2 is also pretty easy, just add everyone who is is missing both of requirements 2 & 3. for student in [s for s in table2_students if s.id not in students2_completed and s.id not in students3_completed]: supervisor_string = get_supervisor_string(student) table2.append_row([student.person.name(), student.person.emplid, student.person.email(), current_semester - student.start_semester + 1, supervisor_string]) # Table 3 will require a bit more work, since we want to also display what requirements aren't met. # First, establish our target students: students3 = [s for s in table3_students if s.id not in students2_completed or s.id not in students3_completed or s.id not in students4_completed] for student in students3: # Build the string telling us which requirement is missing. Stupid, but has to be done. missing_str_list = [] requirement_to_list = [(requirement2, students2_completed), (requirement3, students3_completed), (requirement4, students4_completed)] for requirement, student_list in requirement_to_list: if student.id not in student_list: missing_str_list.append(requirement.description) missing_str = '; '.join(missing_str_list) supervisor_string = get_supervisor_string(student) table3.append_row([student.person.name(), student.person.emplid, student.person.email(), current_semester - student.start_semester + 1, supervisor_string, missing_str]) for table in [table1, table2, table3]: self.artifacts.append(table)
def run(self): semesters = list(semester_range(Semester(1071), current_semester())) # Get the full list of plans in each offering plans_query = PlansInCoursesQuery({'strm': semesters}) plans = plans_query.result() # create a table with the counts of plans, not individual student info programs = Table() programs.append_column('SEMESTER') programs.append_column('SUBJECT') programs.append_column('CATALOG_NBR') programs.append_column('CLASS_SECTION') programs.append_column('CAMPUS') programs.append_column('ENRL_TOTAL') programs.append_column('ENRL_CAP') programs.append_column('PLANS') # group plans by offering offering_plans = ( (offering, (r['ACAD_PLAN'] for r in rows)) for offering, rows in itertools.groupby(plans.row_maps(), _rowkey)) # count for each offering found_plans = set() count = {} # Build an object to count the instance of each gender in each plan for each semester for (strm, subj, nbr, sect, campus, tot, cap, sex), plans in offering_plans: plans = list(plans) found_plans |= set(plans) # We want to count too many things, let's store it in an object: if strm not in count: count[strm] = {} current_strm = count.get(strm) for plan in plans: if plan not in current_strm: current_strm[plan] = {} current_plan = current_strm[plan] current_plan['TOTAL'] = current_plan.get('TOTAL', 0) + 1 if sex == 'M': current_plan['M'] = current_plan.get('M', 0) + 1 elif sex == 'F': current_plan['F'] = current_plan.get('F', 0) +1 # Let's iterate through our counter object and just add one row per semester, concatenating the string with # the breakdown of males/females in each plan. for strm in count: count_str = '' for plan in count[strm]: m_count = count[strm].get(plan).get('M', 0) f_count = count[strm].get(plan).get('F', 0) total_count = count[strm].get(plan).get('TOTAL', 0) count_str += str("%s Total: %i, M: %i, F: %i " % (plan, total_count, m_count, f_count)) programs.append_row((strm, subj, nbr, sect, campus, tot, cap, count_str)) self.artifacts.append(programs) # get a cheat-sheet of the plan codes found_plans = list(found_plans) found_plans.sort() descr = PlansDescriptionQuery({'plans': found_plans}).result() self.artifacts.append(descr)
def run(self): AcceptedStudentsQuery = AcceptedQuery({ 'strm': Semester.current().offset_name(1), 'acad_plans': [ 'CMPTMAJ', 'DCMPT', 'CMPTMIN', 'CMPTHON', 'CMPTJMA', 'CMPTJHO', 'SOSYMAJ', 'ZUSFU' ] }) AcceptedStudents = AcceptedStudentsQuery.result() EnrolledStudentsQuery = EnrolledQuery({ 'strm': Semester.current().offset_name(1), 'acad_progs': ['CMPT', 'CMPT2'] }) EnrolledStudents = EnrolledStudentsQuery.result() # Let's calculate our totals so we can display those numbers as well. accepted_list = AcceptedStudents.column_as_list("SEX") accepted_total = len(accepted_list) accepted_m_count = len([i for i in accepted_list if i == 'M']) accepted_f_count = len([i for i in accepted_list if i == 'F']) accepted_u_count = len([i for i in accepted_list if i == 'U']) enrolled_list = EnrolledStudents.column_as_list("SEX") enrolled_total = len(enrolled_list) enrolled_m_count = len([i for i in enrolled_list if i == 'M']) enrolled_f_count = len([i for i in enrolled_list if i == 'F']) enrolled_u_count = len([i for i in enrolled_list if i == 'U']) # Let's create two new tables to display these results. accepted_totals = Table() accepted_totals.append_column('TOTAL_COUNT') accepted_totals.append_column('M_COUNT') accepted_totals.append_column('M_PERCENT') accepted_totals.append_column('F_TOTAL') accepted_totals.append_column('F_PERCENT') accepted_totals.append_column('U_COUNT') accepted_totals.append_column('U_PERCENT') accepted_totals.append_row([ accepted_total, accepted_m_count, 100.0 * accepted_m_count / accepted_total, accepted_f_count, 100.0 * accepted_f_count / accepted_total, accepted_u_count, 100.0 * accepted_u_count / accepted_total ]) enrolled_totals = Table() enrolled_totals.append_column('TOTAL_COUNT') enrolled_totals.append_column('M_COUNT') enrolled_totals.append_column('M_PERCENT') enrolled_totals.append_column('F_TOTAL') enrolled_totals.append_column('F_PERCENT') enrolled_totals.append_column('U_COUNT') enrolled_totals.append_column('U_PERCENT') enrolled_totals.append_row([ enrolled_total, enrolled_m_count, 100.0 * enrolled_m_count / enrolled_total, enrolled_f_count, 100.0 * enrolled_f_count / enrolled_total, enrolled_u_count, 100.0 * enrolled_u_count / enrolled_total ]) self.artifacts.append(AcceptedStudents) self.artifacts.append(accepted_totals) self.artifacts.append(EnrolledStudents) self.artifacts.append(enrolled_totals)
def run(self): sems = Semester.objects.filter(name__gte='1101', name__lte=Semester.current().name) u = Unit.objects.filter(label__in=['CMPT', 'MSE', 'ENSC']) courses = CourseOffering.objects.prefetch_related( 'meeting_time').filter( semester__in=sems, owner__in=u, graded=True).exclude( flags=CourseOffering.flags.combined).exclude( subject='DDP').order_by('semester', 'subject', 'number') instructors = Member.objects.filter(role='INST', added_reason='AUTO', offering__in=courses) \ .exclude(offering__component='CAN') \ .order_by('person__last_name', 'person__first_name', 'offering__semester__name') course_history = Table() course_history.append_column('Instructor') course_history.append_column('First Teaching Semester (>=1101)') course_history.append_column('Last Teaching Semester') course_history.append_column('Current Rank') course_history.append_column('School') course_history.append_column('Teaching Credits') course_history.append_column('Mean Headcount') course_history.append_column('Crs per Year') course_history.append_column('Unique Crs') course_history.append_column('Crs Levels') for i, memberships in itertools.groupby(instructors, key=lambda i: i.person): memberships = [m for m in memberships if m.teaching_credit() > 0] if i is None or not memberships: continue instr = i.sortname() first_semester = memberships[0].offering.semester last_semester = memberships[-1].offering.semester rank = CareerEvent.current_ranks(i.id) roles = Role.objects.filter(person=i, role='FAC').select_related('unit') unit = ', '.join(r.unit.label for r in roles) if rank == 'unknown': rank = 'non-faculty' if unit == '': unit = ', '.join(set(m.offering.subject for m in memberships)) offerings = [m.offering for m in memberships] num_offerings = float(sum(m.teaching_credit() for m in memberships)) headcount = sum(o.enrl_tot for o in offerings) duration = last_semester - first_semester + 1 levels = sorted(list(set(str(o.number)[0] for o in offerings))) unique = len(set(o.course_id for o in offerings)) course_history.append_row([ instr, first_semester.name, last_semester.name, rank, unit, round(num_offerings, 2), round(headcount / num_offerings, 1), round(num_offerings / duration * 3, 1), unique, ','.join(levels) ]) self.artifacts.append(course_history)
def run(self): semester = current_semester() # Get the full list of plans in each offering plans_query = PlansInCoursesQuery({'strm': semester}) plans = plans_query.result() # create a table with the counts of plans, not individual student info programs = Table() programs.append_column('SEMESTER') programs.append_column('SUBJECT') programs.append_column('CATALOG_NBR') programs.append_column('CLASS_SECTION') programs.append_column('CAMPUS') programs.append_column('ENRL_TOTAL') programs.append_column('ENRL_CAP') programs.append_column('PLANS') # group plans by offering offering_plans = ( (offering, (r['ACAD_PLAN'] for r in rows)) for offering, rows in itertools.groupby(plans.row_maps(), _rowkey)) # count for each offering found_plans = set() for (subj, nbr, sect, campus, tot, cap), plans in offering_plans: plans = list(plans) found_plans |= set(plans) count = counter(plans) count = [(n,plan) for plan,n in count.items()] count.sort() count.reverse() count_str = ', '.join("%i*%s" % (n,plan) for n,plan in count) programs.append_row(("%04i"%(semester), subj, nbr, sect, campus, tot, cap, count_str)) self.artifacts.append(programs) # get a cheat-sheet of the plan codes found_plans = list(found_plans) found_plans.sort() descr = PlansDescriptionQuery({'plans': found_plans}).result() self.artifacts.append(descr)