Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/hop/blob/main/Omega/tests/SuggestReference.swift # hop Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key. Brought by drakestapleton Sign in to star 1 stars 1 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `hop / Omega / tests / SuggestReference.swift` 43 lines ยท 2394 bytes Raw Blame History 1 import 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. 6 enum 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.. $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..= 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 }