Skip to content

Commit d266032

Browse files
authored
Support partially correct quizzes (#764)
* Persist submission score * Handle quiz partially correct state * Handle in discussions * Handle in submissions * Handle in write comment * Handle in solution * Clean up
1 parent 53c7794 commit d266032

30 files changed

+608
-76
lines changed

Stepic.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,7 @@
17761776
2C0B42BF234CD17C00B03EA1 /* CustomMenuBlockTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomMenuBlockTableViewCell.swift; sourceTree = "<group>"; };
17771777
2C0B42C0234CD17C00B03EA1 /* CustomMenuBlockTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CustomMenuBlockTableViewCell.xib; sourceTree = "<group>"; };
17781778
2C0C68FB247DBA6200B950F6 /* IAPReceiptValidationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAPReceiptValidationService.swift; sourceTree = "<group>"; };
1779+
2C0FBEB224E25A4D002CA67F /* Model_quiz_is_partially_correct_v61.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model_quiz_is_partially_correct_v61.xcdatamodel; sourceTree = "<group>"; };
17791780
2C101009239E7A1E00440651 /* Model_discount_policy.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model_discount_policy.xcdatamodel; sourceTree = "<group>"; };
17801781
2C10100A239EFAD700440651 /* DiscountingPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscountingPolicy.swift; sourceTree = "<group>"; };
17811782
2C104B672069064D0026FEB9 /* autocomplete_suggestions.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = autocomplete_suggestions.plist; sourceTree = "<group>"; };
@@ -9881,6 +9882,7 @@
98819882
08D1EF6E1BB5618700BE84E6 /* Model.xcdatamodeld */ = {
98829883
isa = XCVersionGroup;
98839884
children = (
9885+
2C0FBEB224E25A4D002CA67F /* Model_quiz_is_partially_correct_v61.xcdatamodel */,
98849886
2C78573B24DE1EC40042AD2C /* Model_is_vote_notifications_enabled_v60.xcdatamodel */,
98859887
2C619A7824CFF9DC007D3529 /* Model_social_profiles_v59.xcdatamodel */,
98869888
2C46417A24CFD23400FB6696 /* Model_lessons_demo_access_v58.xcdatamodel */,
@@ -9943,7 +9945,7 @@
99439945
0802AC531C7222B200C4F3E6 /* Model_v2.xcdatamodel */,
99449946
08D1EF6F1BB5618700BE84E6 /* Model.xcdatamodel */,
99459947
);
9946-
currentVersion = 2C78573B24DE1EC40042AD2C /* Model_is_vote_notifications_enabled_v60.xcdatamodel */;
9948+
currentVersion = 2C0FBEB224E25A4D002CA67F /* Model_quiz_is_partially_correct_v61.xcdatamodel */;
99479949
path = Model.xcdatamodeld;
99489950
sourceTree = "<group>";
99499951
versionGroupType = wrapper.xcdatamodel;

Stepic/Legacy/Model/AttemptsSumbissions/Submission.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class Submission: JSONSerializable {
1414

1515
var id: IdType = 0
1616
var statusString: String?
17+
var score: Float = 0
1718
var hint: String?
1819
var feedback: SubmissionFeedback?
1920
var time = Date()
@@ -36,6 +37,8 @@ final class Submission: JSONSerializable {
3637

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

40+
var isPartiallyCorrect: Bool { self.isCorrect && self.score < 1.0 }
41+
3942
var json: JSON {
4043
[
4144
JSONKey.attempt.rawValue: attemptID,
@@ -46,6 +49,7 @@ final class Submission: JSONSerializable {
4649
init(
4750
id: IdType,
4851
status: SubmissionStatus? = nil,
52+
score: Float? = 0,
4953
hint: String? = nil,
5054
feedback: SubmissionFeedback? = nil,
5155
time: Date = Date(),
@@ -56,6 +60,7 @@ final class Submission: JSONSerializable {
5660
) {
5761
self.id = id
5862
self.statusString = status?.rawValue
63+
self.score = score ?? 0
5964
self.hint = hint
6065
self.feedback = feedback
6166
self.time = time
@@ -85,6 +90,7 @@ final class Submission: JSONSerializable {
8590
self.init(
8691
id: submission?.id ?? 0,
8792
status: submission?.status,
93+
score: submission?.score,
8894
hint: submission?.hint,
8995
feedback: submission?.feedback,
9096
time: submission?.time ?? Date(),
@@ -97,6 +103,7 @@ final class Submission: JSONSerializable {
97103
func update(json: JSON) {
98104
self.id = json[JSONKey.id.rawValue].intValue
99105
self.statusString = json[JSONKey.status.rawValue].string
106+
self.score = json[JSONKey.score.rawValue].floatValue
100107
self.hint = json[JSONKey.hint.rawValue].string
101108
self.feedback = self.getFeedbackFromJSON(json[JSONKey.feedback.rawValue])
102109
self.attemptID = json[JSONKey.attempt.rawValue].intValue
@@ -151,6 +158,7 @@ final class Submission: JSONSerializable {
151158
enum JSONKey: String {
152159
case id
153160
case status
161+
case score
154162
case hint
155163
case attempt
156164
case reply
@@ -169,6 +177,7 @@ extension Submission: CustomDebugStringConvertible {
169177
"""
170178
Submission(id: \(id), \
171179
status: \(statusString ?? "nil"), \
180+
score: \(score), \
172181
hint: \(hint ?? "nil"), \
173182
feedback: \(feedback ??? "nil"), \
174183
reply: \(reply ??? "nil"), \

Stepic/Legacy/Model/Entities/Submission/SubmissionEntity+CoreDataProperties.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extension SubmissionEntity {
66
@NSManaged var managedAttemptID: NSNumber
77
@NSManaged var managedReply: Reply?
88
@NSManaged var managedLocal: NSNumber
9+
@NSManaged var managedScore: NSNumber
910

1011
@NSManaged var managedHint: String?
1112
@NSManaged var managedStatus: String?

Stepic/Legacy/Model/Entities/Submission/SubmissionEntity.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ final class SubmissionEntity: NSManagedObject {
4444
}
4545
}
4646

47+
var score: Float {
48+
get {
49+
self.managedScore.floatValue
50+
}
51+
set {
52+
self.managedScore = NSNumber(value: newValue)
53+
}
54+
}
55+
4756
var hint: String? {
4857
get {
4958
self.managedHint
@@ -111,6 +120,7 @@ extension SubmissionEntity {
111120
Submission(
112121
id: self.id,
113122
status: self.status,
123+
score: self.score,
114124
hint: self.hint,
115125
feedback: self.feedback,
116126
time: self.time,
@@ -134,6 +144,7 @@ extension SubmissionEntity {
134144
self.attemptID = submission.attemptID
135145
self.reply = submission.reply
136146
self.isLocal = submission.isLocal
147+
self.score = submission.score
137148
self.hint = submission.hint
138149
self.statusString = submission.statusString
139150
self.feedback = submission.feedback

Stepic/Legacy/Model/Model.xcdatamodeld/.xccurrentversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<plist version="1.0">
44
<dict>
55
<key>_XCCurrentVersionName</key>
6-
<string>Model_is_vote_notifications_enabled_v60.xcdatamodel</string>
6+
<string>Model_quiz_is_partially_correct_v61.xcdatamodel</string>
77
</dict>
88
</plist>

0 commit comments

Comments
 (0)