Skip to content

Commit

Permalink
chore: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed May 6, 2024
1 parent a014175 commit 91e146d
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions core/circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,11 @@ func (c *Circuit) ValidatePower(old, new float64) float64 {
}
}

if c.parent != nil {
res := c.parent.ValidatePower(old, new)
if res != new {
c.log.TRACE.Printf("validate power: %gW -> %gW at %gW: capped by parent at %gW", old, new, c.power, res)
}
return res
if c.parent == nil {
return new
}

return new
return c.parent.ValidatePower(old, new)
}

// ValidateCurrent validates current request
Expand All @@ -277,32 +273,9 @@ func (c *Circuit) ValidateCurrent(old, new float64) float64 {
}
}

if c.parent != nil {
res := c.parent.ValidateCurrent(old, new)
if res != new {
c.log.TRACE.Printf("validate current: %gA -> %gA at %gA: capped by parent at %gA", old, new, c.current, res)
}
return res
if c.parent == nil {
return new
}

return new
return c.parent.ValidateCurrent(old, new)
}

// func (c *Circuit) validate(typ string, current, old, new float64, parentFunc func(o, n float64) float64) float64 {
// delta := max(0, new-old)

// if c.maxPower != 0 {
// if c.power+delta > c.maxPower {
// new = max(0, c.maxPower-c.power)
// c.log.TRACE.Printf("validate power: %g -> %g <= %g at %g: capped at %g", old, new, c.maxPower, c.power, new)
// } else {
// c.log.TRACE.Printf("validate power: %g -> %g <= %g at %g: ok", old, new, c.maxPower, c.power)
// }
// }

// if c.parent != nil {
// return c.parent.ValidatePower(c.power, new)
// }

// return new
// }

0 comments on commit 91e146d

Please sign in to comment.