+ -- |rpn-expression defines the formula used to compute the
+ -- PDPs of a COMPUTE data source from other data sources in
+ -- the same \<RRD\>. It is similar to defining a CDEF argument
+ -- for the graph command. For COMPUTE data sources, the
+ -- following RPN operations are not supported: COUNT, PREV,
+ -- TIME, and LTIME. In addition, in defining the RPN
+ -- expression, the COMPUTE data source may only refer to the
+ -- names of data source listed previously in the create
+ -- command. This is similar to the restriction that CDEFs must
+ -- refer only to DEFs and CDEFs previously defined in the same
+ -- graph command.
+ --
+ -- FIXME: doc links
+ , dsExpr :: !a
+ }
+
+dsTest :: DataSource
+dsTest = COMPUTE {
+ dsName = "foo"
+-- , dsExpr = Previous :<: Const 100
+-- , dsExpr = Var "foo" :<: Const 100
+ , dsExpr = AverageOf (Const 100 .*. Const 200 .*. HNil)
+ }
+
+-- MentionedVars
+class VariableSet (MentionedVarsOf a) => MentionedVars a where
+ type MentionedVarsOf a
+
+-- ApplyMentionedVarsOf
+data ApplyMentionedVarsOf = ApplyMentionedVarsOf
+
+instance Applyable ApplyMentionedVarsOf a where
+ type Apply ApplyMentionedVarsOf a = MentionedVarsOf a
+ apply = undefined
+
+-- Expr
+class (Show e, Eq e) => Expr e
+class Expr e => CommonExpr e
+class Expr e => IterativeExpr e
+class Expr e => AggregativeExpr e
+
+class (Show es, Eq es, HList es) => ExprSet es
+instance ExprSet HNil
+instance (Expr e, ExprSet es) => ExprSet (e :*: es)
+
+class (Show es, Eq es, HList es) => CommonExprSet es
+instance CommonExprSet HNil
+instance (CommonExpr e, CommonExprSet es) => CommonExprSet (e :*: es)
+
+
+-- Constants and variable names
+data Constant
+ = Const !Double
+ 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 v, VariableSet vs) => VariableSet (v :*: vs)
+
+-- Common operators
+data CommonUnaryOp a
+ = IsUnknown !a
+ | IsInfinity !a
+ | Sin !a
+ | Cos !a
+ | Log !a
+ | Exp !a
+ | Sqrt !a
+ | Atan !a
+ | Floor !a
+ | Ceil !a
+ | Deg2Rad !a
+ | Rad2Deg !a
+ | Abs !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
+ | !a :<=: !b
+ | !a :>: !b
+ | !a :>=: !b
+ | !a :==: !b
+ | !a :/=: !b
+ | Min !a !b
+ | Max !a !b
+ | !a :+: !b
+ | !a :-: !b
+ | !a :*: !b
+ | !a :/: !b
+ | !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 VariableSet (MentionedVarsOf a :++: MentionedVarsOf b) =>
+ MentionedVars (CommonBinaryOp a b) where
+ type MentionedVarsOf (CommonBinaryOp a b)
+ = MentionedVarsOf a :++: MentionedVarsOf b
+
+
+data CommonTrinaryOp a b c
+ = If !a !b !c
+ | Limit !a !b !c
+ deriving (Show, Eq, Ord)
+
+instance (Expr a, Expr b, Expr c)
+ => Expr (CommonTrinaryOp a b c)
+
+instance (CommonExpr a, CommonExpr b, CommonExpr c)
+ => CommonExpr (CommonTrinaryOp a b c)
+
+instance VariableSet (MentionedVarsOf a :++:
+ MentionedVarsOf b :++:
+ MentionedVarsOf c) =>
+ MentionedVars (CommonTrinaryOp a b c) where
+ type MentionedVarsOf (CommonTrinaryOp a b c)
+ = MentionedVarsOf a :++:
+ MentionedVarsOf b :++:
+ MentionedVarsOf c
+
+-- SORT and REV can't be expressed in this way as they pushes possibly
+-- multiple values onto the stack...
+
+data CommonSetOp es
+ = AverageOf !es
+ deriving (Show, Eq, Ord)
+
+instance ExprSet es => Expr (CommonSetOp es)
+instance (ExprSet es, CommonExprSet es) => CommonExpr (CommonSetOp es)
+instance VariableSet (HConcat (HMap ApplyMentionedVarsOf es)) =>
+ MentionedVars (CommonSetOp es) where
+ type MentionedVarsOf (CommonSetOp es)
+ = HConcat (HMap ApplyMentionedVarsOf 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)
+instance (VarName vn, MentionedVars a) => MentionedVars (TrendOp vn a) where
+ type MentionedVarsOf (TrendOp vn a) = vn :*: MentionedVarsOf 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 (ExprSet ss, CommonExprSet ss, CommonExpr w, VarName vn)
+ => CommonExpr (VariableShiftPredictOp ss w vn)
+instance ( VarName vn
+ , VariableSet (MentionedVarsOf ss :++: MentionedVarsOf w)
+ ) => MentionedVars (VariableShiftPredictOp ss w vn) where
+ type MentionedVarsOf (VariableShiftPredictOp ss w vn)
+ = vn :*: (MentionedVarsOf ss :++: MentionedVarsOf w)
+
+-- FixedShiftPredictOp
+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)
+
+instance ( VarName vn
+ , VariableSet (MentionedVarsOf sm :++: MentionedVarsOf w)
+ ) => MentionedVars (FixedShiftPredictOp sm w vn) where
+ type MentionedVarsOf (FixedShiftPredictOp sm w vn)
+ = vn :*: (MentionedVarsOf sm :++: MentionedVarsOf w)
+
+-- Common special values
+data CommonValue
+ = Unknown
+ | Infinity
+ | NegativeInfinity
+ | Now
+ deriving (Show, Eq, Ord)
+
+instance Expr CommonValue
+
+instance CommonExpr CommonValue
+
+instance MentionedVars CommonValue where
+ type MentionedVarsOf CommonValue = HNil
+
+-- Iterative special values
+data IterativeValue
+ = Previous
+ | Count
+ | TakenTime
+ | TakenLocalTime
+ deriving (Show, Eq, Ord)
+
+instance Expr IterativeValue
+
+instance IterativeExpr IterativeValue
+
+instance MentionedVars IterativeValue where
+ type MentionedVarsOf IterativeValue = HNil
+
+-- Iterative special values of something
+data IterativeValueOf vn
+ = PreviousOf !(Variable vn)