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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations