Skip to content

Commit

Permalink
chore: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jun 15, 2024
1 parent 6dd6a05 commit 925e510
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions tariff/pun.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import (

type Pun struct {
*embed
log *util.Logger
charges float32
tax float32
data *util.Monitor[api.Rates]
log *util.Logger
data *util.Monitor[api.Rates]
}

type NewDataSet struct {
Expand All @@ -51,23 +49,16 @@ func init() {
}

func NewPunFromConfig(other map[string]interface{}) (api.Tariff, error) {
cc := struct {
Charges float32
Tax float32
}{
Charges: 0.0,
Tax: 0.0,
}
var cc embed

if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}

t := &Pun{
log: util.NewLogger("pun"),
charges: cc.Charges,
tax: cc.Tax,
data: util.NewMonitor[api.Rates](2 * time.Hour),
log: util.NewLogger("pun"),
embed: &cc,
data: util.NewMonitor[api.Rates](2 * time.Hour),
}

done := make(chan error)
Expand Down Expand Up @@ -217,7 +208,7 @@ func (t *Pun) getData(day time.Time) (api.Rates, error) {
ar := api.Rate{
Start: start,
End: end,
Price: (price/1000.0 + float64(t.charges)) * (1 + float64(t.tax)),
Price: t.totalPrice(price / 1e3),
}
data = append(data, ar)
}
Expand Down

0 comments on commit 925e510

Please sign in to comment.