Compare commits

...

2 Commits

Author SHA1 Message Date
MassiveBox b720bf4ac0
Squash bugs 2023-06-23 20:39:37 +02:00
MassiveBox d51f42ecb1
Fix linter 2023-06-23 16:51:43 +02:00
4 changed files with 9 additions and 3 deletions

View File

@ -234,6 +234,8 @@ linters:
- wrapcheck
- nonamedreturns
- gomnd
- gosmopolitan
- depguard
enable-all: true
fast: false

View File

@ -75,7 +75,7 @@ func (config *Config) refreshCacheFromPast(pastTime time.Time) error {
}
defer stmtIgnore.Close()
for key, day := range greenEnergyPercentage {
for key, day := range historyPolledSmartEnergySummation {
var stmt *sql.Stmt
if greenEnergyPercentage[key].Value != 0 && historyPolledSmartEnergySummation[key].Value != 0 {
stmt = stmtReplace

View File

@ -155,7 +155,7 @@ func (config *Config) saveAdminForm(c *fiber.Ctx) error {
}
func averageExcludingCurrentDay(data []float32) float32 {
if len(data) == 0 {
if len(data) <= 1 {
return 0
}
data = data[:len(data)-1]

View File

@ -17,8 +17,12 @@ func Hash(toHash string) string {
func TemplateDivide(num1, num2 float32) template.HTML {
division := float64(num1 / num2)
if math.IsNaN(division) || division == 0 {
return "0"
}
powerOfTen := int(math.Floor(math.Log10(division)))
if (powerOfTen >= -2 && powerOfTen <= 2) || division == 0 {
if powerOfTen >= -2 && powerOfTen <= 2 {
// #nosec G203 // We're only printing floats
return template.HTML(strconv.FormatFloat(math.Round(division*100)/100, 'f', -1, 64))
}