Skip to content

Commit

Permalink
changed from int to float64 for integer values (#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Coetzee <[email protected]>
Co-authored-by: Martin Coetzee <[email protected]>
  • Loading branch information
dabump and Martin Coetzee authored May 1, 2024
1 parent a550d5d commit fe3f445
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion internal/notification/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (n *notificationEngine) start(ctx context.Context) {
return
case event := <-n.notificationChannel:

var values []int
var values []float64
for _, s := range event {
values = append(values, s.Usoc)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/notification/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

const (
lowerThresholdNotification int = 20
upperThresholdNotification int = 80
lowerThresholdNotification float64 = 20
upperThresholdNotification float64 = 80
)

type ruleEngine struct {
Expand All @@ -28,7 +28,7 @@ func NewRulesEngine() *ruleEngine {
}
}

func (r *ruleEngine) dispatchNotification(ctx context.Context, values []int) bool {
func (r *ruleEngine) dispatchNotification(ctx context.Context, values []float64) bool {
// Determine initial trend
t := trend.Calculate(values)
logger.LoggerFromContext(ctx).Infof("trend: %v - %v%%", t, values[0])
Expand Down
18 changes: 9 additions & 9 deletions internal/notification/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Test_ruleEngine_dispatchNotification(t *testing.T) {
lastNotificationTrend trend.Trend
}
type args struct {
values []int
values []float64
}
tests := []struct {
name string
Expand All @@ -37,7 +37,7 @@ func Test_ruleEngine_dispatchNotification(t *testing.T) {
},
want: true,
args: args{
values: []int{100, 99},
values: []float64{100, 99},
},
},
{
Expand All @@ -50,7 +50,7 @@ func Test_ruleEngine_dispatchNotification(t *testing.T) {
},
want: false,
args: args{
values: []int{100, 99},
values: []float64{100, 99},
},
},
{
Expand All @@ -63,7 +63,7 @@ func Test_ruleEngine_dispatchNotification(t *testing.T) {
},
want: true,
args: args{
values: []int{100, 99},
values: []float64{100, 99},
},
},
{
Expand All @@ -76,7 +76,7 @@ func Test_ruleEngine_dispatchNotification(t *testing.T) {
},
want: true,
args: args{
values: []int{0, 1, 2},
values: []float64{0, 1, 2},
},
},
{
Expand All @@ -89,7 +89,7 @@ func Test_ruleEngine_dispatchNotification(t *testing.T) {
},
want: false,
args: args{
values: []int{0, 1, 2},
values: []float64{0, 1, 2},
},
},
{
Expand All @@ -102,7 +102,7 @@ func Test_ruleEngine_dispatchNotification(t *testing.T) {
},
want: true,
args: args{
values: []int{0, 1, 2},
values: []float64{0, 1, 2},
},
},
{
Expand All @@ -114,7 +114,7 @@ func Test_ruleEngine_dispatchNotification(t *testing.T) {
},
want: true,
args: args{
values: []int{upperThresholdNotification, upperThresholdNotification - 1, upperThresholdNotification - 2},
values: []float64{upperThresholdNotification, upperThresholdNotification - 1, upperThresholdNotification - 2},
},
},
{
Expand All @@ -126,7 +126,7 @@ func Test_ruleEngine_dispatchNotification(t *testing.T) {
},
want: true,
args: args{
values: []int{lowerThresholdNotification, lowerThresholdNotification + 1, lowerThresholdNotification + 2},
values: []float64{lowerThresholdNotification, lowerThresholdNotification + 1, lowerThresholdNotification + 2},
},
},
}
Expand Down
26 changes: 13 additions & 13 deletions internal/sonnenbatterie/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ type Status struct {
BackupBuffer string `json:"BackupBuffer,omitempty"`
BatteryCharging bool `json:"BatteryCharging,omitempty"`
BatteryDischarging bool `json:"BatteryDischarging,omitempty"`
ConsumptionAvg int `json:"Consumption_Avg,omitempty"`
ConsumptionW int `json:"Consumption_W,omitempty"`
ConsumptionAvg float64 `json:"Consumption_Avg,omitempty"`
ConsumptionW float64 `json:"Consumption_W,omitempty"`
Fac float64 `json:"Fac,omitempty"`
FlowConsumptionBattery bool `json:"FlowConsumptionBattery,omitempty"`
FlowConsumptionGrid bool `json:"FlowConsumptionGrid,omitempty"`
FlowConsumptionProduction bool `json:"FlowConsumptionProduction,omitempty"`
FlowGridBattery bool `json:"FlowGridBattery,omitempty"`
FlowProductionBattery bool `json:"FlowProductionBattery,omitempty"`
FlowProductionGrid bool `json:"FlowProductionGrid,omitempty"`
GridFeedInW int `json:"GridFeedIn_W,omitempty"`
GridFeedInW float64 `json:"GridFeedIn_W,omitempty"`
IsSystemInstalled int `json:"IsSystemInstalled,omitempty"`
OperatingMode string `json:"OperatingMode,omitempty"`
PacTotalW int `json:"Pac_total_W,omitempty"`
ProductionW int `json:"Production_W,omitempty"`
Rsoc int `json:"RSOC,omitempty"`
RemainingCapacityWh int `json:"RemainingCapacity_Wh,omitempty"`
Sac1 int `json:"Sac1,omitempty"`
Sac2 int `json:"Sac2,omitempty"`
Sac3 int `json:"Sac3,omitempty"`
PacTotalW float64 `json:"Pac_total_W,omitempty"`
ProductionW float64 `json:"Production_W,omitempty"`
Rsoc float64 `json:"RSOC,omitempty"`
RemainingCapacityWh float64 `json:"RemainingCapacity_Wh,omitempty"`
Sac1 float64 `json:"Sac1,omitempty"`
Sac2 float64 `json:"Sac2,omitempty"`
Sac3 float64 `json:"Sac3,omitempty"`
SystemStatus string `json:"SystemStatus,omitempty"`
Timestamp string `json:"Timestamp,omitempty"`
Usoc int `json:"USOC,omitempty"`
Uac int `json:"Uac,omitempty"`
Ubat int `json:"Ubat,omitempty"`
Usoc float64 `json:"USOC,omitempty"`
Uac float64 `json:"Uac,omitempty"`
Ubat float64 `json:"Ubat,omitempty"`
DischargeNotAllowed bool `json:"dischargeNotAllowed,omitempty"`
GeneratorAutostart bool `json:"generator_autostart,omitempty"`
}
2 changes: 1 addition & 1 deletion internal/trend/trend.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (
NoTrend Trend = "none"
)

func Calculate(values []int) Trend {
func Calculate(values []float64) Trend {
if len(values) == 0 {
return NoTrend
}
Expand Down
12 changes: 6 additions & 6 deletions internal/trend/trend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "testing"

func Test_calculate(t *testing.T) {
type args struct {
values []int
values []float64
}
tests := []struct {
name string
Expand All @@ -14,35 +14,35 @@ func Test_calculate(t *testing.T) {
{
name: "Upward trend",
args: args{
values: []int{4, 3, 2, 1},
values: []float64{4, 3, 2, 1},
},
want: Upward,
},
{
name: "Downward trend",
args: args{
values: []int{1, 2, 3, 4},
values: []float64{1, 2, 3, 4},
},
want: Downward,
},
{
name: "No trend - Equalise",
args: args{
values: []int{1, 2, 2, 1},
values: []float64{1, 2, 2, 1},
},
want: NoTrend,
},
{
name: "No trend - Too few values",
args: args{
values: []int{1},
values: []float64{1},
},
want: NoTrend,
},
{
name: "No trend - No values",
args: args{
values: []int{},
values: []float64{},
},
want: NoTrend,
},
Expand Down

0 comments on commit fe3f445

Please sign in to comment.