From 4906c4688d6a200cf72b2ba22cf1d3715921c30d Mon Sep 17 00:00:00 2001 From: Bruno Mendes Date: Wed, 20 Sep 2023 16:15:29 +0100 Subject: [PATCH 1/2] Fix status parsing of multiple year UCs --- .../controller/parsers/parser_course_units.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/uni/lib/controller/parsers/parser_course_units.dart b/uni/lib/controller/parsers/parser_course_units.dart index 179ba7b77..bd103ad09 100644 --- a/uni/lib/controller/parsers/parser_course_units.dart +++ b/uni/lib/controller/parsers/parser_course_units.dart @@ -59,14 +59,19 @@ List parseCourseUnitsAndCourseAverage( if (row.children.length <= 6 + i) { break; } - yearIncrement++; - grade = row.children[6 + i].innerHtml.replaceAll(' ', ' ').trim(); - status = row.children[7 + i].innerHtml.replaceAll(' ', ' ').trim(); - if (status != '') { + final candidateStatus = + row.children[7 + i].innerHtml.replaceAll(' ', ' ').trim(); + if (status != null && candidateStatus.isEmpty) { break; } + yearIncrement++; + if (candidateStatus.isNotEmpty) { + grade = row.children[6 + i].innerHtml.replaceAll(' ', ' ').trim(); + status = candidateStatus; + } } - if (yearIncrement < 0) { + + if (status == null) { continue; } From b15861a97cb1ebf575eebf9331ddbe7fd244235d Mon Sep 17 00:00:00 2001 From: Bruno Mendes Date: Wed, 20 Sep 2023 17:44:15 +0100 Subject: [PATCH 2/2] Use different models for different occurrences --- .../parsers/parser_course_units.dart | 48 ++++++++----------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/uni/lib/controller/parsers/parser_course_units.dart b/uni/lib/controller/parsers/parser_course_units.dart index bd103ad09..8131dc51b 100644 --- a/uni/lib/controller/parsers/parser_course_units.dart +++ b/uni/lib/controller/parsers/parser_course_units.dart @@ -52,42 +52,36 @@ List parseCourseUnitsAndCourseAverage( final codeName = row.children[2].children[0].innerHtml; final name = row.children[3].children[0].innerHtml; final ects = row.children[5].innerHtml.replaceAll(',', '.'); - String? grade; - String? status; + var yearIncrement = -1; for (var i = 0;; i += 2) { if (row.children.length <= 6 + i) { break; } - final candidateStatus = - row.children[7 + i].innerHtml.replaceAll(' ', ' ').trim(); - if (status != null && candidateStatus.isEmpty) { - break; - } yearIncrement++; - if (candidateStatus.isNotEmpty) { - grade = row.children[6 + i].innerHtml.replaceAll(' ', ' ').trim(); - status = candidateStatus; + final status = + row.children[7 + i].innerHtml.replaceAll(' ', ' ').trim(); + final grade = + row.children[6 + i].innerHtml.replaceAll(' ', ' ').trim(); + + if (status.isEmpty) { + continue; } - } - if (status == null) { - continue; + final courseUnit = CourseUnit( + schoolYear: + '${firstSchoolYear + yearIncrement}/${firstSchoolYear + yearIncrement + 1}', + occurrId: int.parse(occurId), + abbreviation: codeName, + status: status, + grade: grade, + ects: double.parse(ects), + name: name, + curricularYear: int.parse(year), + semesterCode: semester, + ); + courseUnits.add(courseUnit); } - - final courseUnit = CourseUnit( - schoolYear: - '${firstSchoolYear + yearIncrement}/${firstSchoolYear + yearIncrement + 1}', - occurrId: int.parse(occurId), - abbreviation: codeName, - status: status, - grade: grade, - ects: double.parse(ects), - name: name, - curricularYear: int.parse(year), - semesterCode: semester, - ); - courseUnits.add(courseUnit); } return courseUnits;