List of usage examples for java.lang Double isNaN
public boolean isNaN()
From source file:net.cit.tetrad.dao.management.impl.SubDaoImpl.java
public List<DbStatus> dbLstNan(int deviceCode) { Query query = setDeviceCode(deviceCode); ServerStatus serverStatus = new ServerStatus(); serverStatus = (ServerStatus) monadService.getFindOne(query, ServerStatus.class, COLL_DASHBOARD); List<DbStatus> dbStatus = new ArrayList<DbStatus>(); if (serverStatus != null) dbStatus = serverStatus.getDbInfos(); for (DbStatus db : dbStatus) { Double avg = db.getAvgObjSize(); if (avg.isNaN()) { db.setAvgObjSize(0.0d);//from ww w .ja v a2 s .c o m } } return dbStatus; }
From source file:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java
@SuppressWarnings("nls") private XYDataset getScatterPlotData(SimpleFeatureCollection features) { // "LMiIndex", "LMiZScore", "LMiPValue", "COType" XYSeries xySeries = new XYSeries(features.getSchema().getTypeName()); minMaxVisitor.reset();//from w ww .j a v a2s . c om String typeName = features.getSchema().getTypeName(); SimpleFeatureIterator featureIter = features.features(); try { int i = 0; while (featureIter.hasNext()) { SimpleFeature feature = featureIter.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); Coordinate coordinate = geometry.getCentroid().getCoordinate(); // The X axis of the scatter plot represents the standardised Z values of your // variable (that is, theyve been standardised to their Z scores, with a mean of // zero, and a standard deviation of 1.) Double x = Converters.convert(feature.getAttribute("LMiZScore"), Double.class); if (x == null || x.isInfinite() || x.isNaN()) { continue; } // The Y axis represents the standardised values of the neighbouring values around // your point of interest, that is the lagged values. These are calculated according // to the spatial weights matrix that you specify. So, for instance, if you specify // a contiguous spatial weights matrix, with a first order queen contiguity, the // value of the y axis represents the mean value of the variable for all of the // areas that share a border with the area of interest. SpatialEvent source = new SpatialEvent(typeName + "." + ++i, coordinate); int neighbors = 0; double zSum = 0d; for (int j = 0; j < swMatrix.getEvents().size(); j++) { SpatialEvent target = swMatrix.getEvents().get(j); if (source.id == target.id) { continue; } double wij = swMatrix.getWeight(source, target); if (wij > 0) { neighbors++; zSum += zScore[j]; } } double y = neighbors == 0 ? 0d : zSum / neighbors; minMaxVisitor.visit(x, y); xySeries.add(new XYDataItem2(feature, x, y)); } } finally { featureIter.close(); } return new XYSeriesCollection(xySeries); }
From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java
private XYZDataset getBubbleChartData(SimpleFeatureCollection features, String xField, String yField, String sizeField) {// w w w .ja v a2 s. c om DefaultXYZDataset2 xyzDataset = new DefaultXYZDataset2(); // 1. prepare bubble size minMaxVisitor.visit(features, xField, yField, sizeField); final double minVal = minMaxVisitor.getMinZ(); final double maxVal = minMaxVisitor.getMaxZ(); final double diffVal = maxVal - minVal; final double scale = Math.min(minMaxVisitor.getMaxX(), minMaxVisitor.getMaxY()) / 8d; // 2. calculate x, y, z values final int featureCount = features.size(); double[] xAxis = new double[featureCount]; double[] yAxis = new double[featureCount]; double[] zAxis = new double[featureCount]; String[] featureIDS = new String[featureCount]; Expression xExpression = ff.property(xField); Expression yExpression = ff.property(yField); Expression sizeExpression = ff.property(sizeField); int index = 0; SimpleFeatureIterator featureIter = features.features(); try { while (featureIter.hasNext()) { SimpleFeature feature = featureIter.next(); featureIDS[index] = feature.getID(); Double xVal = xExpression.evaluate(feature, Double.class); if (xVal == null || xVal.isNaN() || xVal.isInfinite()) { continue; } Double yVal = yExpression.evaluate(feature, Double.class); if (yVal == null || yVal.isNaN() || yVal.isInfinite()) { continue; } Double sizeVal = sizeExpression.evaluate(feature, Double.class); if (sizeVal == null || sizeVal.isNaN() || sizeVal.isInfinite()) { continue; } xAxis[index] = xVal; yAxis[index] = yVal; double transformed = 0; if (diffVal != 0) { transformed = (sizeVal - minVal) / diffVal; } zAxis[index] = transformed * scale; index++; } } finally { featureIter.close(); } xyzDataset.addSeries(EMPTY, new double[][] { xAxis, yAxis, zAxis }); xyzDataset.addFeatrureIDS(EMPTY, featureIDS); return xyzDataset; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.directiveCouncil.SummariesControlAction.java
private BigDecimal getDifference(BigDecimal lessonHours, BigDecimal summaryHours) { Double difference; difference = (1 - ((lessonHours.doubleValue() - summaryHours.doubleValue()) / lessonHours.doubleValue())) * 100;//from ww w .j a v a 2s . c o m if (difference.isNaN() || difference.isInfinite()) { difference = 0.0; } return BigDecimal.valueOf(difference).setScale(2, RoundingMode.HALF_UP); }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
@Override protected void initialize() { CoolMapObject obj = getCoolMapObject(); if (!canRender(obj.getViewClass())) { return;/* w w w. j av a2 s . c o m*/ } double minValue = Double.MAX_VALUE; double maxValue = -Double.MAX_VALUE; for (int i = 0; i < obj.getViewNumRows(); i++) { for (int j = 0; j < obj.getViewNumColumns(); j++) { try { Double v = (Double) obj.getViewValue(i, j); if (v == null || v.isNaN()) { continue; } else { if (v < minValue) { minValue = v; } if (v > maxValue) { maxValue = v; } } } catch (Exception e) { } } } minValueField.setText(minValue + ""); maxValueField.setText(maxValue + ""); updateRenderer(); }
From source file:fsu.wdl.processors.customProcessor.MyProcessor.java
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get();//from w w w.j ava 2s . c om if (flowFile == null) { return; } try { String station = flowFile.getAttribute("station"); String rawtime = flowFile.getAttribute("time"); String rawvalue = flowFile.getAttribute(fieldToAggregate); long timevalue = Long.parseLong(rawtime); Double measurementvalue = Double.parseDouble(rawvalue); List<EnergyData> list = getList(station); if (rawtime != null && rawvalue != null) { if (timevalue >= System.currentTimeMillis() - interval) { synchronized (list) { list.add(new EnergyData(timevalue, measurementvalue)); } } } Double avg = 0.0; long counter = 0; synchronized (measurements) { for (Iterator<EnergyData> it = list.iterator(); it.hasNext();) { EnergyData next = it.next(); long timeentry = next.time; double valueentry = next.energy; if (timeentry >= System.currentTimeMillis() - interval) { counter++; avg = avg + valueentry; } else { it.remove(); } } } final Double avginner = avg / counter; // FlowFile output = session.write(flowFile, new OutputStreamCallback(){ // @Override // public void process(OutputStream outputStream) throws IOException { // if(avginner.isNaN()){ // IOUtils.write("NaN", outputStream, "UTF-8"); // }else{ // IOUtils.write(String.valueOf(avginner), outputStream, "UTF-8"); // } // } // }); if (avginner.isNaN()) { flowFile = session.putAttribute(flowFile, fieldToAggregate, "NaN"); } else { flowFile = session.putAttribute(flowFile, fieldToAggregate, String.valueOf(avginner)); } session.transfer(flowFile, REL_SUCCESS); } catch (ProcessException e) { getLogger().error("Unable to aggregate on flowFile with time" + flowFile.getAttribute("time")); session.transfer(flowFile, REL_FAILURE); } // try // { // //Read in Data // InputStream stream = session.read(flowFile); // String csv = IOUtils.toString(stream, "UTF-8"); // stream.close(); // // //Convert CSV data to JSON // List<Map<?,?>> objects = this.readObjectsFromCsv(csv); // // //Convert to JSON String // String json = this.writeAsJson(objects); // // //Output Flowfile // FlowFile output = session.write(flowFile, new OutputStreamCallback(){ // @Override // public void process(OutputStream outputStream) throws IOException { // IOUtils.write(json, outputStream, "UTF-8"); // } // }); // output = session.putAttribute(output, CoreAttributes.MIME_TYPE.key(), APPLICATION_JSON); // // output = session.putAttribute(output, CoreAttributes.FILENAME.key(), UUID.randomUUID().toString()+".json"); // session.transfer(output, REL_SUCCESS); // } catch (IOException e) { // getLogger().error("Unable to process Change CSV to JSON for this file "+flowFile.getAttributes().get(CoreAttributes.FILENAME)); // session.transfer(flowFile, REL_FAILURE); // } }
From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java
private ScreenOverlayType createHistogram(String transportMode, Map<Id, Double> evacuationTimes) throws IOException { /*//ww w. jav a 2 s . c o m * Remove NaN entries from the List */ List<Double> listWithoutNaN = new ArrayList<Double>(); for (Double d : evacuationTimes.values()) if (!d.isNaN()) listWithoutNaN.add(d); /* * If trip with significant to high evacuation times should be cut off */ if (limitMaxEvacuationTime) { double cutOffValue = meanEvacuationTime + standardDeviation * evacuationTimeCutOffFactor; ListIterator<Double> iter = listWithoutNaN.listIterator(); while (iter.hasNext()) { double value = iter.next(); if (value > cutOffValue) iter.remove(); } } double[] array = new double[listWithoutNaN.size()]; int i = 0; for (double d : listWithoutNaN) array[i++] = d; JFreeChart chart = createHistogramChart(transportMode, array); BufferedImage chartImage = chart.createBufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT); BufferedImage image = new BufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT, BufferedImage.TYPE_4BYTE_ABGR); // clone image and set alpha value for (int x = 0; x < OVERALLHISTOGRAMWIDTH; x++) { for (int y = 0; y < OVERALLHISTOGRAMHEIGHT; y++) { int rgb = chartImage.getRGB(x, y); Color c = new Color(rgb); int r = c.getRed(); int b = c.getBlue(); int g = c.getGreen(); int argb = 225 << 24 | r << 16 | g << 8 | b; // 225 as transparency value image.setRGB(x, y, argb); } } byte[] imageBytes = bufferedImageToByteArray(image); this.kmzWriter.addNonKMLFile(imageBytes, transportMode + OVERALLHISTROGRAM); ScreenOverlayType overlay = kmlObjectFactory.createScreenOverlayType(); LinkType icon = kmlObjectFactory.createLinkType(); icon.setHref(transportMode + OVERALLHISTROGRAM); overlay.setIcon(icon); overlay.setName("Histogram " + transportMode); // place the image top right Vec2Type overlayXY = kmlObjectFactory.createVec2Type(); overlayXY.setX(0.0); overlayXY.setY(1.0); overlayXY.setXunits(UnitsEnumType.FRACTION); overlayXY.setYunits(UnitsEnumType.FRACTION); overlay.setOverlayXY(overlayXY); Vec2Type screenXY = kmlObjectFactory.createVec2Type(); screenXY.setX(0.02); screenXY.setY(0.98); screenXY.setXunits(UnitsEnumType.FRACTION); screenXY.setYunits(UnitsEnumType.FRACTION); overlay.setScreenXY(screenXY); return overlay; }
From source file:com.almende.pi5.common.agents.AggregatingAgent.java
/** * Steer.//w w w. ja va2 s .co m * Run on each incoming report, incoming request. */ private void steer() { if (!ControlMode.CONTRACT.equals(modus) && !ControlMode.BALANCE.equals(modus)) { if (!getId().startsWith("bus_")) { sendReport(); } return; } if (!steeringLock.tryLock()) { if (steeringLock.hasQueuedThreads()) { return; } steeringLock.lock(); } final DateTime now = DateTime.now(); if (now.isAfter(currentTimeslot)) { updateTime(); } final PowerProfile aggregate = generateReport(); Double current_diff = getDiff(currentTimeslot.minus(TIMESLOTLENGTH), currentTimeslot, now, aggregate); Double next_diff = getDiff(currentTimeslot, currentTimeslot.plus(TIMESLOTLENGTH), currentTimeslot, aggregate); if (current_diff.isNaN()) { current_diff = 0.0; } if (next_diff.isNaN()) { next_diff = 0.0; } if (Math.abs(current_diff) < steerlimit && Math.abs(next_diff) < steerlimit) { LOG.info(getId() + ": Below steerlimit of " + steerlimit + " Watts (" + current_diff + " - " + next_diff + "):" + now); steeringLock.unlock(); return; } // Current timeslot: double current_percentage; if (current_diff > 0) { current_percentage = (current_diff / getFlexUp(now, aggregate)) * 2; LOG.log(Level.INFO, getId() + ": request: Currently more power usage needed:" + current_diff + " Watt (" + (current_percentage * 100) + "%):" + currentTimeslot.minus(TIMESLOTLENGTH) + "(" + currentTimeslot.minus(TIMESLOTLENGTH).getMillis() + ")"); } else if (current_diff == 0) { current_percentage = 0; } else { current_percentage = (current_diff / getFlexDown(now, aggregate)) * 2; LOG.log(Level.INFO, getId() + ": request: Currently less power usage needed:" + (-current_diff) + " Watt (" + (current_percentage * 100) + "%):" + currentTimeslot.minus(TIMESLOTLENGTH) + "(" + currentTimeslot.minus(TIMESLOTLENGTH).getMillis() + ")"); } if (current_percentage > 1) { current_percentage = 1; } if (current_percentage < 0.01) { current_percentage = 0.01; } // Next timeslot: double next_percentage; if (next_diff > 0) { next_percentage = (next_diff / getFlexUp(currentTimeslot, aggregate)) * 2; LOG.log(Level.INFO, getId() + ": request: Next timeslot more power usage needed:" + next_diff + " Watt (" + (next_percentage * 100) + "%):" + currentTimeslot + "(" + currentTimeslot.getMillis() + ")"); } else if (next_diff == 0) { next_percentage = 0; } else { next_percentage = (next_diff / getFlexDown(currentTimeslot, aggregate)) * 2; LOG.log(Level.INFO, getId() + ": request: Next timeslot less power usage needed:" + (-next_diff) + " Watt (" + (next_percentage * 100) + "%):" + currentTimeslot + "(" + currentTimeslot.getMillis() + ")"); } if (next_percentage > 1) { next_percentage = 1; } if (next_percentage < 0.01) { next_percentage = 0.01; } final List<ReportWrap> list = new ArrayList<ReportWrap>(reports.size()); reportsLock.readLock().lock(); list.addAll(reports); reportsLock.readLock().unlock(); Collections.sort(list); for (ReportWrap wrap : list) { if (Math.abs(current_diff) < 0.01 * steerlimit && Math.abs(next_diff) < 0.01 * steerlimit) { LOG.info(getId() + ": done steering:" + current_diff + " - " + next_diff); break; } LOG.info( getId() + ": still to go:" + current_diff + " - " + next_diff + " checking " + wrap.getOwner()); String agentUrl = wrap.getOwner(); PowerProfile report = wrap.getReport(); report.calcAll(); // Timeline based: PowerTimeLine diffLine = new PowerTimeLine(currentReport.getTimestamp()); CategoryProfile rep = report.getCategoryProfile(Categories.ALL.name()); double influence = 0; if (Math.abs(current_diff) >= 0) { if (current_diff > 0) { final double val = Math.min(current_diff, getFlexUp(now, report) * current_percentage); current_diff -= val; diffLine.addValueAt(now, val); influence += val; } else { final double val = Math.max(current_diff, getFlexDown(now, report) * current_percentage); current_diff -= val; diffLine.addValueAt(now, val); influence -= val; } } diffLine.zeroFrom(currentTimeslot); if (Math.abs(next_diff) >= 0) { if (next_diff > 0) { final double val = Math.min(next_diff, getFlexUp(currentTimeslot, report) * next_percentage); next_diff -= val; diffLine.addValueAt(currentTimeslot, val); influence += val; } else { final double val = Math.max(next_diff, getFlexDown(currentTimeslot, report) * next_percentage); next_diff -= val; diffLine.addValueAt(currentTimeslot, val); influence -= val; } } diffLine.zeroFrom(currentTimeslot.plus(TIMESLOTLENGTH)); if (influence <= 0) { LOG.warning(getId() + ": Not sending zero influence request to:" + agentUrl); continue; } LOG.fine(getId() + " diffLine:" + JOM.getInstance().valueToTree(diffLine)); LOG.fine(getId() + " demand:" + JOM.getInstance().valueToTree(rep.getDemand())); RequestProfile subRequest = new RequestProfile(); subRequest.setTimestamp(currentReport.getTimestamp()); subRequest.getRequest().add(rep.getDemand()).add(diffLine); ObjectNode params = JOM.createObjectNode(); params.set("request", JOM.getInstance().valueToTree(subRequest)); try { LOG.info(getId() + ": Sending request to Child:" + agentUrl + " -> " + params); reportsLock.writeLock().lock(); wrap.getReport() .merge(createProposal(report, subRequest), currentTimeslot.minus(TIMESLOTLENGTH), currentTimeslot.plus(TIMESLOTLENGTH)) .dropHistory(currentTimeslot.minus(TIMESLOTLENGTH)); reportsLock.writeLock().unlock(); getSender().get().call(URI.create(agentUrl), "request", params); } catch (IOException e) { LOG.log(Level.WARNING, getId() + ": Couldn't send profile onwards to:" + agentUrl, e); } } if (Math.abs(current_diff) > steerlimit || Math.abs(next_diff) > steerlimit) { LOG.warning(getId() + ": Reached steering limits, resetting goal and reporting max."); updateCurrentReport(false); sendReport(); } steeringLock.unlock(); }
From source file:at.alladin.rmbt.statisticServer.OpenTestSearchResource.java
public boolean isDouble(String input) { try {/*from w ww . j av a 2 s.c o m*/ Double v = Double.parseDouble(input); if (v.isNaN() || v.isInfinite()) { return false; } return true; } catch (Exception e) { return false; } }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
@Override public void renderCellSD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {/* www. java2 s . c om*/ try { g2D.setColor(UI.colorBlack2); g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); g2D.setColor(barColorNormal); // g2D.setStroke(null); g2D.setStroke(UI.stroke1_5); //This is the //int height = (int)Math.round(cellHeight * (v - _minValue)/(_maxValue - _minValue)); //g2D.fillRect(Math.round(anchorX), Math.round(anchorY + cellHeight - height), Math.round(cellWidth), Math.round(cellHeight)); if (rowNode.isSingleNode() && columnNode.isSingleNode()) { double medianP = (v - _minValue) / (_maxValue - _minValue); if (v >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * medianP), (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * medianP)); } else { // double min = percentile.evaluate(valueArray, 0); // double max = percentile.evaluate(valueArray, 100) double fiveVal[] = boxPlotValues(getCoolMapObject(), rowNode, columnNode); if (fiveVal == null) { g2D.setColor(UI.colorBlack1); g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); } double range = _maxValue - _minValue; double minP = (fiveVal[0] - _minValue) / range; double maxP = (fiveVal[4] - _minValue) / range; double medianP = (fiveVal[2] - _minValue) / range; double q1P = (fiveVal[1] - _minValue) / range; double q3P = (fiveVal[3] - _minValue) / range; try { g2D.drawLine((int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * maxP), (int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * minP)); if (fiveVal[2] >= disectBound) { g2D.setColor(UI.colorLightGreen4); } else { g2D.setColor(UI.colorOrange2); } g2D.fillRect((int) (anchorX + cellWidth / 4), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth / 2), (int) (cellHeight * (q3P - q1P))); if (fiveVal[2] >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } // g2D.setColor(barColorNormal); g2D.drawRect((int) (anchorX + cellWidth / 4), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth / 2), (int) (cellHeight * (q3P - q1P))); g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * medianP), (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * medianP)); } catch (Exception e) { System.err.println("Boxplot render exception"); } } g2D.setColor(UI.colorBlack1); g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); } catch (Exception e) { } } }