This commit is contained in:
2026-01-26 12:46:06 +11:00
parent adaa57f9e2
commit 463ff0d81e
3 changed files with 5 additions and 8 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
test.yaml

View File

@@ -4,8 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"time" "time"
"github.com/jackc/pgx/v5/pgtype"
) )
type InsertWS90Params struct { type InsertWS90Params struct {
@@ -38,8 +36,7 @@ type InsertWS90Params struct {
func (d *DB) InsertWS90(ctx context.Context, p InsertWS90Params) error { func (d *DB) InsertWS90(ctx context.Context, p InsertWS90Params) error {
b, _ := json.Marshal(p.Payload) b, _ := json.Marshal(p.Payload)
var payloadJSON pgtype.JSONB payloadJSON := json.RawMessage(b)
_ = payloadJSON.Set(b)
_, err := d.Pool.Exec(ctx, ` _, err := d.Pool.Exec(ctx, `
INSERT INTO observations_ws90 ( INSERT INTO observations_ws90 (
@@ -90,8 +87,7 @@ type InsertOpenMeteoHourlyParams struct {
func (d *DB) UpsertOpenMeteoHourly(ctx context.Context, p InsertOpenMeteoHourlyParams) error { func (d *DB) UpsertOpenMeteoHourly(ctx context.Context, p InsertOpenMeteoHourlyParams) error {
b, _ := json.Marshal(p.SourcePayload) b, _ := json.Marshal(p.SourcePayload)
var sourceJSON pgtype.JSONB sourceJSON := json.RawMessage(b)
_ = sourceJSON.Set(b)
_, err := d.Pool.Exec(ctx, ` _, err := d.Pool.Exec(ctx, `
INSERT INTO forecast_openmeteo_hourly ( INSERT INTO forecast_openmeteo_hourly (

View File

@@ -40,7 +40,7 @@ func (l *Latest) Update(ts time.Time, p *WS90Payload) {
l.lastTS = ts l.lastTS = ts
l.last = p l.last = p
inc := l.computeRainIncrement(ts, p.RainMM) inc := l.computeRainIncrement(p.RainMM)
// Track last hour increments // Track last hour increments
l.rainIncs = append(l.rainIncs, rainIncPoint{ts: ts, mm: inc}) l.rainIncs = append(l.rainIncs, rainIncPoint{ts: ts, mm: inc})
@@ -75,7 +75,7 @@ func localMidnight(t time.Time) time.Time {
// computeRainIncrement returns the “incremental rain” in mm for this sample, // computeRainIncrement returns the “incremental rain” in mm for this sample,
// regardless of whether the incoming rain_mm is cumulative or incremental. // regardless of whether the incoming rain_mm is cumulative or incremental.
func (l *Latest) computeRainIncrement(ts time.Time, rainMM float64) float64 { func (l *Latest) computeRainIncrement(rainMM float64) float64 {
// First sample: we cant infer anything yet // First sample: we cant infer anything yet
if l.lastRainMM == nil { if l.lastRainMM == nil {
l.lastRainMM = &rainMM l.lastRainMM = &rainMM