DemoData.swift (14832B)
1 // SPDX-License-Identifier: GPL-2.0-only 2 import Foundation 3 import SubsurfaceLog 4 5 /// Demo logbook, written in the real Subsurface format: it is used for trying the app without an account, 6 /// for screenshots and by app store reviewers. Sites and people are fictional. 7 /// 8 /// Everything the user reads (site names, notes, tags, equipment) is localized; Subsurface keywords, file names 9 /// and folder names in the git paths are not. 10 enum DemoData { 11 private struct Site { 12 let uuid: String, name: String, description: String, latitude: Double, longitude: Double, country: String 13 } 14 15 private struct Plan { 16 let number: Int 17 let date: (Int, Int, Int, Int, Int) 18 let site: String 19 let depth: Double 20 let minutes: Int 21 let surfaceTemp: Double, bottomTemp: Double 22 let o2: Int 23 let buddy: String 24 let rating: Int, visibility: Int 25 let tags: [String] 26 let notes: String 27 let trip: String? 28 let cold: Bool 29 } 30 31 private static let sites = [ 32 Site(uuid: "c0000001", name: String(localized: "Sea Fan Reef"), description: String(localized: "Fringing reef, shore entry"), latitude: 12.1600, longitude: -68.2900, country: "Bonaire"), 33 Site(uuid: "c0000002", name: String(localized: "Cormorant Wreck"), description: String(localized: "Small freighter sitting upright on the sand"), latitude: 12.2150, longitude: -68.3450, country: "Bonaire"), 34 Site(uuid: "c0000003", name: String(localized: "Turtle Wall"), description: String(localized: "Gently sloping wall down to 35 m"), latitude: 12.0950, longitude: -68.2850, country: "Bonaire"), 35 Site(uuid: "c0000004", name: String(localized: "North Quarry"), description: String(localized: "Flooded quarry, platforms at 6 m and 12 m"), latitude: 45.6500, longitude: -75.9200, country: "Canada"), 36 Site(uuid: "c0000005", name: String(localized: "Seal Cove"), description: String(localized: "Rocky bottom and kelp"), latitude: 48.8300, longitude: -64.2000, country: "Canada"), 37 Site(uuid: "c0000006", name: String(localized: "Misty Wharf"), description: String(localized: "Dive under the wharf, lots of sessile life"), latitude: 48.4200, longitude: -64.3300, country: "Canada"), 38 ] 39 40 private static let plans: [Plan] = [ 41 Plan(number: 1, date: (2025, 6, 14, 10, 5), site: "c0000004", depth: 12.4, minutes: 38, surfaceTemp: 19, bottomTemp: 11, o2: 21, buddy: "Camille", rating: 3, visibility: 2, tags: [String(localized: "training")], notes: String(localized: "Skills review on the 6 m platform."), trip: nil, cold: true), 42 Plan(number: 2, date: (2025, 7, 5, 9, 40), site: "c0000004", depth: 18.2, minutes: 42, surfaceTemp: 22, bottomTemp: 8, o2: 21, buddy: "Camille", rating: 3, visibility: 3, tags: [], notes: String(localized: "Sharp thermocline at 9 m."), trip: nil, cold: true), 43 Plan(number: 3, date: (2025, 8, 16, 8, 30), site: "c0000005", depth: 16.8, minutes: 47, surfaceTemp: 12, bottomTemp: 6, o2: 21, buddy: "Sam", rating: 5, visibility: 4, tags: [String(localized: "seals")], notes: String(localized: "Three curious seals for the whole dive.\nVery clear water for the season."), trip: "Gaspesie", cold: true), 44 Plan(number: 4, date: (2025, 8, 16, 13, 15), site: "c0000006", depth: 9.6, minutes: 55, surfaceTemp: 12, bottomTemp: 8, o2: 21, buddy: "Sam", rating: 4, visibility: 3, tags: ["macro"], notes: String(localized: "Anemones, nudibranchs and crabs under the pilings."), trip: "Gaspesie", cold: true), 45 Plan(number: 5, date: (2025, 8, 17, 9, 0), site: "c0000005", depth: 22.3, minutes: 41, surfaceTemp: 11, bottomTemp: 5, o2: 32, buddy: "Sam, Alex", rating: 4, visibility: 4, tags: ["nitrox"], notes: String(localized: "Kelp forest, a wolffish in a crevice."), trip: "Gaspesie", cold: true), 46 Plan(number: 6, date: (2025, 8, 18, 20, 45), site: "c0000006", depth: 8.2, minutes: 48, surfaceTemp: 12, bottomTemp: 9, o2: 21, buddy: "Alex", rating: 5, visibility: 3, tags: [String(localized: "night"), "macro"], notes: String(localized: "Night dive: bioluminescence at the safety stop."), trip: "Gaspesie", cold: true), 47 Plan(number: 7, date: (2025, 10, 4, 11, 20), site: "c0000004", depth: 24.6, minutes: 36, surfaceTemp: 14, bottomTemp: 6, o2: 21, buddy: "Camille", rating: 2, visibility: 1, tags: [], notes: String(localized: "Poor visibility after the rain."), trip: nil, cold: true), 48 Plan(number: 8, date: (2026, 5, 23, 10, 0), site: "c0000004", depth: 15.1, minutes: 44, surfaceTemp: 13, bottomTemp: 7, o2: 21, buddy: "Camille", rating: 3, visibility: 3, tags: [String(localized: "tuning")], notes: String(localized: "First dive of the season, weighting needs adjusting."), trip: nil, cold: true), 49 Plan(number: 9, date: (2026, 6, 20, 9, 10), site: "c0000001", depth: 18.9, minutes: 58, surfaceTemp: 28, bottomTemp: 27, o2: 32, buddy: "Sam", rating: 4, visibility: 5, tags: [String(localized: "reef")], notes: String(localized: "Refresher dive, sea fans everywhere."), trip: "Bonaire", cold: false), 50 Plan(number: 10, date: (2026, 6, 20, 14, 30), site: "c0000003", depth: 27.4, minutes: 52, surfaceTemp: 28, bottomTemp: 26, o2: 32, buddy: "Sam", rating: 5, visibility: 5, tags: [String(localized: "turtles"), String(localized: "reef")], notes: String(localized: "Two green turtles and a school of jacks."), trip: "Bonaire", cold: false), 51 Plan(number: 11, date: (2026, 6, 21, 8, 45), site: "c0000002", depth: 30.2, minutes: 46, surfaceTemp: 28, bottomTemp: 26, o2: 32, buddy: "Sam, Alex", rating: 5, visibility: 4, tags: [String(localized: "wreck"), "nitrox"], notes: String(localized: "Around the wreck, starting at the bow.\nGreen moray in the forward hold."), trip: "Bonaire", cold: false), 52 Plan(number: 12, date: (2026, 6, 21, 15, 0), site: "c0000001", depth: 14.3, minutes: 64, surfaceTemp: 29, bottomTemp: 28, o2: 32, buddy: "Alex", rating: 4, visibility: 5, tags: ["photo"], notes: String(localized: "Long photo dive in 10 m of water."), trip: "Bonaire", cold: false), 53 Plan(number: 13, date: (2026, 6, 22, 9, 30), site: "c0000003", depth: 34.8, minutes: 43, surfaceTemp: 28, bottomTemp: 25, o2: 28, buddy: "Sam", rating: 4, visibility: 5, tags: [String(localized: "deep")], notes: String(localized: "Down the wall to the barrel sponges."), trip: "Bonaire", cold: false), 54 Plan(number: 14, date: (2026, 6, 23, 19, 50), site: "c0000001", depth: 12.0, minutes: 61, surfaceTemp: 28, bottomTemp: 28, o2: 32, buddy: "Sam, Alex", rating: 5, visibility: 4, tags: [String(localized: "night")], notes: String(localized: "Hunting octopuses and tarpon in the beams of our lights."), trip: "Bonaire", cold: false), 55 Plan(number: 15, date: (2026, 7, 18, 10, 30), site: "c0000004", depth: 20.4, minutes: 40, surfaceTemp: 23, bottomTemp: 9, o2: 21, buddy: "Camille", rating: 3, visibility: 3, tags: [], notes: String(localized: "Trying out the new regulator."), trip: nil, cold: true), 56 Plan(number: 16, date: (2026, 9, 12, 9, 15), site: "c0000004", depth: 28.7, minutes: 39, surfaceTemp: 20, bottomTemp: 6, o2: 21, buddy: "Camille, Sam", rating: 4, visibility: 4, tags: [String(localized: "deep")], notes: String(localized: "Visit to the old truck at the bottom of the quarry."), trip: nil, cold: true), 57 ] 58 59 private static let weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] 60 61 static func files() -> [String: String] { 62 var files = [String: String]() 63 files["00-Subsurface"] = "version 3\nautogroup\nunits METRIC\n" 64 for site in sites { 65 files["01-Divesites/Site-\(site.uuid)"] = """ 66 name "\(site.name)" 67 description "\(site.description)" 68 gps \(String(format: "%.6f %.6f", site.latitude, site.longitude)) 69 geo cat 2 origin 0 "\(site.country)" 70 71 """ 72 } 73 let tripFolders = ["Gaspesie": "2025/08/16-Gaspesie", "Bonaire": "2026/06/20-Bonaire"] 74 // Folder names in the git paths stay ASCII and are the same in every language; only the trip text is localized. 75 let gaspeLocation = String(localized: "Gaspé Peninsula") 76 let gaspeNotes = String(localized: "Long weekend in cold water") 77 let bonaireNotes = String(localized: "A week of shore diving") 78 files["2025/08/16-Gaspesie/00-Trip"] = "date 2025-08-16\ntime 08:30:00\nlocation \(quoted(gaspeLocation))\nnotes \(quoted(gaspeNotes))\n" 79 files["2026/06/20-Bonaire/00-Trip"] = "date 2026-06-20\ntime 09:10:00\nlocation \"Bonaire\"\nnotes \(quoted(bonaireNotes))\n" 80 81 for plan in plans { 82 let (y, mo, d, h, mi) = plan.date 83 guard let when = NaiveTime.timestamp(year: y, month: mo, day: d, hour: h, minute: mi) else { continue } 84 let weekday = weekdays[((NaiveTime.components(when).weekday ?? 1) - 1) % 7] 85 let name = String(format: "%02d-%@-%02d=%02d=00", d, weekday, h, mi) 86 let folder = plan.trip.flatMap { tripFolders[$0] } ?? String(format: "%04d/%02d", y, mo) 87 let base = "\(folder)/\(name)" 88 let start = plan.cold ? 205.0 : 200.0 89 let used = Double(plan.minutes) * (plan.depth / 20 + 1) * (plan.cold ? 1.5 : 1.25) 90 let end = max(40, (start - used).rounded()) 91 files["\(base)/Dive-\(plan.number)"] = diveFile(plan, start: start, end: end) 92 files["\(base)/Divecomputer"] = computerFile(plan, start: start, end: end) 93 } 94 return files 95 } 96 97 private static func quoted(_ text: String) -> String { 98 "\"" + text.replacingOccurrences(of: "\"", with: "\\\"").replacingOccurrences(of: "\n", with: "\n\t") + "\"" 99 } 100 101 private static func diveFile(_ plan: Plan, start: Double, end: Double) -> String { 102 var text = "duration \(plan.minutes):00 min\n" 103 text += "rating \(plan.rating)\nvisibility \(plan.visibility)\n" 104 if !plan.tags.isEmpty { text += "tags " + plan.tags.map(quoted).joined(separator: ", ") + "\n" } 105 text += "divesiteid \(plan.site)\n" 106 text += "buddy \(quoted(plan.buddy))\n" 107 let suit = plan.cold ? String(localized: "Trilaminate drysuit") : String(localized: "3 mm shorty") 108 text += "suit \(quoted(suit))\n" 109 text += "notes \(quoted(plan.notes))\n" 110 let gas = plan.o2 == 21 ? "" : " o2=\(plan.o2).0%" 111 if plan.cold { 112 let cylinder = String(localized: "12 L steel") 113 let weights = String(localized: "belt") 114 text += "cylinder vol=12.0l workpressure=232.0bar description=\(quoted(cylinder))\(gas) start=\(Int(start)).0bar end=\(Int(end)).0bar\n" 115 text += "weightsystem weight=10.0kg description=\(quoted(weights))\n" 116 } else { 117 let weights = String(localized: "pockets") 118 text += "cylinder vol=11.1l workpressure=207.0bar description=\"AL80\"\(gas) start=\(Int(start)).0bar end=\(Int(end)).0bar\n" 119 text += "weightsystem weight=4.0kg description=\(quoted(weights))\n" 120 } 121 return text 122 } 123 124 /// Depth at time `t`: descent, a two-level bottom that undulates, ascent and safety stop at 5 m. 125 private static func depth(_ plan: Plan, at t: Int) -> Double { 126 let total = plan.minutes * 60 127 let maxDepth = plan.depth 128 let descent = Int(maxDepth / 18 * 60) 129 let stop = maxDepth > 9 ? 180 : 0 130 let finalAscent = Int(5.0 / 9 * 60) + 10 131 let ascent = Int(max(maxDepth * 0.55 - 5, 0) / 9 * 60) 132 let bottomEnd = total - finalAscent - stop - ascent 133 let wobble = sin(Double(t) / 47 + Double(plan.number)) * 0.5 + sin(Double(t) / 13) * 0.2 134 if t <= 0 || t >= total { return 0 } 135 if t < descent { return maxDepth * Double(t) / Double(descent) } 136 if t < bottomEnd { 137 // From the bottom to a second level at 55% of the depth, on a gentle slope. 138 let progress = Double(t - descent) / Double(max(bottomEnd - descent, 1)) 139 let eased = progress < 0.35 ? 0 : (progress - 0.35) / 0.65 140 let level = maxDepth * (1 - 0.45 * eased) 141 return max(1, min(maxDepth, level + wobble)) 142 } 143 let second = max(maxDepth * 0.55, min(maxDepth, 5)) 144 if t < bottomEnd + ascent { 145 return second - (second - 5) * Double(t - bottomEnd) / Double(max(ascent, 1)) 146 } 147 if t < bottomEnd + ascent + stop { return min(second, 5) + wobble * 0.3 } 148 let left = total - t 149 return max(0, min(second, 5) * Double(left) / Double(finalAscent)) 150 } 151 152 private static func milli(_ value: Double) -> String { 153 let rounded = (value * 10).rounded() / 10 154 return String(format: "%.1f", rounded) 155 } 156 157 private static func computerFile(_ plan: Plan, start: Double, end: Double) -> String { 158 let total = plan.minutes * 60 159 var samples = "" 160 var deepest = 0.0, sum = 0.0, count = 0.0 161 var lastTemp = "", lastNDL = -1 162 var loading = 0.0 163 for t in stride(from: 0, through: total, by: 10) { 164 let d = depth(plan, at: t) 165 deepest = max(deepest, d) 166 sum += d; count += 1 167 var line = String(format: "%3d:%02d", t / 60, t % 60) + " \(milli(d))m" 168 let fraction = plan.depth > 0 ? min(d / plan.depth, 1) : 0 169 let temp = milli((plan.surfaceTemp + (plan.bottomTemp - plan.surfaceTemp) * pow(fraction, 0.6)).rounded()) 170 if temp != lastTemp { line += " \(temp)°C"; lastTemp = temp } 171 if t % 30 == 0 { 172 let pressure = start - (start - end) * Double(t) / Double(total) 173 line += " \(milli(pressure))bar:0" 174 } 175 // Very simplified nitrogen loading, just enough to give a plausible no-decompression limit. 176 loading += max(d - 6, 0) * 10 / 60 177 let limit = d < 8 ? 99 : max(2, Int(1400 / pow(d, 1.25) - loading / 14)) 178 let ndl = min(limit, 99) 179 if ndl != lastNDL { line += " ndl=\(ndl):00"; lastNDL = ndl } 180 samples += line + "\n" 181 } 182 let model = String(localized: "Demo computer") 183 let decoModelKey = String(localized: "Deco model") 184 var text = "model \(quoted(model))\n" 185 text += "maxdepth \(milli(deepest))m\n" 186 text += "meandepth \(milli(sum / max(count, 1)))m\n" 187 text += "airtemp \(milli(plan.surfaceTemp + 3))°C\n" 188 text += "watertemp \(milli(plan.bottomTemp))°C\n" 189 text += "surfacepressure 1.013bar\n" 190 text += "salinity \(plan.site == "c0000004" ? 1000 : 1025)g/l\n" 191 text += "keyvalue \(quoted(decoModelKey)) \"GF 30/70\"\n" 192 let gas = plan.o2 == 21 ? " o2=21.0%" : " o2=\(plan.o2).0%" 193 text += "event 0:00 type=25 flags=1 name=\"gaschange\" cylinder=0\(gas)\n" 194 return text + samples 195 } 196 }