Move part of the loader pipeline to ClusterData
[ganeti-local] / Ganeti / HTools / Utils.hs
index 7ae2367..45b9d5e 100644 (file)
@@ -27,7 +27,7 @@ module Ganeti.HTools.Utils
     , debugFn
     , debugXy
     , sepSplit
-    , varianceCoeff
+    , stdDev
     , commaJoin
     , readEitherString
     , loadJSArray
@@ -73,13 +73,13 @@ debugXy a b = debug a `seq` b
 commaJoin :: [String] -> String
 commaJoin = intercalate ","
 
--- | Split a string on a separator and return an array.
-sepSplit :: Char -> String -> [String]
+-- | Split a list on a separator and return an array.
+sepSplit :: Eq a => a -> [a] -> [[a]]
 sepSplit sep s
-    | x == "" && xs == [] = []
-    | xs == []            = [x]
-    | ys == []            = [x,""]
-    | otherwise           = x:sepSplit sep ys
+    | null s    = []
+    | null xs   = [x]
+    | null ys   = [x,[]]
+    | otherwise = x:sepSplit sep ys
     where (x, xs) = break (== sep) s
           ys = drop 1 xs
 
@@ -88,9 +88,9 @@ sepSplit sep s
 -- Simple and slow statistical functions, please replace with better
 -- versions
 
--- | Our modified standard deviation function (not, it's not the variance)
-varianceCoeff :: [Double] -> Double
-varianceCoeff lst =
+-- | Standard deviation function
+stdDev :: [Double] -> Double
+stdDev lst =
   -- first, calculate the list length and sum lst in a single step,
   -- for performance reasons
   let (ll', sx) = foldl' (\(rl, rs) e ->
@@ -100,9 +100,7 @@ varianceCoeff lst =
       ll = fromIntegral ll'::Double
       mv = sx / ll
       av = foldl' (\accu em -> let d = em - mv in accu + d * d) 0.0 lst
-      bv = sqrt (av / ll) -- stddev
-      cv = bv / ll        -- standard deviation divided by list length
-  in cv
+  in sqrt (av / ll) -- stddev
 
 -- * JSON-related functions