extractGradeRow function

GradeRow? extractGradeRow(
  1. Bs4Element gradeRow,
  2. Student student
)

Implementation

GradeRow? extractGradeRow(Bs4Element gradeRow, Student student) {
  var subjectList = gradeRow.children[1].text.split(", ");
  var subject = Subject(
      name: subjectList[0],
      type: SubjectTypes.values
          .where((element) => element.name == subjectList[1])
          .firstOrNull);
  var teamCell = gradeRow.children[0].children[0];
  var teamId = teamCell.getAttrValue("data-lectiocontextcard")!;
  var teamName = teamCell.text;
  var team = Team(name: teamName, id: teamId, displayName: teamName);

  // extract all grades
  List<Grade?> grades = [];
  for (int i = 2; i < 8; i++) {
    var child = gradeRow.children.elementAtOrNull(i);
    if (child == null) {
      grades.add(null);
    } else {
      var grade = extractSingleGrade(gradeRow.children[i]);
      grades.add(grade);
    }
  }
  return GradeRow(
      team: team,
      subject: subject,
      firstStandpunkt: grades[0],
      secondStandpunkt: grades[1],
      finalYearGrade: grades[2],
      internalTest: grades[3],
      yearGrade: grades[4],
      examGrade: grades[5]);
}