Squash bugs
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending

This commit is contained in:
MassiveBox 2023-06-23 20:39:37 +02:00
parent d51f42ecb1
commit b720bf4ac0
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
3 changed files with 7 additions and 3 deletions

View file

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

View file

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

View file

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