interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / Omega / tests / SuggestReference.swift

43 lines · 2394 bytes Raw Blame History
1import Foundation
2
3/// What the one box offered before anything was typed, and the lift from habit, as Hop shipped them in Swift
4/// (Smart.suggest and Habits.lift), written over the plain numbers the Omega core is given. Kept only as the
5/// reference the core is checked against.
6enum SuggestReference {
7 static func rows(_ i: SmartSuggest.Input) -> [SmartSuggest.Row] {
8 typealias Row = SmartSuggest.Row
9 var rows: [Row] = []
10 if i.hasLatest {
11 let s = i.age < 60 ? 130 : (i.age < 600 ? 95 : 70)
12 rows.append(Row(kind: 6, index: 0, score: s, why: i.age < 600 ? 1 : 2))
13 if i.latestIsAddress { rows.append(Row(kind: 2, index: 0, score: s + (i.frontIsBrowser ? -5 : 5), why: 3)) }
14 }
15 var guesses: [Row] = []
16 for (k, a) in i.apps.enumerated() {
17 let total = a.liftFrom + a.liftHour
18 guard total > 0 || a.used > 0 || a.running || a.previous else { continue }
19 let score = 40 + total + a.used / 4 + (a.previous ? 45 : 0) + (a.running ? 8 : 0) + a.lately
20 let why = a.liftFrom > 0 ? 4 : a.previous ? 5 : a.liftHour > 0 ? 6 : a.used > 0 ? 7 : 8
21 guesses.append(Row(kind: 1, index: k, score: score, why: why))
22 }
23 rows += guesses.sorted { $0.score != $1.score ? $0.score > $1.score : $0.index < $1.index }.prefix(6)
24 for k in 0..<min(max(i.rest, 0), 20) { rows.append(Row(kind: 6, index: 1 + k, score: 38 - k)) }
25 if i.paused { rows.append(Row(kind: 3, index: 0, score: 39, why: 9)) }
26 return rows.enumerated().sorted { $0.element.score != $1.element.score ? $0.element.score > $1.element.score : $0.offset < $1.offset }.map(\.element)
27 }
28
29 static func lifts(hour: Int, hasFront: Bool, apps: Int, launches: [(here: Bool, hour: Int, app: Int)]) -> [(from: Int, hour: Int)] {
30 (0..<apps).map { k in
31 var from = 0, around = 0
32 if hasFront {
33 let fromHere = launches.filter { $0.here }
34 let n = fromHere.filter { $0.app == k }.count
35 if n >= 2 { from = 60 * n / fromHere.count }
36 }
37 let near = launches.filter { let d = abs($0.hour - hour); return min(d, 24 - d) <= 1 }
38 let n = near.filter { $0.app == k }.count
39 if n >= 2 { around = 25 * n / near.count }
40 return (from, around)
41 }
42 }
43}