Skip to content

Commit

Permalink
Merge pull request #2226 from iksaif/pr-holt
Browse files Browse the repository at this point in the history
functions: fix holtWinterAberration with multiple targets
  • Loading branch information
iksaif committed Feb 9, 2018
2 parents ba4b77d + 3d12bf7 commit 10cf578
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions webapp/graphite/render/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3607,7 +3607,6 @@ def holtWintersConfidenceBands(requestContext, seriesList, delta=3, bootstrapInt
results = []
for series in previewList:
analysis = holtWintersAnalysis(series, seasonality)

data = analysis['predictions']
windowPoints = previewSeconds // data.step
forecast = TimeSeries(data.name, data.start + previewSeconds, data.end, data.step, data[windowPoints:], xFilesFactor=series.xFilesFactor)
Expand Down Expand Up @@ -3666,10 +3665,12 @@ def holtWintersAberration(requestContext, seriesList, delta=3, bootstrapInterval
positive or negative deviation of the series data from the forecast.
"""
results = []
confidenceBands = holtWintersConfidenceBands(requestContext, seriesList, delta, bootstrapInterval, seasonality)
confidenceBands = {s.name: s for s in confidenceBands}

for series in seriesList:
confidenceBands = holtWintersConfidenceBands(requestContext, [series], delta, bootstrapInterval, seasonality)
lowerBand = confidenceBands[0]
upperBand = confidenceBands[1]
lowerBand = confidenceBands['holtWintersConfidenceLower(%s)' % series.name]
upperBand = confidenceBands['holtWintersConfidenceUpper(%s)' % series.name]
aberration = list()
for i, actual in enumerate(series):
if series[i] is None:
Expand Down Expand Up @@ -4917,6 +4918,7 @@ def timeFunction(requestContext, name, step=60):
Accepts optional second argument as 'step' parameter (default step is 60 sec)
"""
# TODO: align both startTime and endTime when creating the TimeSeries.
delta = timedelta(seconds=step)
when = requestContext["startTime"]
values = []
Expand Down
10 changes: 6 additions & 4 deletions webapp/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5138,14 +5138,15 @@ def test_holtWintersAberration(self):
start_time=2678400 # 1970-02-01
week_seconds=7*86400

def hw_range(x,y,jump):
def hw_range(x,y,jump,t=0):
while x<y:
yield (x/jump)%10
yield t+(x/jump)%10
x+=jump

def gen_seriesList(start=0, points=10):
seriesList = [
TimeSeries('collectd.test-db0.load.value', start, start+(points*step), step, hw_range(0, points*step, step)),
TimeSeries('collectd.test-db0.load.value', start, start+(points*step), step, hw_range(0, points*step, step)),
TimeSeries('collectd.test-db1.load.value', start, start+(points*step), step, hw_range(0, points*step, step, t=10)),
]
for series in seriesList:
series.pathExpression = series.name
Expand All @@ -5157,7 +5158,8 @@ def mock_evaluateTarget(requestContext, targets):
return gen_seriesList(start_time-week_seconds, (week_seconds/step)+points)

expectedResults = [
TimeSeries('holtWintersAberration(collectd.test-db0.load.value)', start_time, start_time+(points*step), step, [-0.2841206166091448, -0.05810270987744115, 0, 0, 0, 0, 0, 0, 0, 0])
TimeSeries('holtWintersAberration(collectd.test-db0.load.value)', start_time, start_time+(points*step), step, [-0.2841206166091448, -0.05810270987744115, 0, 0, 0, 0, 0, 0, 0, 0]),
TimeSeries('holtWintersAberration(collectd.test-db1.load.value)', start_time, start_time+(points*step), step, [-0.284120616609151, -0.05810270987744737, 0, 0, 0, 0, 0, 0, 0, 0]),
]

with patch('graphite.render.functions.evaluateTarget', mock_evaluateTarget):
Expand Down

0 comments on commit 10cf578

Please sign in to comment.