-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1.64 KB
/
main.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
package main
import (
"energy-tracker/model"
"energy-tracker/utils"
"flag"
"fmt"
"math"
"strconv"
"time"
)
var (
fileName string
daysStr string
)
func main() {
flag.StringVar(&fileName, "f", "", "Specify configuration")
flag.StringVar(&daysStr, "days", "10", "Get the last x number of days of data ( default 10 )")
flag.Parse()
properties, err := utils.ReadProperties(fileName)
if err != nil {
panic(err)
}
var days int64
days, err = strconv.ParseInt(daysStr, 10, 64)
if err != nil {
days = 10
}
gasUnitPrice, _ := strconv.ParseFloat(properties["price_gas"], 64)
gasStandingPrice, _ := strconv.ParseFloat(properties["standing_gas"], 64)
electricityUnitPrice, _ := strconv.ParseFloat(properties["price_electricity"], 64)
electricityStandingPrice, _ := strconv.ParseFloat(properties["standing_electricity"], 64)
handler := &model.OctopusHandler{
Start: time.Now().Add(time.Duration(-days*24) * time.Hour),
End: time.Now(),
GasCalculator: model.EnergyCalculator{UnitPrice: gasUnitPrice, StandingCharge: gasStandingPrice},
ElectricityCalculator: model.EnergyCalculator{UnitPrice: electricityUnitPrice, StandingCharge: electricityStandingPrice},
}
provider := model.NewOctopusProvider(properties, handler)
electricalConsumption := provider.FetchElectricity()
gasConsumption := provider.FetchGas()
// fmt.Println(electricalConsumption.Points)
fmt.Println("Data from the last ", days, " days")
fmt.Println("electricity £", math.Round(handler.ElectricityCalculator.GetCost(electricalConsumption.Points)))
fmt.Println("gas £", math.Round(handler.GasCalculator.GetCost(gasConsumption.Points)))
}