/** * Creates a byte array representation from the specified double value; inspired by Xavier Franc's * Qizx/open processor. * * @param dbl double value to be converted * @return byte array */ public static byte[] token(final double dbl) { final byte[] b = tok(dbl); if (b != null) return b; final double a = Math.abs(dbl); return chopNumber(token(a >= 1e-6 && a < 1e6 ? DD.format(dbl) : SD.format(dbl))); }
public static String memoryToString() { DecimalFormat fmt = new DecimalFormat("0.0"); return "Memory: " + fmt.format(RUNTIME.maxMemory() / 1048576D) + "MByte maximum, " + fmt.format(RUNTIME.totalMemory() / 1048576D) + "MByte total, " + fmt.format(RUNTIME.totalMemory() / 1048576D) + "MByte free"; }
/** * Creates a byte array representation from the specified float value. * * @param flt float value to be converted * @return byte array */ public static byte[] token(final float flt) { final byte[] b = tok(flt); if (b != null) return b; // not that brilliant here.. no chance for elegant code either // due to the nifty differences between Java and XQuery for (int i = 0; i < FLT.length; ++i) if (flt == FLT[i]) return FLTSTR[i]; final float a = Math.abs(flt); final boolean small = a >= 1e-6f && a < 1e6f; String s1 = small ? DF.format(flt) : SF.format(flt); final String s2 = Float.toString(flt); if (s2.length() < s1.length() && (!s2.contains("E") || !small)) s1 = s2; return chopNumber(token(s1)); }
/* paint() - get current time and draw (centered) in Component. */ public void paint(Graphics g) { Calendar myCal = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); sb.append(tf.format(myCal.get(Calendar.HOUR))); sb.append(':'); sb.append(tflz.format(myCal.get(Calendar.MINUTE))); sb.append(':'); sb.append(tflz.format(myCal.get(Calendar.SECOND))); String s = sb.toString(); FontMetrics fm = getFontMetrics(getFont()); int x = (getSize().width - fm.stringWidth(s)) / 2; // System.out.println("Size is " + getSize()); g.drawString(s, x, 10); }
public static String getDistanceText(long distance) { DecimalFormat df = new DecimalFormat("#0.0"); if (distance >= (OSMParam.FEET_PER_MILE / 10)) { return df.format((double) distance / OSMParam.FEET_PER_MILE) + " miles"; } else { return distance + " feets"; } }
/** * Adds an editable text field containing the hours spent on a project. * * @param gbl The layout to add the text field to. * @param gbc The layout constraints to use. * @param row The row to link against. * @param hours The number of hours spent on the project. * @see {@link #addRow(GridBagLayout, GridBagConstraints, String, double)} */ private void addMiddleField(GridBagLayout gbl, GridBagConstraints gbc, Row row, double hours) { row.hoursTF.setText(decimalFormat.format(hours)); gbc.gridx = 1; gbc.weightx = 1; gbl.setConstraints(row.hoursTF, gbc); gbc.weightx = 0; reviewPanel.add(row.hoursTF); }
public static void test1() { Sequence[] seqs = Parser.test1(); double[][] distances = (new GappedHammingDistance()).getDistanceMatrix(seqs); DecimalFormat f = new DecimalFormat("0000.000"); System.out.println(" " + seqs.length); for (int i = 0; i < seqs.length; i++) { System.out.print(seqs[i].name); for (int k = 0; k < 10 - seqs[i].name.length(); k++) { System.out.print(" "); } System.out.print(" "); int cols = 1; for (int j = 0; j < seqs.length; j++) { if (i != j) { int di = i; int dj = j; // force symmetric matrix - arg - what the??? // testing!!! if (j > i) { di = j; dj = i; } double d = distances[di][dj]; // testing if (d > 2000) { System.err.println("ARGH"); } System.out.print(f.format(d)); } else { System.out.print(f.format(0)); } System.out.print(" "); cols++; if (cols >= 7) { System.out.println(); System.out.print(" "); cols = 0; } } if (cols != 7) { System.out.println(); } } }
public void write(long time, Instrument instrument1, Instrument instrument2) { double bid1 = instrument1.getBid(); double ask1 = instrument1.getAsk(); double bid2 = instrument2.getBid(); double ask2 = instrument2.getAsk(); if (bid1 > 0 && ask1 > 0 && bid2 > 0 && ask2 > 0) { StringBuilder sb = new StringBuilder(); sb.append(dateFormat.format(new Date(time))).append(","); sb.append(decimalFormat.format(bid1)).append(","); sb.append(decimalFormat.format(ask1)).append(","); sb.append(decimalFormat.format(bid2)).append(","); sb.append(decimalFormat.format(ask2)); writer.println(sb); writer.flush(); } }
public static void matrixToPanel(JTextField[] jtfMatrix, Matrix matrix) { int i, j; DecimalFormat df = new DecimalFormat(String.valueOf(matrix.getAccuracy()).replace('1', '0')); for (i = 0; i < matrix.getLine(); i++) for (j = 0; j < matrix.getRow(); j++) { jtfMatrix[i * matrix.getRow() + j].setText( String.valueOf(df.format(matrix.getElement(i, j)))); } }
/** * This function re-computes the total number of hours for the selected period. It is ran every * time the user edits a text field specifying the number of hours for a particular top-level * project. Percentage labels are also updated. */ private void recomputeTotal() { double total = 0; for (Row row : rows.values()) { try { row.hours = Double.parseDouble(row.hoursTF.getText()); total += row.hours; row.hoursTF.setForeground(normalColour); } catch (NumberFormatException e) { row.hoursTF.setForeground(errorColour); totalLabel.setText("ERROR"); totalLabel.setForeground(errorColour); return; } } totalLabel.setText(decimalFormat.format(total)); totalLabel.setForeground(normalColour); for (Row row : rows.values()) { String percentS = decimalFormat.format(total == 0 ? 0 : 100 * row.hours / total); row.percentL.setText("(" + percentS + "%)"); } pack(); }
private String generateOverviewText() throws InsufficientDataException { StringBuilder sb = new StringBuilder(); final String team = config.getTeam(); double total = checkTotal(); final String nl = System.getProperty("line.separator"); for (Entry<String, Row> entry : rows.entrySet()) { double hours = Double.parseDouble(entry.getValue().hoursTF.getText()); double fraction = hours / total; if (fraction < 0.004) continue; String line = team + ", " + decimalFormat.format(fraction) + ", " + entry.getKey(); sb.append(line + nl); } return sb.toString(); }
public String toString() { StringBuffer buf = new StringBuffer(); // buf.append( "\n" + this.statspec.getId() + "\n" ); if (this.min != null) buf.append(" min=" + format.format(this.min.doubleValue())); if (this.max != null) buf.append(" max=" + format.format(this.max.doubleValue())); if (this.maxminusmin != null) buf.append(" max-min=" + format.format(this.maxminusmin.doubleValue())); if (this.mean != null) buf.append(" mean=" + format.format(this.mean.doubleValue())); if (this.stddev != null) buf.append(" stddev=" + format.format(this.stddev.doubleValue())); if (!PerfReporter.brief) { // buf.append( " start=" + this.trimspec.getStartStr() ); // buf.append( " end=" + this.trimspec.getEndStr() ); buf.append("\n "); // buf.append( " isLargerBetter=" + this.isLargerBetter ); buf.append(" samples=" + this.samples); buf.append(" archives=" + this.archives); // buf.append( " version=" + this.productVersion ); } return buf.toString(); }
/** Converts a byte array into a String. */ protected static String byteArrayToString(byte[] array, boolean quote) { StringBuffer sb = new StringBuffer(); if (quote) sb.append('"'); for (int i = 0; i < array.length; i++) { int b = array[i] & 0xFF; if (b < 0x20 || b >= 0x7f) { sb.append('\\'); sb.append(byteFormat.format(b)); } else if (b == '"' || b == ';' || b == '\\') { sb.append('\\'); sb.append((char) b); } else sb.append((char) b); } if (quote) sb.append('"'); return sb.toString(); }
/** * This is a sample of creating a new Population with 'size_population' organisms , and simulation * of XOR example This sample can be started in two modality : -cold : each time the population is * re-created from 0; -warm : each time the population re-read last population created and restart * from last epoch. (the population backup file is : 'c:\\jneat\\dati\\population.primitive' */ public static void Experiment3(int size_population, int mode, int gens) { Population pop = null; String fname_prefix = "c:\\jneat\\dati\\population.primitive"; String fnamebuf; int gen; int id; int expcount = 0; String mask6 = "000000"; DecimalFormat fmt6 = new DecimalFormat(mask6); System.out.println("------ Start experiment 3 -------"); for (expcount = 0; expcount < Neat.p_num_runs; expcount++) { System.out.println(" Spawned population off genome"); double prb_link = 0.50; boolean recurrent = true; // default cold is : 3 sensor (1 for bias) , 1 out , 5 nodes max, no recurrent if (mode == NeatConstant.COLD) pop = new Population(size_population, 3, 1, 5, recurrent, prb_link); // cold start-up // pop = new Population(size_population, 3, 1, 5, recurrent, prb_link); // cold start-up else pop = new Population(fname_prefix + ".last"); // warm start-up pop.verify(); System.out.print("\n---------------- Generation starting with----------"); System.out.print("\n Population : innov num = " + pop.getCur_innov_num()); System.out.print("\n : cur_node_id = " + pop.getCur_node_id()); System.out.print("\n---------------------------------------------------"); System.out.print("\n"); for (gen = 1; gen <= gens; gen++) { System.out.print("\n---------------- Generation ----------------------" + gen); fnamebuf = "g_" + fmt6.format(gen); boolean esito = xor_epoch(pop, gen, fnamebuf); System.out.print("\n Population : innov num = " + pop.getCur_innov_num()); System.out.print("\n : cur_node_id = " + pop.getCur_node_id()); System.out.print("\n result : " + esito); } } // backup of population for warm startup pop.print_to_filename(fname_prefix + ".last"); System.out.println("\n\n End of experiment"); }
public void printWeightUpdate() { String fileName = "WeightFile.txt"; try { FileWriter fileWriter = new FileWriter(fileName); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); System.out.println( "printWeightUpdate, put this i trainedWeights() and set isTrained to true"); // weights for the hidden layer for (Neuron n : hiddenLayer) { ArrayList<Connection> connections = n.getAllInConnections(); for (Connection con : connections) { String w = df.format(con.getWeight()); System.out.println( "weightUpdate.put(weightKey(" + n.id + ", " + con.id + "), " + w + ");"); bufferedWriter.write(ef.format(n.id)); bufferedWriter.write(" "); bufferedWriter.write(ef.format(con.id)); bufferedWriter.write(" "); bufferedWriter.write(w); bufferedWriter.newLine(); } } // weights for the output layer for (Neuron n : outputLayer) { ArrayList<Connection> connections = n.getAllInConnections(); for (Connection con : connections) { String w = df.format(con.getWeight()); System.out.println( "weightUpdate.put(weightKey(" + n.id + ", " + con.id + "), " + w + ");"); bufferedWriter.write(ef.format(n.id)); bufferedWriter.write(" "); bufferedWriter.write(ef.format(con.id)); bufferedWriter.write(" "); bufferedWriter.write(w); bufferedWriter.newLine(); } } System.out.println(); bufferedWriter.close(); } catch (IOException ex) { System.out.println("Error writing to file " + fileName); } }
public void printQs() { // Print Q-Values System.out.println("Q Values:"); System.out.println(rep("-", sizeX * 6 + 1)); for (int i = 0; i < sizeY; i++) { for (int j = 0; j < sizeX; j++) { if (isGoal(j, i) != null) { System.out.print("| G "); } else if (isAgentHome(j, i) != null) { System.out.print("| A "); } else { String t = " " + df.format(Q[j][i].maxReward()); t = t.substring(t.length() - 5); System.out.print("|" + t); } } System.out.println("|"); System.out.println(rep("-", sizeX * 6 + 1)); } }
public static void main(String[] args) { Scanner cin = new Scanner(System.in); while (true) { int num = cin.nextInt(); if (num == 0) break; int[] list = new int[num]; int max = 0; int min = 1000; int result = 0; int tmp = 0; for (int i = 0; i < num; i++) { tmp = cin.nextInt(); if (tmp > max) max = tmp; if (tmp < min) min = tmp; result += tmp; } result = (result - max - min) / (num - 2); DecimalFormat df = new DecimalFormat(""); System.out.println(df.format(result)); } }
void print(String name, double value) { g.drawString(name + ":" + df.format(value), x, y += 20); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; RenderingHints rh = g2d.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); // Background. D = this.getSize(); g.setColor(backgroundColor); g.fillRect(0, 0, D.width, D.height); Graphics2D g2 = (Graphics2D) g; g2.setStroke(lineStroke); // Axes, bounding box. g.setColor(Color.gray); g.drawLine(inset, D.height - inset, D.width - inset, D.height - inset); g.drawLine(D.width - inset, inset, D.width - inset, D.height - inset); g.drawLine(inset, inset, inset, D.height - inset); g.drawLine(inset, inset, D.width - inset, inset); double xDelta = (maxX - minX) / numIntervals; // X-ticks and labels. for (int i = 1; i <= numIntervals; i++) { double xTickd = i * xDelta; int xTick = (int) (xTickd / (maxX - minX) * (D.width - 2 * inset)); g.drawLine(inset + xTick, D.height - inset - 5, inset + xTick, D.height - inset + 5); double x = minX + i * xDelta; g.drawString(df.format(x), xTick + inset - 5, D.height - inset + 20); } // Y-ticks double yDelta = (maxY - minY) / numIntervals; for (int i = 0; i < numIntervals; i++) { int yTick = (i + 1) * (int) ((D.height - 2 * inset) / (double) numIntervals); g.drawLine(inset - 5, D.height - yTick - inset, inset + 5, D.height - yTick - inset); double y = minY + (i + 1) * yDelta; g.drawString(df.format(y), 1, D.height - yTick - inset); } // Zoom+move Font savedFont = g.getFont(); g.setFont(plusFont); g.drawString("+", D.width - 25, 20); g.setFont(minusFont); g.drawString("-", D.width - 25, 50); drawArrow(g2d, D.width - 70, 20, D.width - 70, 0, 1.0f, lineStroke); // Up drawArrow(g2d, D.width - 70, 30, D.width - 70, 50, 1.0f, lineStroke); // Down drawArrow(g2d, D.width - 65, 25, D.width - 45, 25, 1.0f, lineStroke); // Right drawArrow(g2d, D.width - 75, 25, D.width - 95, 25, 1.0f, lineStroke); // Left g.setFont(savedFont); // See if standard axes are in the middle. g.setColor(Color.gray); if ((minX < 0) && (maxX > 0) && (drawMiddleAxes)) { // Draw y-axis int x = (int) ((0 - minX) / (maxX - minX) * (D.width - 2 * inset)); g.drawLine(inset + x, D.height - inset, inset + x, inset); } if ((minY < 0) && (maxY > 0) && (drawMiddleAxes)) { // Draw x-axis int y = (int) ((0 - minY) / (maxY - minY) * (D.height - 2.0 * inset)); g.drawLine(inset, D.height - y - inset, D.width - inset, D.height - y - inset); } // Draw the objects. drawObjects(g, points, lines, ovals, rectangles, images, labels, eqnLines); if (animationMode) { drawObjects(g, animPoints, animLines, animOvals, animRectangles, null, labels, eqnLines); // No images in animation mode. } drawScribbles(g); }
public static void writeTopValue(double v) { writeTopString("" + df.format(v)); }
public static String format(double value) { return df.format(value); }
/** * this is a standard experiment for XOR emulation; is passed a name of a started genome and a * number of times can be execute this experiment; */ public static void Experiment1(String xFileName, int gens) { String fname_prefix = "c:\\jneat\\dati\\population.natural"; Population pop = null; StringTokenizer st; String curword; String xline; String fnamebuf; int gen; IOseq xFile; int id; int expcount = 0; String mask6 = "000000"; DecimalFormat fmt6 = new DecimalFormat(mask6); System.out.println("------ Start experiment 1 -------"); xFile = new IOseq(xFileName); boolean ret = xFile.IOseqOpenR(); if (ret) { try { System.out.println(" Start XOR experiment"); System.out.println(" .read start genome.."); xline = xFile.IOseqRead(); st = new StringTokenizer(xline); // skip curword = st.nextToken(); // id of genome can be readed curword = st.nextToken(); id = Integer.parseInt(curword); System.out.println(" .create genome id " + id); Genome start_genome = new Genome(id, xFile); // backup this 'initial' genome (is only for test // if the read & write are correct start_genome.print_to_filename("c:\\jneat\\dati\\genome.readed"); for (expcount = 0; expcount < Neat.p_num_runs; expcount++) { System.out.println(" Spawned population off genome"); pop = new Population(start_genome, Neat.p_pop_size); System.out.print("\n\n Verifying Spawned Pop"); pop.verify(); System.out.print("\n"); for (gen = 1; gen <= gens; gen++) { System.out.print("\n---------------- E P O C H < " + gen + " >--------------"); fnamebuf = "g_" + fmt6.format(gen); boolean esito = xor_epoch(pop, gen, fnamebuf); } System.out.print("\n Population : innov num = " + pop.getCur_innov_num()); System.out.print("\n : cur_node_id = " + pop.getCur_node_id()); pop.print_to_filename(fname_prefix); } } catch (Throwable e) { System.err.println(e + " : error during read " + xFileName); } xFile.IOseqCloseR(); } else System.err.print("\n : error during open " + xFileName); System.out.println("\n\n End of experiment"); }
/** * creates a new image * * @param svgHandle a svg handle * @param resourceId the id of the resource from which the image will be created */ protected void createNewImage(SVGHandle svgHandle, String resourceId) { if (svgHandle != null && resourceId != null && !resourceId.equals("")) { Element resourceElement = null; resourceElement = svgHandle.getScrollPane().getSVGCanvas().getDocument().getElementById(resourceId); final String fresourceId = resourceId; if (resourceElement != null) { final SVGHandle fhandle = svgHandle; // creating the canvas and setting its properties final JSVGCanvas canvas = new JSVGCanvas() { @Override public void dispose() { removeKeyListener(listener); removeMouseMotionListener(listener); removeMouseListener(listener); disableInteractions = true; selectableText = false; userAgent = null; bridgeContext.dispose(); super.dispose(); } }; // the element to be added Element elementToAdd = null; canvas.setDocumentState(JSVGComponent.ALWAYS_STATIC); canvas.setDisableInteractions(true); // creating the new document final String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; final SVGDocument doc = (SVGDocument) resourceElement.getOwnerDocument().cloneNode(false); // creating the root element final Element root = (Element) doc.importNode(resourceElement.getOwnerDocument().getDocumentElement(), false); doc.appendChild(root); // removing all the attributes of the root element NamedNodeMap attributes = doc.getDocumentElement().getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { if (attributes.item(i) != null) { doc.getDocumentElement().removeAttribute(attributes.item(i).getNodeName()); } } // adding the new attributes for the root root.setAttributeNS(null, "width", imageSize.width + ""); root.setAttributeNS(null, "height", imageSize.height + ""); root.setAttributeNS(null, "viewBox", "0 0 " + imageSize.width + " " + imageSize.height); // the defs element that will contain the cloned resource node final Element defs = (Element) doc.importNode(resourceElement.getParentNode(), true); root.appendChild(defs); if (resourceElement.getNodeName().equals("linearGradient") || resourceElement.getNodeName().equals("radialGradient") || resourceElement.getNodeName().equals("pattern")) { // the rectangle that will be drawn final Element rect = doc.createElementNS(svgNS, "rect"); rect.setAttributeNS(null, "x", "0"); rect.setAttributeNS(null, "y", "0"); rect.setAttributeNS(null, "width", imageSize.width + ""); rect.setAttributeNS(null, "height", imageSize.height + ""); elementToAdd = rect; // setting that the rectangle uses the resource String id = resourceElement.getAttribute("id"); if (id == null) { id = ""; } rect.setAttributeNS(null, "style", "fill:url(#" + id + ");"); // getting the cloned resource node Node cur = null; Element clonedResourceElement = null; String id2 = ""; for (cur = defs.getFirstChild(); cur != null; cur = cur.getNextSibling()) { if (cur instanceof Element) { id2 = ((Element) cur).getAttribute("id"); if (id2 != null && id.equals(id2)) { clonedResourceElement = (Element) cur; } } } if (clonedResourceElement != null) { // getting the root element of the initial resource // element Element initialRoot = resourceElement.getOwnerDocument().getDocumentElement(); // getting the width and height of the initial root // element double initialWidth = 0, initialHeight = 0; try { initialWidth = EditorToolkit.getPixelledNumber(initialRoot.getAttributeNS(null, "width")); initialHeight = EditorToolkit.getPixelledNumber(initialRoot.getAttributeNS(null, "height")); } catch (DOMException ex) { ex.printStackTrace(); } if (resourceElement.getNodeName().equals("linearGradient")) { if (resourceElement.getAttributeNS(null, "gradientUnits").equals("userSpaceOnUse")) { double x1 = 0, y1 = 0, x2 = 0, y2 = 0; // normalizing the values for the vector to fit // the rectangle try { x1 = Double.parseDouble(resourceElement.getAttributeNS(null, "x1")); y1 = Double.parseDouble(resourceElement.getAttributeNS(null, "y1")); x2 = Double.parseDouble(resourceElement.getAttributeNS(null, "x2")); y2 = Double.parseDouble(resourceElement.getAttributeNS(null, "y2")); x1 = x1 / initialWidth * imageSize.width; y1 = y1 / initialHeight * imageSize.height; x2 = x2 / initialWidth * imageSize.width; y2 = y2 / initialHeight * imageSize.height; } catch (NumberFormatException | DOMException ex) { ex.printStackTrace(); } clonedResourceElement.setAttributeNS(null, "x1", format.format(x1)); clonedResourceElement.setAttributeNS(null, "y1", format.format(y1)); clonedResourceElement.setAttributeNS(null, "x2", format.format(x2)); clonedResourceElement.setAttributeNS(null, "y2", format.format(y2)); } } else if (resourceElement.getNodeName().equals("radialGradient")) { if (resourceElement.getAttributeNS(null, "gradientUnits").equals("userSpaceOnUse")) { double cx = 0, cy = 0, r = 0, fx = 0, fy = 0; // normalizing the values for the circle to fit // the rectangle try { cx = Double.parseDouble(resourceElement.getAttributeNS(null, "cx")); cy = Double.parseDouble(resourceElement.getAttributeNS(null, "cy")); r = Double.parseDouble(resourceElement.getAttributeNS(null, "r")); fx = Double.parseDouble(resourceElement.getAttributeNS(null, "fx")); fy = Double.parseDouble(resourceElement.getAttributeNS(null, "fy")); cx = cx / initialWidth * imageSize.width; cy = cy / initialHeight * imageSize.height; r = r / (Math.abs( Math.sqrt(Math.pow(initialWidth, 2) + Math.pow(initialHeight, 2)))) * Math.abs( Math.sqrt( Math.pow(imageSize.width, 2) + Math.pow(imageSize.width, 2))); fx = fx / initialWidth * imageSize.width; fy = fy / initialHeight * imageSize.height; } catch (NumberFormatException | DOMException ex) { ex.printStackTrace(); } clonedResourceElement.setAttributeNS(null, "cx", format.format(cx)); clonedResourceElement.setAttributeNS(null, "cy", format.format(cy)); clonedResourceElement.setAttributeNS(null, "r", format.format(r)); clonedResourceElement.setAttributeNS(null, "fx", format.format(fx)); clonedResourceElement.setAttributeNS(null, "fy", format.format(fy)); } } else if (resourceElement.getNodeName().equals("pattern")) { if (resourceElement.getAttributeNS(null, "patternUnits").equals("userSpaceOnUse")) { double x = 0, y = 0, w = 0, h = 0; // normalizing the values for the vector to fit // the rectangle try { String xString = resourceElement.getAttributeNS(null, "x"); if (!xString.equals("")) { x = Double.parseDouble(xString); } String yString = resourceElement.getAttributeNS(null, "y"); if (!yString.equals("")) { y = Double.parseDouble(yString); } String wString = resourceElement.getAttributeNS(null, "w"); if (!wString.equals("")) { w = Double.parseDouble(wString); } String hString = resourceElement.getAttributeNS(null, "h"); if (!hString.equals("")) { h = Double.parseDouble(hString); } x = x / initialWidth * imageSize.width; y = y / initialHeight * imageSize.height; w = w / initialWidth * imageSize.width; h = h / initialHeight * imageSize.height; } catch (NumberFormatException | DOMException ex) { ex.printStackTrace(); } clonedResourceElement.setAttributeNS(null, "x", format.format(x)); clonedResourceElement.setAttributeNS(null, "y", format.format(y)); clonedResourceElement.setAttributeNS(null, "width", format.format(w)); clonedResourceElement.setAttributeNS(null, "height", format.format(h)); } } } } else if (resourceElement.getNodeName().equals("marker")) { // the line that will be drawn final Element line = doc.createElementNS(svgNS, "line"); line.setAttributeNS(null, "x1", (((double) imageSize.width) / 2) + ""); line.setAttributeNS(null, "y1", (((double) imageSize.height) / 2) + ""); line.setAttributeNS(null, "x2", ((double) imageSize.width / 2) + ""); line.setAttributeNS(null, "y2", imageSize.height + ""); elementToAdd = line; // setting that the line uses the resource String id = resourceElement.getAttribute("id"); if (id == null) id = ""; line.setAttributeNS( null, "style", "stroke:none;fill:none;marker-start:url(#" + id + ");"); } root.appendChild(elementToAdd); // adding a rendering listener to the canvas GVTTreeRendererAdapter gVTTreeRendererAdapter = new GVTTreeRendererAdapter() { @Override public void gvtRenderingCompleted(GVTTreeRendererEvent evt) { Image bufferedImage = canvas.getOffScreen(); if (bufferedImage != null) { Graphics g = bufferedImage.getGraphics(); Color borderColor = MetalLookAndFeel.getSeparatorForeground(); g.setColor(borderColor); g.drawRect(0, 0, imageSize.width - 1, imageSize.height - 1); } setImage(fhandle, fresourceId, bufferedImage); // refreshing the panels that have been created when no // image was available for them Image image = null; for (ResourceRepresentation resourceRepresentation : new LinkedList<ResourceRepresentation>(resourceRepresentationList)) { if (resourceRepresentation != null) { resourceRepresentation.refreshRepresentation(); image = resourceRepresentation.getImage(); if (image != null) { resourceRepresentationList.remove(resourceRepresentation); } } } canvas.removeGVTTreeRendererListener(this); canvas.stopProcessing(); canvas.dispose(); } }; canvas.addGVTTreeRendererListener(gVTTreeRendererAdapter); // setting the document for the canvas canvas.setSVGDocument(doc); canvas.setBackground(Color.white); canvas.setBounds(1, 1, imageSize.width, imageSize.height); } } }
public String toString() { return index + " : " + inst.getName() + "\t// " + DF.format(score); }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { JspFactory _jspxFactory = null; javax.servlet.jsp.PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; try { _jspxFactory = JspFactory.getDefaultFactory(); response.setContentType("text/html;charset=ISO-8859-1"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\n\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n\n"); out.write("\n\n"); PollerConfiguration pollconfig = getPollerConfiguration(); org.opennms.netmgt.config.poller.Package pkg = null; int pkgIdx = -1; String pkgIdxStr = (String) request.getParameter("pkgidx"); if (pkgIdxStr != null && pkgIdxStr.trim().length() > 0) { try { pkgIdx = Integer.parseInt(pkgIdxStr); if (pkgIdx >= 0) { if (pollconfig != null) { pkg = pollconfig.getPackage(pkgIdx); } } } catch (NumberFormatException ne) { ne.printStackTrace(); } } if (pkg == null) { if ((org.opennms.netmgt.config.poller.Package) request.getSession().getAttribute("pkg") != null) { pkg = (org.opennms.netmgt.config.poller.Package) request.getSession().getAttribute("pkg"); } } if (pkgIdx == -1) { pkgIdxStr = (String) request.getSession().getAttribute("pkgidx"); if (pkgIdxStr != null && pkgIdxStr.trim().length() > 0) { try { pkgIdx = Integer.parseInt(pkgIdxStr); } catch (NumberFormatException ne) { ne.printStackTrace(); } } } request.getSession().setAttribute("pkg", pkg); request.getSession().setAttribute("pkgidx", String.valueOf(pkgIdx)); String title = " Poller Package Downtime Model"; if (pkg != null) { title = " Poller Package - Downtime Model for: " + pkg.getName(); } out.write("\n\n"); out.write("<html>\n"); out.write("<head>\n "); out.write("<title>"); out.print(title); out.write("</title>\n "); out.write( "<link rel=\"stylesheet\" type=\"text/css\" href=\"/wt-portal/css/default.css\" />\n "); out.write("<script type=\"text/javascript\" src=\"/wt-portal/javascript/WTtools.js\">"); out.write("</script>\n\n"); out.write( "<script language=javascript>\nfunction confirmDelete(msg)\n{\n\tvar agree=confirm(msg);\n\tif (agree)\n\t\treturn true;\n\telse\n\t\treturn false;\n}\n\nfunction addDowntime()\n{\n var msg = \"\";\n var error = false;\n var begin = 0;\n var end = 0;\n var interval = 0;\n\n dtbeginday = parseInt(document.downtime.dtbeginday.value) * 24 * 60 * 60 * 1000;\n dtbeginhour = parseInt(document.downtime.dtbeginhour.value) * 60 * 60 * 1000;\n dtbeginminute = parseInt(document.downtime.dtbeginminute.value) * 60 * 1000;\n dtbeginsecond = parseInt(document.downtime.dtbeginsecond.value) * 1000;\n dtbeginmillisecond = parseInt(document.downtime.dtbeginmillisecond.value);\n\n dtendday = parseInt(document.downtime.dtendday.value) * 24 * 60 * 60 * 1000;\n dtendhour = parseInt(document.downtime.dtendhour.value) * 60 * 60 * 1000;\n dtendminute = parseInt(document.downtime.dtendminute.value) * 60 * 1000;\n dtendsecond = parseInt(document.downtime.dtendsecond.value) * 1000;\n dtendmillisecond = parseInt(document.downtime.dtendmillisecond.value);\n"); out.write( "\n dtintervalday = parseInt(document.downtime.dtintervalday.value) * 24 * 60 * 60 * 1000;\n dtintervalhour = parseInt(document.downtime.dtintervalhour.value) * 60 * 60 * 1000;\n dtintervalminute = parseInt(document.downtime.dtintervalminute.value) * 60 * 1000;\n dtintervalsecond = parseInt(document.downtime.dtintervalsecond.value) * 1000;\n dtintervalmillisecond = parseInt(document.downtime.dtintervalmillisecond.value);\n\n document.downtime.dtbegin.value = dtbeginday + dtbeginhour + dtbeginminute + dtbeginsecond + dtbeginmillisecond;\n document.downtime.dtend.value = dtendday + dtendhour + dtendminute + dtendsecond + dtendmillisecond;\n document.downtime.dtinterval.value = dtintervalday + dtintervalhour + dtintervalminute + dtintervalsecond + dtintervalmillisecond;\n\n\tvar beginVal = trim(document.downtime.dtbegin.value);\n\tvar endVal = trim(document.downtime.dtend.value);\n\tvar intervalVal = trim(document.downtime.dtinterval.value);\n\n if (beginVal == \"\") {\n error = true;\n msg += \"Must enter a numeric time value for \\\"begin\\\".\\n\";\n"); out.write( " }\n if (endVal == \"\") {\n error = true;\n msg += \"\\nMust enter a numeric time value for \\\"end\\\".\\n\";\n }\n if (intervalVal == \"\") {\n error = true;\n msg += \"\\nMust enter a numeric time value for \\\"interval\\\".\\n\";\n }\n if (isNaN(beginVal)) {\n error = true;\n msg += \"\\nMust enter a numeric time value for \\\"begin\\\".\\n\";\n }\n if (isNaN(endVal)) {\n error = true;\n msg += \"\\nMust enter a numeric time value for \\\"end\\\".\\n\";\n }\n if (isNaN(intervalVal)) {\n error = true;\n msg += \"\\nMust enter a numeric time value for \\\"interval\\\".\\n\";\n }\n\n if (!error) {\n begin = parseInt(beginVal);\n end = parseInt(endVal);\n interval = parseInt(intervalVal);\n \n if (!(end > 0)) {\n error = true;\n msg = \"The end time must be greater than zero.\\n\";\n }\n if (!(interval > 0)) {\n error = true;\n msg += \"\\nThe 'interval' value must be greater than zero.\\n\";\n }\n"); out.write( " if (!((end - begin) > 0)) {\n error = true;\n msg += \"\\nThe 'end' time must be greater than the 'begin'.\\n\";\n }\n if (!(interval "); out.write( "<= (end - begin))) {\n error = true;\n msg += \"\\nThe 'interval' time must be less than the difference of the 'begin' and the 'end'.\\n\";\n }\n }\n\n if (error) {\n alert (msg);\n return;\n }\n else\n {\n document.downtime.target = \"pollerDetailFrame\";\n \tdocument.downtime.action.value = 'adddt';\n \tdocument.downtime.submit();\n }\n}\n\nfunction removeDowntime(dtidx)\n{\n if (confirmDelete('Are you sure you want to delete this downtime model?')) {\n document.downtime.target = \"pollerDetailFrame\";\n document.downtime.action.value = 'removedt';\n document.downtime.dtidx.value = dtidx;\n \tdocument.downtime.submit();\n }\n}\n\nfunction updateDowntime()\n{\n document.downtime.target = \"_parent\";\n document.downtime.action.value = 'updatedt';\n\tdocument.downtime.submit();\n}\n\nfunction restoreDefaultDowntime()\n{\n if (confirmDelete('Are you sure you want to restore the default downtime model? All your changes will be lost.')) {\n document.downtime.target = \"pollerDetailFrame\";\n"); out.write( " document.downtime.action.value = 'restoredt';\n \tdocument.downtime.submit();\n }\n}\n"); out.write("</script>\n"); out.write("</head>\n"); out.write("<body>\n\n\t"); String breadcrumb1 = "<a href='admin/index.jsp'></a>"; out.write("\n\t"); String breadcrumb2 = "Poller Packages"; out.write("\n\t"); JspRuntimeLibrary.include( request, response, "/includes/header.jsp" + "?" + "title=" + java.net.URLEncoder.encode("" + title) + "&" + "location=" + "admin" + "&" + "help=" + "monitoringadmin%2Fpolling%2FWTHelp_PollerPackageDowntimeModel.html" + "&" + "noPopOut=" + "true" + "&" + "breadcrumb=" + java.net.URLEncoder.encode("" + breadcrumb1) + "&" + "breadcrumb=" + java.net.URLEncoder.encode("" + breadcrumb2), out, false); out.write("\n"); out.write("<!-- BEGIN FRAMING TABLE:open tags, keep at 100%-->\n"); out.write("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t"); out.write("<tr>\n\t\t"); out.write("<td width=\"10\">"); out.write( "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"1\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">"); out.write("</td>\n\t\t"); out.write("<td>\n"); out.write("<!-- END FRAMING TABLE:open tags, keep at 100%-->\n\t"); out.write("<form action=\""); out.print(WTTools.getMonServletURL(request)); out.write("WTPollerPackages\" method=\"post\" name=\"downtime\" target=\"_parent\">\n\t "); out.write("<input type=\"hidden\" name=\"action\" value=\"\">\n\t "); out.write("<input type=\"hidden\" name=\"pkgidx\" value=\"\">\n\t "); out.write("<input type=\"hidden\" name=\"dtidx\" value=\"\">\n\t "); out.write("<input type=\"hidden\" name=\"dtbegin\" value=\"\">\n\t "); out.write("<input type=\"hidden\" name=\"dtend\" value=\"\">\n\t "); out.write("<input type=\"hidden\" name=\"dtinterval\" value=\"\">\n\n"); out.write("<table width=\"98%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n "); out.write("<tr>\n "); out.write("<td colspan=\"4\">"); out.write("<b>Downtime Model:"); out.write("</b>"); out.write("<a class=\"tt\" href=\"javascript: towerTip("); out.print(WTTips.TIP_POLLER_MON_SERVICE); out.write(");\" title=\"Telemetry Tip\">"); out.write("<img src=\"/wt-portal/images/icons/tower_tips.gif\" border=\"0\">"); out.write("</a>"); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableHeader\">\n "); out.write("<td class=\"tableHeader\" width=\"25%\">Begin Time"); out.write("<a class=\"tt\" href=\"javascript: towerTip("); out.print(WTTips.TIP_POLLER_DT_BEGIN); out.write(");\" title=\"Telemetry Tip\">"); out.write("<img src=\"/wt-portal/images/icons/tower_tips.gif\" border=\"0\">"); out.write("</a>"); out.write("</td>\n "); out.write("<td class=\"tableHeader\" width=\"25%\">End Time"); out.write("<a class=\"tt\" href=\"javascript: towerTip("); out.print(WTTips.TIP_POLLER_DT_END); out.write(");\" title=\"Telemetry Tip\">"); out.write("<img src=\"/wt-portal/images/icons/tower_tips.gif\" border=\"0\">"); out.write("</a>"); out.write("</td>\n "); out.write("<td class=\"tableHeader\" width=\"25%\">Polling Interval"); out.write("<a class=\"tt\" href=\"javascript: towerTip("); out.print(WTTips.TIP_POLLER_DT_INTERVAL); out.write(");\" title=\"Telemetry Tip\">"); out.write("<img src=\"/wt-portal/images/icons/tower_tips.gif\" border=\"0\">"); out.write("</a>"); out.write("</td>\n "); out.write("<td class=\"tableHeader\" width=\"25%\">Action"); out.write("</td>\n "); out.write("</tr>\n "); long daymilli = 24 * 60 * 60 * 1000; // 86400000 long hourmlli = 60 * 60 * 1000; // 3600000; long minutemilli = 60 * 1000; // 60000; long secondmilli = 1000; String pattern2digit = "00"; DecimalFormat df2digit = new DecimalFormat(pattern2digit); String pattern3digit = "000"; DecimalFormat df3digit = new DecimalFormat(pattern3digit); long begin = 0; long end = 0; long interval = 0; String delete = null; long addbegin = 0; if (pkg != null) { Downtime[] ds = pkg.getDowntime(); if (ds != null) { for (int i = 0; i < ds.length; i++) { Downtime d = ds[i]; begin = d.getBegin(); end = d.getEnd(); interval = d.getInterval(); delete = d.getDelete(); long dtbegin = begin; long dtend = end; long dtinterval = interval; addbegin = begin; long dtbeginday = 0; long dtbeginhour = 0; long dtbeginminute = 0; long dtbeginsecond = 0; long dtbeginmillisecond = 0; long dtendday = 0; long dtendhour = 0; long dtendminute = 0; long dtendsecond = 0; long dtendmillisecond = 0; long dtintervalday = 0; long dtintervalhour = 0; long dtintervalminute = 0; long dtintervalsecond = 0; long dtintervalmillisecond = 0; if (dtbegin > 0) { dtbeginday = dtbegin / daymilli; dtbegin -= (dtbeginday * daymilli); } if (dtbegin > 0) { dtbeginhour = dtbegin / hourmlli; dtbegin -= (dtbeginhour * hourmlli); } if (dtbegin > 0) { dtbeginminute = dtbegin / minutemilli; dtbegin -= (dtbeginminute * minutemilli); } if (dtbegin > 0) { dtbeginsecond = dtbegin / secondmilli; dtbegin -= (dtbeginsecond * secondmilli); } if (dtbegin > 0) { dtbeginmillisecond = dtbegin; } if (dtend > 0) { dtendday = dtend / daymilli; dtend -= (dtendday * daymilli); } if (dtend > 0) { dtendhour = dtend / hourmlli; dtend -= (dtendhour * hourmlli); } if (dtend > 0) { dtendminute = dtend / minutemilli; dtend -= (dtendminute * minutemilli); } if (dtend > 0) { dtendsecond = dtend / secondmilli; dtend -= (dtendsecond * secondmilli); } if (dtend > 0) { dtendmillisecond = dtend; } if (dtinterval > 0) { dtintervalday = dtinterval / daymilli; dtinterval -= (dtintervalday * daymilli); } if (dtinterval > 0) { dtintervalhour = dtinterval / hourmlli; dtinterval -= (dtintervalhour * hourmlli); } if (dtinterval > 0) { dtintervalminute = dtinterval / minutemilli; dtinterval -= (dtintervalminute * minutemilli); } if (dtinterval > 0) { dtintervalsecond = dtinterval / secondmilli; dtinterval -= (dtintervalsecond * secondmilli); } if (dtinterval > 0) { dtintervalmillisecond = dtinterval; } out.write("\n "); out.write("<!--\n \t\t"); out.write("<TR>\n \t\t"); out.write("<TD align=\"center\">\n \t\t"); out.write("<INPUT name=\"dtbegin_"); out.print(String.valueOf(i)); out.write("\" type=\"text\" value=\""); out.print(begin); out.write("\" disabled>\n \t\t"); out.write("</TD>\n \t\t"); out.write("<TD align=\"center\">"); out.write("<INPUT name=\"dtend_"); out.print(String.valueOf(i)); out.write("\" type=\"text\" value=\""); out.print(end); out.write("\" disabled>"); out.write("</TD>\n \t\t"); out.write("<TD align=\"center\">"); out.write("<INPUT name=\"dtinterval_"); out.print(String.valueOf(i)); out.write("\" type=\"text\" value=\""); out.print(interval); out.write("\" disabled>"); out.write("</TD>\n \t\t"); out.write("<TD align=\"center\">"); out.write("<INPUT name=\"dtdel_"); out.print(String.valueOf(i)); out.write("\" type=\"checkbox\" value=\"true\" "); if (delete != null && delete.equals("true")) { out.write("checked"); } out.write(" disabled>"); out.write("</TD>\n \t\t"); out.write("<TD align=\"center\">\n "); if ((i + 2) == ds.length) { out.write("\n "); out.write("<a HREF=\"javascript:removeDowntime('"); out.print(i); out.write("')\" title=\"Remove Downtime Model\">Remove"); out.write("</a>\n "); } else { out.write("\n \n "); } out.write("\n "); out.write("</TD>\n \t\t"); out.write("</TR>\n \t\t-->\n\n \t\t"); if (i < (ds.length - 1)) { out.write("\n "); out.write("<tr class=\""); out.print(((i % 2) == 0) ? "tableRowLIght" : "tableRowDark"); out.write("\">\n \t\t"); out.write("<td class=\"tableText\">\n \t\t"); out.print(dtbeginday); out.write(" days "); out.print(df2digit.format(dtbeginhour)); out.write(":"); out.print(df2digit.format(dtbeginminute)); out.write(":"); out.print(df2digit.format(dtbeginsecond)); out.write(":"); out.print(df3digit.format(dtbeginmillisecond)); out.write("\n "); out.write("</td>\n \t\t"); out.write("<td class=\"tableText\">\n \t\t "); out.print(dtendday); out.write(" days "); out.print(df2digit.format(dtendhour)); out.write(":"); out.print(df2digit.format(dtendminute)); out.write(":"); out.print(df2digit.format(dtendsecond)); out.write(":"); out.print(df3digit.format(dtendmillisecond)); out.write("\n "); out.write("</td>\n \t\t"); out.write("<td class=\"tableText\">\n \t\t"); out.print(dtintervalday); out.write(" days "); out.print(df2digit.format(dtintervalhour)); out.write(":"); out.print(df2digit.format(dtintervalminute)); out.write(":"); out.print(df2digit.format(dtintervalsecond)); out.write(":"); out.print(df3digit.format(dtintervalmillisecond)); out.write("\n "); out.write("</td>\n "); out.write("<td class=\"tableText\">\n "); if (i == (ds.length - 2)) { out.write("\n "); out.write("<a href=\"javascript:removeDowntime('"); out.print(i); out.write("')\" title=\"Remove Downtime Model\">Remove"); out.write("</a>"); out.write("</td>\n "); } out.write("\n "); out.write("</td>\n \t\t"); } else { out.write("\n\t\t\t\t\t\t"); out.write("<tr>"); out.write("<td colspan=\"3\"> "); out.write("</td>"); out.write("</tr>\n "); out.write("<tr class=\"tableHeader\">\n \t\t"); out.write("<td class=\"tableHeader\" colspan=\"3\">\n "); if ((delete == null || !delete.equals("true")) && end == 0 && interval > 0) { out.write("\n \t\tAfter\n \t\t"); out.write("<b>\n \t\t "); if (dtbeginday > 0) { out.print(dtbeginday); out.write(" days"); } out.write("\n \t\t "); if (dtbeginhour > 0) { out.print(dtbeginhour); out.write(" hr"); } out.write("\n \t\t "); if (dtbeginminute > 0) { out.print(dtbeginminute); out.write(" min"); } out.write("\n \t\t "); if (dtbeginsecond > 0) { out.print(dtbeginsecond); out.write(" sec"); } out.write("\n \t\t "); if (dtbeginmillisecond > 0) { out.print(dtbeginmillisecond); out.write(" ms"); } out.write("\n \t\t"); out.write( "</b>\n \t\tthe system will continue to poll downed nodes at a\n \t\t"); out.write("<b>\n \t\t "); if (dtintervalday > 0) { out.print(dtintervalday); out.write(" day"); } out.write("\n \t\t "); if (dtintervalhour > 0) { out.print(dtintervalhour); out.write(" hr"); } out.write("\n \t\t "); if (dtintervalminute > 0) { out.print(dtintervalminute); out.write(" min"); } out.write("\n \t\t "); if (dtintervalsecond > 0) { out.print(dtintervalsecond); out.write(" sec"); } out.write("\n \t\t "); if (dtintervalmillisecond > 0) { out.print(dtintervalmillisecond); out.write(" ms"); } out.write("\n "); out.write( "</b>\n interval.\n "); } out.write("\n "); out.write("</td>\n "); if (i == (ds.length - 2)) { out.write("\n "); } else { out.write("\n "); out.write("<td class=\"tableHeader\"> "); out.write("</td>\n "); } out.write("\n \t\t"); } out.write("\n \t\t"); out.write("</tr>\n \t\t"); } } } out.write("\n "); out.write("<!--\n \t"); out.write("<TR>\n \t"); out.write("<TD align=\"center\">"); out.write("<INPUT name=\"dtbegin\" type=\"text\" value=\""); out.print(begin); out.write("\" readonly>"); out.write("</TD>\n \t"); out.write("<TD align=\"center\">"); out.write("<INPUT name=\"dtend\" type=\"text\" value=\"\">"); out.write("</TD>\n \t"); out.write("<TD align=\"center\">"); out.write("<INPUT name=\"dtinterval\" type=\"text\" value=\"\">"); out.write("</TD>\n \t"); out.write("<TD align=\"center\">"); out.write("<INPUT name=\"dtdel\" type=\"checkbox\" value=\"true\" disabled>"); out.write("</TD>\n \t"); out.write("<TD align=\"center\">"); out.write("<a HREF=\"javascript:addDowntime()\" title=\"Add Downtime Model\">Add Downtime"); out.write("</a>"); out.write("</TD>\n \t"); out.write("</TR>\n \t-->\n \t"); long dtbeginday = 0; long dtbeginhour = 0; long dtbeginminute = 0; long dtbeginsecond = 0; long dtbeginmillisecond = 0; long dtendday = 0; long dtendhour = 0; long dtendminute = 0; long dtendsecond = 0; long dtendmillisecond = 0; long dtintervalday = 0; long dtintervalhour = 0; long dtintervalminute = 0; long dtintervalsecond = 0; long dtintervalmillisecond = 0; if (addbegin > 0) { dtbeginday = addbegin / daymilli; addbegin = addbegin - (dtbeginday * daymilli); } if (addbegin > 0) { dtbeginhour = addbegin / hourmlli; addbegin = addbegin - (dtbeginhour * hourmlli); } if (addbegin > 0) { dtbeginminute = addbegin / minutemilli; addbegin = addbegin - (dtbeginminute * minutemilli); } if (addbegin > 0) { dtbeginsecond = addbegin / secondmilli; addbegin = addbegin - (dtbeginsecond * secondmilli); } if (addbegin > 0) { dtbeginmillisecond = addbegin; } out.write("\n \t"); out.write("<tr class=\"tableRowLight\">\n \t"); out.write("<td>\n \t "); out.write("<input type=\"hidden\" name=\"dtbeginday\" value=\""); out.print(dtbeginday); out.write("\">\n \t "); out.write("<input type=\"hidden\" name=\"dtbeginhour\" value=\""); out.print(dtbeginhour); out.write("\">\n \t "); out.write("<input type=\"hidden\" name=\"dtbeginminute\" value=\""); out.print(dtbeginminute); out.write("\">\n \t "); out.write("<input type=\"hidden\" name=\"dtbeginsecond\" value=\""); out.print(dtbeginsecond); out.write("\">\n \t "); out.write("<input type=\"hidden\" name=\"dtbeginmillisecond\" value=\""); out.print(dtbeginmillisecond); out.write("\">\n \t "); out.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Days: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.print(dtbeginday); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Hours: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.print(dtbeginhour); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Minutes: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.print(dtbeginminute); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Seconds: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.print(dtbeginsecond); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Milliseconds: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.print(dtbeginmillisecond); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("</table>\n \t"); out.write("</td>\n \t"); out.write("<td>\n \t "); out.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Days: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtendday\">\n\t\t "); for (int i = 0; i <= 365; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtendday == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Hours: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtendhour\">\n\t\t "); for (int i = 0; i < 24; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtendhour == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Minutes: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtendminute\">\n\t\t "); for (int i = 0; i < 60; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtendminute == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Seconds: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtendsecond\">\n\t\t "); for (int i = 0; i < 60; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtendsecond == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Milliseconds: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtendmillisecond\">\n\t\t "); for (int i = 0; i < 1000; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtendmillisecond == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("</table>\n\n \t"); out.write("</td>\n \t"); out.write("<td>\n \t "); out.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Days: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtintervalday\">\n\t\t "); for (int i = 0; i <= 365; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtintervalday == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Hours: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtintervalhour\">\n\t\t "); for (int i = 0; i < 24; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtintervalhour == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Minutes: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtintervalminute\">\n\t\t "); for (int i = 0; i < 60; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtintervalminute == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Seconds: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtintervalsecond\">\n\t\t "); for (int i = 0; i < 60; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtintervalsecond == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("<tr class=\"tableRowLight\">\n \t "); out.write("<td nowrap>Milliseconds: "); out.write("</td>\n \t "); out.write("<td nowrap>"); out.write("<select name=\"dtintervalmillisecond\">\n\t\t "); for (int i = 0; i < 1000; i++) { out.write("\n\t\t "); out.write("<option value="); out.print(i); out.write(" "); if (dtintervalmillisecond == i) { out.write("selected"); } out.write(">"); out.print(df3digit.format(i)); out.write("\n "); } out.write("\n\t\t "); out.write("</select>"); out.write("</td>\n \t "); out.write("</tr>\n \t "); out.write("</table>\n \t"); out.write("</td>\n \t"); out.write("<!--\n \t"); out.write("<TD align=\"center\">\n \t"); out.write("<INPUT name=\"dtdel\" type=\"checkbox\" value=\"true\" disabled>\n \t"); out.write("</TD>\n \t-->\n \t"); out.write("<td align=\"center\" nowrap>"); out.write("<a href=\"javascript:addDowntime()\" title=\"Add Downtime Model\">Add Downtime"); out.write("</a>"); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" colspan=\"4\">"); out.write( "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"4\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">"); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr>\n "); out.write("<td colspan=\"4\">"); out.write("<br />\n "); out.write("<a href=\"javascript:restoreDefaultDowntime()\">"); out.write( "<img src=\"/wt-portal/images/buttons/btn_restore_defaults.gif\" border=\"0\" alt=\"Restore Defaults\">"); out.write("</a>\n \n "); out.write("<!--"); out.write( "<input type=\"submit\" name=\"button\" onclick=\"return restoreDefaultDowntime()\" value=\"Restore Defaults\" title=\"Restore Downtime Model Defaults\">-->"); out.write("<br />\n "); out.write("</td>\n "); out.write("</tr>\n"); out.write("</table>\n"); out.write("</form>\n"); out.write("<!-- BEGIN FRAMING TABLE:close tags-->\n\t\t"); out.write("</td>\n\t"); out.write("</tr>\n"); out.write("</table>\n"); out.write("<!-- END FRAMING TABLE:close tags-->\n"); out.write("<p>\n"); JspRuntimeLibrary.include( request, response, "/includes/footer.jsp" + "?" + "location=" + "admin", out, false); out.write("\n\n "); out.write("</body>\n"); out.write("</html>\n"); } catch (Throwable t) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (pageContext != null) pageContext.handlePageException(t); } finally { if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext); } }
private double test(List baseline, List preferred, List gold) { double bs = 0, ps = 0; if (stat.toUpperCase().equals("F1")) { bs = new Evaluator(gold, baseline).getF1(); ps = new Evaluator(gold, preferred).getF1(); } else if (stat.toUpperCase().equals("P")) { bs = new Evaluator(gold, baseline).getPrecision(); ps = new Evaluator(gold, preferred).getPrecision(); } else if (stat.toUpperCase().equals("R")) { bs = new Evaluator(gold, baseline).getRecall(); ps = new Evaluator(gold, preferred).getRecall(); } double d = Math.abs(ps - bs); double mean = 0; double variance = 0; double sum = 0; double ssum = 0; logger.info( stat + ": original score bs, ps,d: " + formatter.format(bs * 100) + "%, " + formatter.format(ps * 100) + "%, " + formatter.format(d * 100) + "%"); // p - p-value. In general, the lowest the p-value, // the less probable it is that that the null // hypothesis holds. That is, the two systems are // are significantly different. double p = 0; // c - number of times that the pseudostatistic is // greater or equal to the true statistic int c = 0; for (int i = 0; i < iterations; i++) { List baselineCopy = copy(baseline); List preferredCopy = copy(preferred); swap(baselineCopy, preferredCopy, new Random(i * 27)); if (stat.toUpperCase().equals("F1")) { bs = new Evaluator(gold, baselineCopy).getF1(); ps = new Evaluator(gold, preferredCopy).getF1(); } else if (stat.toUpperCase().equals("P")) { bs = new Evaluator(gold, baselineCopy).getPrecision(); ps = new Evaluator(gold, preferredCopy).getPrecision(); } else if (stat.toUpperCase().equals("R")) { bs = new Evaluator(gold, baselineCopy).getRecall(); ps = new Evaluator(gold, preferredCopy).getRecall(); } double di = Math.abs(ps - bs); sum += di; ssum += Math.pow(di, 2); if (di >= d) { c++; // logger.info("score at " + i + " c, bs, ps,d: " + c + ", " + formatter.format(bs * 100) + // "%, " + formatter.format(ps * 100) + "%, " + formatter.format(di * 100) + "%, (" + // formatter.format(d * 100) + "%)"); } } // end for i mean = sum / iterations; variance = (iterations * ssum - Math.pow(sum, 2)) / iterations * (iterations - 1); p = (double) (c + 1) / (iterations + 1); logger.info("mean " + formatter.format(mean) + ", " + formatter.format(Math.sqrt(variance))); logger.info(p + " = (" + c + " + 1) / (" + iterations + " + 1)"); return p; } // end test
private static String time() { float now = (float) (System.currentTimeMillis() - startTime) / 1000; return TIME_FORMAT.format(now); }
void print(String name, Vec value) { g.drawString(name + ":" + df.format(value.x) + " , " + df.format(value.y), x, y += 20); }
/** main method - entry point for the entire program */ public static void main(String[] args) throws IOException // just let IOExceptions terminate the program { // initialize loan variables from constants final double principal = PRINCIPAL; final double rate = RATE / 100; // convert rate into decimal form final double numPayments = TERM * MONTHS_PER_YEAR; // create output and input objects final PrintStream out = System.out; final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // display the header for this assignment out.println("Name : David C. Gibbons "); out.println("Assignment : Workshop 3 "); out.println("-------------------------------------"); // determine interest rate per month final double monthlyRate = (rate / MONTHS_PER_YEAR); // calculate monthly payment final double monthlyPayment = principal * (monthlyRate / (1 - Math.pow(1 + monthlyRate, -numPayments))); // fetch needed decimal formatters needed for output final DecimalFormat numberFmt = new DecimalFormat("#0"); final DecimalFormat currencyFmt = new DecimalFormat("$0.00"); final DecimalFormat percentFmt = new DecimalFormat("0.00 %"); // display overall loan information out.println("Principal : " + currencyFmt.format(principal)); out.println("Interest Rate : " + percentFmt.format(rate)); out.println("# of payments : " + numberFmt.format(numPayments)); out.println("Monthly payment : " + currencyFmt.format(monthlyPayment)); // wait for the user to continue and then display the // details of all the payments out.println(); out.println("Hit Enter to list Payment Detail"); in.readLine(); // calculate the payment detail in yearly blocks double currentPrincipal = principal; for (int month = 0; month < numPayments; month++) { // display header to match the benchmark at the start of the year if (month == 0 || (month % MONTHS_PER_YEAR) == 0) { // display a pause prompt if this isn't the first year if (month > 0) { out.println(); out.println(" Hit Enter to continue"); in.readLine(); } out.println(); out.println("\tInterest Principal Principal"); out.println("Months\tPayment Payment Balance"); out.println(); } // calculate this month's interest payment and then the // principal payment and remaining principal balance double interestPayment = rate / MONTHS_PER_YEAR * currentPrincipal; double principalPayment = monthlyPayment - interestPayment; // always get the absolute value of the current principal as // sometimes the final value of 0 can be -0.0 currentPrincipal = Math.abs(currentPrincipal - principalPayment); // format the fields and display to match benchmark out.print(numberFmt.format(month + 1) + " \t"); out.print(currencyFmt.format(interestPayment) + "\t "); out.print(currencyFmt.format(principalPayment) + "\t"); out.println(currencyFmt.format(currentPrincipal)); } }
// Populate division column - refer to mysoft.stockmasterdetails.stock_cat // nominal_code=glcode=5xxxxx = services we sell // istock_cat = as in stockmasterdetails.stock_cat // 27/03/2012: uses showType to determine which one to show, // 1=default,2=stock-pricing,3=testpackage // 07/03/2013: pricing_lb_headers add "Subcon" column = stockmasterdetails.newfield4 public final void populateTestParametersColumn(String istock_cat, String igroupcode) throws SQLException { Object[] testparameters_lb_headers = { new listboxHeaderObj("mysoftcode", false), new listboxHeaderObj("Test", true), new listboxHeaderObj("Method", true), }; Object[] pricing_lb_headers = { new listboxHeaderObj("mysoftcode", false), new listboxHeaderObj("Stock.Code", true), new listboxHeaderObj("Test", true), new listboxHeaderObj("Method", true), new listboxHeaderObj("Cost", true), new listboxHeaderObj("Selling", true), new listboxHeaderObj("Subcon", true), }; Object[] testpackages_lb_headers = { new listboxHeaderObj("mysoftcode", false), new listboxHeaderObj("Stock.Code", true), new listboxHeaderObj("Test", true), new listboxHeaderObj("Method", true), new listboxHeaderObj("S.Price", true), new listboxHeaderObj("LOR", true), new listboxHeaderObj("Bill", true), new listboxHeaderObj("Units", true), }; Object[] whichheader = null; String sqlstm = ""; // NumberFormat nf = NumberFormat.getCurrencyInstance(); DecimalFormat nf = new DecimalFormat("####.00"); String costprice, sellingprice; switch (showType) { case 1: whichheader = testparameters_lb_headers; // 30/9/2010: put a filter to knockout p-p2-%METALS items sqlstm = "select id,description,description2 from stockmasterdetails where item_type='Service Item' and nominal_code like '5%' " + "and stock_cat='" + istock_cat + "' " + "and groupcode='" + igroupcode + "' " + "and stock_code not like 'p-p2-%METALS' " + "order by description"; break; case 2: whichheader = pricing_lb_headers; sqlstm = "select id,stock_code,description,description2,cost_price,selling_price,newfield4 " + "from stockmasterdetails where item_type='Service Item' and nominal_code like '5%' " + "and stock_cat='" + istock_cat + "' " + "and groupcode='" + igroupcode + "' " + "order by description"; break; case 3: whichheader = testpackages_lb_headers; sqlstm = "select id,stock_code,description,description2,newfield8,newfield9,newfield10,selling_price " + "from stockmasterdetails where item_type='Service Item' and nominal_code like '5%' " + "and stock_cat='" + istock_cat + "' " + "and groupcode='" + igroupcode + "' " + "order by description"; break; } Listbox newlb = lbhand.makeVWListbox(tests_holder, whichheader, tests_lbid, 15); Sql sql = sqlhand.als_mysoftsql(); if (sql == null) return; List<GroovyRowResult> tlist = sql.rows(sqlstm); sql.close(); String lor, bill, units; if (tlist.size() == 0) return; if (testOnClicker != null) newlb.addEventListener("onSelect", testOnClicker); for (GroovyRowResult ilist : tlist) { ArrayList kabom = new ArrayList(); switch (showType) { case 1: kabom.add(String.valueOf(ilist.get("id"))); kabom.add(kiboo.checkNullString((String) ilist.get("description"))); kabom.add(kiboo.checkNullString((String) ilist.get("description2"))); break; case 2: kabom.add(ilist.get("id").toString()); kabom.add(kiboo.checkNullString((String) ilist.get("stock_code"))); kabom.add( lbhand.trimListitemLabel( kiboo.checkNullString((String) ilist.get("description")), 35)); kabom.add( lbhand.trimListitemLabel( kiboo.checkNullString((String) ilist.get("description2")), 35)); costprice = nf.format((Double) ilist.get("cost_price")); kabom.add(costprice); sellingprice = nf.format((Double) ilist.get("selling_price")); kabom.add(sellingprice); kabom.add(kiboo.checkNullString((String) ilist.get("newfield4"))); break; case 3: kabom.add(ilist.get("id").toString()); kabom.add(kiboo.checkNullString((String) ilist.get("stock_code"))); kabom.add(kiboo.checkNullString_RetWat((String) ilist.get("description"), "---")); // methodme = trimListitemLabel(ilist.get("description2"), 30); kabom.add(kiboo.checkNullString_RetWat((String) ilist.get("description2"), "---")); kabom.add(nf.format(ilist.get("selling_price"))); lor = kiboo.checkNullString((String) ilist.get("newfield8")); bill = kiboo.checkNullString((String) ilist.get("newfield9")); units = kiboo.checkNullString((String) ilist.get("newfield10")); lor = (lor.equals("")) ? "----" : lor; bill = (bill.equals("")) ? "---" : bill; units = (units.equals("")) ? "----" : units; kabom.add(lor); kabom.add(bill); kabom.add(units); break; } String[] strarray = kiboo.convertArrayListToStringArray(kabom); lbhand.insertListItems(newlb, strarray, "true", ""); } if (testOnDoubleClicker != null) lbhand.setDoubleClick_ListItems(newlb, testOnDoubleClicker); } // end of populateTestParametersColumn()