Commit 28792f53 authored by Sigbjørn Revheim's avatar Sigbjørn Revheim
Browse files

More fixes for SDTL changes

parent a689d40b
......@@ -45,7 +45,7 @@
:invalid (fn [& args] {"$type" "Invalid"
:Command "invalid"
:Message (str "Invalid/unexpected syntax for \"" (-> args first trim) "\"")
:Messages [{:severity "Error"
:Messages [{:Severity "Error"
:MessageText (str "Invalid syntax for " (first args))}]})
:unsupported (fn [& args] {"$type" "Unsupported"
:Command "unsupported"})
......@@ -115,14 +115,15 @@
:mod-varlist newlist}))
:format_vars (fn [& args] {"$type" "SetDisplayFormat"
:Command "setDisplayFormat"
:Format (if (-> args first string?) (first args) (second args))
:Variables (map variable-symbol-expression (expand-varlist (if (-> args first string?) (second args) (first args)) *variables*))})
:Variables (map variable-symbol-expression (expand-varlist (if (-> args first string?) (second args) (first args)) *variables*))
:Format (if (-> args first string?) (first args) (second args))})
:drop_cases (fn [& [expr]]
{"$type" "Select"
:Command "select"
:condition {:function "not"
:isSdtlName true
:arguments [expr]}})
:Condition {"$type" "FunctionCallExpression"
:Function "not"
:IsSdtlName true
:Arguments [expr]}})
:drop_vars (fn [& [varlist]]
(let [expanded (expand-varlist varlist *variables*)]
{"$type" "DeleteVariables"
......@@ -133,7 +134,7 @@
:keep_cases (fn [& [expr]]
{"$type" "Select"
:Command "select"
:condition expr})
:Condition expr})
:keep_vars (fn [& [varlist]]
(let [expanded (expand-varlist varlist *variables*)]
{"$type" "KeepVariables"
......@@ -166,15 +167,15 @@
(if (second args)
{"$type" "FunctionCallExpression"
:Function "not"
:isSdtlName true
:IsSdtlName true
:Arguments (rest args)}
(first args)
)
)
:primary (fn [& [prim]]
(cond
(number? prim) {"$type" "NumericConstantExpression", :Value prim}
(string? prim) {"$type" "StringConstantExpression", :Value prim}
(number? prim) (numeric-constant-expression prim)
(string? prim) (string-constant-expression prim)
:else prim
)
)
......@@ -195,15 +196,15 @@
(let [varlist (recode-varlist (expand-varlist vars *variables*) (or options {}))]
{"$type" "Recode"
:Command "recode"
:recodedVariables varlist
:rules (apply-options-to-rules rules (or options {}))
:RecodedVariables varlist
:Rules (apply-options-to-rules rules (or options {}))
:mod-varlist (vec (concat *variables* (extract-target-variables varlist)))}))
:simple_recode (fn [& [varname rules filter options]]
(let [varlist (recode-varlist [varname] (or options {}))]
{"$type" "Recode"
:Command "recode"
:recodedVariables varlist
:rules (apply-options-to-rules rules (or options {}))
:RecodedVariables varlist
:Rules (apply-options-to-rules rules (or options {}))
:mod-varlist (vec (concat *variables* (extract-target-variables varlist)))}))
:reshape_long (fn [& [stublist options]]
(if stublist
......@@ -284,9 +285,9 @@
true (concat *variables*)
true distinct
)]
{"$type" ""
:Command "append"
:files (first args)
{"$type" "AppendDatasets"
:Command "appendDatasets"
:FileName (first args)
:options (second args)
:mod-varlist varlist
}))
......
......@@ -61,17 +61,18 @@
{"$type" "VariableListExpression" :Variables (map variable-symbol-expression (expand-varlist varlist *variables*))})
(defn make-compute [varname funcname args _filter]
{:command "compute"
:variableNames [varname]
:expression {:function funcname
:isSdtlName true
:arguments (map-indexed
(fn [i arg] {:argumentName (str "EXP" (inc i))
:argumentValue arg})
{"$type" "Compute"
:Command "compute"
:Variable (variable-symbol-expression varname)
:Expression {"$type" "FunctionCallExpression"
:Function funcname
:IsSdtlName true
:Arguments (map-indexed
(fn [i arg] {:ArgumentName (str "EXP" (inc i))
:ArgumentValue arg})
args
)
"$type" "FunctionCallExpression"}
:condition _filter
)}
:Condition _filter
:mod-varlist (vec (conj *variables* varname))}
)
......@@ -86,9 +87,10 @@
)
(defn make-aggregate [by varname funcname expr _filter]
{:command "aggregate"
:groupByVariables by
:aggregateVariables [(dissoc (make-compute varname funcname expr _filter) :mod-varlist)]
{"$type" "Aggregate"
:Command "aggregate"
:GroupByVariables (map variable-symbol-expression by)
:AggregateVariables [(dissoc (make-compute varname funcname expr _filter) :mod-varlist)]
:mod-varlist (vec (conj *variables* varname))}
)
......@@ -99,7 +101,7 @@
"rowpctile"
(let [p (:p options {:Values [50]})]
[(make-varlist-expression varlist)
{"$type" "NumericConstantExpression" :Value (-> p :Values first)}]
(numeric-constant-expression (-> p :Values first))]
)
_filter)
:rowtotal (make-compute
......@@ -188,8 +190,8 @@
m (if m (get options m) {:Values [0]})
s (if s (get options s) {:Values [1]})]
[expr
{"$type" "NumericConstantExpression" :Value (-> m :Values first)}
{"$type" "NumericConstantExpression" :Value (-> s :Values first)}]
(numeric-constant-expression (-> m :Values first))
(numeric-constant-expression (-> s :Values first))]
)
_filter)
:pctile (make-aggregate
......@@ -197,7 +199,7 @@
varname
(get aggregate-funcs (keyword funcname))
[expr
{"$type" "NumericConstantExpression" :Value (-> (:p options {:Values [50]}) :Values first)}]
(numeric-constant-expression (-> (:p options {:Values [50]}) :Values first))]
_filter)
:pc (make-aggregate
by-clause
......@@ -211,13 +213,12 @@
varname
(get aggregate-funcs (keyword funcname))
[expr
{"$type" "StringConstantExpression"
:Value (cond
(get-var-length-option :field 1 options) "field"
(get-var-length-option :track 1 options) "track"
(get-var-length-option :unique 1 options) "unique"
:else "default"
)}]
(string-constant-expression (cond
(get-var-length-option :field 1 options) "field"
(get-var-length-option :track 1 options) "track"
(get-var-length-option :unique 1 options) "unique"
:else "default"
))]
_filter)
;;; default
......
......@@ -33,13 +33,13 @@
(defn function-lookup [& args]
(let [canonical (get function-mapping (first args))]
{:function (or canonical (first args))
:arguments (map-indexed
(fn [i arg] {:argumentName (str "EXP" (inc i))
:argumentValue arg})
{:Function (or canonical (first args))
:Arguments (map-indexed
(fn [i arg] {:ArgumentName (str "EXP" (inc i))
:ArgumentValue arg})
(rest args)
)
:isSdtlName (some? canonical)
:IsSdtlName (some? canonical)
"$type" "FunctionCallExpression"}
)
)
\ No newline at end of file
......@@ -178,12 +178,13 @@
(fn [var]
(let [src (if (string? var) var (:source var))
trg (if (string? var) var (:target var))]
{:command "compute"
:variableNames [trg]
:expression {"$type" "functionCallExpression"
:function (get collapse-stats (-> aggregation :aggstat keyword))
:isSdtlName true
:arguments (cond-> [(variable-symbol-expression src)]
{"$type" "Compute"
:Command "compute"
:Variable (variable-symbol-expression trg)
:Expression {"$type" "FunctionCallExpression"
:Function (get collapse-stats (-> aggregation :aggstat keyword))
:IsSdtlName true
:Arguments (cond-> [(variable-symbol-expression src)]
(:p aggregation) (conj (:p aggregation))
)
}
......@@ -196,12 +197,13 @@
(defn collapse-vars [& [aggregations filter weight options]]
(let [by-vars (expand-varlist (first (:by options)) *variables*)]
{:command "collapse"
:aggregateVariables (reduce #(concat (make-compute-list %1) (make-compute-list %2)) aggregations)
:condition filter
:weight weight
:cellwise (contains? options :cw)
:groupByVariables by-vars
{"$type" "Collapse"
:Command "collapse"
:GroupByVariables (map variable-symbol-expression by-vars)
:AggregateVariables (reduce #(concat (make-compute-list %1) (make-compute-list %2)) aggregations)
:WeightVariable (variable-symbol-expression weight)
:Condition filter
:Cellwise (contains? options :cw)
:mod-varlist (concat
by-vars
(extract-target-vars-from-aggregations aggregations)
......
......@@ -15,6 +15,16 @@
{"$type" "VariableSymbolExpression"
:VariableName varname})
(defn numeric-constant-expression
[value]
{"$type" "NumericConstantExpression"
:Value value})
(defn string-constant-expression
[value]
{"$type" "StringConstantExpression"
:Value value})
(defn get-var-length-option [k l m]
(loop [opts (keys m)]
(let [looking-for (apply str (take (inc l) (str k)))
......
This diff is collapsed.
This diff is collapsed.
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