X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Database%2FRRDtool.hs;h=6b5734076a4ab446f02aba82e11438fa648e3dd3;hb=2c2948fbfa1b730beafa2dc8a5c6c81de54f2920;hp=f588fdb619686b5b5bd5efda0503e018356a63f2;hpb=79dfae84547f2148b52c317c40bd672e3e52bd5d;p=hs-rrdtool.git diff --git a/Database/RRDtool.hs b/Database/RRDtool.hs index f588fdb..6b57340 100644 --- a/Database/RRDtool.hs +++ b/Database/RRDtool.hs @@ -1,24 +1,31 @@ module Database.RRDtool ( DataSource(..) - , Expr - , CommonExpr + , MentionedVars(..) + , ApplyMentionedVarsOf(..) + + , IsExpr + , IsCommonExpr , IterativeExpr - , AggregativeExpr + , IsAggregativeExpr - , ExprSet - , CommonExprSet + , IsExprSet + , IsCommonExprSet , Constant(..) + , IsVarName(..) , Variable(..) + , IsVariableSet , CommonUnaryOp(..) , CommonBinaryOp(..) , CommonTrinaryOp(..) , CommonSetOp(..) + , TrendOp(..) , VariableShiftPredictOp(..) , FixedShiftPredictOp(..) , CommonValue(..) , IterativeValue(..) + , IterativeValueOf(..) , AggregativeUnaryOp(..) , createRRD @@ -133,7 +140,7 @@ data DataSource -- referred to as \"virtual\" or \"computed\" columns. -- -- FIXME: doc links - | forall a. CommonExpr a => COMPUTE { + | forall a. IsCommonExpr a => COMPUTE { dsName :: !String -- |rpn-expression defines the formula used to compute the -- PDPs of a COMPUTE data source from other data sources in @@ -159,34 +166,56 @@ dsTest = COMPUTE { , dsExpr = AverageOf (Const 100 .*. Const 200 .*. HNil) } -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 +-- MentionedVars +class IsVariableSet (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 -class (Show es, Eq es, HList es) => ExprSet es -instance ExprSet HNil -instance (Expr e, ExprSet es) => ExprSet (HCons e es) +-- IsExpr +class (Show e, Eq e) => IsExpr e +class IsExpr e => IsCommonExpr e +class IsExpr e => IterativeExpr e +class IsExpr e => IsAggregativeExpr e -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) +class (Show es, Eq es, HList es) => IsExprSet es +instance IsExprSet HNil +instance (IsExpr e, IsExprSet es) => IsExprSet (e :*: es) + +class (Show es, Eq es, HList es) => IsCommonExprSet es +instance IsCommonExprSet HNil +instance (IsCommonExpr e, IsCommonExprSet es) => IsCommonExprSet (e :*: es) -- Constants and variable names data Constant = Const !Double deriving (Show, Eq, Ord) -instance Expr Constant -instance CommonExpr Constant +instance IsExpr Constant +instance IsCommonExpr Constant +instance MentionedVars Constant where + type MentionedVarsOf Constant = HNil + +class (Show a, Eq a, Ord a) => IsVarName a where + varName :: a -> String -data Variable - = Var !String +data Variable vn + = Variable !vn deriving (Show, Eq, Ord) -instance Expr Variable -instance CommonExpr Variable + +instance IsVarName vn => IsExpr (Variable vn) +instance IsVarName vn => IsCommonExpr (Variable vn) +instance IsVarName vn => MentionedVars (Variable vn) where + type MentionedVarsOf (Variable vn) = vn :*: HNil + +class HList vs => IsVariableSet vs +instance IsVariableSet HNil +instance (IsVarName v, IsVariableSet vs) => IsVariableSet (v :*: vs) -- Common operators data CommonUnaryOp a @@ -203,11 +232,11 @@ data CommonUnaryOp a | Deg2Rad !a | Rad2Deg !a | Abs !a - | Trend !Variable !a - | TrendNan !Variable !a deriving (Show, Eq, Ord) -instance Expr a => Expr (CommonUnaryOp a) -instance CommonExpr a => CommonExpr (CommonUnaryOp a) +instance IsExpr a => IsExpr (CommonUnaryOp a) +instance IsCommonExpr a => IsCommonExpr (CommonUnaryOp a) +instance IsVariableSet (MentionedVarsOf a) => MentionedVars (CommonUnaryOp a) where + type MentionedVarsOf (CommonUnaryOp a) = MentionedVarsOf a data CommonBinaryOp a b = !a :<: !b @@ -226,19 +255,38 @@ 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 (IsExpr a, IsExpr b) => + IsExpr (CommonBinaryOp a b) + +instance (IsCommonExpr a, IsCommonExpr b) => + IsCommonExpr (CommonBinaryOp a b) + +instance IsVariableSet (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 (IsExpr a, IsExpr b, IsExpr c) + => IsExpr (CommonTrinaryOp a b c) + +instance (IsCommonExpr a, IsCommonExpr b, IsCommonExpr c) + => IsCommonExpr (CommonTrinaryOp a b c) + +instance IsVariableSet (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... @@ -246,26 +294,54 @@ instance (CommonExpr a, CommonExpr b, CommonExpr c) data CommonSetOp es = AverageOf !es deriving (Show, Eq, Ord) -instance ExprSet es => Expr (CommonSetOp es) -instance CommonExprSet es => CommonExpr (CommonSetOp es) -data VariableShiftPredictOp ss w - = VariableShiftPredictAverage !ss !w !Variable - | VariableShiftPredictSigma !ss !w !Variable +instance IsExprSet es => IsExpr (CommonSetOp es) +instance (IsExprSet es, IsCommonExprSet es) => IsCommonExpr (CommonSetOp es) +instance IsVariableSet (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 (IsVarName vn, IsExpr a) => IsExpr (TrendOp vn a) +instance (IsVarName vn, IsCommonExpr a) => IsCommonExpr (TrendOp vn a) +instance (IsVarName 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) - => Expr (VariableShiftPredictOp ss w) -instance (CommonExprSet ss, CommonExpr w) - => CommonExpr (VariableShiftPredictOp ss w) - -data FixedShiftPredictOp sm w - = FixedShiftPredictAverage !sm !w !Variable - | FixedShiftPredictSigma !sm !w !Variable +instance (IsExprSet ss, IsExpr w, IsVarName vn) + => IsExpr (VariableShiftPredictOp ss w vn) +instance (IsExprSet ss, IsCommonExprSet ss, IsCommonExpr w, IsVarName vn) + => IsCommonExpr (VariableShiftPredictOp ss w vn) +instance ( IsVarName vn + , IsVariableSet (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) - => Expr (FixedShiftPredictOp sm w) -instance (CommonExpr sm, CommonExpr w) - => CommonExpr (FixedShiftPredictOp sm w) + +instance (IsExpr sm, IsExpr w, IsVarName vn) + => IsExpr (FixedShiftPredictOp sm w vn) + +instance (IsCommonExpr sm, IsCommonExpr w, IsVarName vn) + => IsCommonExpr (FixedShiftPredictOp sm w vn) + +instance ( IsVarName vn + , IsVariableSet (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 @@ -274,38 +350,64 @@ data CommonValue | NegativeInfinity | Now deriving (Show, Eq, Ord) -instance Expr CommonValue -instance CommonExpr CommonValue + +instance IsExpr CommonValue + +instance IsCommonExpr CommonValue + +instance MentionedVars CommonValue where + type MentionedVarsOf CommonValue = HNil -- Iterative special values data IterativeValue = Previous - | PreviousOf !Variable | Count | TakenTime | TakenLocalTime deriving (Show, Eq, Ord) -instance Expr IterativeValue + +instance IsExpr IterativeValue + instance IterativeExpr IterativeValue +instance MentionedVars IterativeValue where + type MentionedVarsOf IterativeValue = HNil + +-- Iterative special values of something +data IterativeValueOf vn + = PreviousOf !(Variable vn) + deriving (Show, Eq, Ord) + +instance IsVarName vn => IsExpr (IterativeValueOf vn) + +instance IsVarName vn => IterativeExpr (IterativeValueOf vn) + +instance IsVarName vn => MentionedVars (IterativeValueOf vn) where + type MentionedVarsOf (IterativeValueOf vn) = vn :*: HNil + -- Aggregative operators (fairly restricted due to rrdtool's -- restriction) -data AggregativeUnaryOp - = Maximum !Variable - | Minimum !Variable - | Average !Variable - | StandardDeviation !Variable - | First !Variable - | Last !Variable - | Total !Variable - | Percent !Variable !Constant - | PercentNan !Variable !Constant - | LSLSlope !Variable - | LSLInt !Variable - | LSLCorrel !Variable +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 AggregativeUnaryOp -instance AggregativeExpr AggregativeUnaryOp + +instance IsVarName vn => IsExpr (AggregativeUnaryOp vn) + +instance IsVarName vn => IsAggregativeExpr (AggregativeUnaryOp vn) + +instance IsVarName vn => MentionedVars (AggregativeUnaryOp vn) where + type MentionedVarsOf (AggregativeUnaryOp vn) = vn :*: HNil -- |The 'createRRD' function lets you set up new Round Robin Database -- (RRD) files. The file is created at its final, full size and filled