Skip to content

Commit

Permalink
Fix overlapping classes bugs (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisDuarte1 authored Sep 28, 2023
2 parents 1bf751b + e88317d commit 1ade4ec
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ jobs:
with:
token: ${{ secrets.NIAEFEUPBOT_PAT }}

- name: Get develop hash
if: github.ref == 'refs/heads/master'
run: |
git fetch origin develop
current_hash=$(git rev-parse origin/develop)
echo "DEVELOPHASH=$current_hash" >> $GITHUB_ENV
- name: Bump flutter patch version
if: github.ref == 'refs/heads/develop'
if: github.ref == 'refs/heads/develop' || github.sha != env.DEVELOPHASH
run: perl -i -pe 's/^(\d+\.\d+\.)(\d+)(\+)(\d+)$/$1.($2+1).($3).($4+1)/e' ${{ env.APP_VERSION_PATH }}

- name: Bump flutter minor version
if: github.ref == 'refs/heads/master'
if: github.ref == 'refs/heads/master' && github.sha == env.DEVELOPHASH
run: perl -i -pe 's/^(\d+)(\.)(\d+)(\.)(\d+)(\+)(\d+)$/$1.($2).($3+1).($4).(0).($6).($7+1)/e' ${{ env.APP_VERSION_PATH }}

- name: Copy app version to pubspec
Expand All @@ -28,7 +35,6 @@ jobs:
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Bump app version [no ci]"

- name: Propagate master version bump to develop
if: github.ref == 'refs/heads/master'
run: git push --force-with-lease origin HEAD:develop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:http/http.dart';
import 'package:uni/controller/fetchers/schedule_fetcher/schedule_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
Expand Down Expand Up @@ -39,8 +40,11 @@ class ScheduleFetcherHtml extends ScheduleFetcher {
}

final lectures = await Future.wait(
lectureResponses
.map((response) => getScheduleFromHtml(response, session)),
IterableZip(
[lectureResponses, NetworkRouter.getBaseUrlsFromSession(session)],
).map(
(e) => getScheduleFromHtml(e[0] as Response, session, e[1] as String),
),
).then((schedules) => schedules.expand((schedule) => schedule).toList());

lectures.sort((l1, l2) => l1.compare(l2));
Expand Down
31 changes: 23 additions & 8 deletions uni/lib/controller/parsers/parser_schedule_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:uni/model/entities/time_utilities.dart';
Future<List<Lecture>> getOverlappedClasses(
Session session,
Document document,
String faculty,
) async {
final lecturesList = <Lecture>[];

Expand All @@ -21,7 +22,7 @@ Future<List<Lecture>> getOverlappedClasses(
final subject = element.querySelector('acronym > a')?.text;
final typeClass = element
.querySelector('td[headers=t1]')
?.nodes[2]
?.nodes[1]
.text
?.trim()
.replaceAll(RegExp('[()]+'), '');
Expand All @@ -37,22 +38,33 @@ Future<List<Lecture>> getOverlappedClasses(
final classNumber = element.querySelector('td[headers=t6] > a')?.text;

try {
final startTimeList = startTime?.split(':') ?? [];
if (startTimeList.isEmpty) {
throw FormatException(
'Overlapping class $subject has invalid startTime',
);
}
final fullStartTime = monday.add(
Duration(
days: day,
hours: int.parse(startTime!.substring(0, 2)),
minutes: int.parse(startTime.substring(3, 5)),
hours: int.parse(startTimeList[0]),
minutes: int.parse(startTimeList[1]),
),
);
final link =
final href =
element.querySelector('td[headers=t6] > a')?.attributes['href'];

if (link == null) {
if (href == null) {
throw Exception();
}
final response = await NetworkRouter.getWithCookies(link, {}, session);
final response = await NetworkRouter.getWithCookies(
'$faculty$href',
{},
session,
);

final classLectures = await getScheduleFromHtml(response, session);
final classLectures =
await getScheduleFromHtml(response, session, faculty);

lecturesList.add(
classLectures
Expand Down Expand Up @@ -88,6 +100,7 @@ Future<List<Lecture>> getOverlappedClasses(
Future<List<Lecture>> getScheduleFromHtml(
http.Response response,
Session session,
String faculty,
) async {
final document = parse(response.body);
var semana = [0, 0, 0, 0, 0, 0];
Expand Down Expand Up @@ -148,7 +161,9 @@ Future<List<Lecture>> getScheduleFromHtml(
});

lecturesList
..addAll(await getOverlappedClasses(session, document))
..addAll(
await getOverlappedClasses(session, document, faculty),
)
..sort((a, b) => a.compare(b));

return lecturesList;
Expand Down
5 changes: 3 additions & 2 deletions uni/lib/model/entities/lecture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ class Lecture {
String classNumber,
int occurrId,
) {
final startTimeList = startTimeString.split(':');
final startTime = day.add(
Duration(
hours: int.parse(startTimeString.substring(0, 2)),
minutes: int.parse(startTimeString.substring(3, 5)),
hours: int.parse(startTimeList[0]),
minutes: int.parse(startTimeList[1]),
),
);
final endTime = startTime.add(Duration(minutes: 30 * blocks));
Expand Down

0 comments on commit 1ade4ec

Please sign in to comment.