List of usage examples for org.joda.time Minutes getMinutes
public int getMinutes()
From source file:com.thinkbiganalytics.scheduler.util.TimerToCronExpression.java
License:Apache License
private static String getMinutesCron(Period p) { Integer min = p.getMinutes(); Minutes m = p.toStandardMinutes(); Integer minutes = m.getMinutes(); String str = "0" + (min > 0 ? "/" + min : ""); if (minutes > 60) { str = min + ""; }/* w ww.j a v a 2s. co m*/ return str; }
From source file:com.xumpy.timesheets.services.TickedJobsDetailSrv.java
public static TickedJobsDetail calculate(List<? extends TickedJobs> tickedJobs) { TickedJobsDetail tickedJobsDetail = new TickedJobsDetail(); tickedJobsDetail.setTickedJobs(tickedJobs); if (tickedJobs.size() > 0) { tickedJobs = sortTickedJobs(tickedJobs); Date startCounterWork = null; Date startCounterPause = null; BigDecimal workedMinutes = new BigDecimal(0); BigDecimal pausedMinutes = new BigDecimal(0); for (int i = 0; i < tickedJobs.size(); i++) { if (i % 2 == 0) { if (!tickedJobs.get(i).isStarted()) { tickedJobsDetail.setActualPause(new BigDecimal(-1)); tickedJobsDetail.setActualWorked(new BigDecimal(-1)); break; } else { if (startCounterPause != null) { Minutes minutes = Minutes.minutesBetween(new DateTime(startCounterPause), new DateTime(tickedJobs.get(i).getTicked())); pausedMinutes = pausedMinutes.add(new BigDecimal(minutes.getMinutes())); }// w w w . j ava2 s. c om startCounterWork = tickedJobs.get(i).getTicked(); } } else { if (tickedJobs.get(i).isStarted()) { tickedJobsDetail.setActualPause(new BigDecimal(-1)); tickedJobsDetail.setActualWorked(new BigDecimal(-1)); break; } else { Minutes minutes = Minutes.minutesBetween(new DateTime(startCounterWork), new DateTime(tickedJobs.get(i).getTicked())); workedMinutes = workedMinutes.add(new BigDecimal(minutes.getMinutes())); startCounterPause = tickedJobs.get(i).getTicked(); } } tickedJobsDetail.setActualPause(pausedMinutes); tickedJobsDetail.setActualWorked(workedMinutes); } } else { tickedJobsDetail.setTickedJobs(tickedJobs); tickedJobsDetail.setActualWorked(new BigDecimal(0)); tickedJobsDetail.setActualPause(new BigDecimal(0)); } return tickedJobsDetail; }
From source file:edu.jhu.hlt.concrete.gigaword.expt.ConvertGigawordDocuments.java
License:Open Source License
/** * @param args/* w ww.j a v a2 s. com*/ */ public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.error("Thread {} caught unhandled exception.", t.getName()); logger.error("Unhandled exception.", e); } }); if (args.length != 2) { logger.info("Usage: {} {} {}", GigawordConcreteConverter.class.getName(), "path/to/expt/file", "path/to/out/folder"); System.exit(1); } String exptPathStr = args[0]; String outPathStr = args[1]; // Verify path points to something. Path exptPath = Paths.get(exptPathStr); if (!Files.exists(exptPath)) { logger.error("File: {} does not exist. Re-run with the correct path to " + " the experiment 2 column file. See README.md."); System.exit(1); } logger.info("Experiment map located at: {}", exptPathStr); // Create output dir if not yet created. Path outPath = Paths.get(outPathStr); if (!Files.exists(outPath)) { logger.info("Creating directory: {}", outPath.toString()); try { Files.createDirectories(outPath); } catch (IOException e) { logger.error("Caught an IOException when creating output dir.", e); System.exit(1); } } logger.info("Output directory located at: {}", outPathStr); // Read in expt map. See README.md. Map<String, Set<String>> exptMap = null; try (Reader r = ExperimentUtils.createReader(exptPath); BufferedReader br = new BufferedReader(r)) { exptMap = ExperimentUtils.createFilenameToIdMap(br); } catch (IOException e) { logger.error("Caught an IOException when creating expt map.", e); System.exit(1); } // Start a timer. logger.info("Gigaword -> Concrete beginning."); StopWatch sw = new StopWatch(); sw.start(); // Iterate over expt map. exptMap.entrySet() // .parallelStream() .forEach(p -> { final String pathStr = p.getKey(); final Set<String> ids = p.getValue(); final Path lp = Paths.get(pathStr); logger.info("Converting path: {}", pathStr); // Get the file name and immediate folder it is under. int nElements = lp.getNameCount(); Path fileName = lp.getName(nElements - 1); Path subFolder = lp.getName(nElements - 2); String newFnStr = fileName.toString().split("\\.")[0] + ".tar"; // Mirror folders in output dir. Path localOutFolder = outPath.resolve(subFolder); Path localOutPath = localOutFolder.resolve(newFnStr); // Create output subfolders. if (!Files.exists(localOutFolder) && !Files.isDirectory(localOutFolder)) { logger.info("Creating out file: {}", localOutFolder.toString()); try { Files.createDirectories(localOutFolder); } catch (IOException e) { throw new RuntimeException("Caught an IOException when creating output dir.", e); } } // Iterate over communications. Iterator<Communication> citer; try (OutputStream os = Files.newOutputStream(localOutPath); BufferedOutputStream bos = new BufferedOutputStream(os); Archiver archiver = new TarArchiver(bos);) { citer = new ConcreteGigawordDocumentFactory().iterator(lp); while (citer.hasNext()) { Communication c = citer.next(); String cId = c.getId(); // Document ID must be in the set. Remove. boolean wasInSet = ids.remove(cId); if (!wasInSet) { // Some IDs are duplicated in Gigaword. // See ERRATA. logger.debug( "ID: {} was parsed from path: {}, but was not in the experiment map. Attempting to remove dupe.", cId, pathStr); // Attempt to create a duplicate id (append .duplicate to the id). // Then, try to remove again. String newId = RepairDuplicateIDs.repairDuplicate(cId); boolean dupeRemoved = ids.remove(newId); // There are not nested duplicates, so this should never fire. if (!dupeRemoved) { logger.info("Failed to remove dupe."); return; } else // Modify the communication ID to the unique version. c.setId(newId); } archiver.addEntry(new ArchivableCommunication(c)); } logger.info("Finished path: {}", pathStr); } catch (ConcreteException ex) { logger.error("Caught ConcreteException during Concrete mapping.", ex); logger.error("Path: {}", pathStr); } catch (IOException e) { logger.error("Error archiving communications.", e); logger.error("Path: {}", localOutPath.toString()); } }); sw.stop(); logger.info("Finished."); Minutes m = new Duration(sw.getTime()).toStandardMinutes(); logger.info("Runtime: Approximately {} minutes.", m.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 {// w w w .j ava 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); } }
From source file:net.technicpack.launcher.ui.components.news.AuthorshipWidget.java
License:Open Source License
private String getDateText(Date date) { LocalDate posted = new LocalDate(date.getTime()); LocalDate now = new LocalDate(); Years yearsSince = Years.yearsBetween(posted, now); Months monthsSince = Months.monthsBetween(posted, now); Days daysSince = Days.daysBetween(posted, now); Hours hoursSince = Hours.hoursBetween(posted, now); Minutes minutesSince = Minutes.minutesBetween(posted, now); if (yearsSince.getYears() > 1) return resources.getString("time.years", Integer.toString(yearsSince.getYears())); else if (yearsSince.getYears() == 1) return resources.getString("time.year"); else if (monthsSince.getMonths() > 1) return resources.getString("time.months", Integer.toString(monthsSince.getMonths())); else if (monthsSince.getMonths() == 1) return resources.getString("time.month"); else if (daysSince.getDays() > 1) return resources.getString("time.days", Integer.toString(daysSince.getDays())); else if (daysSince.getDays() == 1) return resources.getString("time.day"); else if (hoursSince.getHours() > 1) return resources.getString("time.hours", Integer.toString(hoursSince.getHours())); else if (hoursSince.getHours() == 1) return resources.getString("time.hour"); else if (minutesSince.getMinutes() > 1) return resources.getString("time.minutes", Integer.toString(minutesSince.getMinutes())); else/*from w w w . j ava 2 s . c o m*/ return resources.getString("time.minute"); }
From source file:org.apache.beam.sdk.io.kinesis.SimplifiedKinesisClient.java
License:Apache License
GetMetricStatisticsRequest createMetricStatisticsRequest(String streamName, Instant countSince, Instant countTo, Minutes period) { return new GetMetricStatisticsRequest().withNamespace(KINESIS_NAMESPACE) .withMetricName(INCOMING_RECORDS_METRIC) .withPeriod(period.getMinutes() * PERIOD_GRANULARITY_IN_SECONDS).withStartTime(countSince.toDate()) .withEndTime(countTo.toDate()).withStatistics(Collections.singletonList(SUM_STATISTIC)) .withDimensions(Collections .singletonList(new Dimension().withName(STREAM_NAME_DIMENSION).withValue(streamName))); }
From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISOMinutesBetween.java
License:Apache License
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; }/* ww w . j ava 2 s. com*/ // Set the time to default or the output is in UTC DateTimeZone.setDefault(DateTimeZone.UTC); DateTime startDate = new DateTime(input.get(0).toString()); DateTime endDate = new DateTime(input.get(1).toString()); // Larger date first Minutes m = Minutes.minutesBetween(endDate, startDate); long minutes = m.getMinutes(); return minutes; }
From source file:org.encuestame.utils.DateUtil.java
License:Apache License
/** * Get Minutes Between Dates./*from w ww .j av a 2s . co m*/ * @param initDate * @return */ public static Integer getMinutesBetweenDates(final Date startDate) { final DateTime currentDate = new DateTime(); final DateTime storedDate = new DateTime(startDate); final Minutes minutesBetween = Minutes.minutesBetween(storedDate, currentDate); return minutesBetween.getMinutes(); }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.IntegerColumnMinutesMapper.java
License:Apache License
@Override public String toNonNullString(Minutes value) { return "" + value.getMinutes(); }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.IntegerColumnMinutesMapper.java
License:Apache License
@Override public Integer toNonNullValue(Minutes value) { return value.getMinutes(); }