public static TimeSeries createMovingAverage(TimeSeries source, string name, int periodCount, int skip) { if (source == null) { string str = "Null source."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else if (periodCount < 1) { string str = "periodCount must be greater than or equal to 1."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else { TimeSeries timeSeries = new TimeSeries((IComparable) name); if (source.getItemCount() > 0) { long num1 = source.getDataItem(0).getPeriod().getSerialIndex() + (long) skip; int index1 = source.getItemCount() - 1; while (index1 >= 0) { RegularTimePeriod period1 = source.getDataItem(index1).getPeriod(); if (period1.getSerialIndex() >= num1) { int num2 = 0; double num3 = 0.0; long num4 = period1.getSerialIndex() - (long) periodCount; int num5 = 0; for (int index2 = 0; num5 < periodCount && index2 == 0; ++num5) { if (index1 - num5 >= 0) { TimeSeriesDataItem dataItem = source.getDataItem(index1 - num5); RegularTimePeriod period2 = dataItem.getPeriod(); Number number = dataItem.getValue(); if (period2.getSerialIndex() > num4) { if (number != null) { num3 += number.doubleValue(); ++num2; } } else index2 = 1; } } if (num2 > 0) timeSeries.add(period1, num3 / (double) num2); else timeSeries.add(period1, (Number) null); } index1 += -1; } } return timeSeries; } }
public static TimeSeries createPointMovingAverage(TimeSeries source, string name, int pointCount) { if (source == null) { string str = "Null 'source'."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else if (pointCount < 2) { string str = "periodCount must be greater than or equal to 2."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else { TimeSeries timeSeries = new TimeSeries((IComparable) name); double num = 0.0; for (int index = 0; index < source.getItemCount(); ++index) { TimeSeriesDataItem dataItem1 = source.getDataItem(index); RegularTimePeriod period = dataItem1.getPeriod(); num += dataItem1.getValue().doubleValue(); if (index > pointCount - 1) { TimeSeriesDataItem dataItem2 = source.getDataItem(index - pointCount); num -= dataItem2.getValue().doubleValue(); timeSeries.add(period, num / (double) pointCount); } else if (index == pointCount - 1) timeSeries.add(period, num / (double) pointCount); } return timeSeries; } }