show rainfall data
This commit is contained in:
@@ -21,6 +21,8 @@ type ObservationPoint struct {
|
||||
LightLux *float64 `json:"light_lux,omitempty"`
|
||||
BatteryMV *float64 `json:"battery_mv,omitempty"`
|
||||
SupercapV *float64 `json:"supercap_v,omitempty"`
|
||||
RainMM *float64 `json:"rain_mm,omitempty"`
|
||||
RainStart *int64 `json:"rain_start,omitempty"`
|
||||
}
|
||||
|
||||
type ForecastPoint struct {
|
||||
@@ -66,7 +68,9 @@ func (d *DB) ObservationSeries(ctx context.Context, site, bucket string, start,
|
||||
max(uvi) AS uvi_max,
|
||||
max(light_lux) AS light_lux_max,
|
||||
avg(battery_mv) AS battery_mv_avg,
|
||||
avg(supercap_v) AS supercap_v_avg
|
||||
avg(supercap_v) AS supercap_v_avg,
|
||||
avg(rain_mm) AS rain_mm_avg,
|
||||
max(rain_start) AS rain_start_max
|
||||
FROM observations_ws90
|
||||
WHERE site = $1
|
||||
AND ts >= $2
|
||||
@@ -87,8 +91,10 @@ func (d *DB) ObservationSeries(ctx context.Context, site, bucket string, start,
|
||||
ts time.Time
|
||||
temp, rh, wind, gust sql.NullFloat64
|
||||
dir, uvi, light, battery, supercap sql.NullFloat64
|
||||
rainMM sql.NullFloat64
|
||||
rainStart sql.NullInt64
|
||||
)
|
||||
if err := rows.Scan(&ts, &temp, &rh, &wind, &gust, &dir, &uvi, &light, &battery, &supercap); err != nil {
|
||||
if err := rows.Scan(&ts, &temp, &rh, &wind, &gust, &dir, &uvi, &light, &battery, &supercap, &rainMM, &rainStart); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
points = append(points, ObservationPoint{
|
||||
@@ -102,6 +108,8 @@ func (d *DB) ObservationSeries(ctx context.Context, site, bucket string, start,
|
||||
LightLux: nullFloatPtr(light),
|
||||
BatteryMV: nullFloatPtr(battery),
|
||||
SupercapV: nullFloatPtr(supercap),
|
||||
RainMM: nullFloatPtr(rainMM),
|
||||
RainStart: nullIntPtr(rainStart),
|
||||
})
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
@@ -123,7 +131,9 @@ func (d *DB) LatestObservation(ctx context.Context, site string) (*ObservationPo
|
||||
uvi,
|
||||
light_lux,
|
||||
battery_mv,
|
||||
supercap_v
|
||||
supercap_v,
|
||||
rain_mm,
|
||||
rain_start
|
||||
FROM observations_ws90
|
||||
WHERE site = $1
|
||||
ORDER BY ts DESC
|
||||
@@ -134,8 +144,10 @@ func (d *DB) LatestObservation(ctx context.Context, site string) (*ObservationPo
|
||||
ts time.Time
|
||||
temp, rh, wind, gust sql.NullFloat64
|
||||
dir, uvi, light, battery, supercap sql.NullFloat64
|
||||
rainMM sql.NullFloat64
|
||||
rainStart sql.NullInt64
|
||||
)
|
||||
err := d.Pool.QueryRow(ctx, query, site).Scan(&ts, &temp, &rh, &wind, &gust, &dir, &uvi, &light, &battery, &supercap)
|
||||
err := d.Pool.QueryRow(ctx, query, site).Scan(&ts, &temp, &rh, &wind, &gust, &dir, &uvi, &light, &battery, &supercap, &rainMM, &rainStart)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
@@ -154,6 +166,8 @@ func (d *DB) LatestObservation(ctx context.Context, site string) (*ObservationPo
|
||||
LightLux: nullFloatPtr(light),
|
||||
BatteryMV: nullFloatPtr(battery),
|
||||
SupercapV: nullFloatPtr(supercap),
|
||||
RainMM: nullFloatPtr(rainMM),
|
||||
RainStart: nullIntPtr(rainStart),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -289,3 +303,11 @@ func nullFloatPtr(v sql.NullFloat64) *float64 {
|
||||
val := v.Float64
|
||||
return &val
|
||||
}
|
||||
|
||||
func nullIntPtr(v sql.NullInt64) *int64 {
|
||||
if !v.Valid {
|
||||
return nil
|
||||
}
|
||||
val := v.Int64
|
||||
return &val
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user