Example usage for org.joda.time Duration toStandardMinutes

List of usage examples for org.joda.time Duration toStandardMinutes

Introduction

In this page you can find the example usage for org.joda.time Duration toStandardMinutes.

Prototype

public Minutes toStandardMinutes() 

Source Link

Document

Converts this duration to a period in minutes assuming that there are the standard number of milliseconds in a minute.

Usage

From source file:com.axelor.apps.crm.service.EventReminderService.java

License:Open Source License

public int getMinutesDuration(Duration duration) {

    int minutes = duration.toStandardMinutes().getMinutes() % 60;

    LOG.debug("Minutes : {}", minutes);

    if (minutes >= 53 && minutes < 8) {
        return 00;
    } else if (minutes >= 8 && minutes < 23) {
        return 15;
    } else if (minutes >= 23 && minutes < 38) {
        return 30;
    } else if (minutes >= 38 && minutes < 53) {
        return 45;
    }//  w ww . ja v  a  2 s  .c o m

    return 00;

}

From source file:com.axelor.apps.tool.date.DurationTool.java

License:Open Source License

public static int getMinutesDuration(Duration duration) {

    return duration.toStandardMinutes().getMinutes();
}

From source file:edu.jhu.hlt.concrete.stanford.ConcreteStanfordRunner.java

License:Open Source License

public void run(Path inPath, Path outPath, Analytic<? extends TokenizedCommunication> analytic) {
    LOGGER.debug("Checking input and output directories.");
    try {//from   ww w  . j  av a 2  s .  c o  m
        prepareInputOutput(inPath, outPath);
    } catch (IOException e) {
        LOGGER.error("Caught IOException when checking input and output directories.", e);
    }

    String lowerOutPathStr = inPath.toString().toLowerCase();
    try {
        sed.disable();

        // Outcomes of outPathStr ending:
        // No valid ending (program exit)
        // Ends with .concrete (first if)
        // Ends with .tar (else, first if)
        // Ends with .tar.gz (else, second if)

        boolean isTarExt = lowerOutPathStr.endsWith(".tar");
        boolean isTarGzExt = lowerOutPathStr.endsWith(".tar.gz") || lowerOutPathStr.endsWith(".tgz");
        boolean isConcreteExt = lowerOutPathStr.endsWith(".concrete") || lowerOutPathStr.endsWith(".comm");

        int nElementsInitPath = inPath.getNameCount();
        Path inputFileName = inPath.getName(nElementsInitPath - 1);

        // If no extention matches, exit.
        if (!isTarExt && !isTarGzExt && !isConcreteExt) {
            LOGGER.error("Input file extension was not '.concrete', '.comm', '.tar', or '.tar.gz'; exiting.");
            System.exit(1);
        } else if (isConcreteExt) {
            // IF .concrete, run single communication.
            LOGGER.info("Annotating single .concrete file at: {}", inPath.toString());
            try (InputStream in = Files.newInputStream(inPath);
                    BufferedInputStream bin = new BufferedInputStream(in, 1024 * 8 * 24);) {
                byte[] inputBytes = IOUtils.toByteArray(bin);
                Communication c = ser.fromBytes(inputBytes);
                WrappedCommunication annotated = analytic.annotate(c);
                Communication ar = annotated.getRoot();
                WritableCommunication wc = new WritableCommunication(ar);
                if (Files.isDirectory(outPath))
                    wc.writeToFile(outPath.resolve(inputFileName), true);
                else
                    wc.writeToFile(outPath, true);
            } catch (AnalyticException e) {
                LOGGER.error("Caught exception when running the analytic.", e);
            }
        } else {

            Path localOutPath;
            if (Files.isDirectory(outPath))
                // if directory, use same extension as input.
                localOutPath = outPath.resolve(inputFileName);
            else
                localOutPath = outPath;

            // Iterate over the archive.
            AutoCloseableIterator<byte[]> iter;
            try (InputStream is = Files.newInputStream(inPath);
                    BufferedInputStream bis = new BufferedInputStream(is, 1024 * 8 * 24);) {

                // open iterator based on file extension
                iter = isTarExt ? new TarArchiveEntryByteIterator(bis) : new TarGzArchiveEntryByteIterator(bis);
                try (OutputStream os = Files.newOutputStream(localOutPath);
                        BufferedOutputStream bos = new BufferedOutputStream(os, 1024 * 8 * 24);) {
                    TarArchiver archiver = isTarExt ? new TarArchiver(bos)
                            : new TarArchiver(new GzipCompressorOutputStream(bos));

                    final StopWatch sw = new StopWatch();
                    sw.start();

                    int docCtr = 0;
                    final AtomicInteger tokenCtr = new AtomicInteger(0);
                    LOGGER.info("Iterating over archive: {}", inPath.toString());
                    while (iter.hasNext()) {
                        Communication n = ser.fromBytes(iter.next());
                        LOGGER.info("Annotating communication: {}", n.getId());
                        try {
                            TokenizedCommunication a = analytic.annotate(n);
                            a.getTokenizations().parallelStream()
                                    .map(tkzToInt -> tkzToInt.getTokenList().getTokenListSize())
                                    .forEach(ct -> tokenCtr.addAndGet(ct));
                            archiver.addEntry(new ArchivableCommunication(a.getRoot()));
                            docCtr++;
                        } catch (AnalyticException | IOException | StringIndexOutOfBoundsException e) {
                            LOGGER.error("Caught exception processing document: " + n.getId(), e);
                        }
                    }

                    try {
                        archiver.close();
                        iter.close();
                    } catch (Exception e) {
                        // unlikely.
                        LOGGER.info("Caught exception closing iterator.", e);
                    }

                    sw.stop();
                    Duration rt = new Duration(sw.getTime());
                    Seconds st = rt.toStandardSeconds();
                    Minutes m = rt.toStandardMinutes();
                    int minutesInt = m.getMinutes();

                    LOGGER.info("Complete.");
                    LOGGER.info("Runtime: approximately {} minutes.", minutesInt);
                    LOGGER.info("Processed {} documents.", docCtr);
                    final int tokens = tokenCtr.get();
                    LOGGER.info("Processed {} tokens.", tokens);
                    if (docCtr > 0 && minutesInt > 0) {
                        final float minutesFloat = minutesInt;
                        float perMin = docCtr / minutesFloat;
                        LOGGER.info("Processed approximately {} documents/minute.", perMin);
                        LOGGER.info("Processed approximately {} tokens/second.",
                                st.getSeconds() / minutesFloat);
                    }
                }
            }
        }
    } catch (IOException | ConcreteException e) {
        LOGGER.error("Caught exception while running the analytic over archive.", e);
    }
}