This commit is contained in:
parent
d51f42ecb1
commit
b720bf4ac0
|
@ -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
|
||||||
|
|
|
@ -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]
|
||||||
|
|
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue