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

Sort by urgency instead of deadline #451

Merged
merged 2 commits into from
Apr 21, 2024
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
2 changes: 2 additions & 0 deletions BeeKit/Goal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) ?? []

Expand Down
4 changes: 2 additions & 2 deletions BeeKit/Util/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

22 changes: 2 additions & 20 deletions BeeSwift/Gallery/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "")
}
Expand Down
6 changes: 5 additions & 1 deletion BeeSwiftTests/GoalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
}
""")

Expand Down
Loading