def test_addGradeUserCourse(cls): user3 = User.objects.create_user(username="******", password="******") c = Course.addCourse(user=user3, course_name="NLP", credinitials="3") Grade.addGradeUserCourse(c, 90, 'A', 2021) out = Grade.objects.filter(semester='A') assert list(out.values_list('course', 'grade', 'semester', 'year')) == [(3, 90, 'A', 2021)]
def test_removeGrade(cls): user3 = User.objects.create_user(username="******", password="******") c = Course.addCourse(user=user3, course_name="NLP", credinitials="3") Grade.addGradeUserCourse(c, 50, 'B', 2020) Grade.removeGrade(2) out = Grade.objects.all() assert list(out.values_list('course', 'grade', 'semester', 'year')) == [ (3, 50, 'B', 2020), ]
def get_scaled_multiple_mp_average_by_indices(self, indices, rounding=2): """ Get a scaled mulitple marking period average for this student Requires that the property mps be set previously. This function exists mainly for appy based report cards where speed, and simplicity (in the template) are important. """ from grades.models import Grade mps = [self.mps[i] for i in indices] return Grade.get_scaled_multiple_mp_average(self, mps, rounding)
def get_grade(season, name): match = re.match("^\s*(.*?)\s+\(KG\)\s*", name, re.DOTALL | re.MULTILINE) if match: name = match.group(1) grade = Grade.from_full_name(name) if not grade: raise Exception("Unable to find grade with name '%s'" % name) # get the grade from our tree, this then includes depth and whether it has children # in the context of this season season_grades = season.get_grade_tree() for season_grade in season_grades: if season_grade.id == grade.id: return season_grade raise Exception( "The grade '%s' is not a configured grade for the %s season" % (grade.name, season.name))
def build_grade_fields(self, form): fields = [] for grade in Grade.get_grade_tree(is_active=True): field_name = 'grade__%d' % grade.id grade.field_name = field_name field = forms.BooleanField(label="", required=False) form.fields.insert(len(form.fields), field_name, field) # only add top grade checkboxes to green grades which have no children if not grade.has_children and grade.kind == 'GRE': top_field_name = 'grade__%d__top' % grade.id grade.top_field_name = top_field_name field = forms.BooleanField(label="", required=False) form.fields.insert(len(form.fields), top_field_name, field) fields.append(grade) return fields
def index(): form = StudentForm(request.form) form.discipline.choices = [(d.id, d.name) for d in Discipline.query.all()] grades = Grade.query.all() print(grades) if request.method == 'POST' and form.validate(): if Student.query.filter_by(name=form.name.data).first() is not None: s = Student.query.filter_by(name=form.name.data).first() else: s = Student(name=form.name.data) db.session.add(s) db.session.commit() g = Grade(student=s.id, discipline=form.discipline.data, grade=form.grade.data) db.session.add(g) db.session.commit() return redirect(url_for('index')) # Avg grades for all avg_grades = db.session.query(func.avg(Grade.grade)).all() # Avg grade by subj all_grades = [d.grades.all() for d in Discipline.query.all()] avg_for_discipline = [ (sum([gr.grade for gr in d])/len(d), d[0].discipline_related.name) for d in all_grades if len(d) > 0] # Avg by student students = Student.query.all() student_avg = [(sum([mark.grade for mark in st.grades.all()])/len(st.grades.all()), st.name) for st in students if len(st.grades.all()) > 0] return render_template('index.html', form=form, grades=grades, avg_grades=avg_grades, avg_for_discipline=avg_for_discipline, student_avg=student_avg)
def Delete_grade(request, gradeID): Grade.removeGrade(gradeID) messages.success(request, "Grade Deleted!") return redirect('grades:createGrade')
def parse_data(data, exam, faculty): soup = BeautifulSoup(data, 'html5lib') tables = soup.find_all('table') # Semester info table_info = tables[len(tables) - 4] rows_info = table_info.find_all('tr') td_info = rows_info[1].find_all('td') temp = td_info[1].string.split('-') semester_code = "" if exam == "VÅR": semester_code = "V" elif exam == "SOM": semester_code = "S" elif exam == "HØST": semester_code = "H" semester_code += '%s' % (temp[0].strip()) # Grade info rows_grades = soup.find_all(class_="tableRow") # row 5 and down is subjects print("Found %d exams from %s" % (len(rows_grades) - 1, semester_code)) for i in range(0, len(rows_grades) - 1): td_grades = rows_grades[i].find_all('td') subject_code = td_grades[0].string.split('-') subject_code = subject_code[0].strip() subjects = Course.objects.filter(code=subject_code) if not subjects: if "AVH" in subject_code: continue course = create_course(subject_code, faculty) if not course: continue else: course = subjects[0] grades = Grade.objects.filter(course=course, semester_code=semester_code) if not grades: grades = Grade() attending = int(td_grades[5].string.strip()) grades.course = course grades.semester_code = semester_code grades.f = int(td_grades[6].string.strip()) passing = attending - grades.f grades.a = round((int(td_grades[13].string.strip()) / 100.0) * passing) grades.b = round((int(td_grades[14].string.strip()) / 100.0) * passing) grades.c = round((int(td_grades[15].string.strip()) / 100.0) * passing) grades.d = round((int(td_grades[16].string.strip()) / 100.0) * passing) grades.e = round((int(td_grades[17].string.strip()) / 100.0) * passing) s = grades.a + grades.b + grades.c + grades.d + grades.e + grades.f if s - grades.f == 0: grades.passed = passing if s == 0: grades.average_grade = 0 else: grades.average_grade = (grades.a * 5.0 + grades.b * 4 + grades.c * 3 + grades.d * 2 + grades.e) / s grades.save()
def parse_data(data, exam, faculty): soup = BeautifulSoup(data, 'html5lib') tables = soup.find_all('table') # Semester info table_info = tables[len(tables) - 4] rows_info = table_info.find_all('tr') td_info = rows_info[1].find_all('td') temp = td_info[1].string.split('-') semester_code = "" if exam == "VÅR": semester_code = "V" elif exam == "SOM": semester_code = "S" elif exam == "HØST": semester_code = "H" semester_code += '%s' % (temp[0].strip()) # Grade info rows_grades = soup.find_all(class_="tableRow") # row 5 and down is subjects print("Found %d exams from %s" % (len(rows_grades) - 1, semester_code)) for i in range(0, len(rows_grades) - 1): td_grades = rows_grades[i].find_all('td') subject_code = td_grades[0].string.split('-') subject_code = subject_code[0].strip() subjects = Course.objects.filter(code=subject_code) if not subjects: if "AVH" in subject_code: continue course = create_course(subject_code, faculty) if not course: continue else: course = subjects[0] grades = Grade.objects.filter(course=course, semester_code=semester_code) if not grades: grades = Grade() attending = int(td_grades[5].string.strip()) grades.course = course grades.semester_code = semester_code grades.f = int(td_grades[6].string.strip()) passing = attending - grades.f grades.a = round( (int(td_grades[13].string.strip()) / 100.0) * passing) grades.b = round( (int(td_grades[14].string.strip()) / 100.0) * passing) grades.c = round( (int(td_grades[15].string.strip()) / 100.0) * passing) grades.d = round( (int(td_grades[16].string.strip()) / 100.0) * passing) grades.e = round( (int(td_grades[17].string.strip()) / 100.0) * passing) s = grades.a + grades.b + grades.c + grades.d + grades.e + grades.f if s - grades.f == 0: grades.passed = passing if s == 0: grades.average_grade = 0 else: grades.average_grade = (grades.a * 5.0 + grades.b * 4 + grades.c * 3 + grades.d * 2 + grades.e) / s grades.save()