List of usage examples for java.text DecimalFormat DecimalFormat
public DecimalFormat(String pattern)
From source file:com.ipeirotis.gal.core.CategoryPair.java
public static void main(String[] args) { Category a = new Category("A"); Category b = new Category("B"); a.setPrior(0.5);/*w ww. j a v a2 s . c o m*/ b.setPrior(0.5); a.setCost("A", 0.0); a.setCost("B", 1.0); b.setCost("A", 1.0); b.setCost("B", 0.0); Collection<Category> categories = new HashSet<Category>(); categories.add(a); categories.add(b); Map<String, Category> map = new HashMap<String, Category>(); map.put("A", a); map.put("B", b); ConfusionMatrix cm = new ConfusionMatrix(categories); // FOR TESTS: // q=1 should return 0 cost // q=1 should not be affected by m /* cm.setErrorRate("A", "A", 0.9); cm.setErrorRate("A", "B", 0.1); cm.setErrorRate("B", "B", 0.0); cm.setErrorRate("B", "A", 1.0); double tau=0.01; double w = cm.getWorkerWage(1.0, tau, map); double pwage = Double.valueOf(new DecimalFormat("#.####").format(w)); double pworkers = Double.valueOf(new DecimalFormat("#.####").format(1.0/w)); System.out.print("\t"+pwage+"\t"+pworkers); */ //double q=0.9; for (int Q = 95; Q >= 55; Q -= 5) { double q = Q / 100.0; cm.setErrorRate("A", "A", q); cm.setErrorRate("A", "B", 1 - q); cm.setErrorRate("B", "B", q); cm.setErrorRate("B", "A", 1 - q); // Classification cost of a set of m workers with the confusion matrix given above /* for (int m = 1; m<=40; m+=2) { System.out.print(q+"\t"+m); Double c = cm.getWorkerCost(m, map, 100*m*m); System.out.println("\t"+Math.round(100000*c)/100000.0); } */ for (double tau = 0.1; tau > 0.0001; tau /= 1.5) { double pq = Double.valueOf(new DecimalFormat("#.##").format(q)); double ptau = Double.valueOf(new DecimalFormat("#.####").format((1 - tau))); System.out.print(pq + "\t" + ptau); double w = cm.getWorkerWage(1.0, tau, map); double pwage = Double.valueOf(new DecimalFormat("#.####").format(w)); double pworkers = Double.valueOf(new DecimalFormat("#.####").format(1.0 / w)); System.out.print("\t" + pwage + "\t" + pworkers); double wr = cm.getWorkerWageRegr(1.0, tau, map); double pwager = Double.valueOf(new DecimalFormat("#.####").format(wr)); double pworkersr = Double.valueOf(new DecimalFormat("#.####").format(1.0 / wr)); System.out.print("\t" + pwager + "\t" + pworkersr); System.out.println(); } } }
From source file:com.kryshchuk.maven.plugins.jfreechart.LineChartAxis.java
public void setupAxis(final NumberAxis axis) { if (format != null) { axis.setNumberFormatOverride(new DecimalFormat(format)); }/*from ww w . j ava 2 s . co m*/ axis.setAutoRangeIncludesZero(false); // axis.setStandardTickUnits(new StandardTickUnitSource()); }
From source file:com.uber.hoodie.cli.commands.StatsCommand.java
@CliCommand(value = "stats wa", help = "Write Amplification. Ratio of how many records were upserted to how many records were actually written") public String writeAmplificationStats() throws IOException { long totalRecordsUpserted = 0; long totalRecordsWritten = 0; HoodieActiveTimeline activeTimeline = HoodieCLI.tableMetadata.getActiveTimeline(); HoodieTimeline timeline = activeTimeline.getCommitTimeline().filterCompletedInstants(); String[][] rows = new String[new Long(timeline.countInstants()).intValue() + 1][]; int i = 0;/*www . j ava 2 s. c o m*/ DecimalFormat df = new DecimalFormat("#.00"); for (HoodieInstant commitTime : timeline.getInstants().collect(Collectors.toList())) { String waf = "0"; HoodieCommitMetadata commit = HoodieCommitMetadata .fromBytes(activeTimeline.getInstantDetails(commitTime).get()); if (commit.fetchTotalUpdateRecordsWritten() > 0) { waf = df.format( (float) commit.fetchTotalRecordsWritten() / commit.fetchTotalUpdateRecordsWritten()); } rows[i++] = new String[] { commitTime.getTimestamp(), String.valueOf(commit.fetchTotalUpdateRecordsWritten()), String.valueOf(commit.fetchTotalRecordsWritten()), waf }; totalRecordsUpserted += commit.fetchTotalUpdateRecordsWritten(); totalRecordsWritten += commit.fetchTotalRecordsWritten(); } String waf = "0"; if (totalRecordsUpserted > 0) { waf = df.format((float) totalRecordsWritten / totalRecordsUpserted); } rows[i] = new String[] { "Total", String.valueOf(totalRecordsUpserted), String.valueOf(totalRecordsWritten), waf }; return HoodiePrintHelper.print( new String[] { "CommitTime", "Total Upserted", "Total Written", "Write Amplifiation Factor" }, rows); }
From source file:servlet.SalesReportPieChart.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www . j a v a2 s. com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DefaultPieDataset dataset = new DefaultPieDataset(); int totalTickets = Integer.valueOf(request.getParameter("totalTickets")); int totalSoldTickets = Integer.valueOf(request.getParameter("totalSoldTickets")); dataset.setValue("Unsold Tickets", new Double(totalTickets - totalSoldTickets)); dataset.setValue("Sold Tickets", new Double(totalSoldTickets)); JFreeChart chart = ChartFactory.createPieChart("Ticket Sales", // chart title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("Unsold Tickets", Color.DARK_GRAY); plot.setSectionPaint("Sold Tickets", Color.CYAN); plot.setExplodePercent("Unsold Tickets", 0.10); plot.setSimpleLabels(true); plot.setBackgroundPaint(Color.WHITE); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(gen); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); int width = 500; /* Width of the image */ int height = 400; /* Height of the image */ response.setContentType("image/png"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsPNG(out, chart, 400, 300, info); }
From source file:com.kingcore.framework.util.ConvertUtils.java
/** * ?/*from w ww.j a v a 2s. c om*/ * Create on 2003-6-18 * @param float * @param int ??? * @return * @throws Exception */ public static String formatNumber(float number, int scalar) throws Exception { String zero = "000000000000000000000000000000"; String format = "##0." + zero.substring(0, scalar); NumberFormat nf = new DecimalFormat(format); return nf.format(number); }
From source file:com.sra.biotech.submittool.persistence.service.SubmissionServiceImpl.java
@Override public Submission findSubmission(Long key) { DecimalFormat intFormat = new DecimalFormat("#"); String strKey = intFormat.format(key); Submission submission = restTemplate .getForObject(getSubmissionUrlTemplate() + "/{key}", SubmissionResource.class, strKey).getContent(); return submission; }
From source file:com.pivotal.gemfire.tools.pulse.internal.service.ClusterMemberService.java
public JSONObject execute(final HttpServletRequest request) throws Exception { // get cluster object Cluster cluster = Repository.get().getCluster(); // json object to be sent as response JSONObject responseJSON = new JSONObject(); Cluster.Member[] clusterMembersList = cluster.getMembers(); // create members json List<JSONObject> memberListJson = new ArrayList<JSONObject>(); try {/*from ww w . ja v a2s . c om*/ for (Cluster.Member clusterMember : clusterMembersList) { JSONObject memberJSON = new JSONObject(); // getting members detail memberJSON.put("memberId", clusterMember.getId()); memberJSON.put("name", clusterMember.getName()); memberJSON.put("host", clusterMember.getHost()); DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN); long usedHeapSize = cluster.getUsedHeapSize(); long currentHeap = clusterMember.getCurrentHeapSize(); if (usedHeapSize > 0) { float heapUsage = ((float) currentHeap / (float) usedHeapSize) * 100; memberJSON.put(this.HEAP_USAGE, Double.valueOf(df2.format(heapUsage))); } else { memberJSON.put(this.HEAP_USAGE, 0); } Float currentCPUUsage = clusterMember.getCpuUsage(); memberJSON.put("cpuUsage", Float.valueOf(df2.format(currentCPUUsage))); memberJSON.put("currentHeapUsage", clusterMember.getCurrentHeapSize()); memberJSON.put("isManager", clusterMember.isManager()); memberJSON.put("uptime", TimeUtils.convertTimeSecondsToHMS(clusterMember.getUptime())); memberJSON.put("loadAvg", clusterMember.getLoadAverage()); memberJSON.put("sockets", clusterMember.getTotalFileDescriptorOpen()); memberJSON.put("openFDs", clusterMember.getTotalFileDescriptorOpen()); memberJSON.put("threads", clusterMember.getNumThreads()); // Number of member clients if (PulseController.getPulseProductSupport() .equalsIgnoreCase(PulseConstants.PRODUCT_NAME_GEMFIREXD)) { memberJSON.put("clients", clusterMember.getNumGemFireXDClients()); } else { memberJSON.put("clients", clusterMember.getMemberClientsHMap().size()); } memberJSON.put("queues", clusterMember.getQueueBacklog()); memberListJson.add(memberJSON); } // clucter's Members responseJSON.put("members", memberListJson); // Send json response return responseJSON; } catch (JSONException e) { throw new Exception(e); } }
From source file:com.jennifer.ui.chart.brush.LineBrush.java
protected DomUtil createLine(JSONObject pos, int index) { JSONArray x = JSONUtil.clone(pos.getJSONArray("x")); JSONArray y = JSONUtil.clone(pos.getJSONArray("y")); JSONArray valueList = JSONUtil.clone(pos.getJSONArray("value")); DecimalFormat format = new DecimalFormat(".##"); String _color = color(index); Transform t = null;/*from w w w. ja v a2 s . c om*/ Transform g = new Transform("g"); Path p = new Path(new JSONObject().put("stroke", _color).put("stroke-width", chart.theme("lineBorderWidth")) .put("fill", "transparent")); p.MoveTo(x.getDouble(0), y.getDouble(0)); if (Brush.SYMBOL_CURVE.equals(symbol)) { JSONObject px = this.curvePoints(x); JSONObject py = this.curvePoints(y); for (int i = 0, len = x.length(); i < len; i++) { p.CurveTo(px.getJSONArray("p1").getDouble(i), py.getJSONArray("p1").getDouble(i), px.getJSONArray("p2").getDouble(i), py.getJSONArray("p2").getDouble(i), x.getDouble(i + 1), y.getDouble(i + 1)); } } else { double maxValue = Double.MIN_VALUE; t = null; for (int i = 0, len = x.length(); i < len - 1; i++) { if (Brush.SYMBOL_STEP.equals(symbol)) { p.LineTo(x.getDouble(i), y.getDouble(i + 1)); } double xValue = x.getDouble(i + 1); double yValue = y.getDouble(i + 1); double valueValue = valueList.getDouble(i + 1); p.LineTo(xValue, yValue); // display max value if (valueValue > maxValue) { maxValue = valueValue; t = createMaxElement(xValue, yValue, formatNumber(valueValue), _color); } } } // ?? if (move) { double range = (x.getDouble(2) - x.getDouble(1)) / 2; g.translate(range, 0); } g.append(p); g.append(t); return g; }
From source file:vn.edu.vttu.ui.PanelStatiticsService.java
private void showChart() { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); DefaultPieDataset dataset = new DefaultPieDataset(); int row = tbResult.getRowCount(); for (int i = 0; i < row; i++) { totalNumber = totalNumber + Integer.parseInt(String.valueOf(tbResult.getValueAt(i, 3))); }/*from ww w. j a v a2 s. c o m*/ for (int i = 0; i < row; i++) { double value = 0; try { try { value = Double .parseDouble(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll("\\.", "")); } catch (Exception e) { value = Double .parseDouble(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll(",", "")); } } catch (Exception e) { value = 0; } String name = String.valueOf(tbResult.getValueAt(i, 1)).trim(); DecimalFormat df = new DecimalFormat("###,##"); value = (value / totalNumber) * 100; System.out.println(totalNumber); dataset.setValue(name, value); } JFreeChart chart = ChartFactory.createPieChart3D("TH?NG K T L S DNG DCH V", dataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); p.setNoDataMessage("Khng c d liu thng k"); ChartPanel CP = new ChartPanel(chart); pnChart.removeAll(); pnChart.add(CP); pnChart.updateUI(); pnChart.repaint(); //ChartFrame frame = new ChartFrame("Thng k doanh thu", chart); //frame.setSize(450, 350); //frame.setVisible(true); }
From source file:ChartUsingJava.CombinedXYPlotDemo1.java
/** * Creates an overlaid chart.//from w ww . jav a 2 s . c o m * * @return The chart. */ private static JFreeChart createCombinedChart() { // create plot ... IntervalXYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.blue); DateAxis domainAxis = new DateAxis("Year"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.02); ValueAxis rangeAxis = new NumberAxis("$billion"); XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... IntervalXYDataset data2 = createDataset2(); XYBarRenderer renderer2 = new XYBarRenderer() { public Paint getItemPaint(int series, int item) { XYDataset dataset = getPlot().getDataset(); if (dataset.getYValue(series, item) >= 0.0) { return Color.red; } else { return Color.green; } } }; renderer2.setSeriesPaint(0, Color.red); renderer2.setDrawBarOutline(false); renderer2.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false); chart.setBackgroundPaint(Color.white); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); return chart; }