Java Code Examples for org.joda.time.DateTime#minus()

The following examples show how to use org.joda.time.DateTime#minus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignatureVerificationResult.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public DateTime getVerifiedSigningTime(int amount, TimeUnit unit) {
   Iterator i$ = this.timestampGenTime.iterator();

   DateTime start;
   DateTime end;
   do {
      if (!i$.hasNext()) {
         return new DateTime();
      }

      DateTime genTime = (DateTime)i$.next();
      start = genTime.minus(unit.toMillis((long)amount));
      end = genTime.plus(unit.toMillis((long)amount));
   } while(this.signingTime.isBefore(start) || this.signingTime.isAfter(end));

   return this.signingTime;
}
 
Example 2
Source File: HierarchicalAnomaliesContent.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the average wow baseline values
 * @param anomaly an instance of MergedAnomalyResultDTO
 * @param compareMode the way to compare, WoW, Wo2W, Wo3W, and Wo4W
 * @param start the start time of the monitoring window in millis
 * @param end the end time of the monitoring window in millis
 * @return baseline values based on compareMode
 * @throws Exception
 */
private Double getAvgComparisonBaseline(MergedAnomalyResultDTO anomaly, COMPARE_MODE compareMode,
    long start, long end) throws Exception{
  AnomalyFunctionFactory anomalyFunctionFactory = new AnomalyFunctionFactory(thirdEyeAnomalyConfig.getFunctionConfigPath());
  AnomalyFunctionDTO anomalyFunction = anomaly.getFunction();
  DatasetConfigDTO datasetConfigDTO = DAORegistry.getInstance().getDatasetConfigDAO()
      .findByDataset(anomalyFunction.getCollection());
  AnomalyDetectionInputContextBuilder contextBuilder = new AnomalyDetectionInputContextBuilder(anomalyFunctionFactory);
  contextBuilder.setFunction(anomalyFunction);

  DateTimeZone timeZone = DateTimeZone.forID(datasetConfigDTO.getTimezone());
  DateTime startTime = new DateTime(start, timeZone);
  DateTime endTime = new DateTime(end, timeZone);

  Period baselinePeriod = getBaselinePeriod(compareMode);
  DateTime baselineStartTime = startTime.minus(baselinePeriod);
  DateTime baselineEndTime = endTime.minus(baselinePeriod);

  Pair<Long, Long> timeRange = new Pair<>(baselineStartTime.getMillis(), baselineEndTime.getMillis());
  MetricTimeSeries
      baselineTimeSeries = contextBuilder.fetchTimeSeriesDataByDimension(Arrays.asList(timeRange), anomaly.getDimensions(), false)
      .build().getDimensionMapMetricTimeSeriesMap().get(anomaly.getDimensions());

  return baselineTimeSeries.getMetricAvgs(0d)[0];
}
 
Example 3
Source File: SignatureVerificationResult.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public DateTime getVerifiedSigningTime(int amount, TimeUnit unit) {
   Iterator i$ = this.timestampGenTime.iterator();

   DateTime start;
   DateTime end;
   do {
      if (!i$.hasNext()) {
         return new DateTime();
      }

      DateTime genTime = (DateTime)i$.next();
      start = genTime.minus(unit.toMillis((long)amount));
      end = genTime.plus(unit.toMillis((long)amount));
   } while(this.signingTime.isBefore(start) || this.signingTime.isAfter(end));

   return this.signingTime;
}
 
Example 4
Source File: Retention.java    From btrbck with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculate the instants a snapshot should be retained for, given the
 * current time.
 */
public Set<DateTime> retentionTimes(DateTime now) {
    HashSet<DateTime> result = new HashSet<>();
    Interval interval = new Interval(now.minus(period), now);
    DateTime current = timeUnit.truncate(interval.getStart());
    while (current.isBefore(now)) {
        DateTime endOfUnit = current.plus(timeUnit.getPeriod());
        long step = new Interval(current, endOfUnit).toDurationMillis()
                / snapshotsPerTimeUnit;
        for (int i = 0; i < snapshotsPerTimeUnit; i++) {
            DateTime retentionTime = current.plus(i * step);
            if (interval.contains(retentionTime)) {
                result.add(retentionTime);
            }
        }
        current = endOfUnit;
    }
    return result;
}
 
Example 5
Source File: AnomaliesResource.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private TimeRange getTimeRangeWithOffsets(AnomalyOffset offset, DateTime windowStart, DateTime windowEnd,
    DatasetConfigDTO datasetConfig) {
  Period preOffsetPeriod = offset.getPreOffsetPeriod();
  Period postOffsetPeriod = offset.getPostOffsetPeriod();

  DateTimeZone dateTimeZone = DateTimeZone.forID(datasetConfig.getTimezone());
  DateTime windowStartDateTime = new DateTime(windowStart, dateTimeZone);
  DateTime windowEndDateTime = new DateTime(windowEnd, dateTimeZone);
  windowStartDateTime = windowStartDateTime.minus(preOffsetPeriod);
  windowEndDateTime = windowEndDateTime.plus(postOffsetPeriod);
  long windowStartTime = windowStartDateTime.getMillis();
  long windowEndTime = windowEndDateTime.getMillis();
  try {
    Long maxDataTime = CACHE_REGISTRY.getDatasetMaxDataTimeCache().get(datasetConfig.getDataset());
    if (windowEndTime > maxDataTime) {
      windowEndTime = maxDataTime;
    }
  } catch (ExecutionException e) {
    LOG.error("Exception when reading max time for {}", datasetConfig.getDataset(), e);
  }
  TimeRange range = new TimeRange(windowStartTime, windowEndTime);
  return range;

}
 
Example 6
Source File: AggregatesAlertCondition.java    From graylog-plugin-aggregates with GNU General Public License v3.0 6 votes vote down vote up
protected org.graylog2.plugin.indexer.searches.timeranges.TimeRange restrictTimeRange(
        final org.graylog2.plugin.indexer.searches.timeranges.TimeRange timeRange) {
    final DateTime originalFrom = timeRange.getFrom();
    final DateTime to = timeRange.getTo();
    final DateTime from;

    final SearchesClusterConfig config = clusterConfigService.get(SearchesClusterConfig.class);

    if (config == null || Period.ZERO.equals(config.queryTimeRangeLimit())) {
        from = originalFrom;
    } else {
        final DateTime limitedFrom = to.minus(config.queryTimeRangeLimit());
        from = limitedFrom.isAfter(originalFrom) ? limitedFrom : originalFrom;
    }

    return AbsoluteRange.create(from, to);
}
 
Example 7
Source File: YoutubeProviderTest.java    From streams with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserInfoWithDefaultDates() {
  YoutubeConfiguration config = new YoutubeConfiguration();
  config.setApiKey("API_KEY");
  YoutubeProvider provider = buildProvider(config);

  DateTime afterDate = new DateTime(System.currentTimeMillis());
  DateTime beforeDate = afterDate.minus(10000);

  provider.setDefaultAfterDate(afterDate);
  provider.setDefaultBeforeDate(beforeDate);

  Set<String> users = new HashSet<>();
  users.add("test_user_1");
  users.add("test_user_2");
  users.add("test_user_3");

  provider.setUserInfoWithDefaultDates(users);

  List<UserInfo> youtubeUsers = provider.getConfig().getYoutubeUsers();

  for (UserInfo user : youtubeUsers) {
    assert (user.getAfterDate().equals(afterDate));
    assert (user.getBeforeDate().equals(beforeDate));
  }
}
 
Example 8
Source File: RecompactionConditionTest.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@Test
public void testRecompactionConditionBasedOnDuration() {
  RecompactionConditionFactory factory = new RecompactionConditionBasedOnDuration.Factory();
  RecompactionCondition conditionBasedOnDuration = factory.createRecompactionCondition(dataset);
  DatasetHelper helper = mock (DatasetHelper.class);
  when(helper.getDataset()).thenReturn(dataset);
  PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("m").appendDays().appendSuffix("d").appendHours()
      .appendSuffix("h").appendMinutes().appendSuffix("min").toFormatter();
  DateTime currentTime = getCurrentTime();

  Period period_A = periodFormatter.parsePeriod("11h59min");
  DateTime earliest_A = currentTime.minus(period_A);
  when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_A));
  when(helper.getCurrentTime()).thenReturn(currentTime);
  Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), false);

  Period period_B = periodFormatter.parsePeriod("12h01min");
  DateTime earliest_B = currentTime.minus(period_B);
  when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_B));
  when(helper.getCurrentTime()).thenReturn(currentTime);
  Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), true);
}
 
Example 9
Source File: IndexMetadata.java    From Raigad with Apache License 2.0 5 votes vote down vote up
public DateTime getPastRetentionCutoffDate(DateTime currentDateTime) {
    // After computing the cutoff we print then reparse the cutoff time to round to
    // the significant aspects of the time based on the formatter. For example:
    //
    // currentDateTime = 2018-02-03T23:47
    // retentionPeriod = P2Y
    // cutoff = 2016-02-03T23:47
    //
    // If the index pattern is yyyy, then a 2016 index would be before the cutoff so it
    // would get dropped. We want to floor the cutoff time to only the significant aspects
    // which for this example would be the year.
    DateTime cutoff = currentDateTime.minus(retentionPeriod);
    return formatter.parseDateTime(formatter.print(cutoff));
}
 
Example 10
Source File: ChainingTSCPair.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ChainingTSCPair(@NonNull CollectHistory history, @NonNull ExpressionLookBack lookback) {
    this.history = history;

    Stream<TimeSeriesCollection> filtered;
    try {
        filtered = lookback.filter(new ForwardIterator<>(history.streamReversed().iterator()));
    } catch (UnsupportedOperationException ex) {
        LOG.log(Level.WARNING, "history reverse streaming not supported, fallback to duration hint");
        final DateTime end = history.getEnd();
        final DateTime begin = end.minus(lookback.hintDuration());
        filtered = history.stream(begin, end);
    }

    final TscStreamReductor reduction = filtered
            .collect(TscStreamReductor::new, TscStreamReductor::add, TscStreamReductor::addAll);
    this.timestamps = new TimestampChain(reduction.timestamps);
    this.activeGroups = reduction.groups;
    LOG.log(Level.INFO, "recovered {0} scrapes from history", timestamps.size());

    // Fill data with empty, faultable group data.
    activeGroups.forEachKey(group -> {
        data.put(group, new TsvChain());
        return true;
    });

    validatePrevious();  // Should never trigger.
}
 
Example 11
Source File: EmailHelper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static ContributorViewResponse getContributorDataForDataReport(String collection, String metric,
    List<String> dimensions, Multimap<String, String> filters, AlertConfigBean.COMPARE_MODE compareMode, MetricAggFunction metricAggFunction,
    long startInMillis, long endInMillis) throws Exception {
  DatasetConfigDTO datasetConfigDTO = datasetConfigManager.findByDataset(collection);
  DateTimeZone timeZone = DateTimeZone.forID(datasetConfigDTO.getTimezone());

  Period baselinePeriod = getBaselinePeriod(compareMode);
  ContributorViewRequest request = new ContributorViewRequest();
  request.setCollection(collection);

  List<MetricExpression> metricExpressions =
      Utils.convertToMetricExpressions(metric, metricAggFunction, collection);
  request.setMetricExpressions(metricExpressions);

  long currentEndInMills = endInMillis;
  long maxDataTime = collectionMaxDataTimeCache.get(collection);
  currentEndInMills = Math.min(currentEndInMills, maxDataTime);

  DateTime currentStart = new DateTime(startInMillis, timeZone);
  DateTime currentEnd = new DateTime(currentEndInMills, timeZone);

  String aggTimeGranularity = "HOURS";
  if (datasetConfigDTO != null && TimeUnit.DAYS.equals(datasetConfigDTO.bucketTimeGranularity().getUnit())) {
    aggTimeGranularity = datasetConfigDTO.bucketTimeGranularity().getUnit().name();
  }

  DateTime baselineStart = currentStart.minus(baselinePeriod);
  DateTime baselineEnd = currentEnd.minus(baselinePeriod);

  request.setBaselineStart(baselineStart);
  request.setBaselineEnd(baselineEnd);
  request.setCurrentStart(currentStart);
  request.setCurrentEnd(currentEnd);
  request.setTimeGranularity(Utils.getAggregationTimeGranularity(aggTimeGranularity, collection));
  request.setGroupByDimensions(dimensions);
  request.setFilters(filters);
  ContributorViewHandler handler = new ContributorViewHandler(queryCache);
  return handler.process(request);
}
 
Example 12
Source File: AdministrativeOfficeFeePR.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public AdministrativeOfficeFeePR edit(DateTime startDate, Money fixedAmount, Money penaltyAmount,
        YearMonthDay whenToApplyFixedAmountPenalty) {

    if (!startDate.isAfter(getStartDate())) {
        throw new DomainException(
                "error.AdministrativeOfficeFeePR.startDate.is.before.then.start.date.of.previous.posting.rule");
    }

    deactivate(startDate);

    return new AdministrativeOfficeFeePR(startDate.minus(1000), null, getServiceAgreementTemplate(), fixedAmount,
            penaltyAmount, whenToApplyFixedAmountPenalty);
}
 
Example 13
Source File: CompactionTimeRangeVerifier.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
public Result verify (FileSystemDataset dataset) {
  final DateTime earliest;
  final DateTime latest;
  try {
    CompactionPathParser.CompactionParserResult result = new CompactionPathParser(state).parse(dataset);
    DateTime folderTime = result.getTime();
    DateTimeZone timeZone = DateTimeZone.forID(this.state.getProp(MRCompactor.COMPACTION_TIMEZONE, MRCompactor.DEFAULT_COMPACTION_TIMEZONE));
    DateTime compactionStartTime = new DateTime(this.state.getPropAsLong(CompactionSource.COMPACTION_INIT_TIME), timeZone);
    PeriodFormatter formatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("m").appendDays().appendSuffix("d").appendHours()
            .appendSuffix("h").toFormatter();

    // Dataset name is like 'Identity/MemberAccount' or 'PageViewEvent'
    String datasetName = result.getDatasetName();

    // get earliest time
    String maxTimeAgoStrList = this.state.getProp(TimeBasedSubDirDatasetsFinder.COMPACTION_TIMEBASED_MAX_TIME_AGO, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO);
    String maxTimeAgoStr = getMachedLookbackTime(datasetName, maxTimeAgoStrList, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO);
    Period maxTimeAgo = formatter.parsePeriod(maxTimeAgoStr);
    earliest = compactionStartTime.minus(maxTimeAgo);

    // get latest time
    String minTimeAgoStrList = this.state.getProp(TimeBasedSubDirDatasetsFinder.COMPACTION_TIMEBASED_MIN_TIME_AGO, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO);
    String minTimeAgoStr = getMachedLookbackTime(datasetName, minTimeAgoStrList, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO);
    Period minTimeAgo = formatter.parsePeriod(minTimeAgoStr);
    latest = compactionStartTime.minus(minTimeAgo);

    if (earliest.isBefore(folderTime) && latest.isAfter(folderTime)) {
      log.debug("{} falls in the user defined time range", dataset.datasetRoot());
      return new Result(true, "");
    }
  } catch (Exception e) {
    log.error("{} cannot be verified because of {}", dataset.datasetRoot(), ExceptionUtils.getFullStackTrace(e));
    return new Result(false, e.toString());
  }
  return new Result(false, dataset.datasetRoot() + " is not in between " + earliest + " and " + latest);
}
 
Example 14
Source File: ClientServerTest.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void streamFromTo() {
    final DateTime end = new DateTime(DateTimeZone.UTC);
    final DateTime begin = end.minus(Duration.standardDays(1));
    final List<TimeSeriesCollection> expected = generateCollection().collect(Collectors.toList());
    when(history.stream(Mockito.isA(DateTime.class), Mockito.isA(DateTime.class)))
            .thenAnswer((invocation) -> generateCollection());

    final List<TimeSeriesCollection> result = client.stream(begin, end).collect(Collectors.toList());

    assertEquals(expected, result);

    verify(history, times(1)).stream(Mockito.eq(begin), Mockito.eq(end));
    verifyNoMoreInteractions(history);
}
 
Example 15
Source File: MovingWindowAlgorithm.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public MovingWindowAlgorithm(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);

  Preconditions.checkArgument(config.getProperties().containsKey(PROP_METRIC_URN));

  String metricUrn = MapUtils.getString(config.getProperties(), PROP_METRIC_URN);
  MetricEntity me = MetricEntity.fromURN(metricUrn);

  this.quantileMin = MapUtils.getDoubleValue(config.getProperties(), "quantileMin", Double.NaN);
  this.quantileMax = MapUtils.getDoubleValue(config.getProperties(), "quantileMax", Double.NaN);
  this.zscoreMin = MapUtils.getDoubleValue(config.getProperties(), "zscoreMin", Double.NaN);
  this.zscoreMax = MapUtils.getDoubleValue(config.getProperties(), "zscoreMax", Double.NaN);
  this.zscoreOutlier = MapUtils.getDoubleValue(config.getProperties(), "zscoreOutlier", Double.NaN);
  this.kernelSize = MapUtils.getIntValue(config.getProperties(), "kernelSize", 1);
  this.timezone = DateTimeZone.forID(MapUtils.getString(config.getProperties(), "timezone", "UTC"));
  this.windowSize = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "windowSize", "1week"));
  this.lookbackPeriod = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "lookbackPeriod", "1week"));
  this.reworkPeriod = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "reworkPeriod", "1day"));
  this.changeDuration = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "changeDuration", "5days"));
  this.changeFraction = MapUtils.getDoubleValue(config.getProperties(), "changeFraction", 0.666);
  this.baselineWeeks = MapUtils.getIntValue(config.getProperties(), "baselineWeeks", 0);
  this.applyLog = MapUtils.getBooleanValue(config.getProperties(), "applyLog", true);
  this.learningRate = MapUtils.getDoubleValue(config.getProperties(), "learningRate", 0.666);

  Preconditions.checkArgument(Double.isNaN(this.quantileMin) || (this.quantileMin >= 0 && this.quantileMin <= 1.0), "quantileMin must be between 0.0 and 1.0");
  Preconditions.checkArgument(Double.isNaN(this.quantileMax) || (this.quantileMax >= 0 && this.quantileMax <= 1.0), "quantileMax must be between 0.0 and 1.0");

  this.effectiveStartTime = new DateTime(startTime, this.timezone).minus(this.lookbackPeriod).getMillis();

  DateTime trainStart = new DateTime(this.effectiveStartTime, this.timezone).minus(this.windowSize);
  DateTime dataStart = trainStart.minus(new Period().withField(DurationFieldType.weeks(), baselineWeeks));
  DateTime detectionStart = new DateTime(startTime, this.timezone).minus(this.reworkPeriod);

  this.sliceData = MetricSlice.from(me.getId(), dataStart.getMillis(), endTime, me.getFilters());
  this.sliceDetection = MetricSlice.from(me.getId(), detectionStart.getMillis(), endTime, me.getFilters());

  AnomalySlice slice = new AnomalySlice().withStart(this.sliceData.getStart()).withEnd(this.sliceData.getEnd());
  if (this.config.getId() != null) {
    this.anomalySlice = slice.withDetectionId(this.config.getId());
  } else {
    this.anomalySlice = slice;
  }
}
 
Example 16
Source File: MaintenanceTask.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void executeTask() {
	if (!HousingConfig.ENABLE_HOUSE_PAY) {
		return;
	}

	// Get times based on configuration values
	DateTime now = new DateTime();
	DateTime previousRun = now.minus(getPeriod()); // usually week ago
	DateTime beforePreviousRun = previousRun.minus(getPeriod()); // usually two weeks ago

	for (House house : maintainedHouses) {
		if (house.isFeePaid()) {
			continue; // player already paid, don't check
		}
		long payTime = house.getNextPay().getTime();
		long impoundTime = 0;
		int warnCount = 0;

		PlayerCommonData pcd = null;
		Player player = World.getInstance().findPlayer(house.getOwnerId());
		if (player == null) {
			pcd = DAOManager.getDAO(PlayerDAO.class).loadPlayerCommonData(house.getOwnerId());
		}
		else {
			pcd = player.getCommonData();
		}

		if (pcd == null) {
			// player doesn't exist already for some reasons
			log.warn("[HouseService] House " + house.getAddress().getId() + " had player assigned but no player exists. Auctioned.");
			putHouseToAuction(house, null);
			continue;
		}

		if (payTime <= beforePreviousRun.getMillis()) {
			DateTime plusDay = beforePreviousRun.minusDays(1);
			if (payTime <= plusDay.getMillis()) {
				// player didn't pay after the second warning and one day passed
				impoundTime = now.getMillis();
				warnCount = 3;
				putHouseToAuction(house, pcd);
			}
			else {
				impoundTime = now.plusDays(1).getMillis();
				warnCount = 2;
			}
		}
		else if (payTime <= previousRun.getMillis()) {
			// player did't pay 1 period
			impoundTime = now.plus(getPeriod()).plusDays(1).getMillis();
			warnCount = 1;
		}
		else {
			continue; // should not happen
		}

		if (pcd.isOnline()) {
			if (warnCount == 3) {
				PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_HOUSING_SEQUESTRATE);
			}
			else {
				PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_HOUSING_OVERDUE);
			}
		}
		MailFormatter.sendHouseMaintenanceMail(house, warnCount, impoundTime);
	}
}
 
Example 17
Source File: FetchAnomaliesInRangeAndOutputCSV.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
/**
 * Ouput merged anomaly results for given metric and time range
 * @param args List of arguments
 *             0: path to persistence file
 *             1: collection name
 *             2: metric name
 *             3: monitoring start time in ISO format
 *             4: timezone code
 *             5: monitoring length in days
 *             6: Output path
 */
public static void main(String args[]){
  if(args.length < 7){
    LOG.error("Insufficient number of arguments");
    return;
  }

  String persistencePath = args[0];
  String collection = args[1];
  String metric = args[2];
  String monitoringDateTime = args[3];
  DateTimeZone dateTimeZone = DateTimeZone.forID(args[4]);
  int monitoringLength = Integer.valueOf(args[5]);
  File output_folder = new File(args[6]);

  FetchMetricDataAndExistingAnomaliesTool thirdEyeDAO = null;
  try {
    thirdEyeDAO = new FetchMetricDataAndExistingAnomaliesTool(new File(persistencePath));
  }
  catch (Exception e){
    LOG.error("Error in loading the persistence file: {}", e);
    return;
  }

  DateTime monitoringWindowStartTime = ISODateTimeFormat.dateTimeParser().parseDateTime(monitoringDateTime).withZone(dateTimeZone);
  Period period = new Period(0, 0, 0, monitoringLength, 0, 0, 0, 0);
  dataRangeStart = monitoringWindowStartTime.minus(period); // inclusive start
  dataRangeEnd = monitoringWindowStartTime; // exclusive end

  if(!output_folder.exists() || !output_folder.canWrite()){
    LOG.error("{} is not accessible", output_folder.getAbsoluteFile());
    return;
  }


  // Print Merged Results
  List<FetchMetricDataAndExistingAnomaliesTool.ResultNode> resultNodes = thirdEyeDAO.fetchMergedAnomaliesInRange(
      collection, metric, dataRangeStart, dataRangeEnd);

  LOG.info("Printing merged anomaly results from db...");
  String outputname = output_folder.getAbsolutePath() + "/" +
      "merged_" + metric + "_" + dateTimeFormatter.print(dataRangeStart) +
      "_" + dateTimeFormatter.print(dataRangeEnd) + ".csv";
  outputResultNodesToFile(new File(outputname), resultNodes);
  LOG.info("Finish job and print merged anomaly results from db in {}...", outputname);
}
 
Example 18
Source File: TimeBasedSubDirDatasetsFinder.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 19
Source File: TimeBasedSubDirDatasetsFinder.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 20
Source File: CommitLogRevisionsTranslatorFactory.java    From nomulus with Apache License 2.0 3 votes vote down vote up
/**
 * 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.
 *
 * @see google.registry.config.RegistryConfig#getCommitLogDatastoreRetention()
 */
@Override
ImmutableSortedMap<DateTime, Key<CommitLogManifest>> transformBeforeSave(
    ImmutableSortedMap<DateTime, Key<CommitLogManifest>> revisions) {
  DateTime now = tm().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();
}