-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct the computation of the percentage differences and stats
Fix the computation of the CPU/Memory difference columns to express the result as the increase/decrease of the request in terms of the recommendation. Print the memory recommendation quantity using the same scale as the request in a human-friendly format. Scale the statistics values to the number of replicas requested in the spec of each controller.
- Loading branch information
Showing
7 changed files
with
190 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package humanize | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
) | ||
|
||
var ( | ||
bigSIExp = big.NewInt(1000) | ||
bigIECExp = big.NewInt(1024) | ||
) | ||
|
||
// BigBytes produces a human-readable representation of an SI size. | ||
func BigBytes(s *big.Int, precision int) string { | ||
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} | ||
return humanizeBigBytes(s, bigSIExp, sizes, precision) | ||
} | ||
|
||
// BigIBytes produces a human-readable representation of an IEC size. | ||
func BigIBytes(s *big.Int, precision int) string { | ||
sizes := []string{"B", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"} | ||
return humanizeBigBytes(s, bigIECExp, sizes, precision) | ||
} | ||
|
||
var ten = big.NewInt(10) | ||
|
||
func humanizeBigBytes(s, base *big.Int, sizes []string, precision int) string { | ||
if s.Cmp(ten) < 0 { | ||
return fmt.Sprintf("%d B", s) | ||
} | ||
c := (&big.Int{}).Set(s) | ||
val, mag := orderOfMagnitude(c, base, len(sizes)-1) | ||
suffix := sizes[mag] | ||
f := "%.0f %s" | ||
if val < 10 { | ||
f = fmt.Sprintf("%%.%df %%s", precision) | ||
} | ||
return fmt.Sprintf(f, val, suffix) | ||
} | ||
|
||
func orderOfMagnitude(n, b *big.Int, max int) (float64, int) { | ||
mag := 0 | ||
m := &big.Int{} | ||
for n.Cmp(b) >= 0 { | ||
n.DivMod(n, b, m) | ||
mag++ | ||
if mag == max && max >= 0 { | ||
break | ||
} | ||
} | ||
return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.