Skip to content

Commit f4440f6

Browse files
authored
Sort by urgency instead of deadline (#451)
Beeminder has moved from sorting by deadline to sorting by Urgency. Update the app to use the new name, and also rely on the server provided `urgencykey` to determine sort order.
1 parent 89b4123 commit f4440f6

File tree

4 files changed

+11
-23
lines changed

4 files changed

+11
-23
lines changed

BeeKit/Goal.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class Goal {
5151
public var queued: Bool?
5252
public var todayta: Bool = false
5353
public var hhmmformat: Bool = false
54+
public var urgencykey: String = ""
5455
public var recent_data: [ExistingDataPoint]?
5556

5657
// These are obtained from mathishard
@@ -112,6 +113,7 @@ public class Goal {
112113
self.healthKitMetric = json["healthkitmetric"].string
113114
self.todayta = json["todayta"].bool!
114115
self.hhmmformat = json["hhmmformat"].bool!
116+
self.urgencykey = json["urgencykey"].string!
115117

116118
self.recent_data = (try? ExistingDataPoint.fromJSONArray(array: json["recent_data"].arrayValue).reversed()) ?? []
117119

BeeKit/Util/Constants.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public struct Constants {
2222
public static let recentDataGoalSortString = "Recent Data"
2323
public static let nameGoalSortString = "Name"
2424
public static let pledgeGoalSortString = "Pledge"
25-
public static let deadlineGoalSortString = "Deadline"
25+
public static let urgencyGoalSortString = "Urgency"
2626
public static let healthKitUpdateDictionaryKey = "healthKitUpdateDictionary"
27-
public static let goalSortOptions = [Constants.nameGoalSortString, Constants.deadlineGoalSortString, Constants.pledgeGoalSortString, Constants.recentDataGoalSortString]
27+
public static let goalSortOptions = [Constants.urgencyGoalSortString, Constants.nameGoalSortString, Constants.pledgeGoalSortString, Constants.recentDataGoalSortString]
2828
public static let appGroupIdentifier = "group.beeminder.beeminder"
2929
}
3030

BeeSwift/Gallery/GalleryViewController.swift

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -428,26 +428,8 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
428428
}
429429
}
430430

431-
// Default sort ordering
432-
433-
// Primary Criteria: Sooner deadline/goal end first
434-
let goal1Date = min(goal1.losedate.intValue, goal1.derived_goaldate.intValue)
435-
let goal2Date = min(goal2.losedate.intValue, goal2.derived_goaldate.intValue)
436-
if goal1Date < goal2Date {
437-
return true
438-
} else if goal2Date < goal1Date {
439-
return false
440-
}
441-
442-
// Secondary Criteria: Larger pledge amount first
443-
if goal2.pledge.intValue < goal1.pledge.intValue {
444-
return true
445-
} else if goal1.pledge.intValue < goal2.pledge.intValue {
446-
return false
447-
}
448-
449-
// Tertiary Criteria: Lexographically earlier slug first
450-
return goal1.slug < goal2.slug
431+
// urgencykey is guaranteed to result in goals sorting into the canonical order
432+
return goal1.urgencykey < goal2.urgencykey
451433
})
452434
self.updateFilteredGoals(searchText: self.searchBar.text ?? "")
453435
}

BeeSwiftTests/GoalTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ final class GoalTests: XCTestCase {
4040
"lasttouch": "2022-12-07T03:21:40.000Z",
4141
"safebuf": 3583,
4242
"todayta": false,
43+
"urgencykey": "FROx;PPRx;DL4102469999;P1000000000;test-goal",
4344
"hhmmformat": false,
4445
"yaxis": "cumulative total test-goal",
4546
"initday": 1668963600,
@@ -121,6 +122,7 @@ final class GoalTests: XCTestCase {
121122
XCTAssertEqual(goal.lasttouch, 1670383300)
122123
XCTAssertEqual(goal.safebuf, 3583)
123124
XCTAssertEqual(goal.todayta, false)
125+
XCTAssertEqual(goal.urgencykey, "FROx;PPRx;DL4102469999;P1000000000;test-goal")
124126
XCTAssertEqual(goal.hhmmformat, false)
125127
XCTAssertEqual(goal.yaxis, "cumulative total test-goal")
126128
XCTAssertEqual(goal.initday, 1668963600)
@@ -160,6 +162,7 @@ final class GoalTests: XCTestCase {
160162
"lasttouch": "2022-12-07T03:21:40.000Z",
161163
"safebuf": 3583,
162164
"todayta": false,
165+
"urgencykey": "FROx;PPRx;DL4102469999;P1000000000;test-goal",
163166
"hhmmformat": false,
164167
"yaxis": "cumulative total test-goal",
165168
"initday": 1668963600,
@@ -233,7 +236,8 @@ final class GoalTests: XCTestCase {
233236
"use_defaults": true,
234237
"pledge": 0,
235238
"hhmmformat": false,
236-
"todayta": false
239+
"todayta": false,
240+
"urgencykey": "FROx;PPRx;DL4102469999;P1000000000;test-goal"
237241
}
238242
""")
239243

0 commit comments

Comments
 (0)