Commit be6f669a authored by Ole Voldsæter's avatar Ole Voldsæter

function calls in "egen" conform to new schema

parent d02f70d0
......@@ -54,15 +54,20 @@
:severity "error"}]}
)
(defn make-var-struct [varname]
{:variableName varname , "$type" "VariableSymbolExpression"})
(defn make-varlist-expression [varlist]
{"$type" "VariableListExpression" :variables (map (fn [varname] {:variableName varname , "$type" "VariableSymbolExpression"}) (expand-varlist varlist *variables*))}
)
(defn make-compute [varname funcname args filter]
{:command "compute"
:variable varname
:expression {:function funcname
:isSdtlName true
:arguments args
:arguments (map-indexed
(fn [i arg] {:argumentName (str "EXP" (inc i))
:argumentValue arg})
args
)
"$type" "FunctionCallExpression"}
:condition filter
:mod-varlist (vec (conj *variables* varname))}
......@@ -81,30 +86,25 @@
varname
"rowpctile"
(let [p (:p options [[50]])]
(into
[(-> p (first) (first))]
(map make-var-struct (expand-varlist varlist *variables*)))
[(make-varlist-expression varlist)
{"$type" "NumericConstantExpression" :value (-> p first first)}]
)
filter)
:rowtotal (make-compute
varname
"rowtotal"
(into
[(not (nil? (get-var-length-option :missing 1 options)))]
(map make-var-struct (expand-varlist varlist *variables*)))
[(make-varlist-expression varlist)]
filter)
:tag (make-compute
varname
"tag"
(into
[(not (nil? (get-var-length-option :missing 1 options)))]
(map make-var-struct (expand-varlist varlist *variables*)))
[(make-varlist-expression varlist)]
filter)
; default
(make-compute
varname
(get compute-funcs (keyword funcname))
(map make-var-struct (expand-varlist varlist *variables*))
[(make-varlist-expression varlist)]
filter
)
)
......@@ -113,7 +113,11 @@
(defn varlist-aggregate [by-clause varname funcname varlist filter options]
(case funcname
:mode (unsupported-func funcname)
(make-aggregate by-clause varname (get aggregate-funcs (keyword funcname)) (map make-var-struct (expand-varlist varlist *variables*)) filter)
(make-aggregate
by-clause varname
(get aggregate-funcs (keyword funcname))
[(make-varlist-expression varlist)]
filter)
)
)
......@@ -128,11 +132,7 @@
)
(defn egen-fill [& [varname numlist filter]]
(make-compute
varname
"fill"
(expand-numlist numlist)
filter)
(unsupported-func "fill")
)
(defn egen-mtr [& [varname exp1 exp2 filter]]
......@@ -153,17 +153,30 @@
s (get-var-length-option :std 1 options)
m (if m (get options m) [[0]])
s (if s (get options s) [[1]])]
[(-> m first first) (-> s first first) expr]
[expr
{"$type" "NumericConstantExpression" :value (-> m first first)}
{"$type" "NumericConstantExpression" :value (-> s first first)}]
)
filter)
:pctile (make-aggregate by-clause varname (get aggregate-funcs (keyword funcname)) [expr (-> (:p options [[50]]) first first)] filter)
:pctile (make-aggregate
by-clause
varname
(get aggregate-funcs (keyword funcname))
[expr
{"$type" "NumericConstantExpression" :value (-> (:p options [[50]]) first first)}]
filter)
;;;----- weird ones -------------
:rank (unsupported-func funcname)
:pc (unsupported-func funcname)
;;; default
(make-aggregate by-clause varname (get aggregate-funcs (keyword funcname)) [expr] filter)
(make-aggregate
by-clause
varname
(get aggregate-funcs (keyword funcname))
[expr]
filter)
)
)
)
\ No newline at end of file
......@@ -8,23 +8,25 @@
(is
(= (make-compute "some-var" "min" [5] 5)
'{:command "compute"
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments [5]
:function "min"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue 5})
:function "min"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
)
)
(deftest make-aggregate-test
(is
(= (make-aggregate ["a" "b"] "some-var" :mean 5 5)
(= (make-aggregate ["a" "b"] "some-var" :mean [5] 5)
'{:aggregateVariables [{:command "compute"
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments 5
:arguments ({:argumentName "EXP1"
:argumentValue 5})
:function :mean
:isSdtlName true}
:variable "some-var"}]
......@@ -38,107 +40,121 @@
(deftest varlist-compute-test
(is
(= (varlist-compute "some-var" :rowpctile ["a" "b"] nil nil)
'{:command "compute"
'{:command "compute"
:condition nil
:expression {"$type" "FunctionCallExpression"
:arguments [50
{"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"}]
:function "rowpctile"
:isSdtlName true}
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue {"$type" "VariableListExpression"
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}}
{:argumentName "EXP2"
:argumentValue {"$type" "NumericConstantExpression"
:value 50}})
:function "rowpctile"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
)
(is
(= (varlist-compute "some-var" :rowpctile ["a" "b"] 5 {:p [[10]]})
'{:command "compute"
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments [10
{"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"}]
:function "rowpctile"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
'{:command "compute"
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue {"$type" "VariableListExpression"
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}}
{:argumentName "EXP2"
:argumentValue {"$type" "NumericConstantExpression"
:value 10}})
:function "rowpctile"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
)
(is
(= (varlist-compute "some-var" :rowtotal ["a" "b"] nil nil)
'{:command "compute"
:condition nil
:expression {"$type" "FunctionCallExpression"
:arguments [false
{"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"}]
:function "rowtotal"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
'{:command "compute"
:condition nil
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue {"$type" "VariableListExpression"
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}})
:function "rowtotal"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
)
(is
(= (varlist-compute "some-var" :rowtotal ["a" "b"] 5 {:missing nil})
'{:command "compute"
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments [true
{"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"}]
:function "rowtotal"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
'{:command "compute"
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue {"$type" "VariableListExpression"
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}})
:function "rowtotal"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
)
(is
(= (varlist-compute "some-var" :tag ["a" "b"] nil nil)
'{:command "compute"
:condition nil
:expression {"$type" "FunctionCallExpression"
:arguments [false
{"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"}]
:function "tag"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
:condition nil
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue {"$type" "VariableListExpression"
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}})
:function "tag"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
)
(is
(= (varlist-compute "some-var" :tag ["a" "b"] 5 {:missing nil})
'{:command "compute"
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments [true
{"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"}]
:function "tag"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue {"$type" "VariableListExpression"
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}})
:function "tag"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
)
(is
(= (varlist-compute "some-var" "diff" ["a" "b"] 5 nil)
'{:command "compute"
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})
:function "diff"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
:condition 5
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue {"$type" "VariableListExpression"
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}})
:function "diff"
:isSdtlName true}
:mod-varlist ["some-var"]
:variable "some-var"})
)
)
......@@ -146,75 +162,96 @@
(is
(= (egen-expr nil "somevar" "std" 5 1 nil)
'{:command "compute"
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments [0
1
5]
:function "std_val"
:isSdtlName true}
:mod-varlist ["somevar"]
:variable "somevar"}
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue 5}
{:argumentName "EXP2"
:argumentValue {"$type" "NumericConstantExpression"
:value 0}}
{:argumentName "EXP3"
:argumentValue {"$type" "NumericConstantExpression"
:value 1}})
:function "std_val"
:isSdtlName true}
:mod-varlist ["somevar"]
:variable "somevar"}
)
)
(is
(= (egen-expr nil "somevar" "std" 5 1 {:mean [[7]]})
'{:command "compute"
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments [7
1
5]
:function "std_val"
:isSdtlName true}
:mod-varlist ["somevar"]
:variable "somevar"}
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue 5}
{:argumentName "EXP2"
:argumentValue {"$type" "NumericConstantExpression"
:value 7}}
{:argumentName "EXP3"
:argumentValue {"$type" "NumericConstantExpression"
:value 1}})
:function "std_val"
:isSdtlName true}
:mod-varlist ["somevar"]
:variable "somevar"}
)
)
(is
(= (egen-expr nil "somevar" "std" 5 1 {:std [[2]] :mean [[7]]})
'{:command "compute"
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments [7
2
5]
:function "std_val"
:isSdtlName true}
:mod-varlist ["somevar"]
:variable "somevar"}
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue 5}
{:argumentName "EXP2"
:argumentValue {"$type" "NumericConstantExpression"
:value 7}}
{:argumentName "EXP3"
:argumentValue {"$type" "NumericConstantExpression"
:value 2}})
:function "std_val"
:isSdtlName true}
:mod-varlist ["somevar"]
:variable "somevar"}
)
)
(is
(= (egen-expr ["a" "b"] "somevar" "pctile" 5 1 nil)
'{:aggregateVariables [{:command "compute"
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments [5
50]
:function "agg_pctile"
:isSdtlName true}
:variable "somevar"}]
:command "aggregate"
:groupByVariables ["a"
"b"]
:mod-varlist ["somevar"]}
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue 5}
{:argumentName "EXP2"
:argumentValue {"$type" "NumericConstantExpression"
:value 50}})
:function "agg_pctile"
:isSdtlName true}
:variable "somevar"}]
:command "aggregate"
:groupByVariables ["a"
"b"]
:mod-varlist ["somevar"]}
)
)
(is
(= (egen-expr ["a" "b"] "somevar" "pctile" 5 1 {:p [[10]]})
'{:aggregateVariables [{:command "compute"
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments [5
10]
:function "agg_pctile"
:isSdtlName true}
:variable "somevar"}]
:command "aggregate"
:groupByVariables ["a"
"b"]
:mod-varlist ["somevar"]}
:condition 1
:expression {"$type" "FunctionCallExpression"
:arguments ({:argumentName "EXP1"
:argumentValue 5}
{:argumentName "EXP2"
:argumentValue {"$type" "NumericConstantExpression"
:value 10}})
:function "agg_pctile"
:isSdtlName true}
:variable "somevar"}]
:command "aggregate"
:groupByVariables ["a"
"b"]
:mod-varlist ["somevar"]}
)
)
)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment