Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134import BloomKitimport SwiftUI
/// The explorer: what snapshot is loaded, what's in the core, and what the current cell's file holds.struct DataView: View { @Environment(AppModel.self) private var model @State private var cdn = "" @State private var cacheBytes = 0 @State private var tables: [(String, Int)] = [] @State private var confirmingClear = false
var body: some View { List { if let snap = model.snapshot { Section { row("Version", snap.manifest.version) row("Generated", snap.manifest.generated_at) row("Source", snap.source.rawValue) if let f = snap.manifest.files["core.sqlite"] { row("Core", bytes(f.bytes)) } if let f = snap.manifest.files["core.sqlite.gz"] { row("Core, gzipped", bytes(f.bytes)) } row("Fetched files on device", bytes(cacheBytes)) Button("Clear Fetched Files", role: .destructive) { confirmingClear = true } .confirmationDialog("Clear fetched files?", isPresented: $confirmingClear, titleVisibility: .visible) { Button("Clear", role: .destructive) { Task { await model.store.clearCaches() cacheBytes = await model.store.cacheSize() } } } message: { Text("Place and taxon files are fetched again when you next open them.") } } header: { SectionLabel(text: "Snapshot", symbol: "shippingbox") } }
Section { LabeledContent("Source", value: model.dataSource.title) Text(model.cdnURL.absoluteString).font(.system(.footnote, design: .monospaced)).foregroundStyle(.secondary) .textSelection(.enabled) TextField("https://…", text: $cdn) .keyboardType(.URL).textInputAutocapitalization(.never).autocorrectionDisabled() .font(.system(.body, design: .monospaced)) Button("Reload From This Server") { if let url = URL(string: cdn) { Task { await model.changeCDN(url) } } } } header: { SectionLabel(text: "Server", symbol: "server.rack") } footer: { Text("Pick the source in Settings; a URL loaded here becomes the Custom source.").font(.caption) }
if let cell = model.cell { Section { row("Cell", String(cell.id)) row("H3", cell.h3Hex) row("Centre", String(format: "%.4f, %.4f", cell.latitude, cell.longitude)) if let s = cell.state { row("State", s) } if let data = model.cellData { row("Taxa mentioned", data.ids.count.formatted()) ForEach(Grade.allCases, id: \.self) { g in if let n = data.gradeCounts[g] { row(" \(g.label)", n.formatted()) } } row("Plants with support counts", data.support.count.formatted()) row("Animals with plant counts", data.supportedBy.count.formatted()) row("Layer rankings", data.layers.values.map(\.count).reduce(0, +).formatted()) row("Keystone rankings", data.keystones.values.map(\.count).reduce(0, +).formatted()) row("Clade support lists", data.cladeSupport.count.formatted()) row("Clade observed lists", data.cladeObserved.count.formatted()) NavigationLink("Browse every taxon in this cell", value: MenuRoute.cellTaxa) } } header: { SectionLabel(text: "This cell's file", symbol: "hexagon") } }
Section { if tables.isEmpty { Button("Count rows") { tables = model.core?.tableCounts() ?? [] } } else { ForEach(tables, id: \.0) { name, n in row(name, n.formatted()) } } } header: { SectionLabel(text: "Core tables", symbol: "tablecells") } } .paperBackground() .navigationTitle("Data") .task { cdn = model.cdnURL.absoluteString cacheBytes = await model.store.cacheSize() } }
private func row(_ label: String, _ value: String) -> some View { LabeledContent { Text(value).font(.system(.footnote, design: .monospaced)).foregroundStyle(Color.ink).textSelection(.enabled) } label: { Text(label).font(.subheadline) } }
private func bytes(_ n: Int) -> String { ByteCountFormatter.string(fromByteCount: Int64(n), countStyle: .file) }}
struct CellTaxaView: View { @Environment(AppModel.self) private var model let data: CellData @State private var grade: Grade = .native @State private var plantsOnly = false
var body: some View { let core = model.core! let ids = data.ids.filter { data.grade($0) == grade } let taxa = core.taxa(ids).filter { !plantsOnly || $0.isPlant }.sorted { $0.observations > $1.observations } List { Section { Picker("Grade", selection: $grade) { ForEach(Grade.allCases, id: \.self) { Text($0.label).tag($0) } } Toggle("Plants only", isOn: $plantsOnly) } Section { ForEach(taxa.prefix(500)) { TaxonRow(taxon: $0) } } header: { SectionLabel(text: "\(taxa.count) taxa\(taxa.count > 500 ? ", 500 most observed shown" : "")") } } .paperBackground() .navigationTitle("Cell \(data.cell)") }}