@Test public void executeTest() throws InterruptedException { String pointName = UUID.randomUUID().toString(); // create a point under the top level user with a random name Point point = new PointModel.Builder() .name(pointName) .parent(user.getId()) .highAlarmOn(true) .highAlarm(100.00) .lowAlarmOn(true) .lowAlarm(0.0) .create(); Entity newPoint = nimbits.addPoint(user, point); log("Created : " + newPoint.getName().getValue()); Optional<Point> foundPoint = nimbits.findPointByName(pointName); if (foundPoint.isPresent()) { log("verified point"); if (!foundPoint.get().isHighAlarmOn() || !foundPoint.get().isLowAlarmOn()) { throw new RuntimeException(" Alarm was off when it was set to on!"); } } else { throw new RuntimeException("Point not found after being created and searched for"); } // search for a point that was never created to test absent condition try { Optional<Point> shouldNotExist = nimbits.findPointByName(UUID.randomUUID().toString()); } catch (RetrofitError error) { assertEquals(404, error.getResponse().getStatus()); } // Record some values with the name only double testValue = 100.00 * new Random().nextDouble(); Value value = new Value.Builder().doubleValue(testValue).create(); nimbits.recordValue(pointName, value); Thread.sleep(1000); Value retrieved = nimbits.getSnapshot(pointName); assertEquals(value.getDoubleValue(), retrieved.getDoubleValue(), 0.001); veryifyFindCategory(); veryifyFindWebHook(); }
@Override public Value solveEquation(final User user, final Calculation calculation) throws NimbitsException { final MathEvaluator m = new MathEvaluatorImpl(calculation.getFormula()); log.info(calculation.getFormula()); if (!Utils.isEmptyString(calculation.getX()) && calculation.getFormula().contains("x")) { // Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getX()); final Entity p = EntityServiceFactory.getInstance() .getEntityByKey(user, calculation.getX(), EntityType.point) .get(0); if (p != null) { log.info("calc has an x car and i found " + p.getName()); final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p); final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue(); m.addVariable("x", d); } else { log.severe("calc has an x car and x not found"); } } if (!Utils.isEmptyString(calculation.getY()) && calculation.getFormula().contains("y")) { final Entity p = EntityServiceFactory.getInstance() .getEntityByKey(user, calculation.getY(), EntityType.point) .get(0); // Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getY()); if (p != null) { final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p); final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue(); m.addVariable("y", d); } } if (!Utils.isEmptyString(calculation.getZ()) && calculation.getFormula().contains("z")) { final Entity p = EntityServiceFactory.getInstance() .getEntityByKey(user, calculation.getZ(), EntityType.point) .get(0); // Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getZ()); if (p != null) { final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p); final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue(); m.addVariable("z", d); } } final Double retVal = m.getValue(); if (retVal == null) { throw new NimbitsException("Formula returned a null value: " + calculation.getFormula()); } return ValueFactory.createValueModel(retVal, "CV"); }