Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors due to closure on search by course id endpoints #214

Merged
merged 47 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8a6b888
fix semester parsing error
James-Lu-none Nov 29, 2023
b39aa41
fix class selection table index
James-Lu-none Nov 29, 2023
bb55357
remove deprecated student node parser
James-Lu-none Nov 30, 2023
38faae8
remove deprecated course extra info parser
James-Lu-none Nov 30, 2023
a33fe19
rewrite course extra info parser
James-Lu-none Nov 30, 2023
20c6604
fix course extra href
James-Lu-none Nov 30, 2023
df61768
remove deprecated course student info layout
James-Lu-none Nov 30, 2023
f8f221f
fix course id parsing in getTWCourseMainInfoList
James-Lu-none Nov 30, 2023
7af5b23
fix courseInfo display logic
James-Lu-none Nov 30, 2023
09ccd40
fix courseInfo display logic
James-Lu-none Nov 30, 2023
452c7ce
resolve redundant logic with string filter
James-Lu-none Nov 30, 2023
949f87d
fix unknown characters by changing encryption
James-Lu-none Nov 30, 2023
825744e
fix unable to fetch score
James-Lu-none Nov 30, 2023
5c2cafe
dart reformat
James-Lu-none Nov 30, 2023
b936eed
remove unused items
James-Lu-none Nov 30, 2023
665d7e9
remove unused package
James-Lu-none Nov 30, 2023
0c833c5
fix CourseExtraInfo category symbol
James-Lu-none Dec 1, 2023
afbaf29
Update lib/ui/pages/coursetable/course_table_page.dart
James-Lu-none Dec 3, 2023
5e28563
use runtime constants
James-Lu-none Dec 9, 2023
d4388a5
adding comments for semester parser
James-Lu-none Dec 9, 2023
8f5b5b4
providing meaningful names
James-Lu-none Dec 9, 2023
25353ae
fix un-expected indexing
James-Lu-none Dec 9, 2023
ab8c839
resolving unintuitive variable name
James-Lu-none Dec 9, 2023
8c9b6ab
resolving unintuitive variable name
James-Lu-none Dec 9, 2023
00c938b
unify object names related to studentSemesterDetail
James-Lu-none Dec 9, 2023
094f8c5
add RangeError exception throwing logic on studentSemesterDetails
James-Lu-none Dec 10, 2023
16339a9
add StateError exception throwing logic on CourseId not found
James-Lu-none Dec 10, 2023
c184eba
make studentId TextField read-only
James-Lu-none Dec 15, 2023
8777e3e
Merge branch 'master' into parser_on_couse_id_error
ntut-xuan Dec 18, 2023
3f1e6da
fix application crash on education survay unfinished
James-Lu-none Dec 18, 2023
ed3a835
add error throwing logic on education survay unfinished
James-Lu-none Dec 18, 2023
df1409c
Update lib/src/connector/course_connector.dart
James-Lu-none Dec 19, 2023
efab9e4
Update lib/src/connector/course_connector.dart
James-Lu-none Dec 19, 2023
051d9b5
Update lib/src/connector/course_connector.dart
James-Lu-none Dec 19, 2023
8b38e89
Update lib/src/connector/course_connector.dart
James-Lu-none Dec 19, 2023
48c30d4
change exception type
James-Lu-none Dec 19, 2023
cb7291d
set default course category
James-Lu-none Dec 20, 2023
049d7db
filters out credit doubles
James-Lu-none Dec 20, 2023
38daa22
Merge remote-tracking branch 'origin/parser_on_couse_id_error' into p…
ntut-xuan Dec 20, 2023
639a33c
Fix: Score fetch error caused by semester survey
ntut-xuan Dec 20, 2023
c47aa8e
simplify default course category logic
James-Lu-none Dec 20, 2023
94f6d31
add error rethow on task logic
James-Lu-none Dec 21, 2023
d896162
add error rethow on task logic
James-Lu-none Dec 21, 2023
06be3e5
fix: use `i10n` messages upon `FormatException` of `getScoreRankList()`
rileychh Dec 21, 2023
1a231bd
chore: remove TODOs
rileychh Dec 21, 2023
2b34e6e
Merge branch 'master' into parser_on_couse_id_error
rileychh Dec 21, 2023
d17c243
style: run `dart format`
rileychh Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 47 additions & 31 deletions lib/src/connector/course_connector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CourseConnector {
ConnectorParameter parameter;
Document tagNode;
Element node;
List<Element> courseNodes, nodes, classmateNodes;
List<Element> courseNodes, nodes, classExtraInfoNodes;
Map<String, String> data = {
"code": courseId,
"format": "-1",
Expand All @@ -101,38 +101,57 @@ class CourseConnector {
//取得學期資料
nodes = courseNodes[0].getElementsByTagName("td");
SemesterJson semester = SemesterJson();
semester.year = nodes[1].text;
semester.semester = nodes[2].text;

// the title String of the first course table was stored seperately in its <td> element,
James-Lu-none marked this conversation as resolved.
Show resolved Hide resolved
// but it currently stores all the information in a row,
// (ex: 學號:110310144  姓名:xxx  班級:電機三甲    112 學年度 第 1 學期 上課時間表)
James-Lu-none marked this conversation as resolved.
Show resolved Hide resolved
// so the RegExp is used to filter out only the number parts
final titleString = nodes[0].text;
final RegExp studentSemesterDetailFilter = RegExp(r'\b\d+\b');
final Iterable<RegExpMatch> studentSemesterDetailMatches = studentSemesterDetailFilter.allMatches(titleString);
// "studentSemesterDetails" should consist of three numerical values
// ex: [110310144, 112, 1]
final List<String> studentSemesterDetails = studentSemesterDetailMatches.map((match) => match.group(0)).toList();
if (studentSemesterDetails.isEmpty) {
throw RangeError("[TAT] course_connector.dart: studentSemesterDetails list is empty");
}
if (studentSemesterDetails.length < 3) {
throw RangeError("[TAT] course_connector.dart: studentSemesterDetails list has range less than 3");
}
semester.year = studentSemesterDetails[1];
semester.semester = studentSemesterDetails[2];

courseExtraInfo.courseSemester = semester;

CourseExtraJson courseExtra = CourseExtraJson();

courseExtra.name = nodes[3].getElementsByTagName("a")[0].text;
if (nodes[3].getElementsByTagName("a")[0].attributes.containsKey("href")) {
courseExtra.href = _courseCNHost + nodes[3].getElementsByTagName("a")[0].attributes["href"];
nodes = courseNodes[1].getElementsByTagName("tr");
final List<String> courseIds = nodes.skip(2).map((node) => node.getElementsByTagName("td")[0].text).toList();
final courseIdPosition = courseIds.indexWhere((element) => element.contains(courseId));
if (courseIdPosition == -1) {
throw StateError('[TAT] course_connector.dart: CourseId not found: $courseId');
} else {
node = nodes[courseIdPosition + 2];
}
courseExtra.category = nodes[7].text; // 取得類別
courseExtra.openClass = nodes[9].text;
courseExtra.selectNumber = nodes[11].text;
courseExtra.withdrawNumber = nodes[12].text;
courseExtra.id = courseId;
classExtraInfoNodes = node.getElementsByTagName("td");
courseExtra.id = strQ2B(classExtraInfoNodes[0].text).replaceAll(RegExp(r"[\n| ]"), "");
James-Lu-none marked this conversation as resolved.
Show resolved Hide resolved
courseExtra.name = classExtraInfoNodes[1].getElementsByTagName("a")[0].text;
courseExtra.openClass = classExtraInfoNodes[7].getElementsByTagName("a")[0].text;

courseExtraInfo.course = courseExtra;

nodes = courseNodes[2].getElementsByTagName("tr");
for (int i = 1; i < nodes.length; i++) {
node = nodes[i];
classmateNodes = node.getElementsByTagName("td");
ClassmateJson classmate = ClassmateJson();
classmate.className = classmateNodes[0].text;
classmate.studentId = classmateNodes[1].getElementsByTagName("a")[0].text;
classmate.href = _courseCNHost + classmateNodes[1].getElementsByTagName("a")[0].attributes["href"];
classmate.studentName = classmateNodes[2].text;
classmate.studentEnglishName = classmateNodes[3].text;
classmate.isSelect = !classmateNodes[4].text.contains("撤選");
courseExtraInfo.classmate.add(classmate);
if (classExtraInfoNodes[18].getElementsByTagName("a")[0].attributes.containsKey("href")) {
courseExtra.href = _courseCNHost + classExtraInfoNodes[18].getElementsByTagName("a")[0].attributes["href"];
}

parameter = ConnectorParameter(courseExtra.href);
result = await Connector.getDataByPost(parameter);
tagNode = parse(result);
nodes = tagNode.getElementsByTagName("tr");
courseExtra.category = nodes[1].getElementsByTagName("td")[6].text;

courseExtra.selectNumber = "s?";
courseExtra.withdrawNumber = "w?";

courseExtraInfo.course = courseExtra;
return courseExtraInfo;
} catch (e, stack) {
Log.eWithStack(e.toString(), stack);
Expand Down Expand Up @@ -202,7 +221,7 @@ class CourseConnector {
};
parameter = ConnectorParameter(_postCourseENUrl);
parameter.data = data;
parameter.charsetName = 'big5';
parameter.charsetName = 'utf-8';
Response response = await Connector.getDataByPostResponse(parameter);
tagNode = parse(response.toString());
nodes = tagNode.getElementsByTagName("table");
Expand Down Expand Up @@ -317,11 +336,8 @@ class CourseConnector {
continue;
}
//取得課號
nodes = nodesOne[0].getElementsByTagName("a"); //確定是否有課號
if (nodes.isNotEmpty) {
courseMain.id = nodes[0].text;
courseMain.href = _courseCNHost + nodes[0].attributes["href"];
}
courseMain.id = strQ2B(nodesOne[0].text).replaceAll(RegExp(r"[\n| ]"), "");
James-Lu-none marked this conversation as resolved.
Show resolved Hide resolved

//取的課程名稱/課程連結
nodes = nodesOne[1].getElementsByTagName("a"); //確定是否有連結
if (nodes.isNotEmpty) {
Expand Down
7 changes: 6 additions & 1 deletion lib/src/connector/score_connector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ class ScoreConnector {
parameter = ConnectorParameter(_scoreAllScoreUrl);
parameter.data = data;
result = await Connector.getDataByGet(parameter);
final List<String> evalQuestionnaireCheckTexts = ['教學評量', 'Course Evaluation Questionnaire'];
if (evalQuestionnaireCheckTexts.any((text) => result.contains(text))) {
//TODO: add notification to notify users to complete the Course Evaluation Questionnaire
throw RangeError("[TAT] score_connector.dart: evalQuestionnaireCheckTexts was found in request result");
rileychh marked this conversation as resolved.
Show resolved Hide resolved
}

tagNode = parse(result);
final h3Nodes = tagNode.getElementsByTagName("h3");

//依照學期取得課程資料
for (final h3Node in h3Nodes) {
final siblingOfH3 = h3Node.nextElementSibling;
Expand Down
63 changes: 1 addition & 62 deletions lib/ui/pages/coursedetail/screen/course_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:async';

import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/src/model/course/course_class_json.dart';
import 'package:flutter_app/src/model/course/course_main_extra_json.dart';
import 'package:flutter_app/src/model/coursetable/course_table_json.dart';
import 'package:flutter_app/src/r.dart';
Expand Down Expand Up @@ -87,23 +86,10 @@ class _CourseInfoPageState extends State<CourseInfoPage> with AutomaticKeepAlive
courseMainInfo.getClassroomHrefList(),
));

courseData
.add(_buildCourseInfo(sprintf("%s: %s", [R.current.numberOfStudent, courseExtraInfo.course.selectNumber])));
courseData
.add(_buildCourseInfo(sprintf("%s: %s", [R.current.numberOfWithdraw, courseExtraInfo.course.withdrawNumber])));

listItem.removeRange(0, listItem.length);
listItem.add(_buildInfoTitle(R.current.courseData));
listItem.addAll(courseData);
listItem.add(_buildInfoTitle(R.current.studentList));
for (int i = 0; i < courseExtraInfo.classmate.length; i++) {
listItem.add(
Padding(
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 0),
child: _buildClassmateInfo(i, widget.courseInfo.extra.classmate[i]),
),
);
}

isLoading = false;
setState(() {});
}
Expand Down Expand Up @@ -279,53 +265,6 @@ class _CourseInfoPageState extends State<CourseInfoPage> with AutomaticKeepAlive
);
}

Widget _buildClassmateInfo(int index, ClassmateJson classmate) {
final color = (index % 2 == 1)
? Theme.of(context).colorScheme.surface
: Theme.of(context).colorScheme.surfaceVariant.withAlpha(widget.courseInfoWithAlpha);
return Container(
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Text(
classmate.className,
textAlign: TextAlign.center,
),
),
const SizedBox(width: 4),
Expanded(
child: Text(
classmate.studentId,
textAlign: TextAlign.center,
),
),
const SizedBox(width: 4),
Expanded(
child: Text(
classmate.getName(),
textAlign: TextAlign.center,
),
),
const SizedBox(width: 4),
FittedBox(
child: ElevatedButton(
child: Text(R.current.search),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop(classmate.studentId);
},
),
),
],
),
);
}

@override
bool get wantKeepAlive => true;
}
1 change: 1 addition & 0 deletions lib/ui/pages/coursetable/course_table_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ class _CourseTablePageState extends State<CourseTablePage> {
children: <Widget>[
Expanded(
child: TextField(
readOnly: true,
scrollPadding: const EdgeInsets.all(0),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
Expand Down
11 changes: 5 additions & 6 deletions lib/ui/pages/score/score_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,10 @@ class _ScoreViewerPageState extends State<ScoreViewerPage> with TickerProviderSt
appBar: AppBar(
title: Text(R.current.searchScore),
actions: [
if (courseScoreList.isNotEmpty)
ScorePageAppBarActionButtons(
onRefreshPressed: _addScoreRankTask,
onCalculateCreditPressed: _addSearchCourseTypeTask,
),
ScorePageAppBarActionButtons(
onRefreshPressed: _addScoreRankTask,
onCalculateCreditPressed: _addSearchCourseTypeTask,
),
],
bottom: TabBar(
controller: _tabController,
Expand All @@ -263,7 +262,7 @@ class _ScoreViewerPageState extends State<ScoreViewerPage> with TickerProviderSt
),
),
body: SingleChildScrollView(
child: _isLoading ? const SizedBox.shrink() : tabChildList[_currentTabIndex],
child: (_isLoading || tabChildList.isEmpty) ? const SizedBox.shrink() : tabChildList[_currentTabIndex],
),
),
);
Expand Down
Loading