Search in sources :

Example 11 with DecimalFormat

use of java.text.DecimalFormat in project zeppelin by apache.

the class TransferListener method transferSucceeded.

@Override
public void transferSucceeded(TransferEvent event) {
    transferCompleted(event);
    TransferResource resource = event.getResource();
    long contentLength = event.getTransferredBytes();
    if (contentLength >= 0) {
        String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
        String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";
        String throughput = "";
        long duration = System.currentTimeMillis() - resource.getTransferStartTime();
        if (duration > 0) {
            DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
            double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
            throughput = " at " + format.format(kbPerSec) + " KB/sec";
        }
        logger.info(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len + throughput + ")");
    }
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) TransferResource(org.sonatype.aether.transfer.TransferResource) DecimalFormat(java.text.DecimalFormat)

Example 12 with DecimalFormat

use of java.text.DecimalFormat in project cucumber-jvm by cucumber.

the class JUnitFormatter method sumTimes.

private String sumTimes(NodeList testCaseNodes) {
    double totalDurationSecondsForAllTimes = 0.0d;
    for (int i = 0; i < testCaseNodes.getLength(); i++) {
        try {
            double testCaseTime = Double.parseDouble(testCaseNodes.item(i).getAttributes().getNamedItem("time").getNodeValue());
            totalDurationSecondsForAllTimes += testCaseTime;
        } catch (NumberFormatException e) {
            throw new CucumberException(e);
        } catch (NullPointerException e) {
            throw new CucumberException(e);
        }
    }
    DecimalFormat nfmt = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
    nfmt.applyPattern("0.######");
    return nfmt.format(totalDurationSecondsForAllTimes);
}
Also used : DecimalFormat(java.text.DecimalFormat) CucumberException(cucumber.runtime.CucumberException)

Example 13 with DecimalFormat

use of java.text.DecimalFormat in project cucumber-jvm by cucumber.

the class Stats method printDuration.

private void printDuration(PrintStream out) {
    out.print(String.format("%dm", (totalDuration / ONE_MINUTE)));
    DecimalFormat format = new DecimalFormat("0.000", new DecimalFormatSymbols(locale));
    out.println(format.format(((double) (totalDuration % ONE_MINUTE)) / ONE_SECOND) + "s");
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 14 with DecimalFormat

use of java.text.DecimalFormat in project lucida by claritylab.

the class Experimenter method runExperiments.

/**
     * Runs the experiments specified in the input properties file.  The set of 
     * experiments run is the cross-product of the sets of algorithm configurations, training/testing
     * dataset configurations, and feature type combinations.
     * 
     */
public void runExperiments() {
    DecimalFormat format = new DecimalFormat("#0.00");
    HierarchicalClassifierTrainer qc = new HierarchicalClassifierTrainer(languagePair);
    StringBuilder sb = new StringBuilder();
    for (String alg : learningCombos) {
        properties.setProperty("learners", alg);
        for (String featureTypes : featureTypeCombos) {
            properties.setProperty("featureTypes", featureTypes);
            qc.setProperties(properties);
            Evaluation eval = qc.runExperiment();
            sb.append(alg.replaceAll(",", "-") + "-" + featureTypes.replaceAll(",", "-") + format.format((1.0 - eval.errorRate()) * 100) + "\n");
            String report = qc.createReport();
            log.debug("Report:\n" + report);
            FileUtil.writeFile(report, "reports/report-" + alg.replaceAll(",", "-") + "-" + featureTypes.replaceAll(",", "-") + ".txt", "UTF-8");
        }
    }
    FileUtil.writeFile(sb.toString(), "reports/results-" + System.currentTimeMillis() + ".txt", "UTF-8");
}
Also used : Evaluation(edu.cmu.minorthird.classify.experiments.Evaluation) DecimalFormat(java.text.DecimalFormat)

Example 15 with DecimalFormat

use of java.text.DecimalFormat in project lucida by claritylab.

the class QuestionClassifier method evaluate.

/**
     * Evaluates classification accuracy on a given test set.
     * 
     * @param testSetFileName the name of the file containing the test set to evaluate against
     * @throws Exception
     */
public void evaluate(String testSetFileName) throws Exception {
    DecimalFormat format = new DecimalFormat("#0.00");
    int correct = 0;
    List<GoldStandard> goldStandards;
    goldStandards = GoldStandard.loadFile(testSetFileName);
    int size = goldStandards.size();
    //System.out.println(String.format("%18s / %-18s","Actual","Predicted"));
    for (GoldStandard gs : goldStandards) {
        String question = gs.getQuestion(languagePair.getFirst().name().split("_")[0].toUpperCase());
        String actual = gs.getAnswerType();
        Set<AnswerType> actuals = new HashSet<AnswerType>();
        Set<AnswerType> predicted = new HashSet<AnswerType>();
        for (String atypeStr : actual.split("\\|")) {
            actuals.add(AnswerType.constructFromString(atypeStr));
        }
        List<AnswerType> atypes = getAnswerTypes(question);
        if (atypes.size() > 0) {
            double topConf = atypes.get(0).getConfidence();
            for (int i = 0; i < atypes.size(); i++) {
                if (atypes.get(i).getConfidence() == topConf) {
                    predicted.add(atypes.get(i));
                    atypes.remove(i);
                    i--;
                }
            }
        }
        boolean corr = false;
        for (AnswerType a : predicted) if (actuals.contains(a))
            corr = true;
        if (corr)
            correct++;
        else {
            log.debug("A: " + actuals + ", P: " + predicted + ", " + question);
            if (atypes.size() > 0)
                log.debug("        2nd: " + atypes.get(0));
        }
    }
    if (size > 0)
        System.out.println("Test set accuracy: " + correct + "/" + size + " (" + format.format((double) correct / (double) size * 100) + "%)");
    else
        System.out.println("No examples classified.");
}
Also used : GoldStandard(edu.cmu.lti.javelin.evaluation.GoldStandard) DecimalFormat(java.text.DecimalFormat) HashSet(java.util.HashSet)

Aggregations

DecimalFormat (java.text.DecimalFormat)719 DecimalFormatSymbols (java.text.DecimalFormatSymbols)89 NumberFormat (java.text.NumberFormat)88 BigDecimal (java.math.BigDecimal)45 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)33 ParseException (java.text.ParseException)30 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)29 Support_DecimalFormat (tests.support.Support_DecimalFormat)28 File (java.io.File)24 Date (java.util.Date)24 SimpleDateFormat (java.text.SimpleDateFormat)22 HashMap (java.util.HashMap)21 Locale (java.util.Locale)21 PrintWriter (java.io.PrintWriter)20 UsageVO (com.cloud.usage.UsageVO)19 JFreeChart (org.jfree.chart.JFreeChart)18 List (java.util.List)17 TextView (android.widget.TextView)15