From e7f86623471ec1569736b4d39d04ec3976c02095 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 27 Jun 2023 19:21:24 +0200 Subject: [PATCH] Update precision constants in station.go Refined precision constants in station.go for better clarity and maintainability. Comment descriptions for each precision level have been expanded for better understanding. Strings have been introduced as constants to represent each precision level, enhancing code readability and preventing inconsistencies. Changes are also done to the UnmarshalJSON() and String() of the Precision type to use these new string constants improving overall code quality. --- station.go | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/station.go b/station.go index 1ad46f4..436f12c 100644 --- a/station.go +++ b/station.go @@ -18,16 +18,42 @@ import ( const DefaultRadius int = 10 const ( - // PrecisionSuperHigh represents data of < ~4km resolution + // PrecisionSuperHigh represents the precision level of data corresponding + // to a resolution of less than or approximately equal to 4 kilometers. + // This is the highest level of precision, usually associated with highly + // detailed measurements or observations. PrecisionSuperHigh Precision = iota - // PrecisionHigh represents data of >= ~4km but < ~10km resolution + // PrecisionHigh represents the precision level of data corresponding to a + // resolution between 4 kilometers and 10 kilometers. This is a high precision + // level, suitable for most operational needs that require a balance between + // detail and processing requirements. PrecisionHigh - // PrecisionStandard represents data of >= ~10km resolution + // PrecisionStandard represents the precision level of data corresponding to + // a resolution of 10 kilometers or more. This is the standard level of + // precision, generally used for large-scale analysis and modeling. PrecisionStandard - // PrecisionUnknown is weather station of unknown precision + // PrecisionUnknown is used when the precision level of a weather station + // is unknown. This constant can be used as a placeholder when the resolution + // data is not available. PrecisionUnknown ) +// Precision levels defined as strings to allow for clear, consistent +// use throughout the application. +const ( + // PrecisionStringSuperHigh represents the super high precision level string. + PrecisionStringSuperHigh = "SUPER_HIGH" + + // PrecisionStringHigh represents the high precision level string. + PrecisionStringHigh = "HIGH" + + // PrecisionStringStandard represents the standard precision level string. + PrecisionStringStandard = "STANDARD" + + // PrecisionStringUnknown represents an unknown precision level string. + PrecisionStringUnknown = "UNKNOWN" +) + var ( // ErrRadiusTooSmall is returned if a given radius value is too small ErrRadiusTooSmall = errors.New("given radius is too small") @@ -156,12 +182,12 @@ func (c *Client) StationSearchByCoordinatesWithinRadius(la, lo float64, ra int) func (p *Precision) UnmarshalJSON(s []byte) error { v := string(s) v = strings.ReplaceAll(v, `"`, ``) - switch strings.ToLower(v) { - case "super_high": + switch strings.ToUpper(v) { + case PrecisionStringSuperHigh: *p = PrecisionSuperHigh - case "high": + case PrecisionStringHigh: *p = PrecisionHigh - case "standard": + case PrecisionStringStandard: *p = PrecisionStandard default: *p = PrecisionUnknown @@ -173,14 +199,14 @@ func (p *Precision) UnmarshalJSON(s []byte) error { func (p *Precision) String() string { switch *p { case PrecisionSuperHigh: - return "SUPER_HIGH" + return PrecisionStringSuperHigh case PrecisionHigh: - return "HIGH" + return PrecisionStringHigh case PrecisionStandard: - return "STANDARD" + return PrecisionStringStandard case PrecisionUnknown: - return "UNKNOWN" + return PrecisionStringUnknown default: - return "UNKNOWN" + return PrecisionStringUnknown } }