Commit c05447f6 authored by Ole Voldsæter's avatar Ole Voldsæter
Browse files

fixed "any*" functions

parent b3f17276
......@@ -6,13 +6,13 @@
)
; -------- compute ? ---------------
; anycount
; anymatch
; anyvalue
; ends
; group
(def compute-funcs {
:anycount "anycount"
:anymatch "anymatch"
:anyvalue "anyvalue"
:diff "diff"
:rowfirst "rowfirst"
:rowlast "rowlast"
......@@ -60,7 +60,7 @@
{"$type" "VariableListExpression" :variables (map (fn [varname] {:variableName varname , "$type" "VariableSymbolExpression"}) (expand-varlist varlist *variables*))}
)
(defn make-compute [varname funcname args filter]
(defn make-compute [varname funcname args _filter]
{:command "compute"
:variable varname
:expression {:function funcname
......@@ -71,18 +71,28 @@
args
)
"$type" "FunctionCallExpression"}
:condition filter
:condition _filter
:mod-varlist (vec (conj *variables* varname))}
)
(defn make-aggregate [by varname funcname expr filter]
(defn make-any [varname funcname varlist options _filter]
(make-compute
varname
funcname
[(make-varlist-expression varlist)
{"$type" "NumberListExpression" :values (->> (get-var-length-option :values 1 options) (get options) first)}]
_filter
)
)
(defn make-aggregate [by varname funcname expr _filter]
{:command "aggregate"
:groupByVariables by
:aggregateVariables [(dissoc (make-compute varname funcname expr filter) :mod-varlist)]
:aggregateVariables [(dissoc (make-compute varname funcname expr _filter) :mod-varlist)]
:mod-varlist (vec (conj *variables* varname))}
)
(defn varlist-compute [varname funcname varlist filter options]
(defn varlist-compute [varname funcname varlist _filter options]
(case funcname
:rowpctile (make-compute
varname
......@@ -91,17 +101,17 @@
[(make-varlist-expression varlist)
{"$type" "NumericConstantExpression" :value (-> p :values first)}]
)
filter)
_filter)
:rowtotal (make-compute
varname
"rowtotal"
[(make-varlist-expression varlist) (-> (get-var-length-option :missing 1 options) nil? not)]
filter)
_filter)
:tag (make-compute
varname
"tag"
[(make-varlist-expression varlist) (-> (get-var-length-option :missing 1 options) nil? not)]
filter)
_filter)
:concat (make-compute
varname
"concat"
......@@ -110,7 +120,7 @@
(->> (get-var-length-option :decode 1 options) nil? not)
(->> (get-var-length-option :maxlength 4 options) (get options) first :values first)
(->> (get-var-length-option :punct 1 options) (get options) first)]
filter)
_filter)
:cut (make-compute
varname
"cut"
......@@ -119,51 +129,55 @@
(->> (get-var-length-option :group 1 options) (get options) first :values first)
(->> (get-var-length-option :icodes 2 options) nil? not)
(->> (get-var-length-option :label 3 options) nil? not)]
filter)
_filter)
:anycount (make-any varname funcname varlist options _filter)
:anymatch (make-any varname funcname varlist options _filter)
:anyvalue (make-any varname funcname varlist options _filter)
; default
(make-compute
varname
(get compute-funcs (keyword funcname))
[(make-varlist-expression varlist)]
filter
_filter
)
)
)
(defn varlist-aggregate [by-clause varname funcname varlist filter options]
(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))
[(make-varlist-expression varlist)]
filter)
_filter)
)
)
(defn egen-varlist [& [by-clause varname funcname varlist filter options]]
(defn egen-varlist [& [by-clause varname funcname varlist _filter options]]
(let [funcname (keyword funcname)]
(cond
(some #{funcname} (keys compute-funcs)) (varlist-compute varname funcname varlist filter options)
(some #{funcname} (keys aggregate-funcs)) (varlist-aggregate by-clause varname funcname varlist filter options)
(some #{funcname} (keys compute-funcs)) (varlist-compute varname funcname varlist _filter options)
(some #{funcname} (keys aggregate-funcs)) (varlist-aggregate by-clause varname funcname varlist _filter options)
:default (unsupported-func funcname)
)
)
)
(defn egen-fill [& [varname numlist filter]]
(make-compute varname "fill" [numlist] filter)
(defn egen-fill [& [varname numlist _filter]]
(make-compute varname "fill" [numlist] _filter)
)
(defn egen-mtr [& [varname exp1 exp2 filter]]
(defn egen-mtr [& [varname exp1 exp2 _filter]]
(make-compute
varname
"mtr"
[exp1 exp2]
filter)
_filter)
)
(defn egen-expr [& [by-clause varname funcname expr filter options]]
(defn egen-expr [& [by-clause varname funcname expr _filter options]]
(let [funcname (keyword funcname)]
(case funcname
:std (make-compute
......@@ -177,21 +191,21 @@
{"$type" "NumericConstantExpression" :value (-> m :values first)}
{"$type" "NumericConstantExpression" :value (-> s :values first)}]
)
filter)
_filter)
:pctile (make-aggregate
by-clause
varname
(get aggregate-funcs (keyword funcname))
[expr
{"$type" "NumericConstantExpression" :value (-> (:p options {:values [50]}) :values first)}]
filter)
_filter)
:pc (make-aggregate
by-clause
varname
(get aggregate-funcs (keyword funcname))
[expr
(-> options :prop nil? not)]
filter)
_filter)
:rank (make-aggregate
by-clause
varname
......@@ -204,7 +218,7 @@
(get-var-length-option :unique 1 options) "unique"
:else "default"
)}]
filter)
_filter)
;;; default
(make-aggregate
......@@ -212,7 +226,7 @@
varname
(get aggregate-funcs (keyword funcname))
[expr]
filter)
_filter)
)
)
)
\ 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