]> gitweb @ CieloNegro.org - hs-rrdtool.git/blobdiff - Database/RRDtool.hs
make variables a type class
[hs-rrdtool.git] / Database / RRDtool.hs
index 7d4fda9167bc050e80d2657a7c48ba8ba7ddcde8..45ae91a3a36da7f675fca245a6de2c66abbcf07d 100644 (file)
@@ -10,11 +10,17 @@ module Database.RRDtool
     , CommonExprSet
 
     , Constant(..)
+    , Variable(..)
     , CommonUnaryOp(..)
     , CommonBinaryOp(..)
     , CommonTrinaryOp(..)
     , CommonSetOp(..)
+    , TrendOp(..)
+    , VariableShiftPredictOp(..)
+    , FixedShiftPredictOp(..)
+    , CommonValue(..)
     , IterativeValue(..)
+    , IterativeValueOf(..)
     , AggregativeUnaryOp(..)
 
     , createRRD
@@ -152,21 +158,22 @@ dsTest = COMPUTE {
            dsName = "foo"
 --         , dsExpr = Previous :<: Const 100
 --         , dsExpr = Var "foo" :<: Const 100
-           , dsExpr = Average (Const 100 .*. Const 200 .*. HNil)
+           , dsExpr = AverageOf (Const 100 .*. Const 200 .*. HNil)
          }
 
-class Show e => Expr e
+class (Show e, Eq e) => Expr e
 class Expr e => CommonExpr e
 class Expr e => IterativeExpr e
 class Expr e => AggregativeExpr e
 instance CommonExpr e => IterativeExpr e
-instance CommonExpr e => AggregativeExpr e
 
-class (Show es, HList es) => ExprSet es
+--class MentionedVars
+
+class (Show es, Eq es, HList es) => ExprSet es
 instance ExprSet HNil
 instance (Expr e, ExprSet es) => ExprSet (HCons e es)
 
-class (Show es, HList es) => CommonExprSet es
+class (Show es, Eq es, HList es) => CommonExprSet es
 instance CommonExprSet es => ExprSet es
 instance CommonExprSet HNil
 instance (CommonExpr e, CommonExprSet es) => CommonExprSet (HCons e es)
@@ -175,11 +182,16 @@ instance (CommonExpr e, CommonExprSet es) => CommonExprSet (HCons e es)
 -- Constants and variable names
 data Constant
     = Const !Double
-    | Var   !String
     deriving (Show, Eq, Ord)
 instance Expr Constant
 instance CommonExpr Constant
 
+class (Show a, Eq a) => Variable a where
+    varName :: a -> String
+
+instance Variable a => Expr a
+instance Variable a => CommonExpr a
+
 -- Common operators
 data CommonUnaryOp a
     = IsUnknown  !a
@@ -234,24 +246,80 @@ instance (CommonExpr a, CommonExpr b, CommonExpr c)
 -- multiple values onto the stack...
 
 data CommonSetOp es
-    = Average !es
+    = AverageOf !es
     deriving (Show, Eq, Ord)
 instance ExprSet es => Expr (CommonSetOp es)
 instance CommonExprSet es => CommonExpr (CommonSetOp es)
 
+data TrendOp v a
+    = Trend      !v !a
+    | TrendNan   !v !a
+    deriving (Show, Eq, Ord)
+instance (Variable v, Expr a) => Expr (TrendOp v a)
+instance (Variable v, CommonExpr a) => CommonExpr (TrendOp v a)
+
+data VariableShiftPredictOp ss w v
+    = VariableShiftPredictAverage !ss !w !v
+    | VariableShiftPredictSigma   !ss !w !v
+    deriving (Show, Eq, Ord)
+instance (ExprSet ss, Expr w, Variable v)
+    => Expr (VariableShiftPredictOp ss w v)
+instance (CommonExprSet ss, CommonExpr w, Variable v)
+    => CommonExpr (VariableShiftPredictOp ss w v)
+
+data FixedShiftPredictOp sm w v
+    = FixedShiftPredictAverage !sm !w !v
+    | FixedShiftPredictSigma   !sm !w !v
+    deriving (Show, Eq, Ord)
+instance (Expr sm, Expr w, Variable v)
+    => Expr (FixedShiftPredictOp sm w v)
+instance (CommonExpr sm, CommonExpr w, Variable v)
+    => CommonExpr (FixedShiftPredictOp sm w v)
+
+-- Common special values
+data CommonValue
+    = Unknown
+    | Infinity
+    | NegativeInfinity
+    | Now
+    deriving (Show, Eq, Ord)
+instance Expr CommonValue
+instance CommonExpr CommonValue
+
 -- Iterative special values
 data IterativeValue
     = Previous
+    | Count
+    | TakenTime
+    | TakenLocalTime
     deriving (Show, Eq, Ord)
 instance Expr IterativeValue
 instance IterativeExpr IterativeValue
 
--- Aggregative operators
-data AggregativeUnaryOp a
-    = Maximum !a
+data IterativeValueOf v
+    = PreviousOf !v
+    deriving (Show, Eq, Ord)
+instance Variable v => Expr (IterativeValueOf v)
+instance Variable v => IterativeExpr (IterativeValueOf v)
+
+-- Aggregative operators (fairly restricted due to rrdtool's
+-- restriction)
+data AggregativeUnaryOp v
+    = Maximum    !v
+    | Minimum    !v
+    | Average    !v
+    | StandardDeviation !v
+    | First      !v
+    | Last       !v
+    | Total      !v
+    | Percent    !v !Constant
+    | PercentNan !v !Constant
+    | LSLSlope   !v
+    | LSLInt     !v
+    | LSLCorrel  !v
     deriving (Show, Eq, Ord)
-instance Expr a => Expr (AggregativeUnaryOp a)
-instance AggregativeExpr a => AggregativeExpr (AggregativeUnaryOp a)
+instance Variable v => Expr (AggregativeUnaryOp v)
+instance Variable v => AggregativeExpr (AggregativeUnaryOp v)
 
 -- |The 'createRRD' function lets you set up new Round Robin Database
 -- (RRD) files. The file is created at its final, full size and filled