def report_process_statistics(year): titles = ['Year %s' % (year,) ,] data = [] data.append(['Date', str(datetime.date.today())]) # active prospects data.append([]) data.append(['Admissions Status', '# of prospects']) applicants = Applicant.objects.filter(school_year__in=year) levels = AdmissionLevel.objects.all() for level in levels: lvl_applicants = applicants.filter(level=level).distinct() data.append([level, lvl_applicants.count()]) # application decision data.append([]) data.append(['# of Prospects by Application Decision']) for decision in ApplicationDecisionOption.objects.all(): st_applicants = applicants.filter(application_decision=decision).distinct() data.append([decision, st_applicants.count()]) # by year data.append([]) data.append(['# of Prospects by Grade']) for grade_level in GradeLevel.objects.all(): yr_applicants = applicants.filter(year=grade_level).distinct() data.append([grade_level, yr_applicants.count()]) report = xlsReport(data, titles, "Process Statistics.xls", heading="Process Statistics") return report.finish()
def fail_report(request): from ecwsp.grades.models import Grade form = MarkingPeriodForm(request.POST) if form.is_valid(): marking_periods = form.cleaned_data['marking_period'] students = Student.objects.filter( courseenrollment__course__marking_period__in=marking_periods ).distinct() titles = [''] departments = Department.objects.filter( course__courseenrollment__user__inactive=False).distinct() for department in departments: titles += [department] titles += [ 'Total', '', 'Username', 'Year', 'GPA', '', 'Failed courses' ] passing_grade = float( Configuration.get_or_default('Passing Grade', '70').value) data = [] iy = 3 for student in students: row = [student] ix = 1 # letter A student.failed_grades = Grade.objects.none() for department in departments: failed_grades = Grade.objects.filter( override_final=False, course__department=department, course__courseenrollment__user=student, grade__lte=passing_grade, marking_period__in=marking_periods) row += [failed_grades.count()] student.failed_grades = student.failed_grades | failed_grades ix += 1 row += [ xlwt.Formula('sum(b%s:%s%s)' % (str(iy), i_to_column_letter(ix), str(iy))), '', student.username, student.year, student.gpa, '', ] for grade in student.failed_grades: row += [grade.course, grade.marking_period, grade.grade] data += [row] iy += 1 report = xlsReport(data, titles, "fail_report.xls", heading="Failure Report") return report.finish()
def fail_report(request): from ecwsp.grades.models import Grade form = MarkingPeriodForm(request.POST) if form.is_valid(): marking_periods = form.cleaned_data['marking_period'] students = Student.objects.filter(courseenrollment__course__marking_period__in=marking_periods).distinct() titles = [''] departments = Department.objects.filter(course__courseenrollment__user__inactive=False).distinct() for department in departments: titles += [department] titles += ['Total', '', 'Username', 'Year','GPA', '', 'Failed courses'] passing_grade = float(Configuration.get_or_default('Passing Grade','70').value) data = [] iy=3 for student in students: row = [student] ix = 1 # letter A student.failed_grades = Grade.objects.none() for department in departments: failed_grades = Grade.objects.filter(override_final=False,course__department=department,course__courseenrollment__user=student,grade__lte=passing_grade,marking_period__in=marking_periods) row += [failed_grades.count()] student.failed_grades = student.failed_grades | failed_grades ix += 1 row += [ xlwt.Formula( 'sum(b%s:%s%s)' % (str(iy),i_to_column_letter(ix),str(iy)) ), '', student.username, student.year, student.gpa, '', ] for grade in student.failed_grades: row += [grade.course, grade.marking_period, grade.grade] data += [row] iy += 1 report = xlsReport(data, titles, "fail_report.xls", heading="Failure Report") return report.finish()
def report_process_statistics(year): titles = [ 'Year %s' % (year, ), ] data = [] data.append(['Date', str(datetime.date.today())]) # active prospects data.append([]) data.append(['Admissions Status', '# of prospects']) applicants = Applicant.objects.filter(school_year__in=year) levels = AdmissionLevel.objects.all() for level in levels: lvl_applicants = applicants.filter(level=level).distinct() data.append([level, lvl_applicants.count()]) # application decision data.append([]) data.append(['# of Prospects by Application Decision']) for decision in ApplicationDecisionOption.objects.all(): st_applicants = applicants.filter( application_decision=decision).distinct() data.append([decision, st_applicants.count()]) # by year data.append([]) data.append(['# of Prospects by Grade']) for grade_level in GradeLevel.objects.all(): yr_applicants = applicants.filter(year=grade_level).distinct() data.append([grade_level, yr_applicants.count()]) report = xlsReport(data, titles, "Process Statistics.xls", heading="Process Statistics") return report.finish()
def download_results(self, test): """ Create basic xls report for OMR. Includes summary and details """ # Summary sheet data = [[test.name]] data.append(["Points Possible:", test.points_possible]) data.append(["Results collected: %s" % (test.students_test_results, )]) data.append(['Test average: %s' % (test.points_average, )]) data.append([]) data.append(['Student', 'Points Earned', 'Percentage']) i = 7 for ti in test.testinstance_set.annotate( earned=Sum('answerinstance__points_earned')): data.append( [ti.student, ti.earned, xlwt.Formula("B%s / $B$2" % i)]) i += 1 #xlwt.Formula("B2") report = xlsReport(data, fileName="OMR report.xls", heading="Summary", heading_top=False) # Detail sheets data_points = [] data_answers = [] row_points = ["Student"] row_answers = ["Student"] for question in test.question_set.all(): row_points.append( "%s %s" % (question.order, strip_tags(question.question).strip())) row_answers.append( "%s %s" % (question.order, strip_tags(question.question).strip())) data_points.append(row_points) data_answers.append(row_answers) for test_instance in test.testinstance_set.all(): row_points = [] row_answers = [] row_points.append(test_instance.student) row_answers.append(test_instance.student) for question in test.question_set.all(): try: answer = test_instance.answerinstance_set.get( question=question) row_points.append(answer.points_earned) row_answers.append(strip_tags(answer.answer).strip()) except: row_points.append('') row_answers.append('') data_points.append(row_points) data_answers.append(row_answers) report.addSheet(data_points, heading="Detail Points", heading_top=False) report.addSheet(data_answers, heading="Detail Answers", heading_top=False) # Benchmark sheet data = [] row = ['Benchmark'] row2 = ['Points Possible'] for benchmark in Benchmark.objects.filter( question__test=test).distinct(): row.append(benchmark) row.append('%') row2.append( test.question_set.filter(benchmarks=benchmark).aggregate( Sum('point_value'))['point_value__sum']) row2.append('') data.append(row) data.append(row2) i = 3 # 3 for third row on spreadsheet for test_instance in test.testinstance_set.all(): row = [test_instance.student] a = 98 # the letter c or column c in spreadsheet for benchmark in Benchmark.objects.filter( question__test=test).distinct(): row.append( test_instance.answerinstance_set.filter( question__benchmarks=benchmark).aggregate( Sum('points_earned'))['points_earned__sum']) if a <= 122: # 122 = z row.append( xlwt.Formula(chr(a) + str(i) + '/' + chr(a) + '$2')) elif a <= 148: row.append( xlwt.Formula('A' + chr(a - 26) + str(i) + '/' + 'A' + chr(a - 26) + '$2')) elif a <= 174: row.append( xlwt.Formula('B' + chr(a - 52) + str(i) + '/' + 'B' + chr(a - 52) + '$2')) elif a <= 200: row.append( xlwt.Formula('C' + chr(a - 78) + str(i) + '/' + 'C' + chr(a - 78) + '$2')) a += 2 # skip ahead 2 columns i += 1 data.append(row) report.addSheet(data, heading="Benchmark", heading_top=False) return report.finish()
def discipline_report_view(request): form = DisciplineStudentStatistics() merit_form = MeritForm() if request.method == 'POST': if 'merit' in request.POST: merit_form = MeritForm(request.POST) if merit_form.is_valid(): from ecwsp.sis.report import pod_report_generic data = {} l1 = merit_form.cleaned_data['level_one'] l2 = merit_form.cleaned_data['level_two'] l3 = merit_form.cleaned_data['level_three'] l4 = merit_form.cleaned_data['level_four'] start_date = merit_form.cleaned_data['start_date'] end_date = merit_form.cleaned_data['end_date'] students = Student.objects.filter(inactive=False) if merit_form.cleaned_data['sort_by'] == 'year': students = students.order_by('year') elif merit_form.cleaned_data['sort_by'] == 'cohort': students = students.order_by('cache_cohort') disciplines = StudentDiscipline.objects.filter(date__range=(start_date, end_date)).values('students').annotate(Count('pk')) for student in students: disc = 0 for discipline in disciplines: if discipline['students'] == student.id: disc = discipline['pk__count'] break student.disc_count = disc if student.disc_count <= l1: student.merit_level = 1 elif student.disc_count <= l2: student.merit_level = 2 elif student.disc_count <= l3: student.merit_level = 3 elif student.disc_count <= l4: student.merit_level = 4 data['students'] = students template = Template.objects.get_or_create(name="Merit Level Handout")[0] template = template.get_template_path(request) format_type = UserPreference if template: format_type = UserPreference.objects.get_or_create(user=request.user)[0].get_format() return pod_report_generic(template, data, "Merit Handouts", format=format_type) else: form = DisciplineStudentStatistics(request.POST) if form.is_valid(): data = [] start, end = form.get_dates() if 'student' in request.POST: students = Student.objects.all() school_year = SchoolYear.objects.get(active_year=True) if form.cleaned_data['date_begin']: if SchoolYear.objects.filter(end_date__gte=form.cleaned_data['date_begin']): school_year = SchoolYear.objects.filter(end_date__gte=form.cleaned_data['date_begin']).order_by('start_date')[0] # students belonging to this school year students = students.filter(course__marking_period__school_year__exact=school_year).distinct() if not form.cleaned_data['include_deleted'] : students = students.exclude(inactive=True) if form.cleaned_data['order_by'] == "Year": students = students.order_by('year') subtitles = ["Student",] titles = ["","Infractions",] for infr in Infraction.objects.all(): titles.append("") titles.pop() titles.append("Actions") for infr in Infraction.objects.all(): subtitles.append(unicode(infr)) for action in DisciplineAction.objects.all(): subtitles.append(unicode(action)) titles.append("") titles.pop() data.append(subtitles) pref = UserPreference.objects.get_or_create(user=request.user)[0] for student in students: disciplines = student.studentdiscipline_set.all() disciplines = disciplines.filter(date__range=(start, end)) stats = [unicode(student),] add = True for infr in Infraction.objects.all(): number = disciplines.filter(infraction=infr, students=student).count() stats.append(number) # check for filter if form.cleaned_data['infraction'] == infr: infraction_discipline = disciplines.filter(infraction=form.cleaned_data['infraction']) if number < form.cleaned_data['minimum_infraction']: add = False for action in DisciplineAction.objects.all(): actions = disciplines.filter(disciplineactioninstance__action=action, students=student).count() stats.append(actions) # check for filter if form.cleaned_data['action'] == action: if actions < form.cleaned_data['minimum_action']: add = False pref.get_additional_student_fields(stats, student, students, titles) if add: data.append(stats) report = xlsReport(data, titles, "disc_stats.xls", heading="Discipline Stats") # By Teacher data = [] titles = ['teacher'] for action in DisciplineAction.objects.all(): titles.append(action) teachers = Faculty.objects.filter(studentdiscipline__isnull=False).distinct() disciplines = StudentDiscipline.objects.filter(date__range=(start, end)) for teacher in teachers: row = [teacher] for action in DisciplineAction.objects.all(): row.append(disciplines.filter(teacher=teacher, action=action).count()) data.append(row) report.addSheet(data, titles=titles, heading="By Teachers") return report.finish() elif 'aggr' in request.POST: disciplines = StudentDiscipline.objects.filter(date__range=(start, end)) if form.cleaned_data['this_year']: school_start = SchoolYear.objects.get(active_year=True).start_date school_end = SchoolYear.objects.get(active_year=True).end_date disciplines = disciplines.filter(date__range=(school_start, school_end)) elif not form.cleaned_data['this_year'] and not form.cleaned_data['all_years']: disciplines = disciplines.filter(date__range=(form.cleaned_data['date_begin'], form.cleaned_data['date_end'])) stats = [] titles = [] for infr in Infraction.objects.all(): titles.append(infr) number = disciplines.filter(infraction=infr).count() stats.append(number) for action in DisciplineAction.objects.all(): titles.append(action) number = 0 for a in DisciplineActionInstance.objects.filter(action=action): number += a.quantity stats.append(number) data.append(stats) report = xlsReport(data, titles, "disc_stats.xls", heading="Discipline Stats") return report.finish() else: return render_to_response('discipline/disc_report.html', {'request': request, 'form': form}, RequestContext(request, {}),) return render_to_response('discipline/disc_report.html', {'request': request, 'form': form, 'merit_form':merit_form,}, RequestContext(request, {}),)
def grade_analytics(request): def check_if_match(grade, filter, filter_grade): try: if grade == "P": grade = 100 grade = float(grade) filter_grade = float(filter_grade) if filter == 'lt': if grade < filter_grade: return True elif filter == 'lte': if grade <= filter_grade: return True elif filter == 'gt': if grade > filter_grade: return True elif filter == 'gte': if grade >= filter_grade: return True except: pass return False form = GradeFilterForm() if request.method == 'POST': if 'edit' in request.POST: selected = request.POST.getlist('selected') return redirect('/admin/sis/student/?id__in=%s' % (','.join(selected), )) form = GradeFilterForm(request.POST) if form.is_valid(): ids = [] if 'submit_course' in request.POST and 'course' in request.POST: course_selection = CourseSelectionForm(request.POST) if course_selection.is_valid(): for key in request.POST: if key[:9] == "selected_": ids.append(request.POST[key]) students = Student.objects.filter(id__in=ids) if students and course_selection.cleaned_data['course']: for student in students: CourseEnrollment.objects.get_or_create( user=student, course=course_selection.cleaned_data['course'], role="student") messages.success( request, 'Students added to %s!' % (course_selection.cleaned_data['course'].shortname, )) else: messages.success( request, 'Did not enroll, please select students and a course.' ) course_selection = CourseSelectionForm() data = form.cleaned_data students = Student.objects.all() if not data['include_deleted']: students = students.filter(inactive=False) if data['filter_year']: students = students.filter(year__in=data['filter_year']) if data['in_individual_education_program']: students = students.filter(individual_education_program=True) if data['gpa']: # this will be something like filter(cache_gpa__lte=gpa) arg = 'cache_gpa__' + data['gpa_equality'] students = students.filter(**{ arg: data['gpa'], }) courses = Course.objects.filter( courseenrollment__user__in=students, graded=True) if data['this_year']: courses = courses.filter( marking_period__school_year=SchoolYear.objects.get( active_year=True)) elif not data['all_years']: courses = courses.filter( marking_period__start_date__gte=data['date_begin'], marking_period__end_date__lte=data['date_end'], ) if data['marking_period']: courses = courses.filter( marking_period__in=data['marking_period']) students = students.distinct() courses = courses.distinct() mps_selected = [] for mp in data['marking_period']: mps_selected.append(mp.id) show_students = [] max_courses = 0 (date_begin, date_end) = form.get_dates() # Pre load Discipline data if 'ecwsp.discipline' in settings.INSTALLED_APPS: if data['filter_disc_action'] and data['filter_disc'] and data[ 'filter_disc_times']: student_disciplines = students.filter( studentdiscipline__date__range=(date_begin, date_end), studentdiscipline__action=data['filter_disc_action'], ).annotate(action_count=Count('studentdiscipline__action')) if data['aggregate_disc'] and data['aggregate_disc_times']: if data['aggregate_disc_major']: student_aggregate_disciplines = students.filter( studentdiscipline__date__range=(date_begin, date_end), studentdiscipline__action__major_offense=True, ).annotate(action_count=Count('studentdiscipline')) else: student_aggregate_disciplines = students.filter( studentdiscipline__date__range=( date_begin, date_end), ).annotate( action_count=Count('studentdiscipline')) for student in students: student.aggregate_disciplines = 0 for aggr in student_aggregate_disciplines: if aggr.id == student.id: student.aggregate_disciplines = aggr.action_count break # Pre load Attendance data if data['filter_attn'] and data['filter_attn_times']: student_attendances = students.filter( student_attn__date__range=(date_begin, date_end), student_attn__status__absent=True, ).annotate(attn_count=Count('student_attn')) if data['filter_tardy'] and data['filter_tardy_times']: students_tardies = students.filter( student_attn__date__range=(date_begin, date_end), student_attn__status__tardy=True, ).annotate(tardy_count=Count('student_attn')) for student in students: student.tardy_count = 0 for student_tardies in students_tardies: if student_tardies.id == student.id: student.tardy_count = student_tardies.tardy_count break for student in students: # if this is a report, only calculate for selected students. if not 'xls' in request.POST or "selected" in request.POST: num_matched = 0 add_to_list = True # If all criteria is met, add student to list match_all = True student.courses = [] i_courses = 0 student.departments = [] for dept in Department.objects.all(): student.departments.append("") # for each grade for this student course = None done = False grades_text = "" if add_to_list and data['final_grade'] and data[ 'final_grade_filter'] and data['final_grade_times']: for course in student.course_set.filter( id__in=courses): grade = course.get_final_grade(student) if grade: match = check_if_match( grade, data['final_grade_filter'], data['final_grade']) if match: student.courses.append( str(course.shortname) + ' <br/>' + str(grade)) num_matched += 1 i_courses += 1 if max_courses < i_courses: max_courses = i_courses i = 0 for dept in Department.objects.all(): if dept == course.department: student.departments[i] = "X" i += 1 else: match_all = False if data['final_grade_times'] == "*" and not match_all: add_to_list = False elif data[ 'final_grade_times'] != "*" and not num_matched >= int( data['final_grade_times']): add_to_list = False if add_to_list and data['grade'] and data[ 'grade_filter'] and data['grade_times']: # Using just grades for optimization. Rather than for course, for mp, for grade. for grade in student.grade_set.filter( course__in=courses, course__courseenrollment__user=student ).order_by('course__department', 'marking_period').select_related(): if mps_selected == [] or grade.marking_period_id in mps_selected: # if this is a new course, add previous course to student if grade.course != course: if grades_text: student.courses.append( str(course.shortname) + ' <br/>' + grades_text) i_courses += 1 if max_courses < i_courses: max_courses = i_courses i = 0 for dept in Department.objects.all(): if dept == course.department: student.departments[i] = "X" i += 1 grades_text = "" course = grade.course # data['each_marking_period'] and if grade.override_final == False: grade_value = grade.get_grade() match = check_if_match( grade_value, data['grade_filter'], data['grade']) if match: grades_text += str( grade.marking_period.shortname ) + ':' + str(grade_value) + " " num_matched += 1 else: match_all = False if grades_text: student.courses.append( str(course.shortname) + ' <br/>' + grades_text) i_courses += 1 if max_courses < i_courses: max_courses = i_courses i = 0 for dept in Department.objects.all(): if dept == course.department: student.departments[i] = "X" i += 1 grades_text = "" if data['grade_times'] == "*" and not match_all: add_to_list = False if data['grade_times'] != "*" and not num_matched >= int( data['grade_times']): add_to_list = False # Check discipline if add_to_list and 'ecwsp.discipline' in settings.INSTALLED_APPS: if data['filter_disc_action'] and data[ 'filter_disc'] and data['filter_disc_times']: student.action_count = 0 for disc in student_disciplines: if disc.id == student.id: student.action_count = disc.action_count break if ((data['filter_disc'] == "lt" and not student.action_count < int( data['filter_disc_times'])) or (data['filter_disc'] == "lte" and not student.action_count <= int( data['filter_disc_times'])) or (data['filter_disc'] == "gt" and not student.action_count > int( data['filter_disc_times'])) or (data['filter_disc'] == "gte" and not student.action_count >= int( data['filter_disc_times']))): add_to_list = False else: student.courses.append( '%s: %s' % (data['filter_disc_action'], student.action_count)) if data['aggregate_disc'] and data[ 'aggregate_disc_times']: if ((data['aggregate_disc'] == "lt" and not student.aggregate_disciplines < int( data['aggregate_disc_times'])) or (data['aggregate_disc'] == "lte" and not student.aggregate_disciplines <= int(data['aggregate_disc_times'])) or (data['aggregate_disc'] == "gt" and not student.aggregate_disciplines > int(data['aggregate_disc_times'])) or (data['aggregate_disc'] == "gte" and not student.aggregate_disciplines >= int(data['aggregate_disc_times']))): add_to_list = False else: student.courses.append( '%s: %s' % ("Aggregate Discipline", student.aggregate_disciplines)) # Check Attendance if add_to_list and data['filter_attn'] and data[ 'filter_attn_times']: try: student.attn_count = student_attendances.get( id=student.id).attn_count except: student.attn_count = 0 if ((data['filter_attn'] == "lt" and not student.attn_count < int( data['filter_attn_times'])) or (data['filter_attn'] == "lte" and not student.attn_count <= int( data['filter_attn_times'])) or (data['filter_attn'] == "gt" and not student.attn_count > int( data['filter_attn_times'])) or (data['filter_attn'] == "gte" and not student.attn_count >= int( data['filter_attn_times']))): add_to_list = False else: student.courses.append('Absents: %s' % (student.attn_count, )) # Tardies if add_to_list and data['filter_tardy'] and data[ 'filter_tardy_times']: if ((data['filter_tardy'] == "lt" and not student.tardy_count < int( data['filter_tardy_times'])) or (data['filter_tardy'] == "lte" and not student.tardy_count <= int( data['filter_tardy_times'])) or (data['filter_tardy'] == "gt" and not student.tardy_count > int( data['filter_tardy_times'])) or (data['filter_tardy'] == "gte" and not student.tardy_count >= int( data['filter_tardy_times']))): add_to_list = False else: student.courses.append('Tardies: %s' % (student.tardy_count, )) if add_to_list: show_students.append(student) # Print xls report if 'xls' in request.POST or 'xls_asp' in request.POST: pref = UserPreference.objects.get_or_create( user=request.user)[0] titles = ['Student'] data = [] for student in show_students: if unicode(student.id) in request.POST.getlist('selected'): row = [student] pref.get_additional_student_fields( row, student, show_students, titles) i = 0 for course in student.courses: row.append(course.replace("<br/>", " ")) i += 1 # padding data while i < max_courses: row.append("") i += 1 if 'xls_asp' in request.POST: for dept in student.departments: row.append(dept) data.append(row) titles.append('Grades') i = 1 while i < max_courses: titles.append('') i += 1 if 'xls_asp' in request.POST: for dept in Department.objects.all(): titles.append(dept) report = xlsReport(data, titles, "analytics.xls", heading="Analytics Report") return report.finish() return render_to_response( 'schedule/grade_analytics.html', { 'form': form, 'course_selection': None, 'students': show_students, }, RequestContext(request, {}), ) return render_to_response( 'schedule/grade_analytics.html', { 'form': form, }, RequestContext(request, {}), )
def aggregate_grade_report(request): from ecwsp.grades.models import Grade mp_form = MarkingPeriodForm(request.POST) if mp_form.is_valid(): mps = mp_form.cleaned_data['marking_period'] data = [] titles = ["Teacher", "Range", "No. Students", ""] for level in GradeLevel.objects.all(): titles += [level, ""] ranges = [['100', '90'], ['89.99', '80'], ['79.99', '70'], ['69.99', '60'], ['59.99', '50'], ['49.99', '0']] letter_ranges = ['P', 'F'] for teacher in Faculty.objects.filter(course__marking_period__in=mps).distinct(): data.append([teacher]) grades = Grade.objects.filter( marking_period__in=mps, course__teacher=teacher, student__inactive=False, override_final=False, ).filter( Q(grade__isnull=False) | Q(letter_grade__isnull=False) ) teacher_students_no = grades.distinct().count() if teacher_students_no: for range in ranges: no_students = grades.filter( grade__range=(range[1],range[0]), ).distinct().count() percent = float(no_students) / float(teacher_students_no) percent = ('%.2f' % (percent * 100,)).rstrip('0').rstrip('.') + "%" row = ["", str(range[1]) + " to " + str(range[0]), no_students, percent] for level in GradeLevel.objects.all(): no_students = grades.filter( grade__range=(range[1],range[0]), student__year__in=[level], ).distinct().count() level_students_no = grades.filter( student__year__in=[level], ).distinct().count() percent = "" if level_students_no: percent = float(no_students) / float(level_students_no) percent = ('%.2f' % (percent * 100,)).rstrip('0').rstrip('.') + "%" row += [no_students, percent] data.append(row) for range in letter_ranges: no_students = grades.filter( letter_grade=range, ).distinct().count() if teacher_students_no: percent = float(no_students) / float(teacher_students_no) percent = ('%.2f' % (percent * 100,)).rstrip('0').rstrip('.') + "%" else: percent = "" row = ["", str(range), no_students, percent] for level in GradeLevel.objects.all(): no_students = grades.filter( letter_grade=range, student__year__in=[level], ).distinct().count() level_students_no = grades.filter( student__year__in=[level], ).distinct().count() if level_students_no: percent = float(no_students) / float(level_students_no) percent = ('%.2f' % (percent * 100,)).rstrip('0').rstrip('.') + "%" else: percent = "" row += [no_students, percent] data.append(row) report = xlsReport(data, titles, "aggregate_grade_report.xls", heading="Teacher aggregate") passing = 70 data = [] titles = ['Grade'] for dept in Department.objects.all(): titles.append(dept) titles.append('') for level in GradeLevel.objects.all(): row = [level] for dept in Department.objects.all(): fails = Grade.objects.filter( marking_period__in=mps, course__department=dept, student__inactive=False, student__year__in=[level], # Shouldn't need __in. Makes no sense at all. grade__lt=passing, override_final=False, ).count() total = Grade.objects.filter( marking_period__in=mps, course__department=dept, student__inactive=False, student__year__in=[level], override_final=False, ).count() if total: percent = float(fails) / float(total) else: percent = 0 percent = ('%.2f' % (percent * 100,)).rstrip('0').rstrip('.') row.append(fails) row.append(percent) data.append(row) report.addSheet(data, titles=titles, heading="Class Dept aggregate") return report.finish()
def date_based_gpa_report(request): input = request.POST.copy() input['template'] = 1 # Validation hack form = StudentGradeReportWriterForm(input, request.FILES) if form.is_valid(): data = form.cleaned_data try: students = form.get_students(data) except: students = Student.objects.filter(inactive = False).order_by('-year__id') titles = ["Student", "9th", "10th", "11th","12th", "Current"] data = [] current_year = SchoolYear.objects.get(active_year = True) two_years_ago = (current_year.end_date + timedelta(weeks=-(2*52))).year three_years_ago = (current_year.end_date + timedelta(weeks=-(3*52))).year four_years_ago = (current_year.end_date + timedelta(weeks=-(4*52))).year for student in students: row = [] gpa = [None,None,None,None,None] count = 0 #years is years that student has courses/grades years = SchoolYear.objects.filter(markingperiod__show_reports=True,start_date__lt=date.today(),markingperiod__course__courseenrollment__user=student ).exclude(omityeargpa__student=student).distinct().order_by('start_date') #if student has courses from any year and is given a grade level (freshman,sophomore, etc.), #it checks to see if the student's been at cristorey every year or if they transferred in and when current = 0 try: if student.year.id == 12: current = 3 if years[0].start_date.year > two_years_ago: gpa[0] = "N/A" gpa[1] = "N/A" gpa[2] = "N/A" count = 3 elif years[0].start_date.year > three_years_ago: gpa[0] = "N/A" gpa[1] = "N/A" count = 2 elif years[0].start_date.year > four_years_ago: gpa[0] = "N/A" count = 1 elif student.year.id == 11: current = 2 if years[0].start_date.year > two_years_ago: gpa[1] = "N/A" gpa[0] = "N/A" count = 2 elif years[0].start_date.year > three_years_ago: gpa[0] = "N/A" count = 1 elif student.year.id == 10: current = 1 if two_years_ago: gpa[0] = "N/A" count = 1 elif student.year.id == 9: current = 0 except:pass for year in years: #cumulative gpa per year. Adds one day because it was acting weird and not giving me GPA for first year gpa[count] = student.calculate_gpa(year.end_date + timedelta(days=1)) count +=1 #if calculate_gpa does not return a value, it is set to "N/A" if not gpa[0]: gpa[0] = "N/A" if not gpa[1]: gpa[1] = "N/A" if not gpa[2]: gpa[2] = "N/A" if not gpa[3]: gpa[3] = "N/A" gpa[4] = gpa[current] row = [student, gpa[0],gpa[1],gpa[2],gpa[3],gpa[4]] data.append(row) report = xlsReport(data, titles, "gpas_by_year.xls", heading="GPAs") return report.finish()
def download_results(self, test): """ Create basic xls report for OMR. Includes summary and details """ # Summary sheet data = [[test.name]] data.append(["Points Possible:", test.points_possible]) data.append(["Results collected: %s" % (test.students_test_results,)]) data.append(['Test average: %s' % (test.points_average,)]) data.append([]) data.append(['Student', 'Points Earned', 'Percentage']) i = 7 for ti in test.testinstance_set.annotate(earned=Sum('answerinstance__points_earned')): data.append([ti.student, ti.earned, xlwt.Formula("B%s / $B$2" % i)]) i += 1 #xlwt.Formula("B2") report = xlsReport(data, fileName="OMR report.xls", heading="Summary", heading_top=False) # Detail sheets data_points = [] data_answers = [] row_points = ["Student"] row_answers = ["Student"] for question in test.question_set.all(): row_points.append("%s %s" % (question.order, strip_tags(question.question).strip())) row_answers.append("%s %s" % (question.order, strip_tags(question.question).strip())) data_points.append(row_points) data_answers.append(row_answers) for test_instance in test.testinstance_set.all(): row_points = [] row_answers = [] row_points.append(test_instance.student) row_answers.append(test_instance.student) for question in test.question_set.all(): try: answer = test_instance.answerinstance_set.get(question=question) row_points.append(answer.points_earned) row_answers.append(strip_tags(answer.answer).strip()) except: row_points.append('') row_answers.append('') data_points.append(row_points) data_answers.append(row_answers) report.addSheet(data_points, heading="Detail Points", heading_top=False) report.addSheet(data_answers, heading="Detail Answers", heading_top=False) # Benchmark sheet data = [] row = ['Benchmark'] row2 = ['Points Possible'] for benchmark in Benchmark.objects.filter(question__test=test).distinct(): row.append(benchmark) row.append('%') row2.append(test.question_set.filter(benchmarks=benchmark).aggregate(Sum('point_value'))['point_value__sum']) row2.append('') data.append(row) data.append(row2) i = 3 # 3 for third row on spreadsheet for test_instance in test.testinstance_set.all(): row = [test_instance.student] a = 98 # the letter c or column c in spreadsheet for benchmark in Benchmark.objects.filter(question__test=test).distinct(): row.append(test_instance.answerinstance_set.filter(question__benchmarks=benchmark).aggregate(Sum('points_earned'))['points_earned__sum']) if a <= 122: # 122 = z row.append(xlwt.Formula(chr(a)+str(i)+'/'+chr(a)+'$2')) elif a <= 148: row.append(xlwt.Formula('A'+chr(a-26)+str(i)+'/'+'A'+chr(a-26)+'$2')) elif a <= 174: row.append(xlwt.Formula('B'+chr(a-52)+str(i)+'/'+'B'+chr(a-52)+'$2')) elif a <= 200: row.append(xlwt.Formula('C'+chr(a-78)+str(i)+'/'+'C'+chr(a-78)+'$2')) a += 2 # skip ahead 2 columns i += 1 data.append(row) report.addSheet(data, heading="Benchmark", heading_top=False) return report.finish()
def aggregate_grade_report(request): from ecwsp.grades.models import Grade mp_form = MarkingPeriodForm(request.POST) if mp_form.is_valid(): mps = mp_form.cleaned_data['marking_period'] data = [] titles = ["Teacher", "Range", "No. Students", ""] for level in GradeLevel.objects.all(): titles += [level, ""] ranges = [['100', '90'], ['89.99', '80'], ['79.99', '70'], ['69.99', '60'], ['59.99', '50'], ['49.99', '0']] letter_ranges = ['P', 'F'] for teacher in Faculty.objects.filter( course__marking_period__in=mps).distinct(): data.append([teacher]) grades = Grade.objects.filter( marking_period__in=mps, course__teacher=teacher, student__inactive=False, override_final=False, ).filter(Q(grade__isnull=False) | Q(letter_grade__isnull=False)) teacher_students_no = grades.distinct().count() if teacher_students_no: for range in ranges: no_students = grades.filter( grade__range=(range[1], range[0]), ).distinct().count() percent = float(no_students) / float(teacher_students_no) percent = ('%.2f' % (percent * 100, )).rstrip('0').rstrip('.') + "%" row = [ "", str(range[1]) + " to " + str(range[0]), no_students, percent ] for level in GradeLevel.objects.all(): no_students = grades.filter( grade__range=(range[1], range[0]), student__year__in=[level], ).distinct().count() level_students_no = grades.filter( student__year__in=[level], ).distinct().count() percent = "" if level_students_no: percent = float(no_students) / float( level_students_no) percent = ('%.2f' % (percent * 100, ) ).rstrip('0').rstrip('.') + "%" row += [no_students, percent] data.append(row) for range in letter_ranges: no_students = grades.filter( letter_grade=range, ).distinct().count() if teacher_students_no: percent = float(no_students) / float( teacher_students_no) percent = ( '%.2f' % (percent * 100, )).rstrip('0').rstrip('.') + "%" else: percent = "" row = ["", str(range), no_students, percent] for level in GradeLevel.objects.all(): no_students = grades.filter( letter_grade=range, student__year__in=[level], ).distinct().count() level_students_no = grades.filter( student__year__in=[level], ).distinct().count() if level_students_no: percent = float(no_students) / float( level_students_no) percent = ('%.2f' % (percent * 100, ) ).rstrip('0').rstrip('.') + "%" else: percent = "" row += [no_students, percent] data.append(row) report = xlsReport(data, titles, "aggregate_grade_report.xls", heading="Teacher aggregate") passing = 70 data = [] titles = ['Grade'] for dept in Department.objects.all(): titles.append(dept) titles.append('') for level in GradeLevel.objects.all(): row = [level] for dept in Department.objects.all(): fails = Grade.objects.filter( marking_period__in=mps, course__department=dept, student__inactive=False, student__year__in=[ level ], # Shouldn't need __in. Makes no sense at all. grade__lt=passing, override_final=False, ).count() total = Grade.objects.filter( marking_period__in=mps, course__department=dept, student__inactive=False, student__year__in=[level], override_final=False, ).count() if total: percent = float(fails) / float(total) else: percent = 0 percent = ('%.2f' % (percent * 100, )).rstrip('0').rstrip('.') row.append(fails) row.append(percent) data.append(row) report.addSheet(data, titles=titles, heading="Class Dept aggregate") return report.finish()
def date_based_gpa_report(request): input = request.POST.copy() input['template'] = 1 # Validation hack form = StudentGradeReportWriterForm(input, request.FILES) if form.is_valid(): data = form.cleaned_data try: students = form.get_students(data) except: students = Student.objects.filter( inactive=False).order_by('-year__id') titles = ["Student", "9th", "10th", "11th", "12th", "Current"] data = [] current_year = SchoolYear.objects.get(active_year=True) two_years_ago = (current_year.end_date + timedelta(weeks=-(2 * 52))).year three_years_ago = (current_year.end_date + timedelta(weeks=-(3 * 52))).year four_years_ago = (current_year.end_date + timedelta(weeks=-(4 * 52))).year for student in students: row = [] gpa = [None, None, None, None, None] count = 0 #years is years that student has courses/grades years = SchoolYear.objects.filter( markingperiod__show_reports=True, start_date__lt=date.today(), markingperiod__course__courseenrollment__user=student).exclude( omityeargpa__student=student).distinct().order_by( 'start_date') #if student has courses from any year and is given a grade level (freshman,sophomore, etc.), #it checks to see if the student's been at cristorey every year or if they transferred in and when current = 0 try: if student.year.id == 12: current = 3 if years[0].start_date.year > two_years_ago: gpa[0] = "N/A" gpa[1] = "N/A" gpa[2] = "N/A" count = 3 elif years[0].start_date.year > three_years_ago: gpa[0] = "N/A" gpa[1] = "N/A" count = 2 elif years[0].start_date.year > four_years_ago: gpa[0] = "N/A" count = 1 elif student.year.id == 11: current = 2 if years[0].start_date.year > two_years_ago: gpa[1] = "N/A" gpa[0] = "N/A" count = 2 elif years[0].start_date.year > three_years_ago: gpa[0] = "N/A" count = 1 elif student.year.id == 10: current = 1 if two_years_ago: gpa[0] = "N/A" count = 1 elif student.year.id == 9: current = 0 except: pass for year in years: #cumulative gpa per year. Adds one day because it was acting weird and not giving me GPA for first year gpa[count] = student.calculate_gpa(year.end_date + timedelta(days=1)) count += 1 #if calculate_gpa does not return a value, it is set to "N/A" if not gpa[0]: gpa[0] = "N/A" if not gpa[1]: gpa[1] = "N/A" if not gpa[2]: gpa[2] = "N/A" if not gpa[3]: gpa[3] = "N/A" gpa[4] = gpa[current] row = [student, gpa[0], gpa[1], gpa[2], gpa[3], gpa[4]] data.append(row) report = xlsReport(data, titles, "gpas_by_year.xls", heading="GPAs") return report.finish()
def discipline_report_view(request): form = DisciplineStudentStatistics() merit_form = MeritForm() if request.method == 'POST': if 'merit' in request.POST: merit_form = MeritForm(request.POST) if merit_form.is_valid(): from ecwsp.sis.report import pod_report_generic data = {} l1 = merit_form.cleaned_data['level_one'] l2 = merit_form.cleaned_data['level_two'] l3 = merit_form.cleaned_data['level_three'] l4 = merit_form.cleaned_data['level_four'] start_date = merit_form.cleaned_data['start_date'] end_date = merit_form.cleaned_data['end_date'] students = Student.objects.filter(inactive=False) if merit_form.cleaned_data['sort_by'] == 'year': students = students.order_by('year') elif merit_form.cleaned_data['sort_by'] == 'cohort': students = students.order_by('cache_cohort') disciplines = StudentDiscipline.objects.filter( date__range=(start_date, end_date)).values('students').annotate( Count('pk')) for student in students: disc = 0 for discipline in disciplines: if discipline['students'] == student.id: disc = discipline['pk__count'] break student.disc_count = disc if student.disc_count <= l1: student.merit_level = 1 elif student.disc_count <= l2: student.merit_level = 2 elif student.disc_count <= l3: student.merit_level = 3 elif student.disc_count <= l4: student.merit_level = 4 data['students'] = students template = Template.objects.get_or_create( name="Merit Level Handout")[0] template = template.get_template_path(request) format_type = UserPreference if template: format_type = UserPreference.objects.get_or_create( user=request.user)[0].get_format() return pod_report_generic(template, data, "Merit Handouts", format=format_type) else: form = DisciplineStudentStatistics(request.POST) if form.is_valid(): data = [] start, end = form.get_dates() if 'student' in request.POST: students = Student.objects.all() school_year = SchoolYear.objects.get(active_year=True) if form.cleaned_data['date_begin']: if SchoolYear.objects.filter( end_date__gte=form.cleaned_data['date_begin']): school_year = SchoolYear.objects.filter( end_date__gte=form.cleaned_data['date_begin'] ).order_by('start_date')[0] # students belonging to this school year students = students.filter( course__marking_period__school_year__exact= school_year).distinct() if not form.cleaned_data['include_deleted']: students = students.exclude(inactive=True) if form.cleaned_data['order_by'] == "Year": students = students.order_by('year') subtitles = [ "Student", ] titles = [ "", "Infractions", ] for infr in Infraction.objects.all(): titles.append("") titles.pop() titles.append("Actions") for infr in Infraction.objects.all(): subtitles.append(unicode(infr)) for action in DisciplineAction.objects.all(): subtitles.append(unicode(action)) titles.append("") titles.pop() data.append(subtitles) pref = UserPreference.objects.get_or_create( user=request.user)[0] for student in students: disciplines = student.studentdiscipline_set.all() disciplines = disciplines.filter(date__range=(start, end)) stats = [ unicode(student), ] add = True for infr in Infraction.objects.all(): number = disciplines.filter( infraction=infr, students=student).count() stats.append(number) # check for filter if form.cleaned_data['infraction'] == infr: infraction_discipline = disciplines.filter( infraction=form.cleaned_data['infraction']) if number < form.cleaned_data[ 'minimum_infraction']: add = False for action in DisciplineAction.objects.all(): actions = disciplines.filter( disciplineactioninstance__action=action, students=student).count() stats.append(actions) # check for filter if form.cleaned_data['action'] == action: if actions < form.cleaned_data[ 'minimum_action']: add = False pref.get_additional_student_fields( stats, student, students, titles) if add: data.append(stats) report = xlsReport(data, titles, "disc_stats.xls", heading="Discipline Stats") # By Teacher data = [] titles = ['teacher'] for action in DisciplineAction.objects.all(): titles.append(action) teachers = Faculty.objects.filter( studentdiscipline__isnull=False).distinct() disciplines = StudentDiscipline.objects.filter( date__range=(start, end)) for teacher in teachers: row = [teacher] for action in DisciplineAction.objects.all(): row.append( disciplines.filter(teacher=teacher, action=action).count()) data.append(row) report.addSheet(data, titles=titles, heading="By Teachers") return report.finish() elif 'aggr' in request.POST: disciplines = StudentDiscipline.objects.filter( date__range=(start, end)) if form.cleaned_data['this_year']: school_start = SchoolYear.objects.get( active_year=True).start_date school_end = SchoolYear.objects.get( active_year=True).end_date disciplines = disciplines.filter( date__range=(school_start, school_end)) elif not form.cleaned_data[ 'this_year'] and not form.cleaned_data['all_years']: disciplines = disciplines.filter( date__range=(form.cleaned_data['date_begin'], form.cleaned_data['date_end'])) stats = [] titles = [] for infr in Infraction.objects.all(): titles.append(infr) number = disciplines.filter(infraction=infr).count() stats.append(number) for action in DisciplineAction.objects.all(): titles.append(action) number = 0 for a in DisciplineActionInstance.objects.filter( action=action): number += a.quantity stats.append(number) data.append(stats) report = xlsReport(data, titles, "disc_stats.xls", heading="Discipline Stats") return report.finish() else: return render_to_response( 'discipline/disc_report.html', { 'request': request, 'form': form }, RequestContext(request, {}), ) return render_to_response( 'discipline/disc_report.html', { 'request': request, 'form': form, 'merit_form': merit_form, }, RequestContext(request, {}), )
def grade_analytics(request): def check_if_match(grade, filter, filter_grade): try: if grade == "P": grade = 100 grade = float(grade) filter_grade = float(filter_grade) if filter == 'lt': if grade < filter_grade: return True elif filter == 'lte': if grade <= filter_grade: return True elif filter == 'gt': if grade > filter_grade: return True elif filter == 'gte': if grade >= filter_grade: return True except: pass return False form = GradeFilterForm() if request.method == 'POST': if 'edit' in request.POST: selected = request.POST.getlist('selected') return redirect('/admin/sis/student/?id__in=%s' % (','.join(selected),)) form = GradeFilterForm(request.POST) if form.is_valid(): ids = [] if 'submit_course' in request.POST and 'course' in request.POST: course_selection = CourseSelectionForm(request.POST) if course_selection.is_valid(): for key in request.POST: if key[:9] == "selected_": ids.append(request.POST[key]) students = Student.objects.filter(id__in=ids) if students and course_selection.cleaned_data['course']: for student in students: CourseEnrollment.objects.get_or_create(user=student, course=course_selection.cleaned_data['course'], role="student") messages.success(request, 'Students added to %s!' % (course_selection.cleaned_data['course'].shortname,)) else: messages.success(request, 'Did not enroll, please select students and a course.') course_selection = CourseSelectionForm() data = form.cleaned_data students = Student.objects.all() if not data['include_deleted']: students = students.filter(inactive=False) if data['filter_year']: students = students.filter(year__in=data['filter_year']) if data['in_individual_education_program']: students = students.filter(individual_education_program=True) if data['gpa']: # this will be something like filter(cache_gpa__lte=gpa) arg = 'cache_gpa__' + data['gpa_equality'] students = students.filter(**{arg: data['gpa'],}) courses = Course.objects.filter(courseenrollment__user__in=students, graded=True) if data['this_year']: courses = courses.filter(marking_period__school_year=SchoolYear.objects.get(active_year=True)) elif not data['all_years']: courses = courses.filter( marking_period__start_date__gte=data['date_begin'], marking_period__end_date__lte=data['date_end'], ) if data['marking_period']: courses = courses.filter(marking_period__in=data['marking_period']) students = students.distinct() courses = courses.distinct() mps_selected = [] for mp in data['marking_period']: mps_selected.append(mp.id) show_students = [] max_courses = 0 (date_begin, date_end) = form.get_dates() # Pre load Discipline data if 'ecwsp.discipline' in settings.INSTALLED_APPS: if data['filter_disc_action'] and data['filter_disc'] and data['filter_disc_times']: student_disciplines = students.filter(studentdiscipline__date__range=(date_begin, date_end), studentdiscipline__action=data['filter_disc_action'], ).annotate(action_count=Count('studentdiscipline__action')) if data['aggregate_disc'] and data['aggregate_disc_times']: if data['aggregate_disc_major']: student_aggregate_disciplines = students.filter(studentdiscipline__date__range=(date_begin, date_end), studentdiscipline__action__major_offense=True, ).annotate(action_count=Count('studentdiscipline')) else: student_aggregate_disciplines = students.filter(studentdiscipline__date__range=(date_begin, date_end), ).annotate(action_count=Count('studentdiscipline')) for student in students: student.aggregate_disciplines = 0 for aggr in student_aggregate_disciplines: if aggr.id == student.id: student.aggregate_disciplines = aggr.action_count break # Pre load Attendance data if data['filter_attn'] and data['filter_attn_times']: student_attendances = students.filter(student_attn__date__range=(date_begin, date_end), student_attn__status__absent=True, ).annotate(attn_count=Count('student_attn')) if data['filter_tardy'] and data['filter_tardy_times']: students_tardies = students.filter(student_attn__date__range=(date_begin, date_end), student_attn__status__tardy=True, ).annotate(tardy_count=Count('student_attn')) for student in students: student.tardy_count = 0 for student_tardies in students_tardies: if student_tardies.id == student.id: student.tardy_count = student_tardies.tardy_count break for student in students: # if this is a report, only calculate for selected students. if not 'xls' in request.POST or "selected" in request.POST: num_matched = 0 add_to_list = True # If all criteria is met, add student to list match_all = True student.courses = [] i_courses = 0 student.departments = [] for dept in Department.objects.all(): student.departments.append("") # for each grade for this student course = None done = False grades_text = "" if add_to_list and data['final_grade'] and data['final_grade_filter'] and data['final_grade_times']: for course in student.course_set.filter(id__in=courses): grade = course.get_final_grade(student) if grade: match = check_if_match(grade, data['final_grade_filter'], data['final_grade']) if match: student.courses.append(str(course.shortname) + ' <br/>' + str(grade)) num_matched += 1 i_courses += 1 if max_courses < i_courses: max_courses = i_courses i = 0 for dept in Department.objects.all(): if dept == course.department: student.departments[i] = "X" i += 1 else: match_all = False if data['final_grade_times'] == "*" and not match_all: add_to_list = False elif data['final_grade_times'] != "*" and not num_matched >= int(data['final_grade_times']): add_to_list = False if add_to_list and data['grade'] and data['grade_filter'] and data['grade_times']: # Using just grades for optimization. Rather than for course, for mp, for grade. for grade in student.grade_set.filter(course__in=courses, course__courseenrollment__user=student).order_by('course__department', 'marking_period').select_related(): if mps_selected == [] or grade.marking_period_id in mps_selected: # if this is a new course, add previous course to student if grade.course != course: if grades_text: student.courses.append(str(course.shortname) + ' <br/>' + grades_text) i_courses += 1 if max_courses < i_courses: max_courses = i_courses i = 0 for dept in Department.objects.all(): if dept == course.department: student.departments[i] = "X" i += 1 grades_text = "" course = grade.course # data['each_marking_period'] and if grade.override_final == False: grade_value = grade.get_grade() match = check_if_match(grade_value, data['grade_filter'], data['grade']) if match: grades_text += str(grade.marking_period.shortname) + ':' + str(grade_value) + " " num_matched += 1 else: match_all = False if grades_text: student.courses.append(str(course.shortname) + ' <br/>' + grades_text) i_courses += 1 if max_courses < i_courses: max_courses = i_courses i = 0 for dept in Department.objects.all(): if dept == course.department: student.departments[i] = "X" i += 1 grades_text = "" if data['grade_times'] == "*" and not match_all: add_to_list = False if data['grade_times'] != "*" and not num_matched >= int(data['grade_times']): add_to_list = False # Check discipline if add_to_list and 'ecwsp.discipline' in settings.INSTALLED_APPS: if data['filter_disc_action'] and data['filter_disc'] and data['filter_disc_times']: student.action_count = 0 for disc in student_disciplines: if disc.id == student.id: student.action_count = disc.action_count break if ((data['filter_disc'] == "lt" and not student.action_count < int(data['filter_disc_times'])) or (data['filter_disc'] == "lte" and not student.action_count <= int(data['filter_disc_times'])) or (data['filter_disc'] == "gt" and not student.action_count > int(data['filter_disc_times'])) or (data['filter_disc'] == "gte" and not student.action_count >= int(data['filter_disc_times'])) ): add_to_list = False else: student.courses.append('%s: %s' % (data['filter_disc_action'], student.action_count)) if data['aggregate_disc'] and data['aggregate_disc_times']: if ((data['aggregate_disc'] == "lt" and not student.aggregate_disciplines < int(data['aggregate_disc_times'])) or (data['aggregate_disc'] == "lte" and not student.aggregate_disciplines <= int(data['aggregate_disc_times'])) or (data['aggregate_disc'] == "gt" and not student.aggregate_disciplines > int(data['aggregate_disc_times'])) or (data['aggregate_disc'] == "gte" and not student.aggregate_disciplines >= int(data['aggregate_disc_times'])) ): add_to_list = False else: student.courses.append('%s: %s' % ("Aggregate Discipline", student.aggregate_disciplines)) # Check Attendance if add_to_list and data['filter_attn'] and data['filter_attn_times']: try: student.attn_count = student_attendances.get(id=student.id).attn_count except: student.attn_count = 0 if ((data['filter_attn'] == "lt" and not student.attn_count < int(data['filter_attn_times'])) or (data['filter_attn'] == "lte" and not student.attn_count <= int(data['filter_attn_times'])) or (data['filter_attn'] == "gt" and not student.attn_count > int(data['filter_attn_times'])) or (data['filter_attn'] == "gte" and not student.attn_count >= int(data['filter_attn_times'])) ): add_to_list = False else: student.courses.append('Absents: %s' % (student.attn_count,)) # Tardies if add_to_list and data['filter_tardy'] and data['filter_tardy_times']: if ((data['filter_tardy'] == "lt" and not student.tardy_count < int(data['filter_tardy_times'])) or (data['filter_tardy'] == "lte" and not student.tardy_count <= int(data['filter_tardy_times'])) or (data['filter_tardy'] == "gt" and not student.tardy_count > int(data['filter_tardy_times'])) or (data['filter_tardy'] == "gte" and not student.tardy_count >= int(data['filter_tardy_times'])) ): add_to_list = False else: student.courses.append('Tardies: %s' % (student.tardy_count,)) if add_to_list: show_students.append(student) # Print xls report if 'xls' in request.POST or 'xls_asp' in request.POST: pref = UserPreference.objects.get_or_create(user=request.user)[0] titles = ['Student'] data = [] for student in show_students: if unicode(student.id) in request.POST.getlist('selected'): row = [student] pref.get_additional_student_fields(row, student, show_students, titles) i = 0 for course in student.courses: row.append(course.replace("<br/>", " ")) i += 1 # padding data while i < max_courses: row.append("") i += 1 if 'xls_asp' in request.POST: for dept in student.departments: row.append(dept) data.append(row) titles.append('Grades') i = 1 while i < max_courses: titles.append('') i += 1 if 'xls_asp' in request.POST: for dept in Department.objects.all(): titles.append(dept) report = xlsReport(data, titles, "analytics.xls", heading="Analytics Report") return report.finish() return render_to_response('schedule/grade_analytics.html', {'form': form, 'course_selection': None, 'students': show_students,}, RequestContext(request, {}),) return render_to_response('schedule/grade_analytics.html', {'form': form,}, RequestContext(request, {}),)