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

Support partially correct quizzes #764

Merged
merged 7 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion Stepic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@
2C0B42BF234CD17C00B03EA1 /* CustomMenuBlockTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomMenuBlockTableViewCell.swift; sourceTree = "<group>"; };
2C0B42C0234CD17C00B03EA1 /* CustomMenuBlockTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CustomMenuBlockTableViewCell.xib; sourceTree = "<group>"; };
2C0C68FB247DBA6200B950F6 /* IAPReceiptValidationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAPReceiptValidationService.swift; sourceTree = "<group>"; };
2C0FBEB224E25A4D002CA67F /* Model_quiz_is_partially_correct_v61.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model_quiz_is_partially_correct_v61.xcdatamodel; sourceTree = "<group>"; };
2C101009239E7A1E00440651 /* Model_discount_policy.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model_discount_policy.xcdatamodel; sourceTree = "<group>"; };
2C10100A239EFAD700440651 /* DiscountingPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscountingPolicy.swift; sourceTree = "<group>"; };
2C104B672069064D0026FEB9 /* autocomplete_suggestions.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = autocomplete_suggestions.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9881,6 +9882,7 @@
08D1EF6E1BB5618700BE84E6 /* Model.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
2C0FBEB224E25A4D002CA67F /* Model_quiz_is_partially_correct_v61.xcdatamodel */,
2C78573B24DE1EC40042AD2C /* Model_is_vote_notifications_enabled_v60.xcdatamodel */,
2C619A7824CFF9DC007D3529 /* Model_social_profiles_v59.xcdatamodel */,
2C46417A24CFD23400FB6696 /* Model_lessons_demo_access_v58.xcdatamodel */,
Expand Down Expand Up @@ -9943,7 +9945,7 @@
0802AC531C7222B200C4F3E6 /* Model_v2.xcdatamodel */,
08D1EF6F1BB5618700BE84E6 /* Model.xcdatamodel */,
);
currentVersion = 2C78573B24DE1EC40042AD2C /* Model_is_vote_notifications_enabled_v60.xcdatamodel */;
currentVersion = 2C0FBEB224E25A4D002CA67F /* Model_quiz_is_partially_correct_v61.xcdatamodel */;
path = Model.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down
9 changes: 9 additions & 0 deletions Stepic/Legacy/Model/AttemptsSumbissions/Submission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class Submission: JSONSerializable {

var id: IdType = 0
var statusString: String?
var score: Float = 0
var hint: String?
var feedback: SubmissionFeedback?
var time = Date()
Expand All @@ -36,6 +37,8 @@ final class Submission: JSONSerializable {

var isCorrect: Bool { self.status == .correct }

var isPartiallyCorrect: Bool { self.isCorrect && self.score < 1.0 }

var json: JSON {
[
JSONKey.attempt.rawValue: attemptID,
Expand All @@ -46,6 +49,7 @@ final class Submission: JSONSerializable {
init(
id: IdType,
status: SubmissionStatus? = nil,
score: Float? = 0,
hint: String? = nil,
feedback: SubmissionFeedback? = nil,
time: Date = Date(),
Expand All @@ -56,6 +60,7 @@ final class Submission: JSONSerializable {
) {
self.id = id
self.statusString = status?.rawValue
self.score = score ?? 0
self.hint = hint
self.feedback = feedback
self.time = time
Expand Down Expand Up @@ -85,6 +90,7 @@ final class Submission: JSONSerializable {
self.init(
id: submission?.id ?? 0,
status: submission?.status,
score: submission?.score,
hint: submission?.hint,
feedback: submission?.feedback,
time: submission?.time ?? Date(),
Expand All @@ -97,6 +103,7 @@ final class Submission: JSONSerializable {
func update(json: JSON) {
self.id = json[JSONKey.id.rawValue].intValue
self.statusString = json[JSONKey.status.rawValue].string
self.score = json[JSONKey.score.rawValue].floatValue
self.hint = json[JSONKey.hint.rawValue].string
self.feedback = self.getFeedbackFromJSON(json[JSONKey.feedback.rawValue])
self.attemptID = json[JSONKey.attempt.rawValue].intValue
Expand Down Expand Up @@ -151,6 +158,7 @@ final class Submission: JSONSerializable {
enum JSONKey: String {
case id
case status
case score
case hint
case attempt
case reply
Expand All @@ -169,6 +177,7 @@ extension Submission: CustomDebugStringConvertible {
"""
Submission(id: \(id), \
status: \(statusString ?? "nil"), \
score: \(score), \
hint: \(hint ?? "nil"), \
feedback: \(feedback ??? "nil"), \
reply: \(reply ??? "nil"), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extension SubmissionEntity {
@NSManaged var managedAttemptID: NSNumber
@NSManaged var managedReply: Reply?
@NSManaged var managedLocal: NSNumber
@NSManaged var managedScore: NSNumber

@NSManaged var managedHint: String?
@NSManaged var managedStatus: String?
Expand Down
11 changes: 11 additions & 0 deletions Stepic/Legacy/Model/Entities/Submission/SubmissionEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ final class SubmissionEntity: NSManagedObject {
}
}

var score: Float {
get {
self.managedScore.floatValue
}
set {
self.managedScore = NSNumber(value: newValue)
}
}

var hint: String? {
get {
self.managedHint
Expand Down Expand Up @@ -111,6 +120,7 @@ extension SubmissionEntity {
Submission(
id: self.id,
status: self.status,
score: self.score,
hint: self.hint,
feedback: self.feedback,
time: self.time,
Expand All @@ -134,6 +144,7 @@ extension SubmissionEntity {
self.attemptID = submission.attemptID
self.reply = submission.reply
self.isLocal = submission.isLocal
self.score = submission.score
self.hint = submission.hint
self.statusString = submission.statusString
self.feedback = submission.feedback
Expand Down
2 changes: 1 addition & 1 deletion Stepic/Legacy/Model/Model.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Model_is_vote_notifications_enabled_v60.xcdatamodel</string>
<string>Model_quiz_is_partially_correct_v61.xcdatamodel</string>
</dict>
</plist>
Loading