List of usage examples for java.text DecimalFormat setDecimalFormatSymbols
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
public static String summarizeDetailedOccupancyStats(Map<Id<Vehicle>, double[]> vehicleDistances, String del, int maxcap) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1);//from w ww .j a va 2s. c om format.setMaximumFractionDigits(2); format.setGroupingUsed(false); double[] sum = new double[maxcap + 1]; for (double[] dist : vehicleDistances.values()) { double emptyD = dist[0] - dist[2]; sum[0] += emptyD; for (int i = 3; i < maxcap + 3; i++) { sum[i - 2] += dist[i]; } } String result = ""; for (int i = 0; i <= maxcap; i++) { result = result + ";" + format.format(sum[i]); } return result; }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
/** * @param vehicleDistances//w w w. j a va 2 s .c o m * @param string * @return */ public static String summarizeVehicles(Map<Id<Vehicle>, double[]> vehicleDistances, String del) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(2); format.setGroupingUsed(false); DescriptiveStatistics driven = new DescriptiveStatistics(); DescriptiveStatistics revenue = new DescriptiveStatistics(); DescriptiveStatistics occupied = new DescriptiveStatistics(); DescriptiveStatistics empty = new DescriptiveStatistics(); for (double[] dist : vehicleDistances.values()) { driven.addValue(dist[0]); revenue.addValue(dist[1]); occupied.addValue(dist[2]); double emptyD = dist[0] - dist[2]; empty.addValue(emptyD); } double d_r_d_t = revenue.getSum() / driven.getSum(); // bw.write("iteration;vehicles;totalDistance;totalEmptyDistance;emptyRatio;totalRevenueDistance;averageDrivenDistance;averageEmptyDistance;averageRevenueDistance"); String result = vehicleDistances.size() + del + format.format(driven.getSum()) + del + format.format(empty.getSum()) + del + format.format(empty.getSum() / driven.getSum()) + del + format.format(revenue.getSum()) + del + format.format(driven.getMean()) + del + format.format(empty.getMean()) + del + format.format(revenue.getMean()) + del + format.format(d_r_d_t); return result; }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
/** * @param vehicleDistances/* w w w . j a v a2s. c om*/ * @param iterationFilename */ public static void writeVehicleDistances(Map<Id<Vehicle>, double[]> vehicleDistances, String iterationFilename) { String header = "vehicleId;drivenDistance_m;occupiedDistance_m;emptyDistance_m;revenueDistance_pm"; BufferedWriter bw = IOUtils.getBufferedWriter(iterationFilename); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(2); format.setGroupingUsed(false); try { bw.write(header); for (Entry<Id<Vehicle>, double[]> e : vehicleDistances.entrySet()) { double drivenDistance = e.getValue()[0]; double revenueDistance = e.getValue()[1]; double occDistance = e.getValue()[2]; double emptyDistance = drivenDistance - occDistance; bw.newLine(); bw.write(e.getKey().toString() + ";" + format.format(drivenDistance) + ";" + format.format(occDistance) + ";" + format.format(emptyDistance) + ";" + format.format(revenueDistance)); } bw.flush(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static DecimalFormat createDecimalFormat(int minInt, int maxInt, int minFract, int maxFract, char separator, RoundingMode mode) { DecimalFormat format = (DecimalFormat) DecimalFormat.getNumberInstance(); format.setRoundingMode(mode);/* w ww . jav a2s .c o m*/ format.setMaximumFractionDigits(maxFract); format.setMinimumFractionDigits(minFract); format.setMaximumIntegerDigits(maxInt); format.setMinimumIntegerDigits(minInt); DecimalFormatSymbols decimalSymbolComma = new DecimalFormatSymbols(); decimalSymbolComma.setDecimalSeparator(separator); format.setDecimalFormatSymbols(decimalSymbolComma); format.setGroupingUsed(false); return format; }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
public static String summarizeTrips(List<DynModeTrip> trips, String delimiter) { DescriptiveStatistics waitStats = new DescriptiveStatistics(); DescriptiveStatistics rideStats = new DescriptiveStatistics(); DescriptiveStatistics distanceStats = new DescriptiveStatistics(); DescriptiveStatistics directDistanceStats = new DescriptiveStatistics(); DescriptiveStatistics traveltimes = new DescriptiveStatistics(); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1);//w w w. j a va 2s . c o m format.setMaximumFractionDigits(2); format.setGroupingUsed(false); for (DynModeTrip trip : trips) { if (trip.getToLinkId() == null) { continue; } waitStats.addValue(trip.getWaitTime()); rideStats.addValue(trip.getInVehicleTravelTime()); distanceStats.addValue(trip.getTravelDistance()); directDistanceStats.addValue(trip.getUnsharedDistanceEstimate_m()); traveltimes.addValue(trip.getInVehicleTravelTime() + trip.getWaitTime()); } String value = format.format(waitStats.getValues().length) + delimiter + format.format(waitStats.getMean()) + delimiter + format.format(waitStats.getMax()) + delimiter + format.format(waitStats.getPercentile(95)) + delimiter + format.format(waitStats.getPercentile(75)) + delimiter + format.format(waitStats.getPercentile(50)) + delimiter + format.format(rideStats.getMean()) + delimiter + format.format(distanceStats.getMean()) + delimiter + format.format(directDistanceStats.getMean()) + delimiter + format.format(traveltimes.getMean()); return value; }
From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java
public static String formatVolume(String stringToFormat) { if (stringToFormat == null || stringToFormat.length() == 0) { return null; }//from w ww .j a va 2 s . c o m String result = null; DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(getDefaultFormattingLocale())); formatter.setGroupingUsed(true); formatter.setGroupingSize(3); formatter.setMaximumFractionDigits(0); result = formatter.format(Double.parseDouble(stringToFormat)); return result; }
From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java
private static void setupFormatter(DecimalFormat formatter, int minumumDecimals, int maximumDecimals) { formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(getDefaultFormattingLocale())); formatter.setMinimumIntegerDigits(1); if (minumumDecimals > -1) { formatter.setMinimumFractionDigits(minumumDecimals); }/* w ww .j av a 2 s. co m*/ if (maximumDecimals > -1) { formatter.setMaximumFractionDigits(maximumDecimals); } formatter.setGroupingUsed(true); formatter.setGroupingSize(3); }
From source file:org.mitre.ccv.mapred.CompleteCompositionVectorUtils.java
/** * Writes out the {@link SequenceFile} feature vectors in row major (packed) order. No labels are outputed. * * @param jobConf/*from w w w . ja v a 2 s .c o m*/ * @param input top level SequenceFile directory path * @param output path to output the matrix * @param digits the maximum number of fraction digits * @throws IOException */ public static void featureVectors2RowMajorMatrix(JobConf jobConf, String input, String output, int digits) throws IOException { JobConf conf = new JobConf(jobConf, CalculateCosineDistanceMatrix.class); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(digits); //format.setMinimumFractionDigits(fractionDigits); format.setGroupingUsed(false); final Path inputPath = new Path(input); final FileSystem fs = inputPath.getFileSystem(conf); final Path qInputPath = fs.makeQualified(inputPath); final Path outputPath = new Path(output); Path[] paths = FileUtils.ls(conf, qInputPath.toString() + Path.SEPARATOR + "part-*"); FSDataOutputStream fos = fs.create(outputPath, true); // throws nothing! final Writer writer = new OutputStreamWriter(fos); final Text key = new Text(); final SparseVectorWritable value = new SparseVectorWritable(); for (int idx = 0; idx < paths.length; idx++) { SequenceFile.Reader reader = new SequenceFile.Reader(fs, paths[idx], conf); boolean hasNext = reader.next(key, value); while (hasNext) { final SparseVector vector = value.get(); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < vector.getCardinality(); i++) { final String s = format.format(vector.get(i)); // format the number sb.append(s); sb.append(' '); } writer.write(sb.toString()); hasNext = reader.next(key, value); } try { writer.flush(); reader.close(); } catch (IOException ioe) { // closing the SequenceFile.Reader will throw an exception if the file is over some unknown size LOG.debug("Probably caused by closing the SequenceFile.Reader. All is well", ioe); } } try { writer.close(); fos.flush(); fos.close(); } catch (IOException ioe) { LOG.debug("Caused by distributed cache output stream.", ioe); } }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
public static void analyseWaitTimes(String fileName, List<DynModeTrip> trips, int binsize_s) { Collections.sort(trips);//ww w .j av a2 s.com if (trips.size() == 0) return; int startTime = ((int) (trips.get(0).getDepartureTime() / binsize_s)) * binsize_s; int endTime = ((int) (trips.get(trips.size() - 1).getDepartureTime() / binsize_s) + binsize_s) * binsize_s; Map<Double, List<DynModeTrip>> splitTrips = splitTripsIntoBins(trips, startTime, endTime, binsize_s); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(2); format.setGroupingUsed(false); SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss"); BufferedWriter bw = IOUtils.getBufferedWriter(fileName + ".csv"); TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeriesCollection datasetrequ = new TimeSeriesCollection(); TimeSeries averageWaitC = new TimeSeries("average"); TimeSeries medianWait = new TimeSeries("median"); TimeSeries p_5Wait = new TimeSeries("5th percentile"); TimeSeries p_95Wait = new TimeSeries("95th percentile"); TimeSeries requests = new TimeSeries("Ride requests"); try { bw.write("timebin;trips;average_wait;min;p_5;p_25;median;p_75;p_95;max"); for (Entry<Double, List<DynModeTrip>> e : splitTrips.entrySet()) { long rides = 0; double averageWait = 0; double min = 0; double p_5 = 0; double p_25 = 0; double median = 0; double p_75 = 0; double p_95 = 0; double max = 0; if (!e.getValue().isEmpty()) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (DynModeTrip t : e.getValue()) { stats.addValue(t.getWaitTime()); } rides = stats.getN(); averageWait = stats.getMean(); min = stats.getMin(); p_5 = stats.getPercentile(5); p_25 = stats.getPercentile(25); median = stats.getPercentile(50); p_75 = stats.getPercentile(75); p_95 = stats.getPercentile(95); max = stats.getMax(); } Minute h = new Minute(sdf2.parse(Time.writeTime(e.getKey()))); medianWait.addOrUpdate(h, Double.valueOf(median)); averageWaitC.addOrUpdate(h, Double.valueOf(averageWait)); p_5Wait.addOrUpdate(h, Double.valueOf(p_5)); p_95Wait.addOrUpdate(h, Double.valueOf(p_95)); requests.addOrUpdate(h, rides * 3600. / binsize_s);// normalised [req/h] bw.newLine(); bw.write(Time.writeTime(e.getKey()) + ";" + rides + ";" + format.format(averageWait) + ";" + format.format(min) + ";" + format.format(p_5) + ";" + format.format(p_25) + ";" + format.format(median) + ";" + format.format(p_75) + ";" + format.format(p_95) + ";" + format.format(max)); } bw.flush(); bw.close(); dataset.addSeries(averageWaitC); dataset.addSeries(medianWait); dataset.addSeries(p_5Wait); dataset.addSeries(p_95Wait); datasetrequ.addSeries(requests); JFreeChart chart = chartProfile(splitTrips.size(), dataset, "Waiting times", "Wait time (s)"); JFreeChart chart2 = chartProfile(splitTrips.size(), datasetrequ, "Ride requests per hour", "Requests per hour (req/h)"); ChartSaveUtils.saveAsPNG(chart, fileName, 1500, 1000); ChartSaveUtils.saveAsPNG(chart2, fileName + "_requests", 1500, 1000); } catch (IOException | ParseException e) { e.printStackTrace(); } }
From source file:nc.noumea.mairie.appock.core.utility.AppockUtil.java
private static DecimalFormat construitFormatterCfp(String formatCfp) { DecimalFormat formatter = new DecimalFormat(formatCfp); DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); symbols.setGroupingSeparator(' '); formatter.setDecimalFormatSymbols(symbols); return formatter; }