Add report type

This commit is contained in:
Elara 2023-09-23 18:16:18 -07:00
parent 15be73cbc5
commit cf76638b8a
6 changed files with 32 additions and 1 deletions

View File

@ -1,5 +1,16 @@
package taf package taf
func convertReportType(s string) ReportType {
switch s {
case "AMD":
return Amended
case "COR":
return Corrected
default:
return ""
}
}
func convertSkyConditionType(s string) SkyConditionType { func convertSkyConditionType(s string) SkyConditionType {
switch s { switch s {
case "FEW": case "FEW":

View File

@ -5,7 +5,8 @@ import (
) )
var lex = lexer.MustSimple([]lexer.SimpleRule{ var lex = lexer.MustSimple([]lexer.SimpleRule{
{Name: "header", Pattern: `TAF (AMD|COR)? ?`}, {Name: "header", Pattern: `TAF ?`},
{Name: "Type", Pattern: "AMD|COR"},
{Name: "Remark", Pattern: `RMK[^\n]*`}, {Name: "Remark", Pattern: `RMK[^\n]*`},
{Name: "Number", Pattern: `\d+`}, {Name: "Number", Pattern: `\d+`},
{Name: "Modifier", Pattern: `[+-]|VC`}, {Name: "Modifier", Pattern: `[+-]|VC`},

View File

@ -6,6 +6,7 @@ import (
) )
type AST struct { type AST struct {
Type *string `(@Type WS)?`
Items []*Item `@@*` Items []*Item `@@*`
} }

4
taf.go
View File

@ -92,6 +92,10 @@ func DecodeWithOptions(r io.Reader, opts Options) (*Forecast, error) {
fc := &Forecast{} fc := &Forecast{}
out := reflect.ValueOf(fc).Elem() out := reflect.ValueOf(fc).Elem()
if ast.Type != nil {
fc.ReportType = convertReportType(*ast.Type)
}
for _, item := range ast.Items { for _, item := range ast.Items {
switch { switch {
case item.ID != nil: case item.ID != nil:

View File

@ -207,6 +207,7 @@ func TestZGSZ(t *testing.T) {
TEMPO 2204/2208 TSRA SCT020 FEW023CB` TEMPO 2204/2208 TSRA SCT020 FEW023CB`
expected := &Forecast{ expected := &Forecast{
ReportType: Amended,
Identifier: "ZGSZ", Identifier: "ZGSZ",
Airport: airports.Airport{ Airport: airports.Airport{
ICAO: "ZGSZ", ICAO: "ZGSZ",

View File

@ -9,6 +9,9 @@ import (
// Forecast represents a Terminal Aerodrome Forecast (TAF) weather report for a specific airport. // Forecast represents a Terminal Aerodrome Forecast (TAF) weather report for a specific airport.
type Forecast struct { type Forecast struct {
// ReportType represents the type of report this forecast describes.
ReportType ReportType `json:"report_type,omitempty"`
// Identifier holds the ICAO airport identifier for which this forecast was issued. // Identifier holds the ICAO airport identifier for which this forecast was issued.
Identifier string `json:"identifier,omitempty"` Identifier string `json:"identifier,omitempty"`
@ -130,6 +133,16 @@ type Visibility struct {
Unit units.Distance `json:"unit,omitempty"` Unit units.Distance `json:"unit,omitempty"`
} }
// ReportType represents different types of reports.
type ReportType string
const (
// Amended represents a report issued when the previous report is no longer accurate.
Amended ReportType = "Amended"
// Corrected represents a correction to a previous report.
Corrected ReportType = "Corrected"
)
// SkyConditionType represents different types of sky conditions in the forecast. // SkyConditionType represents different types of sky conditions in the forecast.
type SkyConditionType string type SkyConditionType string