Skip to content

Commit

Permalink
chore: fix Entsoe
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Oct 22, 2023
1 parent cd3e03e commit aa4b39d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions tariff/entsoe.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (t *Entsoe) run(done chan error) {
}

// extract desired series
tsdata, err := entsoe.GetTsPriceData(tr.TimeSeries, entsoe.ResolutionHour)
res, err := entsoe.GetTsPriceData(tr.TimeSeries, entsoe.ResolutionHour)
if err != nil {
once.Do(func() { done <- err })
t.log.ERROR.Println(err)
Expand All @@ -160,11 +160,11 @@ func (t *Entsoe) run(done chan error) {
t.mux.Lock()
t.updated = time.Now()

t.data = make(api.Rates, 0, len(tsdata))
for _, r := range tsdata {
t.data = make(api.Rates, 0, len(res))
for _, r := range res {
ar := api.Rate{
Start: r.ValidityStart,
End: r.ValidityEnd,
Start: r.Start,
End: r.End,
Price: t.totalPrice(r.Value),
}
t.data = append(t.data, ar)
Expand Down
18 changes: 9 additions & 9 deletions tariff/entsoe/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ func DayAheadPricesRequest(domain string, duration time.Duration) *http.Request
return req
}

// RateData defines the per-unit Value over a period of time spanning Start and End.
type RateData struct {
// Rate defines the per-unit Value over a period of time spanning Start and End.
type Rate struct {
Start time.Time
End time.Time
Value float64
}

// GetTsPriceData accepts a set of TimeSeries data entries, and
// returns a sorted array of RateData based on the timestamp of each data entry.
func GetTsPriceData(ts []TimeSeries, resolution ResolutionType) ([]RateData, error) {
var res []RateData
// returns a sorted array of Rate based on the timestamp of each data entry.
func GetTsPriceData(ts []TimeSeries, resolution ResolutionType) ([]Rate, error) {
var res []Rate

for _, v := range ts {
if v.Period.Resolution != resolution {
Expand All @@ -73,9 +73,9 @@ func GetTsPriceData(ts []TimeSeries, resolution ResolutionType) ([]RateData, err
return res, nil
}

// ExtractTsPriceData massages the given TimeSeries data set to provide RateData entries with associated start and end timestamps.
func ExtractTsPriceData(timeseries *TimeSeries) ([]RateData, error) {
data := make([]RateData, 0, len(timeseries.Period.Point))
// ExtractTsPriceData massages the given TimeSeries data set to provide Rate entries with associated start and end timestamps.
func ExtractTsPriceData(timeseries *TimeSeries) ([]Rate, error) {
data := make([]Rate, 0, len(timeseries.Period.Point))

duration, err := iso8601.ParseDuration(string(timeseries.Period.Resolution))
if err != nil {
Expand All @@ -88,7 +88,7 @@ func ExtractTsPriceData(timeseries *TimeSeries) ([]RateData, error) {

ts := timeseries.Period.TimeInterval.Start.Time
for _, point := range timeseries.Period.Point {
d := RateData{
d := Rate{
Value: point.PriceAmount / 1e3, // Price/MWh to Price/kWh
Start: ts,
}
Expand Down

0 comments on commit aa4b39d

Please sign in to comment.