]> gitweb @ CieloNegro.org - hs-rrdtool.git/blobdiff - Database/RRDtool.hs
beginning of my own HList with type families...
[hs-rrdtool.git] / Database / RRDtool.hs
index 7d4fda9167bc050e80d2657a7c48ba8ba7ddcde8..34867d0f19372ac2a80ec50a42feb1ae9944c086 100644 (file)
@@ -1,6 +1,8 @@
 module Database.RRDtool
     ( DataSource(..)
 
+    , MentionedVars(..)
+
     , Expr
     , CommonExpr
     , IterativeExpr
@@ -10,11 +12,19 @@ module Database.RRDtool
     , CommonExprSet
 
     , Constant(..)
+    , VarName(..)
+    , Variable(..)
+    , VariableSet
     , CommonUnaryOp(..)
     , CommonBinaryOp(..)
     , CommonTrinaryOp(..)
     , CommonSetOp(..)
+    , TrendOp(..)
+    , VariableShiftPredictOp(..)
+    , FixedShiftPredictOp(..)
+    , CommonValue(..)
     , IterativeValue(..)
+    , IterativeValueOf(..)
     , AggregativeUnaryOp(..)
 
     , createRRD
@@ -152,21 +162,23 @@ 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 VariableSet (MentionedVarsOf a) => MentionedVars a where
+    type MentionedVarsOf a
+
+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 (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,10 +187,27 @@ 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
+instance MentionedVars Constant where
+    type MentionedVarsOf Constant = HNil
+
+class (Show a, Eq a, Ord a) => VarName a where
+    varName :: a -> String
+
+data Variable vn
+    = Variable !vn
+    deriving (Show, Eq, Ord)
+
+instance VarName vn => Expr (Variable vn)
+instance VarName vn => CommonExpr (Variable vn)
+instance VarName vn => MentionedVars (Variable vn) where
+    type MentionedVarsOf (Variable vn) = vn :*: HNil
+
+class HList vs => VariableSet vs
+instance VariableSet HNil
+instance (VarName vn, VariableSet vs) => VariableSet (HCons vn vs)
 
 -- Common operators
 data CommonUnaryOp a
@@ -198,6 +227,8 @@ data CommonUnaryOp a
     deriving (Show, Eq, Ord)
 instance Expr a => Expr (CommonUnaryOp a)
 instance CommonExpr a => CommonExpr (CommonUnaryOp a)
+instance VariableSet (MentionedVarsOf a) => MentionedVars (CommonUnaryOp a) where
+    type MentionedVarsOf (CommonUnaryOp a) = MentionedVarsOf a
 
 data CommonBinaryOp a b
     = !a :<:  !b
@@ -216,10 +247,20 @@ data CommonBinaryOp a b
     | AddNaN !a !b
     | AtanXY !a !b
     deriving (Show, Eq, Ord)
-instance (Expr a, Expr b)
-    => Expr (CommonBinaryOp a b)
-instance (CommonExpr a, CommonExpr b)
-    => CommonExpr (CommonBinaryOp a b)
+
+instance (Expr a, Expr b) =>
+    Expr (CommonBinaryOp a b)
+
+instance (CommonExpr a, CommonExpr b) =>
+    CommonExpr (CommonBinaryOp a b)
+
+instance (VariableSet (MentionedVarsOf a),
+          VariableSet (MentionedVarsOf b),
+          VariableSet (HAppend (MentionedVarsOf a) (MentionedVarsOf b))) =>
+    MentionedVars (CommonBinaryOp a b) where
+        type MentionedVarsOf (CommonBinaryOp a b)
+            = HAppend (MentionedVarsOf a) (MentionedVarsOf b)
+        
 
 data CommonTrinaryOp a b c
     = If !a !b !c
@@ -234,24 +275,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 vn a
+    = Trend      !(Variable vn) !a
+    | TrendNan   !(Variable vn) !a
+    deriving (Show, Eq, Ord)
+instance (VarName vn, Expr a) => Expr (TrendOp vn a)
+instance (VarName vn, CommonExpr a) => CommonExpr (TrendOp vn a)
+
+data VariableShiftPredictOp ss w vn
+    = VariableShiftPredictAverage !ss !w !(Variable vn)
+    | VariableShiftPredictSigma   !ss !w !(Variable vn)
+    deriving (Show, Eq, Ord)
+instance (ExprSet ss, Expr w, VarName vn)
+    => Expr (VariableShiftPredictOp ss w vn)
+instance (CommonExprSet ss, CommonExpr w, VarName vn)
+    => CommonExpr (VariableShiftPredictOp ss w vn)
+
+data FixedShiftPredictOp sm w vn
+    = FixedShiftPredictAverage !sm !w !(Variable vn)
+    | FixedShiftPredictSigma   !sm !w !(Variable vn)
+    deriving (Show, Eq, Ord)
+instance (Expr sm, Expr w, VarName vn)
+    => Expr (FixedShiftPredictOp sm w vn)
+instance (CommonExpr sm, CommonExpr w, VarName vn)
+    => CommonExpr (FixedShiftPredictOp sm w vn)
+
+-- 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 vn
+    = PreviousOf !(Variable vn)
+    deriving (Show, Eq, Ord)
+instance VarName vn => Expr (IterativeValueOf vn)
+instance VarName vn => IterativeExpr (IterativeValueOf vn)
+
+-- Aggregative operators (fairly restricted due to rrdtool's
+-- restriction)
+data AggregativeUnaryOp vn
+    = Maximum    !(Variable vn)
+    | Minimum    !(Variable vn)
+    | Average    !(Variable vn)
+    | StandardDeviation !(Variable vn)
+    | First      !(Variable vn)
+    | Last       !(Variable vn)
+    | Total      !(Variable vn)
+    | Percent    !(Variable vn) !Constant
+    | PercentNan !(Variable vn) !Constant
+    | LSLSlope   !(Variable vn)
+    | LSLInt     !(Variable vn)
+    | LSLCorrel  !(Variable vn)
     deriving (Show, Eq, Ord)
-instance Expr a => Expr (AggregativeUnaryOp a)
-instance AggregativeExpr a => AggregativeExpr (AggregativeUnaryOp a)
+instance VarName vn => Expr (AggregativeUnaryOp vn)
+instance VarName vn => AggregativeExpr (AggregativeUnaryOp vn)
 
 -- |The 'createRRD' function lets you set up new Round Robin Database
 -- (RRD) files. The file is created at its final, full size and filled