-
Notifications
You must be signed in to change notification settings - Fork 0
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
IGC: Grade Calculator (v1) #144
Conversation
@azooz2003-bit this is ready to review. |
@azooz2003-bit @iwatger if possible, please confirm whether the values you get from the grade calc is the same as what you see on canvas |
static func getAssignmentsForCourse(courseID: String) async -> [Assignment] { | ||
await CourseAssignmentManager.fetchAssignments(courseID: courseID) | ||
} | ||
|
||
private static func fetchAssignments(courseID: String) async -> [Assignment] { | ||
guard let (data, _) = try? await CanvasService.shared.fetchResponse(CanvasRequest.getAssignments(courseId: courseID)) else { | ||
print("Failed to fetch assignments.") | ||
return [] | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the getAssignmentsForCourse redundant? Other than the name making more sense
|
||
/* MARK: Request Caching (Optional Implementation) | ||
var requestId: Int? { courseId.asInt } | ||
var requestIdKey: ParentKeyPath<AssignmentGroup, Int?> { .createReadable(\.courseId) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should note now, use createWritable
when the property (courseId
in this case) doesn't come with fetch result. This allows the service layer to set that property before returning it. e.g. Since courseId
isn't in assignment group by default, you probs wanna make it createWritable
.
guard let courseID = courseID, let (data, _) = try? await CanvasService.shared.fetchResponse(CanvasRequest.getAssignments(courseId: courseID)) else { | ||
print("Failed to fetch assignments.") | ||
func fetchAssignmentGroups() async { | ||
guard let courseID = courseID, let (data, _) = try? await CanvasService.shared.fetchResponse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use fetch
instead of fetchResponse
. Handles the decoding and returns an array of assignment groups.
|
||
import Foundation | ||
|
||
struct CourseGradeCalculator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var totalPossible: Double = 0 | ||
let earned: Double = assignmentGroups.reduce(0) { total, group in | ||
total + group.assignments.reduce(0) { total, assignment in | ||
guard let score = assignment.score, let pointsPossible = assignment.pointsPossible else { | ||
return total | ||
} | ||
|
||
totalPossible += pointsPossible | ||
|
||
return Double(total + score) | ||
} | ||
} | ||
|
||
return earned / totalPossible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not weighting per assignment right? Wouldn't it be more correct to take each assignment as a percentage instead of total points. (quiz out of 8 has same weight as quiz out of 6)
private func setEnrollment(enrollments: [Enrollment], currentUserID: Int) { | ||
guard enrollments.count == 1, | ||
let first = enrollments.first, | ||
first.userID == currentUserID else { | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS, I think a user may have multiple enrollments if they have multiple roles (i.e. both TA and Student), so we should remove that count == 1 check and find the enrollment with a student
role.
Needs more thinking, closing for now. |
Known Issues
EDIT: It seems like we cannot fetch the official "grade" value for completed courses, but assignment grades still work.