feat(2-4): implement altitude colour bands and aircraft type icons

Implements altitude_to_colour() mapping altitude bands to the 6 e-ink
palette colours, and classify_aircraft_type() resolving ADS-B category,
callsign prefix, and altitude fallback to AircraftType enum. Adds 21
new tests (13 parametrised boundary cases + 8 icon classification);
89 tests total, all quality gates green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt Edholm
2026-04-22 23:21:50 -04:00
parent b9ccdc4916
commit 2c86ffd422
6 changed files with 186 additions and 33 deletions
@@ -1,6 +1,6 @@
# Story 2.4: Altitude Colour Bands & Aircraft Type Icons
Status: ready-for-dev
Status: review
## Story
@@ -26,16 +26,16 @@ AC7: **Given** an `Aircraft` with no category and `altitude_ft=38000` (> 30,000f
## Tasks / Subtasks
- [ ] Task 1: Implement `altitude_to_colour()` in `src/planemapper/renderer/colours.py` (AC: #1)
- [ ] 1.1 Replace `# stub` with full implementation
- [ ] 1.2 Imports: `from planemapper.constants import ALTITUDE_BANDS_FT, ALTITUDE_COLOURS`
- [ ] 1.3 Signature: `def altitude_to_colour(altitude_ft: int) -> tuple[int, int, int]:`
- [ ] 1.4 Iterate `ALTITUDE_BANDS_FT` with `enumerate`; return `ALTITUDE_COLOURS[i]` for the first band where `altitude_ft <= band`
- [x] Task 1: Implement `altitude_to_colour()` in `src/planemapper/renderer/colours.py` (AC: #1)
- [x] 1.1 Replace `# stub` with full implementation
- [x] 1.2 Imports: `from planemapper.constants import ALTITUDE_BANDS_FT, ALTITUDE_COLOURS`
- [x] 1.3 Signature: `def altitude_to_colour(altitude_ft: int) -> tuple[int, int, int]:`
- [x] 1.4 Iterate `ALTITUDE_BANDS_FT` with `enumerate`; return `ALTITUDE_COLOURS[i]` for the first band where `altitude_ft <= band`
- [ ] Task 2: Implement `AircraftType` enum and `classify_aircraft_type()` in `src/planemapper/renderer/icons.py` (AC: #2#7)
- [ ] 2.1 Replace `# stub` with full implementation
- [ ] 2.2 Imports: `from enum import Enum`; `from planemapper.models import Aircraft`
- [ ] 2.3 Define `AircraftType` enum:
- [x] Task 2: Implement `AircraftType` enum and `classify_aircraft_type()` in `src/planemapper/renderer/icons.py` (AC: #2#7)
- [x] 2.1 Replace `# stub` with full implementation
- [x] 2.2 Imports: `from enum import Enum`; `from planemapper.models import Aircraft`
- [x] 2.3 Define `AircraftType` enum:
```python
from enum import Enum
class AircraftType(Enum):
@@ -47,9 +47,9 @@ AC7: **Given** an `Aircraft` with no category and `altitude_ft=38000` (> 30,000f
MILITARY = "military"
UNKNOWN = "unknown"
```
- [ ] 2.4 Define `AIRLINE_PREFIXES` as a `frozenset` of 3-letter ICAO codes: `{"BAW", "EIN", "RYR", "EZY", "THY", "DLH", "AFR", "IBE", "KLM", "UAE", "SWR"}`
- [ ] 2.5 Signature: `def classify_aircraft_type(aircraft: Aircraft) -> AircraftType:`
- [ ] 2.6 Implement priority logic (in order):
- [x] 2.4 Define `AIRLINE_PREFIXES` as a `frozenset` of 3-letter ICAO codes: `{"BAW", "EIN", "RYR", "EZY", "THY", "DLH", "AFR", "IBE", "KLM", "UAE", "SWR"}`
- [x] 2.5 Signature: `def classify_aircraft_type(aircraft: Aircraft) -> AircraftType:`
- [x] 2.6 Implement priority logic (in order):
1. `category == "A7"` → `HELICOPTER`
2. `category` in `{"A1", "A2"}` → `GA_LIGHT`
3. `category` in `{"A3", "A4", "A5"}` → `COMMERCIAL`
@@ -60,9 +60,9 @@ AC7: **Given** an `Aircraft` with no category and `altitude_ft=38000` (> 30,000f
- `altitude_ft >= 30000` → `AIRLINER`
6. Default → `UNKNOWN`
- [ ] Task 3: Write tests in `tests/test_colours.py` (AC: #1)
- [ ] 3.1 Replace `def test_placeholder(): pass` with real tests
- [ ] 3.2 Test boundary values: 0, 1500, 1501, 5000, 5001, 10000, 10001, 20000, 20001, 35000, 35001 — assert each returns the expected colour from `ALTITUDE_COLOURS`
- [x] Task 3: Write tests in `tests/test_colours.py` (AC: #1)
- [x] 3.1 Replace `def test_placeholder(): pass` with real tests
- [x] 3.2 Test boundary values: 0, 1500, 1501, 5000, 5001, 10000, 10001, 20000, 20001, 35000, 35001 — assert each returns the expected colour from `ALTITUDE_COLOURS`
- `0` → `COLOUR_GREEN` (≤ 1500)
- `1500` → `COLOUR_GREEN` (boundary inclusive)
- `1501` → `COLOUR_BLUE` (≤ 5000)
@@ -74,23 +74,23 @@ AC7: **Given** an `Aircraft` with no category and `altitude_ft=38000` (> 30,000f
- `20001` → `COLOUR_BLACK` (≤ 35000)
- `35000` → `COLOUR_BLACK` (boundary inclusive)
- `35001` → `COLOUR_WHITE` (≤ 99999, last band catches all)
- [ ] 3.3 Verify all 6 colours are reachable (assert the union of test return values equals the full `ALTITUDE_COLOURS` set)
- [x] 3.3 Verify all 6 colours are reachable (assert the union of test return values equals the full `ALTITUDE_COLOURS` set)
- [ ] Task 4: Write tests in `tests/test_icons.py` (AC: #2#7)
- [ ] 4.1 Replace `def test_placeholder(): pass` with real tests
- [ ] 4.2 One test function per AC:
- [x] Task 4: Write tests in `tests/test_icons.py` (AC: #2#7)
- [x] 4.1 Replace `def test_placeholder(): pass` with real tests
- [x] 4.2 One test function per AC:
- `test_category_a1_returns_ga_light` — `Aircraft(icao="X", lat=0.0, lon=0.0, category="A1")` → `AircraftType.GA_LIGHT` (AC2)
- `test_ba_callsign_returns_commercial` — `Aircraft(icao="X", lat=0.0, lon=0.0, callsign="BAW123")` → `AircraftType.COMMERCIAL` (AC3)
- `test_category_a7_returns_helicopter` — `Aircraft(icao="X", lat=0.0, lon=0.0, category="A7")` → `AircraftType.HELICOPTER` (AC4)
- `test_no_category_low_altitude_returns_ga_light` — `Aircraft(icao="X", lat=0.0, lon=0.0, altitude_ft=5000)` → `AircraftType.GA_LIGHT` (AC5)
- `test_no_category_mid_altitude_returns_private_jet` — `Aircraft(icao="X", lat=0.0, lon=0.0, altitude_ft=18000)` → `AircraftType.PRIVATE_JET` (AC6)
- `test_no_category_high_altitude_returns_airliner` — `Aircraft(icao="X", lat=0.0, lon=0.0, altitude_ft=38000)` → `AircraftType.AIRLINER` (AC7)
- [ ] 4.3 Use `Aircraft(icao="X", lat=0.0, lon=0.0, ...)` to construct test aircraft; supply only the fields relevant to each AC
- [x] 4.3 Use `Aircraft(icao="X", lat=0.0, lon=0.0, ...)` to construct test aircraft; supply only the fields relevant to each AC
- [ ] Task 5: Run quality gates
- [ ] 5.1 `python -m pytest tests/` — all tests pass
- [ ] 5.2 `python -m ruff check .` — zero violations
- [ ] 5.3 `python -m ruff format --check .` — no formatting issues
- [x] Task 5: Run quality gates
- [x] 5.1 `python -m pytest tests/` — all tests pass
- [x] 5.2 `python -m ruff check .` — zero violations
- [x] 5.3 `python -m ruff format --check .` — no formatting issues
## Implementation Notes
@@ -35,7 +35,7 @@
# - Dev moves story to 'review', then runs code-review (fresh context, different LLM recommended)
generated: 2026-04-22
last_updated: 2026-04-22 # 2-1 done, 2-2 done, 2-3 done, 2-4 ready-for-dev, epic-2 in-progress
last_updated: 2026-04-22 # 2-1 done, 2-2 done, 2-3 done, 2-4 review, epic-2 in-progress
project: planeMapper
project_key: NOKEY
tracking_system: file-system
@@ -56,7 +56,7 @@ development_status:
2-1-aircraft-data-model-and-fetcher: done
2-2-coordinate-projection-and-base-map-loading: done
2-3-home-marker-and-airspace-outlines: done
2-4-altitude-colour-bands-and-aircraft-type-icons: ready-for-dev
2-4-altitude-colour-bands-and-aircraft-type-icons: review
2-5-per-aircraft-drawing: backlog
2-6-stateful-renderer-and-display-interface: backlog
2-7-operational-radar-loop-startup-screen-and-systemd-wiring: backlog