From 05795c441601853dee01264b7a936c46900736ee Mon Sep 17 00:00:00 2001 From: Nico Mack Date: Tue, 4 Apr 2017 15:08:42 +0200 Subject: [PATCH] Fixed logging --- .../system/executor/JavascriptExecutor.java | 18 +++--- .../cps/system/executor/OctaveExecutor.java | 18 +++--- .../cps/system/executor/PythonExecutor.java | 61 ++++++++++++------- .../tui/cps/system/executor/SqlExecutor.java | 16 +++-- .../dkd/tui/cps/variable/VectorVariable.java | 7 +++ 5 files changed, 72 insertions(+), 48 deletions(-) diff --git a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/JavascriptExecutor.java b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/JavascriptExecutor.java index 800c6e6..6ad26f5 100644 --- a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/JavascriptExecutor.java +++ b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/JavascriptExecutor.java @@ -28,10 +28,10 @@ public class JavascriptExecutor extends Executor { } @Override - public void set(Variable variable) { + public void set(Variable variable) { engine.put(variable.getName(), variable.getValue()); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Parameter {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Parameter {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ } } @@ -41,8 +41,8 @@ public class JavascriptExecutor extends Executor { long elapsed = System.currentTimeMillis(); result = engine.eval(script); elapsed = System.currentTimeMillis() - elapsed; - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Eval => {} | took {} ms!", script, elapsed); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Eval => {} | took {} ms!", script, elapsed); //$NON-NLS-1$ } } catch (ScriptException exception) { this.executionErrors.append(exception.toString()); @@ -54,10 +54,10 @@ public class JavascriptExecutor extends Executor { } @Override - public Variable get(Variable variable) { - variable.setValue(result); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Result {} = {}", variable.getName(), result); //$NON-NLS-1$ + public Variable get(Variable variable) { + variable.setValueFromObject(result); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Result {} = {}", variable.getName(), result); //$NON-NLS-1$ } return variable; } diff --git a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/OctaveExecutor.java b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/OctaveExecutor.java index 8a7d734..5577cc2 100644 --- a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/OctaveExecutor.java +++ b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/OctaveExecutor.java @@ -44,11 +44,11 @@ public class OctaveExecutor extends Executor { } @Override - public void set(Variable variable) { + public void set(Variable variable) { Double numericValue = Double.valueOf(variable.getValue().toString()); engine.put(variable.getName(), Octave.scalar(numericValue)); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Parameter {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Parameter {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ } } @@ -57,18 +57,18 @@ public class OctaveExecutor extends Executor { long elapsed = System.currentTimeMillis(); engine.eval(script); elapsed = System.currentTimeMillis() - elapsed; - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Eval => {} | took {} ms!", script, elapsed); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Eval => {} | took {} ms!", script, elapsed); //$NON-NLS-1$ } return true; } @Override - public Variable get(Variable variable) { + public Variable get(Variable variable) { OctaveDouble result = engine.get(OctaveDouble.class, variable.getName()); - variable.setValue(result.get(1)); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Result {} = {}", variable.getName(), result.get(1)); //$NON-NLS-1$ + variable.setValueFromObject(result.get(1)); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Result {} = {}", variable.getName(), result.get(1)); //$NON-NLS-1$ } return variable; diff --git a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java index a12e2a1..31448c6 100644 --- a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java +++ b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java @@ -6,6 +6,7 @@ import lu.list.itis.dkd.tui.cps.variable.VectorVariable; import org.python.core.PyArray; import org.python.core.PyFloat; +import org.python.core.PyInteger; import org.python.core.PyObject; import org.python.core.PyTuple; import org.python.util.PythonInterpreter; @@ -51,27 +52,45 @@ public class PythonExecutor extends Executor { @Override public void set(Variable variable) { if (variable instanceof VectorVariable) { - VectorVariable vector = (VectorVariable) variable; - List list = vector.getValue(); - if (!list.isEmpty()) { - PyArray array = new PyArray(Double.class, list.size()); - int index = 0; - for (Double value : list) { - if (value == null) - value = Double.valueOf(0); - array.set(index++, new PyFloat(value)); - } - engine.set(variable.getName(), array); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Parameter -> {} = {}", variable.getName(), list.toString()); //$NON-NLS-1$ + VectorVariable vector = (VectorVariable) variable; + if (!vector.isEmpty()) { + PyArray array = null; + + if (Double.class.isAssignableFrom(vector.getClassOfValues())) { + List list = (List) vector.getValue(); + array = new PyArray(Double.class, list.size()); + int index = 0; + for (Double value : list) { + if (value == null) + value = Double.valueOf(0); + array.set(index++, new PyFloat(value)); + } + engine.set(variable.getName(), array); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Parameter -> {} = {}", variable.getName(), list.toString()); //$NON-NLS-1$ + } + + } else if (Integer.class.isAssignableFrom(vector.getClassOfValues())) { + List list = (List) vector.getValue(); + array = new PyArray(Integer.class, list.size()); + int index = 0; + for (Integer value : list) { + if (value == null) + value = Integer.valueOf(0); + array.set(index++, new PyInteger(value)); + } + engine.set(variable.getName(), array); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Parameter -> {} = {}", variable.getName(), list.toString()); //$NON-NLS-1$ + } } } } else { Double numericValue = Double.valueOf(variable.getValue().toString()); engine.set(variable.getName(), new PyFloat(numericValue)); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Parameter -> {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Parameter -> {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ } } } @@ -81,8 +100,8 @@ public class PythonExecutor extends Executor { long elapsed = System.currentTimeMillis(); engine.exec(script); elapsed = System.currentTimeMillis() - elapsed; - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Eval took {} ms | {}", elapsed, script); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Eval took {} ms | {}", elapsed, script); //$NON-NLS-1$ } return true; } @@ -96,14 +115,14 @@ public class PythonExecutor extends Executor { if (tupleMatcher.matches()) { PyTuple tuple = (PyTuple) engine.get(tupleMatcher.group(1)); result = tuple.__getattr__(tupleMatcher.group(2)); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Result <- {} = {}.{} = {}", variable.getName(), tupleMatcher.group(1), tupleMatcher.group(2), result); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Result <- {} = {}.{} = {}", variable.getName(), tupleMatcher.group(1), tupleMatcher.group(2), result); //$NON-NLS-1$ } } } else { result = engine.get(variable.getName()); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Result <- {} = {}", variable.getName(), result); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Result <- {} = {}", variable.getName(), result); //$NON-NLS-1$ } } diff --git a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/SqlExecutor.java b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/SqlExecutor.java index 2c629fb..e10577f 100644 --- a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/SqlExecutor.java +++ b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/SqlExecutor.java @@ -291,8 +291,8 @@ public class SqlExecutor extends Executor { @Override public void set(Variable variable) { parameters.put(variable.getName(), variable.getValue()); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Parameter -> {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Parameter -> {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ } } @@ -319,8 +319,8 @@ public class SqlExecutor extends Executor { columnTypes = this.getColumnTypes(rows); columnValues = this.convertResults(rows); elapsed = System.currentTimeMillis() - elapsed; - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Eval took {} ms | {}", elapsed, script); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Eval took {} ms | {}", elapsed, script); //$NON-NLS-1$ } } catch (SQLException e) { @@ -388,14 +388,12 @@ public class SqlExecutor extends Executor { Object[] values = columnValues.get(0); variable.setValueFromObject(values[index]); } else { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Query returned no results!"); //$NON-NLS-1$ - } + LOGGER.info("Query returned no results!"); //$NON-NLS-1$ } } } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Result <- {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Result <- {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$ } return variable; diff --git a/CPS/src/lu/list/itis/dkd/tui/cps/variable/VectorVariable.java b/CPS/src/lu/list/itis/dkd/tui/cps/variable/VectorVariable.java index 89f676d..1590da3 100644 --- a/CPS/src/lu/list/itis/dkd/tui/cps/variable/VectorVariable.java +++ b/CPS/src/lu/list/itis/dkd/tui/cps/variable/VectorVariable.java @@ -35,6 +35,13 @@ public class VectorVariable extends Variable> implements Collection(); } + public Class getClassOfValues() { + if (!value.isEmpty()) { + return value.get(0).getClass(); + } + return value.getClass(); + } + /** {@inheritDoc} */ @Override public List getValue() { -- GitLab