Skip to content

Commit

Permalink
Merge pull request #336 from HydrogenC/main
Browse files Browse the repository at this point in the history
Fix inconsistent results caused by course review editor
  • Loading branch information
w568w committed Mar 13, 2024
2 parents 0132085 + 5cb3d14 commit c00b746
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
18 changes: 5 additions & 13 deletions lib/model/danke/course_grade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,20 @@ class CourseGrade with ChangeNotifier {
notifyListeners();
}

// Indicates the format of the grade
bool isClientFormat = false;

CourseGrade(this._overall, this._content, this._workload, this._assessment,
{this.isClientFormat = false});
CourseGrade(this._overall, this._content, this._workload, this._assessment);

CourseGrade clone() =>
CourseGrade(_overall, _content, _workload, _assessment);

CourseGrade convertFormat() {
// Reverse the content and workload score
return CourseGrade(_overall, 6 - _content!, 6 - _workload!, _assessment,
isClientFormat: !isClientFormat);
}

factory CourseGrade.fromJson(Map<String, dynamic> json) {
final obj = CourseGradeObject.fromJson(json);
return CourseGrade(obj.overall, obj.content, obj.workload, obj.assessment);
return CourseGrade(
obj.overall, 6 - obj.content!, 6 - obj.workload!, obj.assessment);
}

Map<String, dynamic> toJson() {
final raw = isClientFormat ? convertFormat() : this;
final raw =
CourseGrade(_overall, 6 - _content!, 6 - _workload!, _assessment);
return CourseGradeObject(
raw.overall, raw.content, raw.workload, raw.assessment)
.toJson();
Expand Down
5 changes: 0 additions & 5 deletions lib/page/danke/course_group_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ class CourseGroupDetailState extends State<CourseGroupDetail> {
// Attach information about its parent course for each review
rev.linkCourse(elem.getSummary());

// Convert grades to client format
if (!rev.rank!.isClientFormat) {
rev.rank = rev.rank?.convertFormat();
}

// calculate average score
totalScore += rev.rank!.overall!;
}
Expand Down
10 changes: 2 additions & 8 deletions lib/page/danke/course_review_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final PostInterceptor _kStopWordInterceptor = (context, text) async {

class CourseReviewEditorText with ChangeNotifier {
int _courseId = -1;
CourseGrade _grade = CourseGrade(0, 0, 0, 0, isClientFormat: true);
CourseGrade _grade = CourseGrade(0, 0, 0, 0);
String? _content, _title;

int get courseId => _courseId;
Expand Down Expand Up @@ -129,12 +129,6 @@ class CourseReviewEditorText with ChangeNotifier {
_inRange(_grade.assessment ?? 0);
}

// The server and client handles the content and workload scores reversely, the function does the convertion
CourseReviewEditorText convertFormat() {
return CourseReviewEditorText(
_content, _title, _courseId, _grade.convertFormat());
}

static bool _inRange(int val, [int min = 1, int max = 5]) {
return val >= min && val <= max;
}
Expand Down Expand Up @@ -798,7 +792,7 @@ class CourseReviewEditorPageState extends State<CourseReviewEditorPage> {
if (!review.isValid()) return;

if ((await _interceptor?.call(context, review)) ?? true) {
Navigator.pop<CourseReviewEditorText>(context, review.convertFormat());
Navigator.pop<CourseReviewEditorText>(context, review);
}
}
}

0 comments on commit c00b746

Please sign in to comment.