List of usage examples for java.lang Double MAX_VALUE
double MAX_VALUE
To view the source code for java.lang Double MAX_VALUE.
Click Source Link
From source file:com.act.lcms.db.io.report.IonAnalysisInterchangeModel.java
/** * This function is used to compute log frequency distribution of the ion model vs a metric. * @param metric The metric on which the frequency distribution is plotted * @return A map of a range to the count of molecules that get bucketed in that range *///from w ww. j ava 2 s. c om public Map<Pair<Double, Double>, Integer> computeLogFrequencyDistributionOfMoleculeCountToMetric( METRIC metric) { Map<Pair<Double, Double>, Integer> rangeToHitCount = new HashMap<>(); // This variable represents the total number of statistics that have zero values. Integer countOfZeroStats = 0; // This statistic represents the log value of the min statistic. Double minLogValue = Double.MAX_VALUE; for (ResultForMZ resultForMZ : this.getResults()) { for (HitOrMiss molecule : resultForMZ.getMolecules()) { Double power = 0.0; switch (metric) { case TIME: power = Math.log10(molecule.getTime()); break; case INTENSITY: power = Math.log10(molecule.getIntensity()); break; case SNR: power = Math.log10(molecule.getSnr()); break; } if (power.equals(Double.NEGATIVE_INFINITY)) { // We know the statistic was 0 here. countOfZeroStats++; break; } Double floor = Math.floor(power); Double lowerBound = Math.pow(10.0, floor); Double upperBound = Math.pow(10.0, floor + 1); minLogValue = Math.min(minLogValue, lowerBound); Pair<Double, Double> key = Pair.of(lowerBound, upperBound); rangeToHitCount.compute(key, (k, v) -> (v == null) ? 1 : v + 1); } // We count the total number of zero statistics and put them in the 0 to minLog metric bucket. if (countOfZeroStats > 0) { Pair<Double, Double> key = Pair.of(0.0, minLogValue); rangeToHitCount.put(key, countOfZeroStats); } } return rangeToHitCount; }
From source file:gda.device.detector.mythen.data.MythenDataFileUtils.java
public static double[][][] binMythenData(double[][][] input, double binSize) { // Find min/max angle double minAngle = Double.MAX_VALUE; double maxAngle = Double.MIN_VALUE; for (double[][] dataset : input) { for (double[] channel : dataset) { minAngle = Math.min(channel[0], minAngle); maxAngle = Math.max(channel[0], maxAngle); }/* w ww . j a va 2 s . co m*/ } // Determine bins final int minBinNum = (int) Math.floor(minAngle / binSize); final int maxBinNum = (int) Math.ceil(maxAngle / binSize); final int numBins = maxBinNum - minBinNum + 1; final int numDatasets = input.length; // Create binned data array double[][][] binnedData = new double[numDatasets][][]; // Create array for each dataset for (int dataset = 0; dataset < numDatasets; dataset++) { binnedData[dataset] = new double[numBins][]; } // Within each dataset, create array for each bin // Iterate through bins first, then datasets, for efficiency (only calculate a bin's start angle once) for (int bin = 0; bin < numBins; bin++) { final double binStartAngle = (bin + minBinNum) * binSize; for (int dataset = 0; dataset < numDatasets; dataset++) { binnedData[dataset][bin] = new double[] { binStartAngle, 0 }; } } // Bin data for (int dataset = 0; dataset < numDatasets; dataset++) { // logger.debug(String.format("Dataset %d of %d", dataset+1, numDatasets)); final double[][] inputDataset = input[dataset]; for (double[] channel : inputDataset) { final double angle = channel[0]; final int binNumForAngle = (int) Math.floor(angle / binSize); final int binIndexForAngle = binNumForAngle - minBinNum; final double[] binForAngle = binnedData[dataset][binIndexForAngle]; final double count = channel[1]; // logger.debug(String.format("%.16f %.1f = %.16f => %d/%d\tcount=%.0f", angle, binSize, // (angle/binSize), binNumForAngle, binIndexForAngle, count)); binForAngle[1] = Math.max(binForAngle[1], count); } } return binnedData; }
From source file:org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.ObsResource1_8Test.java
@Test public void asRepresentation_shouldReturnProperlyEncodedValues() throws Exception { Obs obs = getObject();//ww w . j ava 2s.c om obs.setComment(null); // to test that we don't get a NPE when no comment (specifically with the Location example) // coded Concept concept = Context.getConceptService().getConceptByUuid("a09ab2c5-878e-4905-b25d-5784167d0216"); clearAndSetValue(obs, ObsType.CODED, concept); SimpleObject rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertTrue(rep.keySet().contains("value")); rep = (SimpleObject) rep.get("value"); Assert.assertEquals("coded", concept.getUuid(), rep.get("uuid")); // datetime Date datetime = new Date(); clearAndSetValue(obs, ObsType.DATETIME, datetime); rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertEquals("datetime", datetime, ConversionUtil.convert(rep.get("value"), Date.class)); // drug Drug drug = Context.getConceptService().getDrugByUuid("3cfcf118-931c-46f7-8ff6-7b876f0d4202"); clearAndSetValue(obs, ObsType.DRUG, drug); rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertTrue(rep.keySet().contains("value")); rep = (SimpleObject) rep.get("value"); Assert.assertEquals("drug", drug.getUuid(), rep.get("uuid")); // string-based (complex, text) String test = "whoa"; clearAndSetValue(obs, ObsType.COMPLEX, test); rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertEquals("complex", test, rep.get("value")); clearAndSetValue(obs, ObsType.TEXT, test); rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertEquals("text", test, rep.get("value")); // numeric Double number = Double.MAX_VALUE; clearAndSetValue(obs, ObsType.NUMERIC, number); rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertEquals("numeric", number, rep.get("value")); // location Location location = Context.getLocationService().getLocation(2); clearAndSetValue(obs, ObsType.TEXT, location.getId().toString()); obs.setComment("org.openmrs.Location"); rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertTrue(rep.keySet().contains("value")); rep = (SimpleObject) rep.get("value"); Assert.assertEquals("location", location.getUuid(), rep.get("uuid")); ; // location referenced by uuid location = Context.getLocationService().getLocation(2); clearAndSetValue(obs, ObsType.TEXT, location.getUuid()); obs.setComment("org.openmrs.Location"); rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertTrue(rep.keySet().contains("value")); rep = (SimpleObject) rep.get("value"); Assert.assertEquals("location", location.getUuid(), rep.get("uuid")); // location that doesn't exist shouldn't cause error, just return null clearAndSetValue(obs, ObsType.TEXT, "20000"); obs.setComment("org.openmrs.Location"); rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertNull(rep.get("value")); rep = (SimpleObject) rep.get("value"); }
From source file:mil.tatrc.physiology.utilities.csv.plots.MultiPlotter.java
@Override public void plot(LogListener listener, SESubstanceManager subMgr) { //fill PlotJob with needed data if it doesn't exist PlotJob job = (PlotJob) listener;//ww w.j a va2 s . c o m if (job.dataPath == null || job.dataPath.isEmpty()) { job.dataPath = "../verification/Scenarios/" + job.verificationDirectory + "/Current Baseline/"; } if (job.dataFile == null || job.dataFile.isEmpty()) { job.dataFile = job.name + "Results.zip"; } //Get data contents for all headers when all data is in one file if ((data.isEmpty() || data == null) && job.experimentalData == null) { try { CSVContents csv = new CSVContents(job.dataPath + job.dataFile); csv.abbreviateContents = job.resultsSkipNum; for (int i = 0; i < job.headers.size(); i++) { List<Double> headerData = new ArrayList<Double>(); csv.readHeader(csv.unitUnderscoreToSpace(job.headers.get(i)), headerData); data.put(job.headers.get(i), headerData); } } catch (IOException e) { Log.error("Could not analyze file " + job.dataPath + job.dataFile); } } //Get data contents when we're also using experimental files else if ((data.isEmpty() || data == null) && job.experimentalData != null) { CSVContents dataCsv = null; CSVContents expCsv = null; try { dataCsv = new CSVContents(job.dataPath + job.dataFile); dataCsv.abbreviateContents = job.resultsSkipNum; } catch (IOException e) { Log.error("Could not analyze file " + job.dataPath + job.dataFile); } try { expCsv = new CSVContents(job.experimentalData); expCsv.abbreviateContents = 0; //we'll use all of the experimental data } catch (IOException e) { Log.error("Could not analyze file " + job.experimentalData); } try { //Get data from X1 and Y1, which should always be from our normal data file for (int i = 0; i < job.Y1headers.size(); i++) { List<Double> headerData = new ArrayList<Double>(); dataCsv.readHeader(dataCsv.unitUnderscoreToSpace(job.Y1headers.get(i)), headerData); data.put(job.Y1headers.get(i), headerData); } List<Double> headerData = new ArrayList<Double>(); dataCsv.readHeader(dataCsv.unitUnderscoreToSpace(job.X1header), headerData); data.put(job.X1header, headerData); for (int i = 0; i < job.Y2headers.size(); i++) { List<Double> headerData2 = new ArrayList<Double>(); expCsv.readHeader(expCsv.unitUnderscoreToSpace(job.Y2headers.get(i)), headerData2); expData.put(job.Y2headers.get(i), headerData2); } List<Double> headerData2 = new ArrayList<Double>(); expCsv.readHeader(expCsv.unitUnderscoreToSpace(job.X2header), headerData2); expData.put(job.X2header, headerData2); } catch (Exception e) { Log.error("A problem was encountered reading headers from files."); } } //Catch some errors if (job.Y2headers.size() > 0 && job.X2header == null) { Log.error("No X2 header specified for job " + job.name + ". Each Y axis must have a corresponding X axis."); return; } //Make a dataSeries for desired headers and add to collection(s) CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions String title = job.name + "_"; XYSeriesCollection dataSet1 = new XYSeriesCollection(); XYSeriesCollection dataSet2 = new XYSeriesCollection(); double maxY1 = 0; double minY1 = Double.MAX_VALUE; double maxY2 = 0; double minY2 = Double.MAX_VALUE; for (int i = 0; i < job.Y1headers.size(); i++) { XYSeries dataSeries; if (job.experimentalData != null) dataSeries = plotTool.createXYSeries("BioGears " + job.Y1headers.get(i), data.get(job.X1header), data.get(job.Y1headers.get(i))); else dataSeries = plotTool.createXYSeries(job.Y1headers.get(i), data.get(job.X1header), data.get(job.Y1headers.get(i))); dataSet1.addSeries(dataSeries); title = title + job.Y1headers.get(i) + "_"; maxY1 = maxY1 < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY1; minY1 = minY1 > dataSeries.getMinY() ? dataSeries.getMinY() : minY1; } for (int i = 0; i < job.Y2headers.size(); i++) { XYSeries dataSeries; if (job.experimentalData != null) dataSeries = plotTool.createXYSeries("Experimental " + job.Y2headers.get(i), expData.get(job.X2header), expData.get(job.Y2headers.get(i))); else dataSeries = plotTool.createXYSeries(job.Y2headers.get(i), data.get(job.X2header), data.get(job.Y2headers.get(i))); dataSet2.addSeries(dataSeries); title = title + job.Y2headers.get(i) + "_"; maxY2 = maxY2 < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY2; minY2 = minY2 > dataSeries.getMinY() ? dataSeries.getMinY() : minY2; } title = title + "vs_" + job.X1header; if (job.X2header != null && !job.X1header.equalsIgnoreCase(job.X2header)) title = title + "_" + job.X2header; //Override the constructed title if desired if (job.titleOverride != null && !job.titleOverride.isEmpty() && !job.titleOverride.equalsIgnoreCase("None")) title = job.titleOverride; //set labels String XAxisLabel = job.X1header; String YAxisLabel = job.Y1headers.get(0); JFreeChart chart = ChartFactory.createXYLineChart( job.titleOverride != null && job.titleOverride.equalsIgnoreCase("None") ? "" : title, // chart title XAxisLabel, // x axis label YAxisLabel, // y axis label dataSet1, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); Log.info("Creating Graph " + title); XYPlot plot = (XYPlot) chart.getPlot(); if (!job.logAxis) { // Determine Y1 range double resMax0 = maxY1; double resMin0 = minY1; if (Double.isNaN(resMax0) || Double.isNaN(resMin0)) plot.getDomainAxis(0).setLabel("Range is NaN"); if (DoubleUtils.isZero(resMin0)) resMin0 = -0.001; if (DoubleUtils.isZero(resMax0)) resMax0 = 0.001; double rangeLength = resMax0 - resMin0; ValueAxis yAxis = plot.getRangeAxis(0); if (rangeLength != 0) yAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);//15% buffer so we can see top and bottom clearly //Override the bounds if desired try { if (job.Y1LowerBound != null) yAxis.setLowerBound(job.Y1LowerBound); if (job.Y1UpperBound != null) yAxis.setUpperBound(job.Y1UpperBound); } catch (Exception e) { Log.error( "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist."); } plot.setRangeAxis(0, yAxis); //Add the second Y axis to the right side if (!job.Y2headers.isEmpty()) { ValueAxis rightYAxis = new NumberAxis(); // Determine Y2 range double resMax1 = maxY2; double resMin1 = minY2; if (Double.isNaN(resMax1) || Double.isNaN(resMin1)) plot.getDomainAxis(1).setLabel("Range is NaN"); if (DoubleUtils.isZero(resMin1)) resMin1 = -0.001; if (DoubleUtils.isZero(resMax1)) resMax1 = 0.001; rangeLength = resMax1 - resMin1; if (rangeLength != 0) rightYAxis.setRange(resMin1 - 0.15 * rangeLength, resMax1 + 0.15 * rangeLength); rightYAxis.setLabel(job.Y2headers.get(0)); //Override the bounds if desired try { if (job.Y2LowerBound != null) rightYAxis.setLowerBound(job.Y2LowerBound); if (job.Y2UpperBound != null) rightYAxis.setUpperBound(job.Y2UpperBound); } catch (Exception e) { Log.error( "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist."); } plot.setRangeAxis(1, rightYAxis); } } else { double resMin = minY1 < minY2 ? minY1 : minY2; if (resMin <= 0.0) resMin = .00001; LogarithmicAxis yAxis = new LogarithmicAxis("Log(" + YAxisLabel + ")"); yAxis.setLowerBound(resMin); //Override the bounds if desired try { if (job.Y1LowerBound != null) yAxis.setLowerBound(job.Y1LowerBound); if (job.Y1UpperBound != null) yAxis.setUpperBound(job.Y1UpperBound); } catch (Exception e) { Log.error( "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist."); } plot.setRangeAxis(0, yAxis); if (!job.Y2headers.isEmpty()) { LogarithmicAxis rightYAxis = new LogarithmicAxis("Log(" + job.Y2headers.get(0) + ")"); rightYAxis.setLowerBound(resMin); //Override the bounds if desired try { if (job.Y2LowerBound != null) rightYAxis.setLowerBound(job.Y2LowerBound); if (job.Y2UpperBound != null) rightYAxis.setUpperBound(job.Y2UpperBound); } catch (Exception e) { Log.error( "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist."); } plot.setRangeAxis(1, rightYAxis); } } //Override X bounds if desired try { if (job.X1LowerBound != null) plot.getDomainAxis(0).setLowerBound(job.X1LowerBound); if (job.X1UpperBound != null) plot.getDomainAxis(0).setUpperBound(job.X1UpperBound); if (job.X2LowerBound != null) plot.getDomainAxis(1).setLowerBound(job.X2LowerBound); if (job.X2UpperBound != null) plot.getDomainAxis(1).setUpperBound(job.X2UpperBound); } catch (Exception e) { Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist."); } //Add the second dataset if necessary if (!job.Y2headers.isEmpty()) { plot.setDataset(1, dataSet2); plot.mapDatasetToRangeAxis(1, 1); } //Override labels if desired if (job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN")) plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None") ? "" : job.X1Label); if (job.X2Label != null && plot.getDomainAxis(1) != null) plot.getDomainAxis(1).setLabel(job.X2Label.equalsIgnoreCase("None") ? "" : job.X2Label); if (job.Y1Label != null) plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None") ? "" : job.Y1Label); if (job.Y2Label != null && plot.getRangeAxis(1) != null) plot.getRangeAxis(1).setLabel(job.Y2Label.equalsIgnoreCase("None") ? "" : job.Y2Label); //Format lines and colors plot.setDomainGridlinesVisible(job.showGridLines); plot.setRangeGridlinesVisible(job.showGridLines); formatMultiPlot(job, chart, dataSet1, dataSet2); //Handle legends if (job.removeAllLegends) chart.removeLegend(); //Make the file try { FileUtils.createDirectory(job.outputDir); String filename = job.outputFilename == null ? job.outputDir + "/" + plotTool.MakeFileName(title) + ".jpg" : job.outputDir + "/" + job.outputFilename; if (!filename.endsWith(".jpg")) filename = filename + ".jpg"; File JPGFile = new File(filename); if (job.imageHeight != null && job.imageWidth != null) ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight); else ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800); } catch (IOException e) { Log.error(e.getMessage()); } }
From source file:com.flowpowered.api.geo.discrete.Point.java
/** * Gets the Manhattan distance between two points. * * This will return Double.MAX_VALUE if the other Point is null, either world is null, or the two points are in different worlds. * * Otherwise, it returns the Manhattan distance. *//*ww w .ja va 2s . c om*/ public double getManhattanDistance(Point other) { if (other == null || world == null || other.world == null || !world.equals(other.world)) { return Double.MAX_VALUE; } return Math.abs(getX() - other.getX()) + Math.abs(getY() - other.getY()) + Math.abs(getZ() - other.getZ()); }
From source file:com.joptimizer.algebra.Matrix1NornRescaler.java
/** * Check if the scaling algorithm returned proper results. * Note that AOriginal cannot be only subdiagonal filled, because this check * is for both symm and bath notsymm matrices. * @param AOriginal the ORIGINAL (before scaling) matrix * @param U the return of the scaling algorithm * @param V the return of the scaling algorithm * @param base/*from w ww . j a va 2 s. c om*/ * @return */ @Override public boolean checkScaling(final DoubleMatrix2D AOriginal, final DoubleMatrix1D U, final DoubleMatrix1D V) { int c = AOriginal.columns(); int r = AOriginal.rows(); final double[] maxValueHolder = new double[] { -Double.MAX_VALUE }; IntIntDoubleFunction myFunct = new IntIntDoubleFunction() { @Override public double apply(int i, int j, double pij) { maxValueHolder[0] = Math.max(maxValueHolder[0], Math.abs(pij)); return pij; } }; DoubleMatrix2D AScaled = ColtUtils.diagonalMatrixMult(U, AOriginal, V); //view A row by row boolean isOk = true; for (int i = 0; isOk && i < r; i++) { maxValueHolder[0] = -Double.MAX_VALUE; DoubleMatrix2D P = AScaled.viewPart(i, 0, 1, c); P.forEachNonZero(myFunct); isOk = Math.abs(1. - maxValueHolder[0]) < eps; } //view A col by col for (int j = 0; isOk && j < c; j++) { maxValueHolder[0] = -Double.MAX_VALUE; DoubleMatrix2D P = AScaled.viewPart(0, j, r, 1); P.forEachNonZero(myFunct); isOk = Math.abs(1. - maxValueHolder[0]) < eps; } return isOk; }
From source file:fr.lig.sigma.astral.gui.graph.sugiyama.SugiyamaLayerStack.java
void xPosDown(int staticIndex, int flexIndex) { List<Node<E>> flex = layers.get(flexIndex); for (int i = 0; i < flex.size(); i++) { Node<E> n = flex.get(i); double min = i > 0 ? flex.get(i - 1).getPos().x + flex.get(i - 1).getSize().x + X_SEP : -Double.MAX_VALUE; List<Node<E>> neighbors = getConnectedTo(n, staticIndex); double avg = avgX(neighbors); if (!Double.isNaN(avg)) { n.setPos(max(min, avg - n.getSize().x / 2d), n.getPos().y); }//w w w. ja v a 2 s.c o m } }
From source file:mil.tatrc.physiology.utilities.csv.plots.ConvexHullPlotter.java
public void plot(LogListener listener, SESubstanceManager subMgr) { //fill PlotJob with needed data if it doesn't exist PlotJob job = (PlotJob) listener;//from w w w . ja v a 2s . co m if (job.dataPath == null || job.dataPath.isEmpty()) { job.dataPath = "../verification/Scenarios/" + job.verificationDirectory + "/Current Baseline/"; } if (job.dataFile == null || job.dataFile.isEmpty()) { job.dataFile = job.name + "Results.zip"; } //Get data contents for all headers if (data.isEmpty() || data == null) { try { CSVContents csv = new CSVContents(job.dataPath + job.dataFile); csv.abbreviateContents = job.resultsSkipNum; for (int i = 0; i < job.headers.size(); i++) { List<Double> headerData = new ArrayList<Double>(); csv.readHeader(csv.unitUnderscoreToSpace(job.headers.get(i)), headerData); data.put(job.headers.get(i), headerData); } } catch (IOException e) { Log.error("Could not analyze file " + job.dataPath + job.dataFile); } } //Catch some errors if (job.Y2headers.size() > 0 && job.X2header == null) { Log.error("No X2 header specified for job " + job.name + ". Each Y axis must have a corresponding X axis."); return; } //Make a dataSeries for desired headers and add to collection(s) CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions String title = job.name + "_"; XYSeriesCollection dataSet1 = new XYSeriesCollection(); XYSeriesCollection dataSet2 = new XYSeriesCollection(); double maxY1 = 0; double minY1 = Double.MAX_VALUE; double maxY2 = 0; double minY2 = Double.MAX_VALUE; for (int i = 0; i < job.Y1headers.size(); i++) { XYSeries dataSeriesTop; XYSeries dataSeriesBottom; XYSeries dataSeriesLeft; XYSeries dataSeriesRight; //For convex hulls, we have to reorder points before inserting into the dataset ConvexHullMaker maker = new ConvexHullMaker(); List<List<Double>> newVals = new ArrayList<List<Double>>(); List<List<Double>> splitVals = new ArrayList<List<Double>>(); newVals = maker.make(data.get(job.X1header), data.get(job.Y1headers.get(i))); splitVals = splitHull(newVals); dataSeriesTop = plotTool.createXYSeries(job.Y1headers.get(i), splitVals.get(0), splitVals.get(1)); dataSeriesBottom = plotTool.createXYSeries("", splitVals.get(2), splitVals.get(3)); dataSeriesLeft = plotTool.createXYSeries("", splitVals.get(4), splitVals.get(5)); dataSeriesRight = plotTool.createXYSeries("", splitVals.get(6), splitVals.get(7)); dataSeriesBottom.setKey("REMOVE"); dataSeriesLeft.setKey("REMOVE"); dataSeriesRight.setKey("REMOVE"); dataSet1.addSeries(dataSeriesTop); dataSet1.addSeries(dataSeriesBottom); dataSet1.addSeries(dataSeriesLeft); dataSet1.addSeries(dataSeriesRight); title = title + job.Y1headers.get(i) + "_"; maxY1 = maxY1 < dataSeriesTop.getMaxY() ? dataSeriesTop.getMaxY() : maxY1; minY1 = minY1 > dataSeriesBottom.getMinY() ? dataSeriesBottom.getMinY() : minY1; } for (int i = 0; i < job.Y2headers.size(); i++) { XYSeries dataSeriesTop; XYSeries dataSeriesBottom; XYSeries dataSeriesLeft; XYSeries dataSeriesRight; ConvexHullMaker maker = new ConvexHullMaker(); List<List<Double>> newVals = new ArrayList<List<Double>>(); List<List<Double>> splitVals = new ArrayList<List<Double>>(); newVals = maker.make(data.get(job.X2header), data.get(job.Y2headers.get(i))); splitVals = splitHull(newVals); dataSeriesTop = plotTool.createXYSeries(job.Y2headers.get(i), splitVals.get(0), splitVals.get(1)); dataSeriesBottom = plotTool.createXYSeries("", splitVals.get(2), splitVals.get(3)); dataSeriesLeft = plotTool.createXYSeries("", splitVals.get(4), splitVals.get(5)); dataSeriesRight = plotTool.createXYSeries("", splitVals.get(6), splitVals.get(7)); dataSeriesBottom.setKey("REMOVE"); dataSeriesLeft.setKey("REMOVE"); dataSeriesRight.setKey("REMOVE"); dataSet2.addSeries(dataSeriesTop); dataSet2.addSeries(dataSeriesBottom); dataSet2.addSeries(dataSeriesLeft); dataSet2.addSeries(dataSeriesRight); title = title + job.Y2headers.get(i) + "_"; maxY2 = maxY2 < dataSeriesTop.getMaxY() ? dataSeriesTop.getMaxY() : maxY2; minY2 = minY2 > dataSeriesBottom.getMinY() ? dataSeriesBottom.getMinY() : minY2; } title = title + "vs_" + job.X1header; if (job.X2header != null && !job.X1header.equalsIgnoreCase(job.X2header)) title = title + "_" + job.X2header; //Override the constructed title if desired if (job.titleOverride != null && !job.titleOverride.isEmpty() && !job.titleOverride.equalsIgnoreCase("None")) title = job.titleOverride; //set labels String XAxisLabel = job.X1header; String YAxisLabel = job.Y1headers.get(0); JFreeChart chart = ChartFactory.createXYLineChart( job.titleOverride != null && job.titleOverride.equalsIgnoreCase("None") ? "" : title, // chart title XAxisLabel, // x axis label YAxisLabel, // y axis label dataSet1, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); Log.info("Creating Graph " + title); XYPlot plot = (XYPlot) chart.getPlot(); if (!job.logAxis) { // Determine Y1 range double resMax0 = maxY1; double resMin0 = minY1; if (Double.isNaN(resMax0) || Double.isNaN(resMin0)) plot.getDomainAxis(0).setLabel("Range is NaN"); if (DoubleUtils.isZero(resMin0)) resMin0 = -0.001; if (DoubleUtils.isZero(resMax0)) resMax0 = 0.001; double rangeLength = resMax0 - resMin0; ValueAxis yAxis = plot.getRangeAxis(0); yAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);//15% buffer so we can see top and bottom clearly //Override the bounds if desired try { if (job.Y1LowerBound != null) yAxis.setLowerBound(job.Y1LowerBound); if (job.Y1UpperBound != null) yAxis.setUpperBound(job.Y1UpperBound); } catch (Exception e) { Log.error( "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist."); } plot.setRangeAxis(0, yAxis); //Add the second Y axis to the right side if (!job.Y2headers.isEmpty()) { ValueAxis rightYAxis = new NumberAxis(); // Determine Y2 range double resMax1 = maxY2; double resMin1 = minY2; if (Double.isNaN(resMax1) || Double.isNaN(resMin1)) plot.getDomainAxis(1).setLabel("Range is NaN"); if (DoubleUtils.isZero(resMin1)) resMin1 = -0.001; if (DoubleUtils.isZero(resMax1)) resMax1 = 0.001; rangeLength = resMax1 - resMin1; rightYAxis.setRange(resMin1 - 0.15 * rangeLength, resMax1 + 0.15 * rangeLength); rightYAxis.setLabel(job.Y2headers.get(0)); //Override the bounds if desired try { if (job.Y2LowerBound != null) rightYAxis.setLowerBound(job.Y2LowerBound); if (job.Y2UpperBound != null) rightYAxis.setUpperBound(job.Y2UpperBound); } catch (Exception e) { Log.error( "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist."); } plot.setRangeAxis(1, rightYAxis); } } else { double resMin = minY1 < minY2 ? minY1 : minY2; if (resMin <= 0.0) resMin = .00001; LogarithmicAxis yAxis = new LogarithmicAxis("Log(" + YAxisLabel + ")"); yAxis.setLowerBound(resMin); //Override the bounds if desired try { if (job.Y1LowerBound != null) yAxis.setLowerBound(job.Y1LowerBound); if (job.Y1UpperBound != null) yAxis.setUpperBound(job.Y1UpperBound); } catch (Exception e) { Log.error( "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist."); } plot.setRangeAxis(0, yAxis); if (!job.Y2headers.isEmpty()) { LogarithmicAxis rightYAxis = new LogarithmicAxis("Log(" + job.Y2headers.get(0) + ")"); rightYAxis.setLowerBound(resMin); //Override the bounds if desired try { if (job.Y2LowerBound != null) rightYAxis.setLowerBound(job.Y2LowerBound); if (job.Y2UpperBound != null) rightYAxis.setUpperBound(job.Y2UpperBound); } catch (Exception e) { Log.error( "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist."); } plot.setRangeAxis(1, rightYAxis); } } //Override X bounds if desired try { if (job.X1LowerBound != null) plot.getDomainAxis(0).setLowerBound(job.X1LowerBound); if (job.X1UpperBound != null) plot.getDomainAxis(0).setUpperBound(job.X1UpperBound); if (job.X2LowerBound != null) plot.getDomainAxis(1).setLowerBound(job.X2LowerBound); if (job.X2UpperBound != null) plot.getDomainAxis(1).setUpperBound(job.X2UpperBound); } catch (Exception e) { Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist."); } //Add the second dataset if necessary if (!job.Y2headers.isEmpty()) { plot.setDataset(1, dataSet2); plot.mapDatasetToRangeAxis(1, 1); } //Override labels if desired if (job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN")) plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None") ? "" : job.X1Label); if (job.X2Label != null && plot.getDomainAxis(1) != null) plot.getDomainAxis(1).setLabel(job.X2Label.equalsIgnoreCase("None") ? "" : job.X2Label); if (job.Y1Label != null) plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None") ? "" : job.Y1Label); if (job.Y2Label != null && plot.getRangeAxis(1) != null) plot.getRangeAxis(1).setLabel(job.Y2Label.equalsIgnoreCase("None") ? "" : job.Y2Label); //Format lines and colors plotTool.formatXYPlot(chart, job.bgColor); plot.setDomainGridlinesVisible(job.showGridLines); plot.setRangeGridlinesVisible(job.showGridLines); formatConvexHullPlot(job, chart, dataSet1, dataSet2); //Handle legends if (job.removeAllLegends) chart.removeLegend(); //Make the file try { FileUtils.createDirectory(job.outputDir); String filename = job.outputFilename == null ? job.outputDir + "/" + plotTool.MakeFileName(title) + ".jpg" : job.outputDir + "/" + job.outputFilename; if (!filename.endsWith(".jpg")) filename = filename + ".jpg"; File JPGFile = new File(filename); if (job.imageHeight != null && job.imageWidth != null) ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight); else ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800); } catch (IOException e) { Log.error(e.getMessage()); } }
From source file:edu.cens.loci.components.GoogleLocalSearchHandler.java
private ArrayList<GoogleLocalSearchResult> getResults(JSONObject jsonObj) { ArrayList<GoogleLocalSearchResult> results = new ArrayList<GoogleLocalSearchResult>(); JSONArray jsonArr;/*from w w w . ja v a 2s . c o m*/ JSONObject jsonArrItem; try { jsonArr = jsonObj.getJSONArray("results"); } catch (JSONException e) { e.printStackTrace(); return null; } for (int i = 0; i < jsonArr.length(); i++) { try { jsonArrItem = jsonArr.getJSONObject(i); } catch (JSONException e) { continue; } GoogleLocalSearchResult result = new GoogleLocalSearchResult(); try { result.title = jsonArrItem.getString("titleNoFormatting"); } catch (JSONException e) { continue; } try { result.address = jsonArrItem.getString("streetAddress"); result.city = jsonArrItem.getString("city"); result.region = jsonArrItem.getString("region"); result.country = jsonArrItem.getString("country"); } catch (JSONException e) { result.address = ""; result.city = ""; result.region = ""; result.country = ""; } try { result.latitude = jsonArrItem.getDouble("lat"); result.longitude = jsonArrItem.getDouble("lng"); } catch (JSONException e) { result.latitude = Double.MAX_VALUE; result.longitude = Double.MAX_VALUE; } try { result.url = URLDecoder.decode(jsonArrItem.getString("url")); } catch (JSONException e) { result.url = null; } results.add(result); } return results; }
From source file:com.pinterest.pinlater.PinLaterQueueConfig.java
@VisibleForTesting double getDequeueRate(String queueName) { MorePreconditions.checkNotBlank(queueName); ImmutableMap<String, QueueRateLimiter.IFace> queueRateLimitMap = queueRateLimitMapRef.get(); if (queueRateLimitMap != null && queueRateLimitMap.containsKey(queueName)) { return queueRateLimitMap.get(queueName).getRate(); } else {//from w ww . j av a 2s. c om // No rate limit specified for this queue. return Double.MAX_VALUE; } }