Skip to content

Commit

Permalink
修复特殊课表的解析错误
Browse files Browse the repository at this point in the history
  • Loading branch information
nano71 committed Nov 21, 2024
1 parent dd78811 commit a2f0a6b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 36 deletions.
2 changes: 1 addition & 1 deletion android/local.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sdk.dir=C:\\sdk\\android-sdk
flutter.sdk=C:\\sdk\\flutter
flutter.buildMode=release
flutter.buildMode=debug
flutter.versionName=1.6.241118
flutter.versionCode=71
81 changes: 47 additions & 34 deletions lib/common/get.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Future<dynamic> getSchedule() async {
String weekCN = innerHtmlTrimReplace(tableCells(tableRows(i)[j])[1]);
String courseVenue = teachLocation(innerHtmlTrim(tableCells(tableRows(i)[j])[3]));
bool specialWeek = true;

List<String> initList(bool isEven) {
List<String> list = [];
for (int i = int.parse(weekList.first); i <= int.parse(weekList.last); i++) {
Expand All @@ -167,28 +168,50 @@ Future<dynamic> getSchedule() async {
return list;
}

void step3() {
List<String> cache = weekInterval.split(",");
for (int i = 0; i < cache.length; i++) {
if (cache[i].split("-").length == 1) {
weekList.add(cache[i]);
continue;
}
for (int j = int.parse(cache[i].split("-")[0]); j <= int.parse(cache[i].split("-")[1]); j++) {
weekList.add(j.toString());
}
}
}

void step4(bool isEven) {
String key = isEven ? "双" : "单";
if (weekInterval.indexOf(",") != -1) {
List<String> cache = weekInterval.split(",");
if (cache[0].indexOf(key) != -1) {
weekList = cache[0].replaceAll(key, "").split("-");
weekInterval = cache[1];
} else {
weekList = cache[1].replaceAll(key, "").split("-");
weekInterval = cache[0];
}
weekList = initList(isEven);

step3();
weekList.sort((a, b) => int.parse(a) - int.parse(b));
} else {
weekInterval = weekInterval.replaceAll(key, "");
weekList = weekInterval.split("-");
weekList = initList(isEven);
}
}

//单周
if (weekInterval.indexOf("单") != -1) {
weekInterval = weekInterval.replaceAll("单", "");
weekList = weekInterval.split("-");
weekList = initList(false);
step4(false);
//双周
} else if (weekInterval.indexOf("双") != -1) {
weekInterval = weekInterval.replaceAll("双", "");
weekList = weekInterval.split("-");
weekList = initList(true);
step4(true);
} else if (weekInterval.indexOf(",") != -1) {
if (weekInterval.indexOf("-") != -1) {
List<String> cache = weekInterval.split(",");
for (int i = 0; i < cache.length; i++) {
if (cache[i].split("-").length == 1) {
weekList.add(cache[i]);
continue;
}
for (int j = int.parse(cache[i].split("-")[0]); j <= int.parse(cache[i].split("-")[1]); j++) {
weekList.add(j.toString());
}
}
step3();
} else {
weekInterval = weekInterval.replaceAll(",", "-");
weekList = weekInterval.split("-");
Expand All @@ -198,12 +221,14 @@ Future<dynamic> getSchedule() async {
specialWeek = false;
weekList = weekInterval.split("-");
}

if (lessonList.length > 1 && weekCN != "&nbsp;")
for (int lesson = int.parse(lessonList[0]); lesson <= int.parse(lessonList[1]); lesson++) {
if (weekList.length > 1 && specialWeek) {
weekList.forEach((teachWeek) {
// 普通模式
if ((weekList.length > 1 && specialWeek) || weekList.length >= 3) {
for (String teachWeek in weekList) {
// print(teachWeek);
_schedule[teachWeek.toString()]?[week(i, j)]?[lesson.toString()] = [
_schedule[teachWeek]?[week(i, j)]?[lesson.toString()] = [
//课程名
course(i),
//老师名字
Expand All @@ -213,7 +238,8 @@ Future<dynamic> getSchedule() async {
//备注
remark(i, j)
];
});
}
// 区间模式
} else if (weekList.length == 2) {
for (int teachWeek = int.parse(weekList[0]); teachWeek <= int.parse(weekList[1]); teachWeek++) {
_schedule[teachWeek.toString()]?[week(i, j)]?[lesson.toString()] = [
Expand All @@ -227,20 +253,7 @@ Future<dynamic> getSchedule() async {
remark(i, j)
];
}
} else if (weekList.length >= 3) {
for (String teachWeek in weekList) {
// print(teachWeek);
_schedule[teachWeek]?[week(i, j)]?[lesson.toString()] = [
//课程名
course(i),
//老师名字
teacher(i),
//上课地点
courseVenue,
//备注
remark(i, j)
];
}
// 一周模式
} else {
_schedule[weekInterval]?[week(i, j)]?[lesson.toString()] = [
//课程名
Expand Down
8 changes: 7 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: "https://pub.flutter-io.cn" # Remove this line if you wish to publis
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.6.241114+70
version: 1.6.241121+72

environment:
sdk: ">=2.14.0 <4.0.0"
Expand Down Expand Up @@ -44,6 +44,7 @@ dependencies:
sentry_flutter: ^8.10.1
share_plus: ^10.1.2
dev_dependencies:
sentry_dart_plugin: ^2.1.0
flutter_test:
sdk: flutter

Expand Down Expand Up @@ -101,3 +102,8 @@ development—environment:
kotlin: 2.0.0
gradle: 8.7.0

sentry:
project: glut-assistant-n
org: lightningdevelopmentteam
auth_token: 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
upload_sources: true

0 comments on commit a2f0a6b

Please sign in to comment.