1
0
Fork 0
mirror of https://github.com/Luzifer/go-metar.git synced 2024-10-18 05:04:21 +00:00

Added KtsToBft helper function

This commit is contained in:
Knut Ahlers 2016-05-21 13:48:30 +02:00
parent 90abe311d0
commit b2652f54be
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 73 additions and 20 deletions

53
helpers.go Normal file
View file

@ -0,0 +1,53 @@
package metar
// InHgTohPa converts "inch of mercury" to "hectopascal"
func InHgTohPa(inHg float64) float64 {
return inHg * 33.8638866667
}
// KtsToMs converts "knots" to "meters per second"
func KtsToMs(kts float64) float64 {
return kts * 0.514444
}
// KtsToBft converts "knots" to "bft"
func KtsToBft(kts float64) int {
switch {
case kts < 1:
return 0
case kts < 4:
return 1
case kts < 7:
return 2
case kts < 11:
return 3
case kts < 16:
return 4
case kts < 22:
return 5
case kts < 28:
return 6
case kts < 34:
return 7
case kts < 41:
return 8
case kts < 48:
return 9
case kts < 56:
return 10
case kts < 64:
return 11
default:
return 12
}
}
// StatMileToKm converts "statute miles" to "kilometers"
func StatMileToKm(sm float64) float64 {
return sm * 1.60934
}
// MbTohPa converts "millibar" to "hectopascal"
func MbTohPa(mb float64) float64 {
return mb * 0.1
}

20
helpers_test.go Normal file
View file

@ -0,0 +1,20 @@
package metar_test
import (
. "github.com/Luzifer/go-metar"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Helpers", func() {
It("should convert values into expected results", func() {
Expect(KtsToMs(1)).To(Equal(0.514444))
Expect(InHgTohPa(1)).To(Equal(33.8638866667))
Expect(StatMileToKm(1)).To(Equal(1.60934))
Expect(MbTohPa(1)).To(Equal(0.1))
Expect(KtsToBft(5)).To(Equal(2))
})
})

View file

@ -107,23 +107,3 @@ func FetchCurrentStationWeather(station string) (*Result, error) {
return &r.Data.Results[0], nil return &r.Data.Results[0], nil
} }
// InHgTohPa converts "inch of mercury" to "hectopascal"
func InHgTohPa(inHg float64) float64 {
return inHg * 33.8638866667
}
// KtsToMs converts "knots" to "meters per second"
func KtsToMs(kts float64) float64 {
return kts * 0.514444
}
// StatMileToKm converts "statute miles" to "kilometers"
func StatMileToKm(sm float64) float64 {
return sm * 1.60934
}
// MbTohPa converts "millibar" to "hectopascal"
func MbTohPa(mb float64) float64 {
return mb * 0.1
}