List of usage examples for org.joda.time DateTime minus
public DateTime minus(ReadablePeriod period)
From source file:fi.hsl.parkandride.core.domain.prediction.RelativizedAverageOfPreviousWeeksPredictor.java
License:EUPL
private Double getUtilizationMultiplier(DateTime now, UtilizationHistory inMemoryHistory) { final List<Utilization> recentUtilizations = inMemoryHistory.getRange(now.minus(LOOKBACK_MINUTES), now); Double recentUtilizationArea = Math.max(1, calculateAreaAverageByDataPoints(recentUtilizations)); Double referenceUtilizationAreaAverage = Math.max(1, LOOKBACK_PERIODS.stream().map(offset -> now.minus(offset)) .map(referenceTime -> inMemoryHistory.getRange(referenceTime.minus(LOOKBACK_MINUTES), referenceTime)) .filter(utilizationList -> !utilizationList.isEmpty()) .mapToDouble(utilizationList -> calculateAreaAverageByDataPoints(utilizationList)).average() .orElseGet(() -> recentUtilizationArea)); return Math.max(1, recentUtilizationArea / referenceUtilizationAreaAverage); }
From source file:fi.hsl.parkandride.dev.DevController.java
License:EUPL
@RequestMapping(method = PUT, value = DEV_PREDICTION_HISTORY) @TransactionalRead // each call to predictionService.updatePredictionsHistoryForFacility creates a separate write transaction to avoid too long transactions public ResponseEntity<Void> generatePredictionHistory(@NotNull @PathVariable(FACILITY_ID) Long facilityId) { facilityRepository.getFacility(facilityId); // ensure facility exists final UtilizationSearch utilizationSearch = new UtilizationSearch(); utilizationSearch.start = DateTime.now().minusWeeks(5); utilizationSearch.end = DateTime.now(); utilizationSearch.facilityIds = Collections.singleton(facilityId); final List<Utilization> utilizations = Lists .newArrayList(utilizationRepository.findUtilizations(utilizationSearch)); DateTime lastTimestamp = utilizations.stream().map(u -> u.timestamp).max(DateTime::compareTo) .orElse(utilizationSearch.end); StreamSupport//from w w w . j av a 2s.co m .stream(spliteratorUnknownSize(new DateTimeIterator(utilizationSearch.start.plusWeeks(4), lastTimestamp.minus(PredictionRepository.PREDICTION_RESOLUTION), // avoid collision with scheduled predictions PredictionRepository.PREDICTION_RESOLUTION), Spliterator.ORDERED), false) .map(endTime -> utilizations.stream().filter(utilization -> utilization.timestamp.isBefore(endTime)) .collect(toList())) .forEach(utilizationList -> predictionService.updatePredictionsHistoryForFacility(utilizationList)); return new ResponseEntity<>(CREATED); }
From source file:fr.mby.saml2.sp.opensaml.core.OpenSaml20IdpConnector.java
License:Apache License
/** * Build the NotBefore time considering the time validity window parameter. * //from w w w . j a v a2s.c om * @param issueInstant * the request issue instant * @return the NotBefore time */ protected DateTime buildNotBeforeTime(final DateTime issueInstant) { return issueInstant.minus(this.idpConfig.getTimeValidityWindow()); }
From source file:gobblin.compaction.conditions.RecompactionConditionBasedOnDuration.java
License:Apache License
public boolean isRecompactionNeeded(DatasetHelper datasetHelper) { Optional<DateTime> earliestFileModificationTime = datasetHelper.getEarliestLateFileModificationTime(); DateTime currentTime = datasetHelper.getCurrentTime(); if (earliestFileModificationTime.isPresent()) { DateTime checkpoint = currentTime.minus(duration); logger.info("Current time is " + currentTime + " checkpoint is " + checkpoint); logger.info("Earliest late file has timestamp " + earliestFileModificationTime.get() + " inside " + datasetHelper.getDataset().outputLatePath()); if (earliestFileModificationTime.get().isBefore(checkpoint)) { return true; }/*ww w . ja v a2 s .c o m*/ } return false; }
From source file:gobblin.compaction.dataset.TimeBasedSubDirDatasetsFinder.java
License:Apache License
private DateTime getEarliestAllowedFolderTime(DateTime currentTime, PeriodFormatter periodFormatter) { String maxTimeAgoStr = this.state.getProp(COMPACTION_TIMEBASED_MAX_TIME_AGO, DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO); Period maxTimeAgo = periodFormatter.parsePeriod(maxTimeAgoStr); return currentTime.minus(maxTimeAgo); }
From source file:gobblin.compaction.dataset.TimeBasedSubDirDatasetsFinder.java
License:Apache License
private DateTime getLatestAllowedFolderTime(DateTime currentTime, PeriodFormatter periodFormatter) { String minTimeAgoStr = this.state.getProp(COMPACTION_TIMEBASED_MIN_TIME_AGO, DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO); Period minTimeAgo = periodFormatter.parsePeriod(minTimeAgoStr); return currentTime.minus(minTimeAgo); }
From source file:gobblin.compaction.mapreduce.MRCompactorTimeBasedJobPropCreator.java
License:Open Source License
private DateTime getEarliestAllowedFolderTime(DateTime currentTime, PeriodFormatter periodFormatter) { String maxTimeAgoStr = this.state.getProp(ConfigurationKeys.COMPACTION_TIMEBASED_MAX_TIME_AGO, ConfigurationKeys.DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO); Period maxTimeAgo = periodFormatter.parsePeriod(maxTimeAgoStr); return currentTime.minus(maxTimeAgo); }
From source file:gobblin.compaction.mapreduce.MRCompactorTimeBasedJobPropCreator.java
License:Open Source License
private DateTime getLatestAllowedFolderTime(DateTime currentTime, PeriodFormatter periodFormatter) { String minTimeAgoStr = this.state.getProp(ConfigurationKeys.COMPACTION_TIMEBASED_MIN_TIME_AGO, ConfigurationKeys.DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO); Period minTimeAgo = periodFormatter.parsePeriod(minTimeAgoStr); return currentTime.minus(minTimeAgo); }
From source file:gobblin.policies.time.RecordTimestampLowerBoundPolicy.java
License:Apache License
private Optional<Long> getEarliestAllowedTimestamp() { if (!this.state.contains(RECORD_MAX_ALLOWED_TIME_AGO)) { return Optional.<Long>absent(); }/* www.ja va2 s.c om*/ DateTime currentTime = new DateTime(this.timeZone); String maxTimeAgoStr = this.state.getProp(RECORD_MAX_ALLOWED_TIME_AGO); Period maxTimeAgo = PERIOD_FORMATTER.parsePeriod(maxTimeAgoStr); return Optional.of(currentTime.minus(maxTimeAgo).getMillis()); }
From source file:google.registry.model.translators.CommitLogRevisionsTranslatorFactory.java
License:Open Source License
/** * Add a reference to the current commit log to the resource's revisions map. * * <p>This method also prunes the revisions map. It guarantees to keep enough data so that floor * will work going back N days. It does this by making sure one entry exists before that duration, * and pruning everything after it. The size of the map is guaranteed to never exceed N+2. * * <p>We store a maximum of one entry per day. It will be the last transaction that happened on * that day./*w w w . j a v a2 s . c o m*/ * * @see google.registry.config.RegistryConfig#getCommitLogDatastoreRetention() */ @Override ImmutableSortedMap<DateTime, Key<CommitLogManifest>> transformBeforeSave( ImmutableSortedMap<DateTime, Key<CommitLogManifest>> revisions) { DateTime now = ofy().getTransactionTime(); DateTime threshold = now.minus(getCommitLogDatastoreRetention()); DateTime preThresholdTime = firstNonNull(revisions.floorKey(threshold), START_OF_TIME); return new ImmutableSortedMap.Builder<DateTime, Key<CommitLogManifest>>(Ordering.natural()) .putAll(revisions.subMap(preThresholdTime, true, now.withTimeAtStartOfDay(), false)) .put(now, ofy().getCommitLogManifestKey()).build(); }