org.python.core.PyInteger Java Examples

The following examples show how to use org.python.core.PyInteger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XunfengInner.java    From TrackRay with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void process() {

    try {
        PythonInterpreter interpreter = python.interpreter();
        interpreter.execfile(filename);
        PyFunction check = interpreter.get("check", PyFunction.class);

        PyObject check_call = check.__call__(new PyString(ip), new PyInteger(port), new PyInteger(timeout));

        String result = check_call.toString();
        if (result!=null &&
                !StringUtils.contains(result,"None")
                && !StringUtils.contains(result,"False")) {

            //PyObject get_plugin_info = interpreter.get("get_plugin_info").__call__();
            //Map map = (Map) get_plugin_info.getDict().__tojava__(Map.class);
            this.result = result;
            return;
        }
    }catch (Exception e){
        log.error(e.toString());
    }

    result="";
}
 
Example #2
Source File: ListUtilities.java    From constellation with Apache License 2.0 5 votes vote down vote up
public Object mean(final Collection<Object> collection) throws ScriptException {
    final PyList pylist = new PyList(collection);
    if (pylist.__len__() == 0) {
        return null;
    }
    PyObject acc = __builtin__.sum(pylist);
    acc = acc.__div__(new PyInteger(pylist.__len__()));
    return acc;
}
 
Example #3
Source File: PythonStreamExecutionEnvironment.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void registerJythonSerializers(StreamExecutionEnvironment env) {
	env.registerTypeWithKryoSerializer(PyBoolean.class, PyBooleanSerializer.class);
	env.registerTypeWithKryoSerializer(PyFloat.class, PyFloatSerializer.class);
	env.registerTypeWithKryoSerializer(PyInteger.class, PyIntegerSerializer.class);
	env.registerTypeWithKryoSerializer(PyLong.class, PyLongSerializer.class);

	env.registerTypeWithKryoSerializer(PyString.class, PyStringSerializer.class);
	env.registerTypeWithKryoSerializer(PyUnicode.class, PyObjectSerializer.class);

	env.registerTypeWithKryoSerializer(PyTuple.class, PyObjectSerializer.class);
	env.registerTypeWithKryoSerializer(PyObjectDerived.class, PyObjectSerializer.class);
	env.registerTypeWithKryoSerializer(PyInstance.class, PyObjectSerializer.class);
}
 
Example #4
Source File: JythonUtils.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
public static double getFloat(ArgParser ap, int position)
/*     */   {
/* 129 */     PyObject arg = ap.getPyObject(position);
/*     */
/* 131 */     if (Py.isInstance(arg, PyFloat.TYPE)) {
/* 132 */       return ((PyFloat)arg).asDouble();
/*     */     }
/* 134 */     if (Py.isInstance(arg, PyInteger.TYPE)) {
/* 135 */       return ((PyInteger)arg).asDouble();
/*     */     }
/* 137 */     throw Py.TypeError("Unable to parse argument: " + position);
/*     */   }
 
Example #5
Source File: JythonUtils.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
public static double getFloat(ArgParser ap, int position, double defaultValue)
/*     */   {
/* 149 */     PyObject arg = ap.getPyObject(position, new PyFloat(defaultValue));
/*     */
/* 151 */     if (Py.isInstance(arg, PyFloat.TYPE)) {
/* 152 */       return ((PyFloat)arg).asDouble();
/*     */     }
/* 154 */     if (Py.isInstance(arg, PyInteger.TYPE)) {
/* 155 */       return ((PyInteger)arg).asDouble();
/*     */     }
/* 157 */     throw Py.TypeError("Unable to parse argument: " + position);
/*     */   }
 
Example #6
Source File: JythonUtils.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
private static PyObject convertObject(Object o) {
/* 222 */     if ((o instanceof String))
/* 223 */       return new PyString((String)o);
/* 224 */     if ((o instanceof Double))
/* 225 */       return new PyFloat(((Double)o).doubleValue());
/* 226 */     if ((o instanceof Integer))
/* 227 */       return new PyInteger(((Integer)o).intValue());
/* 228 */     if ((o instanceof Float)) {
/* 229 */       float f = ((Float)o).floatValue();
/* 230 */       return new PyFloat(f);
/*     */     }
/* 232 */     return Py.None;
/*     */   }
 
Example #7
Source File: PythonOperatorTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testJavaOperator()
{
  PythonOperator oper = new PythonOperator();
  String setupScript = "import operator\n";
  setupScript += "def square():\n";
  setupScript += "  return val*val\n\n";
  oper.addSetupScript(setupScript);
  oper.setScript("square()");
  oper.setPassThru(true);

  CollectorTestSink sink = new CollectorTestSink();
  oper.result.setSink(sink);
  HashMap<String, Object> tuple = new HashMap<String, Object>();
  tuple.put("val", new Integer(2));
  oper.setup(null);
  oper.beginWindow(0);
  oper.inBindings.process(tuple);
  oper.endWindow();

  Assert.assertEquals("number emitted tuples", 1, sink.collectedTuples.size());
  for (Object o : sink.collectedTuples) {
    PyInteger val = (PyInteger)o;
    Assert.assertEquals("emitted should be 4", new Integer(4),
        (Integer)val.__tojava__(Integer.class));
  }
}
 
Example #8
Source File: PyIntegerSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, PyInteger object) {
	output.writeInt(object.getValue());
}
 
Example #9
Source File: PyIntegerSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public PyInteger read(Kryo kryo, Input input, Class<PyInteger> type) {
	return new PyInteger(input.readInt());
}
 
Example #10
Source File: FlightTelemetry.java    From hazelcast-jet-demos with Apache License 2.0 4 votes vote down vote up
private void fromAirCraftEntry(KeyedWindowResult<Long, Aircraft> aircraftEntry) {
    Aircraft aircraft = aircraftEntry.getValue();
    metricName = new PyString(replaceWhiteSpace(aircraft.getAirport()) + "." + aircraft.getVerticalDirection());
    timestamp = new PyInteger(getEpochSecond(aircraft.getPosTime()));
    metricValue = new PyFloat(1);
}
 
Example #11
Source File: FlightTelemetry.java    From hazelcast-jet-demos with Apache License 2.0 4 votes vote down vote up
private void fromMaxNoiseEntry(KeyedWindowResult<String, Integer> entry) {
    metricName = new PyString(replaceWhiteSpace(entry.getKey()));
    timestamp = new PyInteger(getEpochSecond(entry.end()));
    metricValue = new PyFloat(entry.getValue());
}
 
Example #12
Source File: FlightTelemetry.java    From hazelcast-jet-demos with Apache License 2.0 4 votes vote down vote up
private void fromTotalC02Entry(KeyedWindowResult<String, Double> entry) {
    metricName = new PyString(replaceWhiteSpace(entry.getKey()));
    timestamp = new PyInteger(getEpochSecond(entry.end()));
    metricValue = new PyFloat(entry.getValue());
}
 
Example #13
Source File: AndroidRobot.java    From sikuli-monkey with MIT License 4 votes vote down vote up
public void tap(int x, int y) {
    _device.touch(new PyObject[] { new PyInteger(x), new PyInteger(y), new PyString("DOWN_AND_UP")}, null);
}
 
Example #14
Source File: AndroidRobot.java    From sikuli-monkey with MIT License 4 votes vote down vote up
public void longPress(int x, int y) {
    PyTuple point = new PyTuple(new PyInteger(x), new PyInteger(y));
    _device.drag(new PyObject[] { point, point, new PyInteger(2), new PyInteger(2) }, null);
}