Search in sources :

Example 91 with Interval

use of org.joda.time.Interval in project head by mifos.

the class DecliningBalanceWithInterestCalculatedDailyFormula method calculate.

@Override
public Money calculate(Money principalOutstanding, Double aprInterestRate, LocalDate interestPeriodStartDate, LocalDate interestPeriodEndDate) {
    Interval installmentPeriod = null;
    if (interestPeriodStartDate.isAfter(interestPeriodEndDate)) {
        installmentPeriod = new Interval(interestPeriodEndDate.toDateMidnight().toDateTime(), interestPeriodStartDate.toDateMidnight().toDateTime());
    } else {
        installmentPeriod = new Interval(interestPeriodStartDate.toDateMidnight().toDateTime(), interestPeriodEndDate.toDateMidnight().toDateTime());
    }
    Integer installmentPeriodDuration = Days.daysIn(installmentPeriod).getDays();
    BigDecimal periodicInterestRate = BigDecimal.valueOf(aprInterestRate / Double.valueOf("365.0"));
    BigDecimal interestDue = principalOutstanding.getAmount().divide(BigDecimal.valueOf(Long.valueOf("100"))).multiply(periodicInterestRate).multiply(BigDecimal.valueOf(installmentPeriodDuration.doubleValue()));
    return new Money(principalOutstanding.getCurrency(), interestDue);
}
Also used : Money(org.mifos.framework.util.helpers.Money) BigDecimal(java.math.BigDecimal) Interval(org.joda.time.Interval)

Example 92 with Interval

use of org.joda.time.Interval in project pinot by linkedin.

the class BackwardAnomalyFunctionUtils method splitSetsOfTimeSeries.

/**
   * Splits a MetricTimeSeries to current (observed) time series and baselines. The list of time
   * series is sorted by the start time of their interval in the reversed natural order. Therefore,
   * the current time series is located at the beginning of the returned list.
   *
   * @param metricTimeSeries the metric time series that contains current and baseline time series.
   * @param metricName the metric name to retrieve the value from the given metric time series.
   * @param timeSeriesIntervals the intervals of the split time series.
   * @return a list of time series, which are split from the metric time series.
   */
public static List<TimeSeries> splitSetsOfTimeSeries(MetricTimeSeries metricTimeSeries, String metricName, List<Interval> timeSeriesIntervals) {
    List<TimeSeries> timeSeriesList = new ArrayList<>(timeSeriesIntervals.size());
    for (Interval interval : timeSeriesIntervals) {
        TimeSeries timeSeries = new TimeSeries();
        timeSeries.setTimeSeriesInterval(interval);
        timeSeriesList.add(timeSeries);
    }
    // Sort time series by their start time in reversed natural order, i.e., the latest time series
    // is arranged in the front of the list
    Collections.sort(timeSeriesList, new TimeSeriesStartTimeComparator().reversed());
    // the timestamp and its value could be inserted to multiple time series.
    for (long timestamp : metricTimeSeries.getTimeWindowSet()) {
        for (TimeSeries timeSeries : timeSeriesList) {
            if (timeSeries.getTimeSeriesInterval().contains(timestamp)) {
                double value = metricTimeSeries.get(timestamp, metricName).doubleValue();
                timeSeries.set(timestamp, value);
            }
        }
    }
    return timeSeriesList;
}
Also used : TimeSeries(com.linkedin.thirdeye.anomalydetection.context.TimeSeries) MetricTimeSeries(com.linkedin.thirdeye.api.MetricTimeSeries) ArrayList(java.util.ArrayList) Interval(org.joda.time.Interval)

Example 93 with Interval

use of org.joda.time.Interval in project pinot by linkedin.

the class BackwardAnomalyFunctionUtils method buildAnomalyDetectionContext.

/**
   * Returns an anomaly detection context from the given information.
   *
   * @param anomalyFunction the anomaly function for anomaly detection.
   * @param timeSeries the given time series.
   * @param metric the metric name of the given time series.
   * @param exploredDimensions the dimension map of the given time series.
   * @param windowStart the start of the interval of the time series.
   * @param windowEnd the end of the interval of the time series.
   *
   * @return an anomaly detection context from the given information.
   */
public static AnomalyDetectionContext buildAnomalyDetectionContext(AnomalyDetectionFunction anomalyFunction, MetricTimeSeries timeSeries, String metric, DimensionMap exploredDimensions, int bucketSize, TimeUnit bucketUnit, DateTime windowStart, DateTime windowEnd) {
    // Create the anomaly detection context for the new modularized anomaly function
    AnomalyDetectionContext anomalyDetectionContext = new AnomalyDetectionContext();
    anomalyDetectionContext.setBucketSizeInMS(AnomalyDetectionUtils.getBucketInMillis(bucketSize, bucketUnit));
    anomalyDetectionContext.setAnomalyDetectionFunction(anomalyFunction);
    // Construct TimeSeriesKey
    TimeSeriesKey timeSeriesKey = new TimeSeriesKey();
    timeSeriesKey.setDimensionMap(exploredDimensions);
    timeSeriesKey.setMetricName(metric);
    anomalyDetectionContext.setTimeSeriesKey(timeSeriesKey);
    // Split time series to observed time series and baselines for each metric
    for (String metricName : anomalyFunction.getSpec().getMetrics()) {
        List<Interval> intervals = anomalyFunction.getTimeSeriesIntervals(windowStart.getMillis(), windowEnd.getMillis());
        List<TimeSeries> timeSeriesList = BackwardAnomalyFunctionUtils.splitSetsOfTimeSeries(timeSeries, metricName, intervals);
        anomalyDetectionContext.setCurrent(metricName, timeSeriesList.get(0));
        timeSeriesList.remove(0);
        anomalyDetectionContext.setBaselines(metricName, timeSeriesList);
    }
    return anomalyDetectionContext;
}
Also used : AnomalyDetectionContext(com.linkedin.thirdeye.anomalydetection.context.AnomalyDetectionContext) TimeSeries(com.linkedin.thirdeye.anomalydetection.context.TimeSeries) MetricTimeSeries(com.linkedin.thirdeye.api.MetricTimeSeries) TimeSeriesKey(com.linkedin.thirdeye.anomalydetection.context.TimeSeriesKey) Interval(org.joda.time.Interval)

Example 94 with Interval

use of org.joda.time.Interval in project pinot by linkedin.

the class NoopDataModel method getAllDataIntervals.

@Override
public List<Interval> getAllDataIntervals(long monitoringWindowStartTime, long monitoringWindowEndTime) {
    Interval interval = new Interval(monitoringWindowStartTime, monitoringWindowEndTime);
    List<Interval> ret = new ArrayList<>();
    ret.add(interval);
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Interval(org.joda.time.Interval)

Example 95 with Interval

use of org.joda.time.Interval in project pinot by linkedin.

the class SeasonalDataModel method getAllDataIntervals.

@Override
public List<Interval> getAllDataIntervals(long monitoringWindowStartTime, long monitoringWindowEndTime) {
    List<Interval> intervals = getTrainingDataIntervals(monitoringWindowStartTime, monitoringWindowEndTime);
    Interval currentInterval = new Interval(monitoringWindowStartTime, monitoringWindowEndTime);
    intervals.add(0, currentInterval);
    return intervals;
}
Also used : Interval(org.joda.time.Interval)

Aggregations

Interval (org.joda.time.Interval)1052 Test (org.junit.Test)604 DateTime (org.joda.time.DateTime)316 ArrayList (java.util.ArrayList)186 DataSegment (org.apache.druid.timeline.DataSegment)145 DataSegment (io.druid.timeline.DataSegment)138 List (java.util.List)134 Map (java.util.Map)131 HashMap (java.util.HashMap)106 File (java.io.File)91 IOException (java.io.IOException)75 ImmutableList (com.google.common.collect.ImmutableList)71 ImmutableMap (com.google.common.collect.ImmutableMap)56 Period (org.joda.time.Period)56 TreeMap (java.util.TreeMap)55 ISE (org.apache.druid.java.util.common.ISE)53 HashSet (java.util.HashSet)50 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)49 QueryRunner (io.druid.query.QueryRunner)47 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)45