Skip to content

Commit

Permalink
forecast history needs a tag for each forecast because otherwise it o…
Browse files Browse the repository at this point in the history
…verwrites.
  • Loading branch information
Ted Pearson committed Sep 3, 2020
1 parent 8089ebd commit 1fa6c58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 7 additions & 3 deletions influx/influx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/tedpearson/weather2influxdb/weather"
"log"
"reflect"
"strconv"
"time"
)

Expand All @@ -28,7 +29,7 @@ type WriteOptions struct {
ForecastSource string
MeasurementName string
Location string
ForecastTime int64
ForecastTime *int64
}

func New(config Config) Writer {
Expand All @@ -54,8 +55,11 @@ func makePoint(record weather.Record, options WriteOptions) *write.Point {
p := influxdb2.NewPointWithMeasurement(options.MeasurementName).
AddTag("source", options.ForecastSource).
AddTag("location", options.Location).
SetTime(record.Time).
AddField("forecast_time", options.ForecastTime)
SetTime(record.Time)
if options.ForecastTime != nil {
p.AddField("forecast_time", *options.ForecastTime)
p.AddTag("forecast_time_tag", strconv.FormatInt(*options.ForecastTime, 10))
}
time.Now().UnixNano()
for i := 0; i < e.NumField(); i++ {
name := strcase.ToSnake(e.Type().Field(i).Name)
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func RunForecast(config Config, source string, location Location, writer influx.
ForecastSource: source,
MeasurementName: config.Forecast.MeasurementName,
Location: location.Name,
ForecastTime: forecastTime,
}, records)
handleError(err)
if config.Forecast.History.Enabled {
Expand All @@ -57,7 +56,7 @@ func RunForecast(config Config, source string, location Location, writer influx.
ForecastSource: source,
MeasurementName: config.Forecast.History.MeasurementName,
Location: location.Name,
ForecastTime: forecastTime,
ForecastTime: &forecastTime,
}, records)
handleError(err)
}
Expand Down

0 comments on commit 1fa6c58

Please sign in to comment.