Commit 05795c44 authored by Nico Mack's avatar Nico Mack

Fixed logging

parent 39819854
......@@ -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;
}
......
......@@ -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;
......
......@@ -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<Double> vector = (VectorVariable<Double>) variable;
List<Double> 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<Double>) variable;
if (!vector.isEmpty()) {
PyArray array = null;
if (Double.class.isAssignableFrom(vector.getClassOfValues())) {
List<Double> list = (List<Double>) 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<Integer> list = (List<Integer>) 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$
}
}
......
......@@ -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;
......
......@@ -35,6 +35,13 @@ public class VectorVariable<B> extends Variable<List<B>> implements Collection<B
value = new ArrayList<B>();
}
public Class<?> getClassOfValues() {
if (!value.isEmpty()) {
return value.get(0).getClass();
}
return value.getClass();
}
/** {@inheritDoc} */
@Override
public List<B> getValue() {
......
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