{-
-Copyright (C) 2009 Google Inc.
+Copyright (C) 2009, 2010 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
module Ganeti.HTools.Utils
(
debug
+ , debugFn
+ , debugXy
, sepSplit
, varianceCoeff
, commaJoin
, tryRead
, formatTable
, annotateResult
+ , defaultGroupID
) where
import Control.Monad (liftM)
debug :: Show a => a -> a
debug x = trace (show x) x
+-- | Displays a modified form of the second parameter before returning it
+debugFn :: Show b => (a -> b) -> a -> a
+debugFn fn x = debug (fn x) `seq` x
+
+-- | Show the first parameter before returning the second one
+debugXy :: Show a => a -> b -> b
+debugXy a b = debug a `seq` b
+
-- * Miscelaneous
-- | Comma-join a string list.
-- Simple and slow statistical functions, please replace with better
-- versions
--- | The covariance of the list
+-- | Our modified standard deviation function (not, it's not the variance)
varianceCoeff :: [Double] -> Double
varianceCoeff lst =
- let ll = fromIntegral (length lst)::Double -- length of list
- mv = sum lst / ll -- mean value
- av = foldl' (\accu em -> let d = em - mv in accu + d * d) 0.0 lst
- bv = sqrt (av / ll) -- stddev
- cv = bv / ll -- covariance
- in cv
+ -- first, calculate the list length and sum lst in a single step,
+ -- for performance reasons
+ let (ll', sx) = foldl' (\(rl, rs) e ->
+ let rl' = rl + 1
+ rs' = rs + e
+ in rl' `seq` rs' `seq` (rl', rs')) (0::Int, 0) 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
-- * JSON-related functions
) flds
) (zip3 vtrans numpos mlens)
in transpose expnd
+
+-- | Default group UUID (just a string, not a real UUID)
+defaultGroupID :: GroupID
+defaultGroupID = "00000000-0000-0000-0000-000000000000"