aboutsummaryrefslogtreecommitdiffstats
path: root/internal/weather/types.go
blob: 5563bfaa0e520759d9657b9292b930090e6d222a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package weather

import (
	"encoding/json"
	"math"
	"time"
)

// Observation represents a weather observation from a station
type Observation struct {
	Station   int       `json:"station"`
	Parameter string    `json:"parameter"`
	Time      time.Time `json:"time"`
	Value     *float64  `json:"value,omitempty"`
}

// ForecastValue represents a weather forecast value
type ForecastValue struct {
	Location struct {
		Lat float64 `json:"lat"`
		Lon float64 `json:"lon"`
	} `json:"location"`
	Model        string    `json:"model"`
	RunTime      time.Time `json:"run_time"`
	ForecastTime time.Time `json:"forecast_time"`
	Parameter    string    `json:"parameter"`
	Value        *float64  `json:"value,omitempty"`
}

// JSONFloat64 handles NaN values properly in JSON
type JSONFloat64 float64

func (f JSONFloat64) MarshalJSON() ([]byte, error) {
	if math.IsNaN(float64(f)) {
		return []byte("null"), nil
	}
	return json.Marshal(float64(f))
}

// TopicStats tracks message statistics for subscribers
type TopicStats struct {
	MessagesReceived map[string]int
	LastMessageTime  map[string]time.Time
}