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>
61 lines
2.3 KiB
Go
61 lines
2.3 KiB
Go
package weather
|
|
|
|
import "time"
|
|
|
|
// Wind represents wind information
|
|
type Wind struct {
|
|
Direction int `json:"direction"` // Degrees
|
|
Speed int `json:"speed"` // KT or MPS
|
|
Gust int `json:"gust,omitempty"` // Gust speed
|
|
Variable bool `json:"variable,omitempty"` // VRB
|
|
VariableFrom int `json:"variable_from,omitempty"` // Variable wind from direction
|
|
VariableTo int `json:"variable_to,omitempty"` // Variable wind to direction
|
|
Unit string `json:"unit"` // "KT", "MPS"
|
|
}
|
|
|
|
// Visibility represents visibility information
|
|
type Visibility struct {
|
|
Distance float64 `json:"distance"` // Meters or statute miles
|
|
Unit string `json:"unit"` // "M", "SM"
|
|
Direction string `json:"direction,omitempty"` // Directional visibility
|
|
Modifier string `json:"modifier,omitempty"` // +, -, M, P
|
|
}
|
|
|
|
// Cloud represents cloud information
|
|
type Cloud struct {
|
|
Type string `json:"type"` // FEW, SCT, BKN, OVC, VV
|
|
Altitude int `json:"altitude"` // Feet
|
|
Modifier string `json:"modifier,omitempty"` // CB, TCU
|
|
}
|
|
|
|
// Temperature represents temperature or dewpoint
|
|
type Temperature struct {
|
|
Value float64 `json:"value"`
|
|
Unit string `json:"unit"` // "C"
|
|
}
|
|
|
|
// Altimeter represents altimeter setting
|
|
type Altimeter struct {
|
|
Value float64 `json:"value"`
|
|
Unit string `json:"unit"` // "QNH" (hPa), "A" (inHg)
|
|
}
|
|
|
|
// Phenomenon represents weather phenomenon
|
|
type Phenomenon struct {
|
|
Intensity string `json:"intensity,omitempty"` // -, +
|
|
Descriptor string `json:"descriptor,omitempty"` // MI, BC, PR, TS, etc.
|
|
Weather string `json:"weather"` // RA, SN, FG, etc.
|
|
}
|
|
|
|
// TafPeriod represents a TAF period (FM, TEMPO, BECMG, or main forecast)
|
|
type TafPeriod struct {
|
|
Type string `json:"type"` // "FM", "TEMPO", "BECMG", "MAIN"
|
|
ValidFrom time.Time `json:"valid_from,omitempty"`
|
|
ValidTo time.Time `json:"valid_to,omitempty"`
|
|
Wind *Wind `json:"wind,omitempty"`
|
|
Visibility *Visibility `json:"visibility,omitempty"`
|
|
Clouds []Cloud `json:"clouds,omitempty"`
|
|
Phenomena []Phenomenon `json:"phenomena,omitempty"`
|
|
Probability int `json:"probability,omitempty"` // PROB30, PROB40
|
|
}
|