From c39b0bf3da583fd1c3c9010b4569eb81c961b89b Mon Sep 17 00:00:00 2001 From: Theo Spears Date: Sat, 20 Apr 2024 14:16:33 -0700 Subject: [PATCH 1/2] Support sorting by urgency --- BeeKit/Goal.swift | 2 ++ BeeKit/Util/Constants.swift | 4 ++-- BeeSwift/Gallery/GalleryViewController.swift | 22 ++------------------ 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/BeeKit/Goal.swift b/BeeKit/Goal.swift index 579956876..1cdc18e46 100644 --- a/BeeKit/Goal.swift +++ b/BeeKit/Goal.swift @@ -51,6 +51,7 @@ public class Goal { public var queued: Bool? public var todayta: Bool = false public var hhmmformat: Bool = false + public var urgencykey: String = "" public var recent_data: [ExistingDataPoint]? // These are obtained from mathishard @@ -112,6 +113,7 @@ public class Goal { self.healthKitMetric = json["healthkitmetric"].string self.todayta = json["todayta"].bool! self.hhmmformat = json["hhmmformat"].bool! + self.urgencykey = json["urgencykey"].string! self.recent_data = (try? ExistingDataPoint.fromJSONArray(array: json["recent_data"].arrayValue).reversed()) ?? [] diff --git a/BeeKit/Util/Constants.swift b/BeeKit/Util/Constants.swift index 2df44265c..25e7b7b29 100644 --- a/BeeKit/Util/Constants.swift +++ b/BeeKit/Util/Constants.swift @@ -22,9 +22,9 @@ public struct Constants { public static let recentDataGoalSortString = "Recent Data" public static let nameGoalSortString = "Name" public static let pledgeGoalSortString = "Pledge" - public static let deadlineGoalSortString = "Deadline" + public static let urgencyGoalSortString = "Urgency" public static let healthKitUpdateDictionaryKey = "healthKitUpdateDictionary" - public static let goalSortOptions = [Constants.nameGoalSortString, Constants.deadlineGoalSortString, Constants.pledgeGoalSortString, Constants.recentDataGoalSortString] + public static let goalSortOptions = [Constants.urgencyGoalSortString, Constants.nameGoalSortString, Constants.pledgeGoalSortString, Constants.recentDataGoalSortString] public static let appGroupIdentifier = "group.beeminder.beeminder" } diff --git a/BeeSwift/Gallery/GalleryViewController.swift b/BeeSwift/Gallery/GalleryViewController.swift index 79034ee44..083e3206b 100644 --- a/BeeSwift/Gallery/GalleryViewController.swift +++ b/BeeSwift/Gallery/GalleryViewController.swift @@ -428,26 +428,8 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou } } - // Default sort ordering - - // Primary Criteria: Sooner deadline/goal end first - let goal1Date = min(goal1.losedate.intValue, goal1.derived_goaldate.intValue) - let goal2Date = min(goal2.losedate.intValue, goal2.derived_goaldate.intValue) - if goal1Date < goal2Date { - return true - } else if goal2Date < goal1Date { - return false - } - - // Secondary Criteria: Larger pledge amount first - if goal2.pledge.intValue < goal1.pledge.intValue { - return true - } else if goal1.pledge.intValue < goal2.pledge.intValue { - return false - } - - // Tertiary Criteria: Lexographically earlier slug first - return goal1.slug < goal2.slug + // urgencykey is guaranteed to result in goals sorting into the canonical order + return goal1.urgencykey < goal2.urgencykey }) self.updateFilteredGoals(searchText: self.searchBar.text ?? "") } From 6ab39f01d674cf4ae63dee2b58922172037a3daa Mon Sep 17 00:00:00 2001 From: Theo Spears Date: Sat, 20 Apr 2024 19:12:25 -0700 Subject: [PATCH 2/2] Update unit tests --- BeeSwiftTests/GoalTests.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BeeSwiftTests/GoalTests.swift b/BeeSwiftTests/GoalTests.swift index a2d080778..befc55fd4 100644 --- a/BeeSwiftTests/GoalTests.swift +++ b/BeeSwiftTests/GoalTests.swift @@ -40,6 +40,7 @@ final class GoalTests: XCTestCase { "lasttouch": "2022-12-07T03:21:40.000Z", "safebuf": 3583, "todayta": false, + "urgencykey": "FROx;PPRx;DL4102469999;P1000000000;test-goal", "hhmmformat": false, "yaxis": "cumulative total test-goal", "initday": 1668963600, @@ -121,6 +122,7 @@ final class GoalTests: XCTestCase { XCTAssertEqual(goal.lasttouch, 1670383300) XCTAssertEqual(goal.safebuf, 3583) XCTAssertEqual(goal.todayta, false) + XCTAssertEqual(goal.urgencykey, "FROx;PPRx;DL4102469999;P1000000000;test-goal") XCTAssertEqual(goal.hhmmformat, false) XCTAssertEqual(goal.yaxis, "cumulative total test-goal") XCTAssertEqual(goal.initday, 1668963600) @@ -160,6 +162,7 @@ final class GoalTests: XCTestCase { "lasttouch": "2022-12-07T03:21:40.000Z", "safebuf": 3583, "todayta": false, + "urgencykey": "FROx;PPRx;DL4102469999;P1000000000;test-goal", "hhmmformat": false, "yaxis": "cumulative total test-goal", "initday": 1668963600, @@ -233,7 +236,8 @@ final class GoalTests: XCTestCase { "use_defaults": true, "pledge": 0, "hhmmformat": false, - "todayta": false + "todayta": false, + "urgencykey": "FROx;PPRx;DL4102469999;P1000000000;test-goal" } """)