Skip to content

Commit

Permalink
Merge pull request #1977 from deniszh/DZ-HW-fix
Browse files Browse the repository at this point in the history
Introducing bootstrapInterval for HoltWinters functions
  • Loading branch information
deniszh committed Jun 23, 2017
2 parents 7d5d1f6 + f31d195 commit 47f529c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions webapp/graphite/render/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2754,12 +2754,14 @@ def getLastDeviation(i):
}
return results

def holtWintersForecast(requestContext, seriesList):
def holtWintersForecast(requestContext, seriesList, bootstrapInterval='7d'):
"""
Performs a Holt-Winters forecast using the series as input data. Data from
one week previous to the series is used to bootstrap the initial forecast.
`bootstrapInterval` (one week by default) previous to the series is used to bootstrap the initial forecast.
"""
previewSeconds = 7 * 86400 # 7 days
bootstrap = parseTimeOffset(bootstrapInterval)
previewSeconds = bootstrap.seconds + (bootstrap.days * 86400)

# ignore original data and pull new, including our preview
newContext = requestContext.copy()
newContext['startTime'] = requestContext['startTime'] - timedelta(seconds=previewSeconds)
Expand All @@ -2774,12 +2776,14 @@ def holtWintersForecast(requestContext, seriesList):
results.append(result)
return results

def holtWintersConfidenceBands(requestContext, seriesList, delta=3):
def holtWintersConfidenceBands(requestContext, seriesList, delta=3, bootstrapInterval='7d'):
"""
Performs a Holt-Winters forecast using the series as input data and plots
upper and lower bands with the predicted forecast deviations.
"""
previewSeconds = 7 * 86400 # 7 days
bootstrap = parseTimeOffset(bootstrapInterval)
previewSeconds = bootstrap.seconds + (bootstrap.days * 86400)

# ignore original data and pull new, including our preview
newContext = requestContext.copy()
newContext['startTime'] = requestContext['startTime'] - timedelta(seconds=previewSeconds)
Expand Down Expand Up @@ -2826,14 +2830,14 @@ def holtWintersConfidenceBands(requestContext, seriesList, delta=3):
results.append(upperSeries)
return results

def holtWintersAberration(requestContext, seriesList, delta=3):
def holtWintersAberration(requestContext, seriesList, delta=3, bootstrapInterval='7d'):
"""
Performs a Holt-Winters forecast using the series as input data and plots the
positive or negative deviation of the series data from the forecast.
"""
results = []
for series in seriesList:
confidenceBands = holtWintersConfidenceBands(requestContext, [series], delta)
confidenceBands = holtWintersConfidenceBands(requestContext, [series], delta, bootstrapInterval)
lowerBand = confidenceBands[0]
upperBand = confidenceBands[1]
aberration = list()
Expand All @@ -2852,12 +2856,12 @@ def holtWintersAberration(requestContext, seriesList, delta=3):
, series.step, aberration))
return results

def holtWintersConfidenceArea(requestContext, seriesList, delta=3):
def holtWintersConfidenceArea(requestContext, seriesList, delta=3, bootstrapInterval='7d'):
"""
Performs a Holt-Winters forecast using the series as input data and plots the
area between the upper and lower bands of the predicted forecast deviations.
"""
bands = holtWintersConfidenceBands(requestContext, seriesList, delta)
bands = holtWintersConfidenceBands(requestContext, seriesList, delta, bootstrapInterval)
results = areaBetween(requestContext, bands)
for series in results:
series.name = series.name.replace('areaBetween', 'holtWintersConfidenceArea')
Expand Down

0 comments on commit 47f529c

Please sign in to comment.