Implement comprehensive weather parsing capabilities following Clean Architecture principles with composite parser pattern for routing between aviation and weather messages. ## Features Added - Weather report parsing (METAR, SPECI, TAF) - Composite parser pattern for message routing - Lenient parsing with warnings for unrecognized tokens - Support for PROB and RMK sections in TAF - Rich domain modeling with typed weather elements ## Architecture **Domain Layer** (internal/domain/weather/): - WeatherMessage interface with Metar and Taf implementations - Weather elements: Wind, Visibility, Cloud, Temperature, Altimeter, Phenomenon - Domain errors: ErrInvalidFormat, ErrMissingStation, ErrMissingTime **Port Layer** (internal/port/weather_parser.go): - WeatherParser interface with CanParse and Parse methods **Adapter Layer** (internal/adapter/parser/weather/): - WeatherParserImpl with classification and parsing logic - Comprehensive regex patterns for weather elements - METAR/SPECI parser with element extraction - TAF parser with period handling (FM, TEMPO, BECMG, PROB) - Helper functions for time parsing and unit conversions **Composite Parser** (internal/adapter/parser/composite.go): - Routes weather reports to weather parser - Falls back to aviation parser for telegrams - Converts WeatherMessage to ParsedTelegram format ## Integration - Updated ProvideParser to create composite parser with weather parser - Added weather parser to Wire DI configuration - Updated processor_bench_test.go for weather parser integration - Documentation added in docs/weather-parser.md ## Testing - 29 comprehensive tests for weather parsing (all passing) - Tests for classification, METAR, SPECI, TAF, and composite routing - Benchmark compatibility maintained ## Fixes Applied - TAF PROB parsing: Include PROB/RMK in special section detection - Composite test: Updated to use properly formatted AFTN telegram - Linter issues: Switch statement refactor, removed unused patterns - Ineffective break statement fixed in TAF parser ## Coverage ~1,743 lines of new code with: - Complete METAR/SPECI parsing - TAF parsing with period support - Lenient error handling with warnings - Unit conversions and time utilities 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
122 lines
4.0 KiB
Markdown
122 lines
4.0 KiB
Markdown
# Weather Parser Documentation
|
|
|
|
## Overview
|
|
|
|
The weather parser module provides parsing capabilities for aviation weather reports including METAR, SPECI, and TAF messages. It is integrated into the system using a composite parser pattern that routes weather reports to the weather parser while maintaining backward compatibility with existing aviation telegram parsing.
|
|
|
|
## Architecture
|
|
|
|
The weather parser follows Clean Architecture principles:
|
|
|
|
- **Domain Layer** (`internal/domain/weather/`): Core domain types and interfaces
|
|
- **Port Layer** (`internal/port/weather_parser.go`): Parser interface definition
|
|
- **Adapter Layer** (`internal/adapter/parser/weather/`): Parser implementation
|
|
- **Composite Parser** (`internal/adapter/parser/composite.go`): Routes messages to appropriate parser
|
|
|
|
## Supported Report Types
|
|
|
|
### METAR (Aviation Routine Weather Report)
|
|
Standard hourly weather observations from airports.
|
|
|
|
**Example:**
|
|
```
|
|
METAR KJFK 251200Z 35012KT 10SM FEW020 25/18 Q1013=
|
|
```
|
|
|
|
### SPECI (Aviation Selected Special Weather Report)
|
|
Special weather observations issued when conditions change significantly.
|
|
|
|
**Example:**
|
|
```
|
|
SPECI KORD 251215Z 27015G25KT 5SM -RA BKN030 OVC050 20/18 A2992=
|
|
```
|
|
|
|
### TAF (Terminal Aerodrome Forecast)
|
|
Forecast weather conditions for airports, typically valid for 24-30 hours.
|
|
|
|
**Example:**
|
|
```
|
|
TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020 FM251800 36015KT 10SM SCT030=
|
|
```
|
|
|
|
## Parsed Elements
|
|
|
|
### Core Elements
|
|
|
|
- **Station**: 4-letter ICAO airport code
|
|
- **Time**: Issue/observation time (DDHHmmZ format)
|
|
- **Wind**: Direction, speed, gusts, variable conditions
|
|
- **Visibility**: Distance, unit (meters or statute miles), directional visibility
|
|
- **Clouds**: Type (FEW/SCT/BKN/OVC/VV), altitude, modifiers (CB/TCU)
|
|
- **Temperature/Dewpoint**: Temperature in Celsius
|
|
- **Altimeter**: Pressure setting (QNH in hPa or A in inHg)
|
|
- **Weather Phenomena**: Intensity, descriptors, weather codes
|
|
|
|
### TAF-Specific Elements
|
|
|
|
- **Validity Period**: Forecast valid from/to times
|
|
- **Periods**: Main forecast, FM (from), TEMPO (temporary), BECMG (becoming)
|
|
- **Probability**: PROB30, PROB40 for uncertain conditions
|
|
|
|
## Error Handling
|
|
|
|
The parser uses a lenient approach:
|
|
|
|
- **Unrecognized tokens**: Recorded in `warnings` array, parsing continues
|
|
- **Missing required fields**: Returns appropriate domain errors
|
|
- **Invalid format**: Returns `ErrInvalidFormat`
|
|
|
|
This ensures that partial parsing is possible even when some elements are not recognized.
|
|
|
|
## Usage
|
|
|
|
The weather parser is automatically integrated via the composite parser. No special configuration is required.
|
|
|
|
### Message Flow
|
|
|
|
1. Raw message received
|
|
2. Composite parser checks if message is a weather report
|
|
3. If weather report: parsed by weather parser
|
|
4. If not: parsed by aviation parser (existing behavior)
|
|
5. Parsed result stored in `telegrams` table with `category` = "METAR"/"SPECI"/"TAF"
|
|
6. Structured data stored in `body_data` JSONB field
|
|
|
|
### Database Storage
|
|
|
|
Weather reports are stored in the existing `telegrams` table:
|
|
|
|
- `category`: "METAR", "SPECI", or "TAF"
|
|
- `body_data`: JSONB containing structured weather data
|
|
- `content`: Original raw text
|
|
- `message_id`: Generated as `{station}-{issue_time}`
|
|
|
|
## Testing
|
|
|
|
Test files are located in `internal/adapter/parser/weather/`:
|
|
|
|
- `classifier_test.go`: Tests report type classification
|
|
- `metar_parser_test.go`: Tests METAR/SPECI parsing
|
|
- `taf_parser_test.go`: Tests TAF parsing
|
|
- `composite_test.go`: Tests composite parser routing
|
|
|
|
Run tests:
|
|
```bash
|
|
go test ./internal/adapter/parser/weather/... -v
|
|
```
|
|
|
|
## Limitations and Future Enhancements
|
|
|
|
Current implementation covers core METAR/TAF elements. Future enhancements may include:
|
|
|
|
- Runway Visual Range (RVR) parsing
|
|
- More comprehensive weather phenomenon codes
|
|
- Enhanced TAF period parsing
|
|
- Additional METAR modifiers
|
|
- Station metadata integration
|
|
|
|
## References
|
|
|
|
- [ICAO Annex 3: Meteorological Service for International Air Navigation](https://www.icao.int/safety/meteorology/pages/annex-3.aspx)
|
|
- [WMO Manual on Codes](https://library.wmo.int/index.php?lvl=notice_display&id=13617)
|
|
|