-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumption.go
107 lines (99 loc) · 3.22 KB
/
consumption.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package gorte
import (
"net/http"
"time"
"github.com/dhia-gharsallaoui/gorte/utils"
)
type AnnualForecastsResp struct {
AnnualForecasts []struct {
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
Values []struct {
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
AverageLoadSaturdayToFriday int `json:"average_load_saturday_to_friday"`
AverageLoadMondayToSunday int `json:"average_load_monday_to_sunday"`
WeeklyMinimum int `json:"weekly_minimum"`
WeeklyMaximum int `json:"weekly_maximum"`
AverageLoadUpdatedDate string `json:"average_load_updated_date"`
MarginUpdatedDate string `json:"margin_updated_date"`
ForecastMargin int `json:"forecast_margin"`
} `json:"values"`
} `json:"annual_forecasts"`
}
func (co *consumption) GetAnnualForecasts(opt utils.Period) (*AnnualForecastsResp, *http.Response, error) {
c := co.client
req, err := c.NewRequest(http.MethodGet, "open_api/consumption/v1/annual_forecasts", opt)
if err != nil {
c.logger.Err(err.Error())
return nil, nil, err
}
var sig *AnnualForecastsResp
resp, err := c.Do(req, &sig)
if err != nil {
c.logger.Err(err.Error())
return nil, resp, err
}
return sig, resp, err
}
type WeeklyForecastsResp struct {
WeeklyForecasts []struct {
EndDate time.Time `json:"end_date"`
Values []struct {
EndDate time.Time `json:"end_date"`
Value int `json:"value"`
StartDate time.Time `json:"start_date"`
} `json:"values"`
UpdatedDate time.Time `json:"updated_date"`
Peak struct {
TemperatureDeviation float64 `json:"temperature_deviation"`
Value int `json:"value"`
PeakHour time.Time `json:"peak_hour"`
Temperature float64 `json:"temperature"`
} `json:"peak"`
StartDate time.Time `json:"start_date"`
} `json:"weekly_forecasts"`
}
func (co *consumption) GetWeeklyForecasts(opt utils.Period) (*WeeklyForecastsResp, *http.Response, error) {
c := co.client
req, err := c.NewRequest(http.MethodGet, "open_api/consumption/v1/weekly_forecasts", opt)
if err != nil {
c.logger.Err(err.Error())
return nil, nil, err
}
var sig *WeeklyForecastsResp
resp, err := c.Do(req, &sig)
if err != nil {
c.logger.Err(err.Error())
return nil, resp, err
}
return sig, resp, err
}
type ShortTermResp struct {
ShortTerm []struct {
Type string `json:"type"`
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
Values []struct {
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
UpdatedDate time.Time `json:"updated_date"`
Value int `json:"value"`
} `json:"values"`
} `json:"short_term"`
}
func (co *consumption) GetShortTerm(opt utils.Period) (*ShortTermResp, *http.Response, error) {
c := co.client
req, err := c.NewRequest(http.MethodGet, "open_api/consumption/v1/short_term", opt)
if err != nil {
c.logger.Err(err.Error())
return nil, nil, err
}
var sig *ShortTermResp
resp, err := c.Do(req, &sig)
if err != nil {
c.logger.Err(err.Error())
return nil, resp, err
}
return sig, resp, err
}