Added a /conditions/current endpoint with computed best-guess values for current conditions
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -9,10 +9,15 @@ import (
|
||||
type Converter interface {
|
||||
TemperatureCToOutput(celsius *float64) *float64
|
||||
SpeedKmhToOutput(kmh *float64) *float64
|
||||
System() string
|
||||
}
|
||||
|
||||
type USConverter struct{}
|
||||
|
||||
func (USConverter) System() string {
|
||||
return "us"
|
||||
}
|
||||
|
||||
func (USConverter) TemperatureCToOutput(celsius *float64) *float64 {
|
||||
if celsius == nil {
|
||||
return nil
|
||||
@@ -29,6 +34,28 @@ func (USConverter) SpeedKmhToOutput(kmh *float64) *float64 {
|
||||
return &mph
|
||||
}
|
||||
|
||||
type MetricConverter struct{}
|
||||
|
||||
func (MetricConverter) System() string {
|
||||
return "metric"
|
||||
}
|
||||
|
||||
func (MetricConverter) TemperatureCToOutput(celsius *float64) *float64 {
|
||||
return clone(celsius)
|
||||
}
|
||||
|
||||
func (MetricConverter) SpeedKmhToOutput(kmh *float64) *float64 {
|
||||
return clone(kmh)
|
||||
}
|
||||
|
||||
func clone(v *float64) *float64 {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
out := *v
|
||||
return &out
|
||||
}
|
||||
|
||||
func round(v float64, precision int) float64 {
|
||||
pow := math.Pow(10, float64(precision))
|
||||
return math.Round(v*pow) / pow
|
||||
|
||||
Reference in New Issue
Block a user