forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeseries.go
40 lines (32 loc) · 826 Bytes
/
timeseries.go
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
package provider
import (
"context"
"encoding/json"
"time"
"github.com/evcc-io/evcc/api"
"github.com/jinzhu/now"
)
type timeseriesProvider struct{}
func init() {
registry.AddCtx("timeseries", TimeSeriesFromConfig)
}
// TimeSeriesFromConfig creates timeseries provider
func TimeSeriesFromConfig(_ context.Context, _ map[string]interface{}) (Provider, error) {
return new(timeseriesProvider), nil
}
var _ StringProvider = (*timeseriesProvider)(nil)
func (p *timeseriesProvider) StringGetter() (func() (string, error), error) {
return func() (string, error) {
res := make(api.Rates, 48)
ts := now.BeginningOfHour()
for i := 0; i < 48; i++ {
res[i] = api.Rate{
Start: ts,
End: ts.Add(time.Hour),
}
ts = ts.Add(time.Hour)
}
b, err := json.Marshal(res)
return string(b), err
}, nil
}