diff --git a/clouds/clouds.go b/clouds/clouds.go index 0e2c39b..e200b18 100644 --- a/clouds/clouds.go +++ b/clouds/clouds.go @@ -10,13 +10,13 @@ import ( // Cloud - cloud representation type Cloud struct { - Type CloudType + Type CloudType `json:"cloud_type"` // the height is stored in hundreds of feet, as Flight Level - height int - HeightNotDefined bool - Cumulonimbus bool - ToweringCumulus bool - CBNotDefined bool + Height int `json:"height"` + HeightNotDefined bool `json:"height_not_defined"` + Cumulonimbus bool `json:"cumulonimbus"` + ToweringCumulus bool `json:"towering_cumulus"` + CBNotDefined bool `json:"cb_not_defined"` } // Clouds - an array of heights and types of clouds @@ -50,12 +50,12 @@ const ( // HeightM - returns height above surface of the lower base of cloudiness in meters func (cl Cloud) HeightM() int { - return cnv.FtToM(cl.height * 100) + return cnv.FtToM(cl.Height * 100) } // HeightFt - returns height above surface of the lower base of cloudiness in feet func (cl Cloud) HeightFt() int { - return cl.height * 100 + return cl.Height * 100 } // ParseCloud - identify and parses the representation of cloudiness in the string @@ -74,7 +74,7 @@ func ParseCloud(token string) (cl Cloud, ok bool) { } if matches[2] != "///" && matches[2] != "" { - cl.height, _ = strconv.Atoi(matches[2]) + cl.Height, _ = strconv.Atoi(matches[2]) } else { cl.HeightNotDefined = true } diff --git a/clouds/clouds_test.go b/clouds/clouds_test.go index 9a35e40..cc0ea7d 100644 --- a/clouds/clouds_test.go +++ b/clouds/clouds_test.go @@ -48,14 +48,14 @@ func TestParseCloud(t *testing.T) { Convey("height in feet must calculated correctly", func() { for _, pair := range tests { cloud, _ := ParseCloud(pair.input) - So(cloud.HeightFt(), ShouldEqual, pair.expected.height*100) + So(cloud.HeightFt(), ShouldEqual, pair.expected.Height*100) } }) Convey("height in meters must calculated correctly", func() { for _, pair := range tests { cloud, _ := ParseCloud(pair.input) - So(cloud.HeightM(), ShouldEqual, FtToM(pair.expected.height*100)) + So(cloud.HeightM(), ShouldEqual, FtToM(pair.expected.Height*100)) } }) diff --git a/phenomena/phenomena.go b/phenomena/phenomena.go index 01faa6e..a058e00 100644 --- a/phenomena/phenomena.go +++ b/phenomena/phenomena.go @@ -26,9 +26,9 @@ const ( // Phenomenon - Weather phenomenon with intensity/proximity indicator type Phenomenon struct { // proximity indicator - Vicinity bool - Intensity Intensity - Abbreviation string + Vicinity bool `json:"vicinity"` + Intensity Intensity `json:"intensity"` + Abbreviation string `json:"abbreviation"` } // Phenomena - List of current or past weather events diff --git a/trend.go b/trend.go index b7380ab..2b5ec85 100644 --- a/trend.go +++ b/trend.go @@ -1,6 +1,7 @@ package metar import ( + "fmt" "log" "regexp" "strings" @@ -26,18 +27,22 @@ const ( // Trend - forecast of changes for a specified period type Trend struct { - Type TypeTrend - Probability int // used only in TAFs. Maybe only 30 or 40. The PROBdd group is not used in conjunction with BECMG and FM + Type TypeTrend `json:"type_trend"` + Probability int `json:"probability"` + // used only in TAFs. Maybe only 30 or 40. The PROBdd group is not used in conjunction with BECMG and FM // In case of in metar use values indicated time of changes. hh:mm (BECMG FM1030 TL1130) // In TAFs used from - until fields as date/time. ddhh/ddhh (TEMPO 2208/2218) - FM time.Time // FroM (time) - TL time.Time // unTiL (time) - AT time.Time // AT time + FM time.Time `json:"from_time"` + // FroM (time) + TL time.Time `json:"till_time"` + // unTiL (time) + AT time.Time `json:"at_time"` + // AT time v.Visibility - VerticalVisibility int - VerticalVisibilityNotDefined bool + VerticalVisibility int `json:"vertical_visibility"` + VerticalVisibilityNotDefined bool `json:"vertical_visibility_not_defined"` wind.Wind - CAVOK bool + CAVOK bool `json:"cavok"` ph.Phenomena clouds.Clouds } @@ -127,6 +132,7 @@ func (trend *Trend) setProbability(input string) bool { } func (trend *Trend) setPeriodOfChanges(input string) (ok bool) { + fmt.Println(input) switch input[0:2] { case "AT": timeofaction, err := time.Parse("200601021504", CurYearStr+CurMonthStr+CurDayStr+input[2:]) diff --git a/visibility/visibility.go b/visibility/visibility.go index e3216be..b6a9b3e 100644 --- a/visibility/visibility.go +++ b/visibility/visibility.go @@ -23,17 +23,19 @@ const ( // Distance in units of measure type Distance struct { // By default, meters. Or feet in US RVR. Both integer - Value int + Value int `json:"value"` // Used only for horizontal visibility in miles - FractionValue float64 - Unit + FractionValue float64 `json:"fraction_value"` + Unit `json:"unit"` } // BaseVisibility - the basis of visibility: one measurement type BaseVisibility struct { Distance - AboveMax bool // more than reported value (P5000, P6SM...) - BelowMin bool // less than reported value (M1/4SM, M0050...) + // more than reported value (P5000, P6SM...) + AboveMax bool `json:"above_max"` + // less than reported value (M1/4SM, M0050...) + BelowMin bool `json:"below_min"` } // Visibility - prevailing visibility @@ -41,7 +43,7 @@ type Visibility struct { BaseVisibility // sector visibility LowerDistance Distance - LowerDirection string + LowerDirection string `json:"lower_direction"` } // Meters - returns the distance in meters diff --git a/wind/wind.go b/wind/wind.go index 48d3175..053c6eb 100644 --- a/wind/wind.go +++ b/wind/wind.go @@ -23,36 +23,36 @@ const ( // Wind - wind on surface representation type Wind struct { - WindDirection int - speed int - gustsSpeed int - Variable bool - VariableFrom int - VariableTo int - Above50MPS bool - SpeedNotDefined bool - DirectionNotDefined bool - unit speedUnit + WindDirection int `json:"wind_direction"` + Speed int `json:"speed"` + GustsSpeed int `json:"gusts_speed"` + Variable bool `json:"variable"` + VariableFrom int `json:"variable_from"` + VariableTo int `json:"variable_to"` + Above50MPS bool `json:"above50mps"` + SpeedNotDefined bool `json:"speed_not_defined"` + DirectionNotDefined bool `json:"direction_not_defined"` + unit speedUnit `json:"unit"` } // SpeedKt - returns wind speed in knots. In Russian messages, the speed is specified in m/s, but it makes sense to receive it in knots for aviation purposes func (w *Wind) SpeedKt() (speed int) { - return getSpeedValue(w.speed, w.unit, KT) + return getSpeedValue(w.Speed, w.unit, KT) } // SpeedMps - returns wind speed in meters per second. func (w *Wind) SpeedMps() (speed int) { - return getSpeedValue(w.speed, w.unit, MPS) + return getSpeedValue(w.Speed, w.unit, MPS) } // GustsSpeedKt - returns gusts speed in knots. func (w *Wind) GustsSpeedKt() (speed int) { - return getSpeedValue(w.gustsSpeed, w.unit, KT) + return getSpeedValue(w.GustsSpeed, w.unit, KT) } // GustsSpeedMps - returns gusts speed in meters per second. func (w *Wind) GustsSpeedMps() (speed int) { - return getSpeedValue(w.gustsSpeed, w.unit, MPS) + return getSpeedValue(w.GustsSpeed, w.unit, MPS) } func getSpeedValue(speed int, unit speedUnit, needUnit speedUnit) (result int) { @@ -91,10 +91,10 @@ func (w *Wind) ParseWind(token string) (tokensused int) { w.Above50MPS = matches[2] != "" w.SpeedNotDefined = matches[3] == "//" if matches[3] != "" && !w.SpeedNotDefined { - w.speed, _ = strconv.Atoi(matches[3]) + w.Speed, _ = strconv.Atoi(matches[3]) } if matches[4] != "" { - w.gustsSpeed, _ = strconv.Atoi(matches[4][1:]) + w.GustsSpeed, _ = strconv.Atoi(matches[4][1:]) } w.unit = speedUnit(matches[5]) // Two tokens have been used diff --git a/wind/wind_test.go b/wind/wind_test.go index 96d2d29..017744f 100644 --- a/wind/wind_test.go +++ b/wind/wind_test.go @@ -46,14 +46,14 @@ func TestParseWind(t *testing.T) { wnd.ParseWind(pair.input) switch wnd.unit { case KPH, KMH: - So(wnd.SpeedMps(), ShouldAlmostEqual, KphToMps(wnd.speed), .5) - So(wnd.GustsSpeedMps(), ShouldAlmostEqual, KphToMps(wnd.gustsSpeed), .5) + So(wnd.SpeedMps(), ShouldAlmostEqual, KphToMps(wnd.Speed), .5) + So(wnd.GustsSpeedMps(), ShouldAlmostEqual, KphToMps(wnd.GustsSpeed), .5) case KT: - So(wnd.SpeedMps(), ShouldAlmostEqual, KtsToMps(float64(wnd.speed)), .5) - So(wnd.GustsSpeedMps(), ShouldAlmostEqual, KtsToMps(float64(wnd.gustsSpeed)), .5) + So(wnd.SpeedMps(), ShouldAlmostEqual, KtsToMps(float64(wnd.Speed)), .5) + So(wnd.GustsSpeedMps(), ShouldAlmostEqual, KtsToMps(float64(wnd.GustsSpeed)), .5) case MPS: - So(wnd.SpeedMps(), ShouldEqual, wnd.speed) - So(wnd.GustsSpeedMps(), ShouldEqual, wnd.gustsSpeed) + So(wnd.SpeedMps(), ShouldEqual, wnd.Speed) + So(wnd.GustsSpeedMps(), ShouldEqual, wnd.GustsSpeed) } } }) @@ -64,14 +64,14 @@ func TestParseWind(t *testing.T) { wnd.ParseWind(pair.input) switch wnd.unit { case MPS: - So(wnd.SpeedKt(), ShouldAlmostEqual, MpsToKts(float64(wnd.speed)), .5) - So(wnd.GustsSpeedKt(), ShouldAlmostEqual, MpsToKts(float64(wnd.gustsSpeed)), .5) + So(wnd.SpeedKt(), ShouldAlmostEqual, MpsToKts(float64(wnd.Speed)), .5) + So(wnd.GustsSpeedKt(), ShouldAlmostEqual, MpsToKts(float64(wnd.GustsSpeed)), .5) case KPH, KMH: - So(wnd.SpeedKt(), ShouldAlmostEqual, KphToKts(wnd.speed), .5) - So(wnd.GustsSpeedKt(), ShouldAlmostEqual, KphToKts(wnd.gustsSpeed), .5) + So(wnd.SpeedKt(), ShouldAlmostEqual, KphToKts(wnd.Speed), .5) + So(wnd.GustsSpeedKt(), ShouldAlmostEqual, KphToKts(wnd.GustsSpeed), .5) case KT: - So(wnd.SpeedKt(), ShouldEqual, wnd.speed) - So(wnd.GustsSpeedKt(), ShouldEqual, wnd.gustsSpeed) + So(wnd.SpeedKt(), ShouldEqual, wnd.Speed) + So(wnd.GustsSpeedKt(), ShouldEqual, wnd.GustsSpeed) } }