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

Fix an incorrect number of points for steps with discounting policy #768

Merged
merged 2 commits into from
Aug 14, 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 @@ -1743,6 +1743,7 @@
1F870E016B8AB15AD3033816 /* Pods-StepicTests.release release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StepicTests.release release.xcconfig"; path = "Target Support Files/Pods-StepicTests/Pods-StepicTests.release release.xcconfig"; sourceTree = "<group>"; };
27CF7A377B4C8BC247ECBD29 /* NewProfileUserActivityViewController.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = NewProfileUserActivityViewController.swift; sourceTree = "<group>"; };
2C00186524C71404006C5094 /* Model_new_profile_created_courses_v56.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model_new_profile_created_courses_v56.xcdatamodel; sourceTree = "<group>"; };
2C00396424E61B3000EBC7FF /* Model_assignment_progress_id_v64.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model_assignment_progress_id_v64.xcdatamodel; sourceTree = "<group>"; };
2C01BB67233CD92C00C8DCF0 /* Require.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Require.swift; sourceTree = "<group>"; };
2C01D3A922DDB7EA00C84CEE /* DefaultsContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultsContainer.swift; sourceTree = "<group>"; };
2C01D3AB22DDB98900C84CEE /* LaunchDefaultsContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LaunchDefaultsContainer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9892,6 +9893,7 @@
08D1EF6E1BB5618700BE84E6 /* Model.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
2C00396424E61B3000EBC7FF /* Model_assignment_progress_id_v64.xcdatamodel */,
2CDC9EFB24E516F800916BAE /* Model_course_preview_lesson_id_v63.xcdatamodel */,
2C67CA5124E3F9D0002634EB /* Model_profile_personal_preferences_v62.xcdatamodel */,
2C0FBEB224E25A4D002CA67F /* Model_quiz_is_partially_correct_v61.xcdatamodel */,
Expand Down Expand Up @@ -9957,7 +9959,7 @@
0802AC531C7222B200C4F3E6 /* Model_v2.xcdatamodel */,
08D1EF6F1BB5618700BE84E6 /* Model.xcdatamodel */,
);
currentVersion = 2CDC9EFB24E516F800916BAE /* Model_course_preview_lesson_id_v63.xcdatamodel */;
currentVersion = 2C00396424E61B3000EBC7FF /* Model_assignment_progress_id_v64.xcdatamodel */;
path = Model.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ extension Assignment {
@NSManaged var managedId: NSNumber?
@NSManaged var managedStepId: NSNumber?
@NSManaged var managedUnitId: NSNumber?
@NSManaged var managedProgressId: String?

@NSManaged var managedUnit: Unit?
@NSManaged var managedProgress: Progress?

static var oldEntity: NSEntityDescription {
NSEntityDescription.entity(forEntityName: "Assignment", in: CoreDataHelper.shared.context)!
Expand Down Expand Up @@ -55,4 +59,31 @@ extension Assignment {
managedUnitId?.intValue ?? -1
}
}

var progressId: String {
get {
self.managedProgressId ?? ""
}
set {
self.managedProgressId = newValue
}
}

var unit: Unit? {
get {
self.managedUnit
}
set {
self.managedUnit = newValue
}
}

var progress: Progress? {
get {
self.managedProgress
}
set {
self.managedProgress = newValue
}
}
}
18 changes: 13 additions & 5 deletions Stepic/Legacy/Model/Entities/Assignment/Assignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ final class Assignment: NSManagedObject, IDFetchable {

required convenience init(json: JSON) {
self.init()
initialize(json)
self.initialize(json)
}

func initialize(_ json: JSON) {
id = json["id"].intValue
stepId = json["step"].intValue
unitId = json["unit"].intValue
self.id = json[JSONKey.id.rawValue].intValue
self.unitId = json[JSONKey.unit.rawValue].intValue
self.stepId = json[JSONKey.step.rawValue].intValue
self.progressId = json[JSONKey.progress.rawValue].stringValue
}

func update(json: JSON) {
initialize(json)
self.initialize(json)
}

enum JSONKey: String {
case id
case unit
case step
case progress
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extension Progress {
@NSManaged var managedCost: NSNumber?
@NSManaged var managedLastViewed: NSNumber?

@NSManaged var managedAssignment: Assignment?
@NSManaged var managedStep: Step?
@NSManaged var managedSection: Section?
@NSManaged var managedUnit: Unit?
Expand Down Expand Up @@ -65,12 +66,12 @@ extension Progress {
}
}

var score: Int {
var score: Float {
get {
managedScore?.intValue ?? 0
self.managedScore?.floatValue ?? 0
}
set(value) {
managedScore = value as NSNumber?
set {
self.managedScore = NSNumber(value: newValue)
}
}

Expand Down Expand Up @@ -100,4 +101,49 @@ extension Progress {
managedCost = value as NSNumber?
}
}

var assignment: Assignment? {
get {
self.managedAssignment
}
set {
self.managedAssignment = newValue
}
}

var step: Step? {
get {
self.managedStep
}
set {
self.managedStep = newValue
}
}

var section: Section? {
get {
self.managedSection
}
set {
self.managedSection = newValue
}
}

var unit: Unit? {
get {
self.managedUnit
}
set {
self.managedUnit = newValue
}
}

var course: Course? {
get {
self.managedCourse
}
set {
self.managedCourse = newValue
}
}
}
52 changes: 31 additions & 21 deletions Stepic/Legacy/Model/Entities/Progress/Progress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,50 @@ import SwiftyJSON
final class Progress: NSManagedObject, JSONSerializable, IDFetchable {
typealias IdType = String

var json: JSON {
[
JSONKey.id.rawValue: self.id,
JSONKey.isPassed.rawValue: self.isPassed,
JSONKey.score.rawValue: self.score,
JSONKey.cost.rawValue: self.cost,
JSONKey.numberOfSteps.rawValue: self.numberOfSteps,
JSONKey.numberOfStepsPassed.rawValue: self.numberOfStepsPassed,
JSONKey.lastViewed.rawValue: self.lastViewed
]
}

required convenience init(json: JSON) {
self.init()
initialize(json)
self.initialize(json)
}

func initialize(_ json: JSON) {
id = json["id"].stringValue
isPassed = json["is_passed"].boolValue
score = json["score"].intValue
cost = json["cost"].intValue
numberOfSteps = json["n_steps"].intValue
numberOfStepsPassed = json["n_steps_passed"].intValue
lastViewed = json["last_viewed"].doubleValue
}

var json: JSON {
[
"id": id,
"is_passed": isPassed,
"score": score,
"cost": cost,
"n_steps": numberOfSteps,
"n_steps_passed": numberOfStepsPassed,
"last_viewed": lastViewed
]
self.id = json[JSONKey.id.rawValue].stringValue
self.isPassed = json[JSONKey.isPassed.rawValue].boolValue
self.score = json[JSONKey.score.rawValue].floatValue
self.cost = json[JSONKey.cost.rawValue].intValue
self.numberOfSteps = json[JSONKey.numberOfSteps.rawValue].intValue
self.numberOfStepsPassed = json[JSONKey.numberOfStepsPassed.rawValue].intValue
self.lastViewed = json[JSONKey.lastViewed.rawValue].doubleValue
}

func update(json: JSON) {
initialize(json)
self.initialize(json)
}

var percentPassed: Float {
self.numberOfSteps != 0
? Float(self.numberOfStepsPassed) / Float(self.numberOfSteps) * 100
: 100.0
}

enum JSONKey: String {
case id
case score
case cost
case isPassed = "is_passed"
case numberOfSteps = "n_steps"
case numberOfStepsPassed = "n_steps_passed"
case lastViewed = "last_viewed"
}
}
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_course_preview_lesson_id_v63.xcdatamodel</string>
<string>Model_assignment_progress_id_v64.xcdatamodel</string>
</dict>
</plist>
Loading