aboutsummaryrefslogtreecommitdiff
path: root/libpod/util.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2017-12-04 15:06:06 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2017-12-13 21:15:09 +0000
commit9cc0c8ae143070c4d4ee691cab6a0fd0ebcaa538 (patch)
tree9736c47af7246c93e2e2b6d6d246653ca57cc316 /libpod/util.go
parent61f606e192ad67b4819a909a6f1b18c41e33db2d (diff)
downloadpodman-9cc0c8ae143070c4d4ee691cab6a0fd0ebcaa538.tar.gz
podman-9cc0c8ae143070c4d4ee691cab6a0fd0ebcaa538.tar.bz2
podman-9cc0c8ae143070c4d4ee691cab6a0fd0ebcaa538.zip
kpod stats
Move kpod stats to the libpod backend. Signed-off-by: baude <bbaude@redhat.com> Closes: #113 Approved by: baude
Diffstat (limited to 'libpod/util.go')
-rw-r--r--libpod/util.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/libpod/util.go b/libpod/util.go
index 61089b525..de5c3ff31 100644
--- a/libpod/util.go
+++ b/libpod/util.go
@@ -9,6 +9,8 @@ import (
"github.com/containers/image/signature"
"github.com/containers/image/types"
+ "github.com/pkg/errors"
+ "strconv"
)
// Runtime API constants
@@ -76,3 +78,21 @@ func GetPolicyContext(path string) (*signature.PolicyContext, error) {
}
return signature.NewPolicyContext(policy)
}
+
+// RemoveScientificNotationFromFloat returns a float without any
+// scientific notation if the number has any.
+// golang does not handle conversion of float64s that have scientific
+// notation in them and otherwise stinks. please replace this if you have
+// a better implementation.
+func RemoveScientificNotationFromFloat(x float64) (float64, error) {
+ bigNum := strconv.FormatFloat(x, 'g', -1, 64)
+ breakPoint := strings.IndexAny(bigNum, "Ee")
+ if breakPoint > 0 {
+ bigNum = bigNum[:breakPoint]
+ }
+ result, err := strconv.ParseFloat(bigNum, 64)
+ if err != nil {
+ return x, errors.Wrapf(err, "unable to remove scientific number from calculations")
+ }
+ return result, nil
+}