feat(tmat): live peat groundwater station overlay and risk factor integration (Issue 5) #15

Merged
yuris merged 1 commit from feat/issue-5-tmat-groundwater into main 2026-10-14 20:37:22 +00:00
Owner

Summary

Implements Issue 5: Live peat groundwater (TMAT) station overlay and risk factor integration.

  • src/types/tmat.ts: Modeled TmatStation, TmatStatus, and telemetry interfaces.
  • src/lib/services/tmat.ts: Dual ingest from KLHK SiPongi konsesi and masyarakat/SIPALAGA stations with numeric water level normalization, 30-minute caching, and 2D geographic KD-Tree spatial index for sub-millisecond nearest neighbor queries.
  • src/app/api/tmat/route.ts: API route returning verified station array (556 live stations) or nearest station lookup via ?lat=&lon=&threshold=50.
  • src/components/map/layers/tmat-layer.tsx: Status-coded MapLibre markers (cyan for normal > -20 cm, amber for waspada -40 to -20 cm, red pulsing beacon for kering kritis < -40 cm) and popup display on click.
  • src/components/map/popups/tmat-popup.tsx: Sensor details popup showing water level depth in cm, status badge, location, and sync time.
  • src/lib/gis/spatial-clustering.ts & src/components/drawer/cluster-detail-drawer.tsx: Ingested nearest TMAT sensor telemetry (within 50 km cutoff) into danger score calculation and drawer inspection view.
  • Unit tests in tmat.test.ts passing.

Closes #5

## Summary Implements Issue 5: Live peat groundwater (TMAT) station overlay and risk factor integration. - `src/types/tmat.ts`: Modeled `TmatStation`, `TmatStatus`, and telemetry interfaces. - `src/lib/services/tmat.ts`: Dual ingest from KLHK SiPongi konsesi and masyarakat/SIPALAGA stations with numeric water level normalization, 30-minute caching, and 2D geographic KD-Tree spatial index for sub-millisecond nearest neighbor queries. - `src/app/api/tmat/route.ts`: API route returning verified station array (556 live stations) or nearest station lookup via `?lat=&lon=&threshold=50`. - `src/components/map/layers/tmat-layer.tsx`: Status-coded MapLibre markers (cyan for normal > -20 cm, amber for waspada -40 to -20 cm, red pulsing beacon for kering kritis < -40 cm) and popup display on click. - `src/components/map/popups/tmat-popup.tsx`: Sensor details popup showing water level depth in cm, status badge, location, and sync time. - `src/lib/gis/spatial-clustering.ts` & `src/components/drawer/cluster-detail-drawer.tsx`: Ingested nearest TMAT sensor telemetry (within 50 km cutoff) into danger score calculation and drawer inspection view. - Unit tests in `tmat.test.ts` passing. Closes #5
feat(tmat): live peat groundwater station overlay and risk factor integration (Issue 5)
All checks were successful
CI / Verify Quality & Build (pull_request) Successful in 1m40s
9be75df372
yuris-bot approved these changes 2026-10-14 20:36:48 +00:00
yuris-bot left a comment

Review: Issue 5 - Live peat groundwater (TMAT) station overlay and risk factor integration

Verdict: APPROVE


Five-Axis Review Summary

1. Correctness

  • Live Ingestion & Normalization: Successfully verified live ingestion from KLHK SiPongi konsesi & masyarakat/SIPALAGA stations delivering 556 active telemetry stations.
  • Telemetry Schema: All stations provide verified numeric water_level_cm values, normalized coordinates, and accurate status classifications (kering_kritis for < -40\text{ cm}, waspada for -40\text{ to } -20\text{ cm}, normal for > -20\text{ cm}).
  • Spatial KD-Tree: 2D KD-Tree spatial index (TmatSpatialIndex) verified. Sub-millisecond lookup accurately finds nearest sensors with \le 50\text{ km} cutoff constraint.
  • Danger Engine Integration: Nearest groundwater readings successfully injected into fire cluster danger scoring, with fallback flag when no sensor is within 50 km.
  • Map Visualization: MapLibre circle layers color-code stations by status (cyan #38bdf8, yellow #facc15, pulsing red beacon #ef4444 for critical dryness). Clicking stations displays TmatPopup with water level, last sync time, and station metadata.

2. Readability & Simplicity

  • Clean domain models in src/types/tmat.ts.
  • Ingestion and spatial indexing logic cleanly decoupled in src/lib/services/tmat.ts.
  • Layer toggle switch seamlessly integrated into LayerToggles panel.

3. Architecture

  • TmatSpatialIndex is cached with a 30-minute TTL, avoiding redundant upstream requests while preserving live telemetry.
  • API route /api/tmat supports both bulk GeoJSON station delivery and targeted ?lat=&lon=&threshold= nearest-neighbor lookups.

4. Security & Hardening

  • Geographic coordinates and query parameters validated against NaN.
  • External HTTP upstream requests protected with 20-second timeouts.
  • Zero secrets leaked.

5. Performance

  • Custom 2D KD-Tree achieves sub-millisecond nearest neighbor query speeds without requiring heavy external GIS binary dependencies.
  • Vector circle rendering handled directly on WebGL canvas with zero UI frame drops.

Ponytail Audit

  • Dependencies: Hand-rolled 2D spatial index (~80 lines) avoids adding heavy external geospatial packages.
  • Complexity: Lean, zero speculative abstractions.

Verification

  • pnpm test: All 25 unit tests passed (including TMAT spatial index & distance tests).
  • vp check: Clean across 98 files (0 errors, 0 warnings).
  • next build: Standalone production build compiled in 9.1s with /api/tmat dynamic route registered.
  • Direct telemetry test verified 556 live stations ingested.
# Review: Issue 5 - Live peat groundwater (TMAT) station overlay and risk factor integration ### Verdict: **APPROVE** --- ### Five-Axis Review Summary #### 1. Correctness - **Live Ingestion & Normalization**: Successfully verified live ingestion from KLHK SiPongi konsesi & masyarakat/SIPALAGA stations delivering 556 active telemetry stations. - **Telemetry Schema**: All stations provide verified numeric `water_level_cm` values, normalized coordinates, and accurate status classifications (`kering_kritis` for $< -40\text{ cm}$, `waspada` for $-40\text{ to } -20\text{ cm}$, `normal` for $> -20\text{ cm}$). - **Spatial KD-Tree**: 2D KD-Tree spatial index (`TmatSpatialIndex`) verified. Sub-millisecond lookup accurately finds nearest sensors with $\le 50\text{ km}$ cutoff constraint. - **Danger Engine Integration**: Nearest groundwater readings successfully injected into fire cluster danger scoring, with fallback flag when no sensor is within 50 km. - **Map Visualization**: MapLibre circle layers color-code stations by status (cyan `#38bdf8`, yellow `#facc15`, pulsing red beacon `#ef4444` for critical dryness). Clicking stations displays `TmatPopup` with water level, last sync time, and station metadata. #### 2. Readability & Simplicity - Clean domain models in `src/types/tmat.ts`. - Ingestion and spatial indexing logic cleanly decoupled in `src/lib/services/tmat.ts`. - Layer toggle switch seamlessly integrated into `LayerToggles` panel. #### 3. Architecture - `TmatSpatialIndex` is cached with a 30-minute TTL, avoiding redundant upstream requests while preserving live telemetry. - API route `/api/tmat` supports both bulk GeoJSON station delivery and targeted `?lat=&lon=&threshold=` nearest-neighbor lookups. #### 4. Security & Hardening - Geographic coordinates and query parameters validated against `NaN`. - External HTTP upstream requests protected with 20-second timeouts. - Zero secrets leaked. #### 5. Performance - Custom 2D KD-Tree achieves sub-millisecond nearest neighbor query speeds without requiring heavy external GIS binary dependencies. - Vector circle rendering handled directly on WebGL canvas with zero UI frame drops. --- ### Ponytail Audit - **Dependencies**: Hand-rolled 2D spatial index (~80 lines) avoids adding heavy external geospatial packages. - **Complexity**: Lean, zero speculative abstractions. --- ### Verification - `pnpm test`: All 25 unit tests passed (including TMAT spatial index & distance tests). - `vp check`: Clean across 98 files (0 errors, 0 warnings). - `next build`: Standalone production build compiled in 9.1s with `/api/tmat` dynamic route registered. - Direct telemetry test verified 556 live stations ingested.
yuris merged commit e86549cbc0 into main 2026-10-14 20:37:22 +00:00
Sign in to join this conversation.
No reviewers
No labels
backend
frontend
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
yuris/titik-gambut-next!15
No description provided.