2023-05-22 17:13:36 +02:00
|
|
|
// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package meteologix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Precipitation is a type wrapper of an WeatherData for holding precipitation
|
|
|
|
// values in WeatherData
|
|
|
|
type Precipitation WeatherData
|
|
|
|
|
|
|
|
// IsAvailable returns true if an Precipitation value was
|
|
|
|
// available at time of query
|
2023-05-23 20:00:42 +02:00
|
|
|
func (p Precipitation) IsAvailable() bool {
|
|
|
|
return !p.na
|
2023-05-22 17:13:36 +02:00
|
|
|
}
|
|
|
|
|
2023-06-27 18:57:33 +02:00
|
|
|
// DateTime returns the DateTime when the Precipitation value was recorded
|
2023-05-23 20:00:42 +02:00
|
|
|
func (p Precipitation) DateTime() time.Time {
|
|
|
|
return p.dt
|
2023-05-22 17:13:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// String satisfies the fmt.Stringer interface for the Precipitation type
|
2023-05-23 20:00:42 +02:00
|
|
|
func (p Precipitation) String() string {
|
2023-05-24 22:00:47 +02:00
|
|
|
return fmt.Sprintf("%.1fmm", p.fv)
|
2023-05-23 20:00:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Source returns the Source of Precipitation
|
|
|
|
// If the Source is not available it will return SourceUnknown
|
|
|
|
func (p Precipitation) Source() Source {
|
|
|
|
return p.s
|
2023-05-22 17:13:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Value returns the float64 value of an Precipitation
|
2023-06-26 12:21:36 +02:00
|
|
|
// If the Precipitation is not available in the WeatherData
|
2023-05-22 17:13:36 +02:00
|
|
|
// Vaule will return math.NaN instead.
|
2023-05-23 20:00:42 +02:00
|
|
|
func (p Precipitation) Value() float64 {
|
|
|
|
if p.na {
|
2023-05-22 17:13:36 +02:00
|
|
|
return math.NaN()
|
|
|
|
}
|
2023-05-24 22:00:47 +02:00
|
|
|
return p.fv
|
2023-05-22 17:13:36 +02:00
|
|
|
}
|