Commit bb6579fe06
bb6579fe06b678568d97aedc83ed4ef6925bd015
parent: e4ed078778
Unsigned
cmc <hello@cleberg.net> · 2026-10-21 23:35 UTC
Sun snapshot: zlib-compress the OVATION grid (!98)
- `Ovation` encodes its 360 × 181 byte grid zlib-compressed under `gridz`. Decodes `gridz`, then `grid` (uncompressed), then `cells`.
- Live feed (2026-10-21): grid 86,880 → 8,612 bytes base64. Snapshot about 156 KB → 78 KB (X-ray series unchanged at 69 KB).
- Test for reading the uncompressed grid; size bound tightened to 20 KB. All MoonriseKit tests pass (203); iOS build passes.
Layout: unified · split
PLAN.org
+2 −2
| @@ -482,8 +482,8 @@ Sky, System, Sun, Launches, Library core (above). |
| 482 | 23:29 UTC. |
482 | 23:29 UTC. |
| 483 | - Performance: Sun tab first open still has frames over 100 ms (SwiftUI and |
483 | - Performance: Sun tab first open still has frames over 100 ms (SwiftUI and |
| 484 | Charts start-up); RealityKit's first start (about 1.4 s) when switching to |
484 | Charts start-up); RealityKit's first start (about 1.4 s) when switching to |
| 485 | 3D, checked on a device; Sun snapshot OVATION grid compressed (156 KB to |
485 | 3D, checked on a device. Done: Sun snapshot OVATION grid zlib-compressed |
| 486 | about 90 KB). |
486 | (grid 87 KB to 9 KB base64; snapshot 156 KB to about 78 KB). |
| 487 | |
487 | |
| 488 | ** v4.2: widgets and controls |
488 | ** v4.2: widgets and controls |
| 489 | - Lock Screen: Kp, next launch. Home Screen: Voyager 1 distance, today's Sun |
489 | - Lock Screen: Kp, next launch. Home Screen: Voyager 1 distance, today's Sun |
Packages/MoonriseKit/Sources/Feeds/Sun.swift
+6 −5
| @@ -224,17 +224,18 @@ public struct Ovation: Sendable, Equatable, Codable { |
| 224 | } |
224 | } |
| 225 | } |
225 | } |
| 226 | |
226 | |
| 227 | /// Saved as the feed's grid, one byte per cell in the feed's order (longitude 0...359, then latitude −90...90). |
227 | /// Saved as the feed's grid, one byte per cell in the feed's order (longitude 0...359, then latitude −90...90), |
| 228 | /// Snapshots saved before the grid hold `cells`. |
228 | /// zlib-compressed. Older snapshots hold the grid uncompressed (`grid`) or as `cells`. |
| 229 | extension Ovation { |
229 | extension Ovation { |
| 230 | enum CodingKeys: String, CodingKey { |
230 | enum CodingKeys: String, CodingKey { |
| 231 | case forecastTime, grid, cells |
231 | case forecastTime, gridz, grid, cells |
| 232 | } |
232 | } |
| 233 | |
233 | |
| 234 | public init(from decoder: Decoder) throws { |
234 | public init(from decoder: Decoder) throws { |
| 235 | let c = try decoder.container(keyedBy: CodingKeys.self) |
235 | let c = try decoder.container(keyedBy: CodingKeys.self) |
| 236 | forecastTime = try c.decode(Date.self, forKey: .forecastTime) |
236 | forecastTime = try c.decode(Date.self, forKey: .forecastTime) |
| 237 | if let grid = try c.decodeIfPresent(Data.self, forKey: .grid) { |
237 | let packed = try c.decodeIfPresent(Data.self, forKey: .gridz).map { try ($0 as NSData).decompressed(using: .zlib) as Data } |
| |
238 | if let grid = try packed ?? c.decodeIfPresent(Data.self, forKey: .grid) { |
| 238 | cells = grid.enumerated().compactMap { i, p in |
239 | cells = grid.enumerated().compactMap { i, p in |
| 239 | p > 0 ? Cell(lon: Double(i / 181), lat: Double(i % 181 - 90), probability: Double(p)) : nil |
240 | p > 0 ? Cell(lon: Double(i / 181), lat: Double(i % 181 - 90), probability: Double(p)) : nil |
| 240 | } |
241 | } |
| @@ -252,6 +253,6 @@ extension Ovation { |
| 252 | } |
253 | } |
| 253 | var c = encoder.container(keyedBy: CodingKeys.self) |
254 | var c = encoder.container(keyedBy: CodingKeys.self) |
| 254 | try c.encode(forecastTime, forKey: .forecastTime) |
255 | try c.encode(forecastTime, forKey: .forecastTime) |
| 255 | try c.encode(grid, forKey: .grid) |
256 | try c.encode(try (grid as NSData).compressed(using: .zlib) as Data, forKey: .gridz) |
| 256 | } |
257 | } |
| 257 | } |
258 | } |
Packages/MoonriseKit/Tests/FeedsTests/SunTests.swift
+10 −1
| @@ -105,10 +105,19 @@ func solarFrameUsable(name: String, image: SolarImage, usable: Bool) throws { |
| 105 | let feed = Data(#"{"Forecast Time": "2026-10-18T00:37:00Z", "coordinates": [\#(rows.joined(separator: ","))]}"#.utf8) |
105 | let feed = Data(#"{"Forecast Time": "2026-10-18T00:37:00Z", "coordinates": [\#(rows.joined(separator: ","))]}"#.utf8) |
| 106 | let o = try Ovation.decode(feed) |
106 | let o = try Ovation.decode(feed) |
| 107 | let data = try JSONEncoder().encode(o) |
107 | let data = try JSONEncoder().encode(o) |
| 108 | #expect(data.count < 90_000) |
108 | #expect(data.count < 20_000) |
| 109 | #expect(try JSONDecoder().decode(Ovation.self, from: data) == o) |
109 | #expect(try JSONDecoder().decode(Ovation.self, from: data) == o) |
| 110 | } |
110 | } |
| 111 | |
111 | |
| |
112 | @Test func ovationReadsUncompressedGridFromOlderSnapshots() throws { |
| |
113 | var grid = Data(count: 360 * 181) |
| |
114 | grid[0 * 181 + 155] = 12 |
| |
115 | grid[359 * 181 + 30] = 3 |
| |
116 | let data = Data(#"{"forecastTime": 782614800, "grid": "\#(grid.base64EncodedString())"}"#.utf8) |
| |
117 | let o = try JSONDecoder().decode(Ovation.self, from: data) |
| |
118 | #expect(o.cells == [Ovation.Cell(lon: 0, lat: 65, probability: 12), Ovation.Cell(lon: 359, lat: -60, probability: 3)]) |
| |
119 | } |
| |
120 | |
| 112 | @Test func ovationReadsCellsFromOlderSnapshots() throws { |
121 | @Test func ovationReadsCellsFromOlderSnapshots() throws { |
| 113 | let data = Data(#"{"forecastTime": 782614800, "cells": [{"lon": 0, "lat": 65, "probability": 12}, {"lon": 359, "lat": -60, "probability": 3}]}"#.utf8) |
122 | let data = Data(#"{"forecastTime": 782614800, "cells": [{"lon": 0, "lat": 65, "probability": 12}, {"lon": 359, "lat": -60, "probability": 3}]}"#.utf8) |
| 114 | let o = try JSONDecoder().decode(Ovation.self, from: data) |
123 | let o = try JSONDecoder().decode(Ovation.self, from: data) |