From 56183cba81736086e9a9e05f938f8c100632f356 Mon Sep 17 00:00:00 2001 From: stevereis <stevereis93@gmail.com> Date: Wed, 6 Oct 2021 16:22:30 +0200 Subject: [PATCH] Add rounded result to descriptive stats --- .../connectors/exareme/transformations.ts | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/api/src/engine/connectors/exareme/transformations.ts b/api/src/engine/connectors/exareme/transformations.ts index 76b5158..8df362c 100644 --- a/api/src/engine/connectors/exareme/transformations.ts +++ b/api/src/engine/connectors/exareme/transformations.ts @@ -34,19 +34,24 @@ export const transformToExperiment = jsonata(` ) `); -export const descriptiveModelToTables = jsonata(` -( - $e := function($x, $r) {($x != null) ? $x : ($r ? $r : '')}; +const headerDescriptivie = ` +$e := function($x, $r) {($x != null) ? $fnum($x) : ($r ? $r : '')}; + +$fnum := function($x) { $type($x) = 'number' ? $round($number($x),3) : $x }; + +$fn := function($o, $prefix) { + $type($o) = 'object' ? + $each($o, function($v, $k) {( + $type($v) = 'object' ? { $k: $v.count & ' (' & $v.percentage & '%)' } : { + $k: $v + } + )}) ~> $merge() + : {} +};`; - $fn := function($o, $prefix) { - $type($o) = 'object' ? - $each($o, function($v, $k) {( - $type($v) = 'object' ? { $k: $v.count & ' (' & $v.percentage & '%)' } : { - $k: $v - } - )}) ~> $merge() - : {} - }; +export const descriptiveModelToTables = jsonata(` +( + ${headerDescriptivie} $vars := $count(data.single.*)-1; $varName := $keys(data.single); @@ -79,17 +84,7 @@ export const descriptiveModelToTables = jsonata(` export const descriptiveSingleToTables = jsonata(` ( - $e := function($x, $r) {($x != null) ? $x : ($r ? $r : '')}; - - $fn := function($o, $prefix) { - $type($o) = 'object' ? - $each($o, function($v, $k) {( - $type($v) = 'object' ? { $k: $v.count & ' (' & $v.percentage & '%)' } : { - $k: $v - } - )}) ~> $merge() - : {} - }; + ${headerDescriptivie} data.[ $.single.*@$p#$i.( -- GitLab