Skip to content

Commit

Permalink
update exams parser to get subject full name
Browse files Browse the repository at this point in the history
  • Loading branch information
thePeras committed Nov 4, 2024
1 parent d7ae8a6 commit 9f66705
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/uni_app/lib/controller/fetchers/exam_fetcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ExamFetcher implements SessionDependantFetcher {
) &&
courseExam.examType != 'EE' &&
courseExam.examType != 'EAE' &&
courseExam.subject == uc.abbreviation &&
courseExam.subjectAcronym == uc.abbreviation &&
uc.enrollmentIsValid() &&
!courseExam.hasEnded()) {
exams.add(courseExam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import 'package:uni/model/entities/exam.dart';
/// See the [Exam] class to see what data is stored in this database.
class AppExamsDatabase extends AppDatabase<List<Exam>> {
AppExamsDatabase()
: super('exams.db', [_createScript], onUpgrade: migrate, version: 7);
: super('exams.db', [_createScript], onUpgrade: migrate, version: 8);

static const _createScript = '''
CREATE TABLE exams(id TEXT, subject TEXT, start TEXT, finish TEXT,
CREATE TABLE exams(id TEXT, subjectAcronym TEXT, subject TEXT, start TEXT, finish TEXT,
rooms TEXT, examType TEXT, faculty TEXT, PRIMARY KEY (id,faculty)) ''';

/// Returns a list containing all of the exams stored in this database.
Expand All @@ -24,6 +24,7 @@ CREATE TABLE exams(id TEXT, subject TEXT, start TEXT, finish TEXT,
return List.generate(maps.length, (i) {
return Exam.secConstructor(
maps[i]['id'] as String,
maps[i]['subjectAcronym'] as String,
maps[i]['subject'] as String,
DateTime.parse(maps[i]['start'] as String),
DateTime.parse(maps[i]['finish'] as String),
Expand Down
5 changes: 4 additions & 1 deletion packages/uni_app/lib/controller/parsers/parser_exams.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ParserExams {
final dates = <String>[];
final examTypes = <String>[];
var rooms = <String>[];
String? subjectAcronym;
String? subject;
var id = '0';
var days = 0;
Expand All @@ -46,7 +47,8 @@ class ParserExams {
if (exams.querySelector('td.exame') != null) {
exams.querySelectorAll('td.exame').forEach((examsDay) {
if (examsDay.querySelector('a') != null) {
subject = examsDay.querySelector('a')!.text;
subjectAcronym = examsDay.querySelector('a')!.text;
subject = examsDay.querySelector('a')!.attributes['title'];
id = Uri.parse(examsDay.querySelector('a')!.attributes['href']!)
.queryParameters['p_exa_id']!;
}
Expand All @@ -73,6 +75,7 @@ class ParserExams {
id,
begin,
end,
subjectAcronym ?? '',
subject ?? '',
rooms,
examTypes[tableNum],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/uni_app/lib/generated/model/entities/exam.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/uni_app/lib/generated/model/entities/trip.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/uni_app/lib/model/entities/exam.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Exam {
this.id,
this.start,
this.finish,
this.subjectAcronym,
this.subject,
this.rooms,
this.examType,
Expand All @@ -31,6 +32,7 @@ class Exam {

Exam.secConstructor(
this.id,
this.subjectAcronym,
this.subject,
this.start,
this.finish,
Expand All @@ -42,6 +44,7 @@ class Exam {
final DateTime start;
final DateTime finish;
final String id;
final String subjectAcronym;
final String subject;
final List<String> rooms;
final String examType;
Expand Down Expand Up @@ -81,7 +84,7 @@ class Exam {

@override
String toString() {
return '''$id - $subject - ${start.year} - $month - ${start.day} - $startTime-$finishTime - $examType - $rooms - $weekDay''';
return '''$id - $subjectAcronym - ${start.year} - $month - ${start.day} - $startTime-$finishTime - $examType - $rooms - $weekDay''';
}

/// Prints the data in this exam to the [Logger] with an INFO level.
Expand All @@ -92,7 +95,7 @@ class Exam {
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Exam && id == other.id && subject == other.subject;
other is Exam && id == other.id && subjectAcronym == other.subjectAcronym;

@override
int get hashCode => id.hashCode;
Expand Down
5 changes: 2 additions & 3 deletions packages/uni_app/lib/view/academic_path/exam_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class _ExamsPageState extends State<ExamsPage> {
physics: const NeverScrollableScrollPhysics(),
itemCount: entry.value.length,
prototypeItem: const ExamCard(
//TODO(thePeras): Solve this at parser level
name: 'Computer Laboratory',
acronym: 'LCOM',
rooms: ['B315', 'B224', 'B207'],
Expand All @@ -73,8 +72,8 @@ class _ExamsPageState extends State<ExamsPage> {
itemBuilder: (context, index) {
final exam = entry.value[index];
return ExamCard(
name: 'Subject Name',
acronym: exam.subject,
name: exam.subject,
acronym: exam.subjectAcronym,
//TODO(thePeras): Solve this at parser level
rooms: exam.rooms.where((room) => room.isNotEmpty).toList(),
type: exam.examType,
Expand Down
6 changes: 3 additions & 3 deletions packages/uni_app/lib/view/exams/widgets/exam_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _ExamRowState extends State<ExamRow> {
@override
Widget build(BuildContext context) {
final roomsKey =
'${widget.exam.subject}-${widget.exam.rooms}-${widget.exam.startTime}-'
'${widget.exam.subjectAcronym}-${widget.exam.rooms}-${widget.exam.startTime}-'
'${widget.exam.finishTime}';
return Center(
child: Container(
Expand All @@ -63,7 +63,7 @@ class _ExamRowState extends State<ExamRow> {
: [],
),
ExamTitle(
subject: widget.exam.subject,
subject: widget.exam.subjectAcronym,
type: widget.exam.examType,
),
Row(
Expand Down Expand Up @@ -144,7 +144,7 @@ class _ExamRowState extends State<ExamRow> {

Event createExamEvent() {
return Event(
title: '${widget.exam.examType} ${widget.exam.subject}',
title: '${widget.exam.examType} ${widget.exam.subjectAcronym}',
location: widget.exam.rooms.toString(),
startDate: widget.exam.start,
endDate: widget.exam.finish,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RemainingExamsWidget extends StatelessWidget {
style: Theme.of(context).textTheme.bodyLarge,
),
ExamTitle(
subject: exam.subject,
subject: exam.subjectAcronym,
type: exam.examType,
reverseOrder: true,
),
Expand Down
15 changes: 13 additions & 2 deletions packages/uni_app/test/unit/view/Pages/exams_page_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ void main() async {
await initTestEnvironment();

group('ExamsPage', () {
const firstExamSubject = 'SOPE';
const firstExamSubjectAcronym = 'SOPE';
const firstExamSubject = 'Sistemas Operativos';
const firstExamDate = '2019-09-11';
const secondExamSubject = 'SDIS';
const secondExamSubjectAcronym = 'SDIS';
const secondExamSubject = 'Sistemas Distribuídos';
const secondExamDate = '2019-09-12';

testWidgets('When given an empty list', (tester) async {
Expand All @@ -37,6 +39,7 @@ void main() async {
'1230',
firstExamBegin,
firstExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand All @@ -63,6 +66,7 @@ void main() async {
'1231',
firstExamBegin,
firstExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand All @@ -74,6 +78,7 @@ void main() async {
'1232',
secondExamBegin,
secondExamEnd,
secondExamSubjectAcronym,
secondExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand Down Expand Up @@ -109,6 +114,7 @@ void main() async {
'1233',
firstExamBegin,
firstExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand All @@ -120,6 +126,7 @@ void main() async {
'1234',
secondExamBegin,
secondExamEnd,
secondExamSubjectAcronym,
secondExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand Down Expand Up @@ -154,6 +161,7 @@ void main() async {
'1235',
firstExamBegin,
firstExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
rooms,
'ER',
Expand All @@ -165,6 +173,7 @@ void main() async {
'1236',
secondExamBegin,
secondExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
rooms,
'ER',
Expand All @@ -176,6 +185,7 @@ void main() async {
'1237',
thirdExamBegin,
thirdExamEnd,
secondExamSubjectAcronym,
secondExamSubject,
rooms,
'ER',
Expand All @@ -187,6 +197,7 @@ void main() async {
'1238',
fourthExamBegin,
fourthExamEnd,
secondExamSubjectAcronym,
secondExamSubject,
rooms,
'ER',
Expand Down
Loading

0 comments on commit 9f66705

Please sign in to comment.