s/window/period/g

This commit is contained in:
Will Charczuk 2016-07-18 15:06:42 -07:00
parent f1376c6566
commit 6d6778d729

View File

@ -9,7 +9,7 @@ type BollingerBandsSeries struct {
Style Style Style Style
YAxis YAxisType YAxis YAxisType
WindowSize int Period int
K float64 K float64
InnerSeries ValueProvider InnerSeries ValueProvider
@ -31,15 +31,12 @@ func (bbs BollingerBandsSeries) GetYAxis() YAxisType {
return bbs.YAxis return bbs.YAxis
} }
// GetWindowSize returns the window size. // GetPeriod returns the window size.
func (bbs BollingerBandsSeries) GetWindowSize(defaults ...int) int { func (bbs BollingerBandsSeries) GetPeriod() int {
if bbs.WindowSize == 0 { if bbs.Period == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return DefaultSimpleMovingAveragePeriod return DefaultSimpleMovingAveragePeriod
} }
return bbs.WindowSize return bbs.Period
} }
// GetK returns the K value. // GetK returns the K value.
@ -64,9 +61,9 @@ func (bbs *BollingerBandsSeries) GetBoundedValue(index int) (x, y1, y2 float64)
return return
} }
if bbs.valueBuffer == nil || index == 0 { if bbs.valueBuffer == nil || index == 0 {
bbs.valueBuffer = NewRingBufferWithCapacity(bbs.GetWindowSize()) bbs.valueBuffer = NewRingBufferWithCapacity(bbs.GetPeriod())
} }
if bbs.valueBuffer.Len() >= bbs.GetWindowSize() { if bbs.valueBuffer.Len() >= bbs.GetPeriod() {
bbs.valueBuffer.Dequeue() bbs.valueBuffer.Dequeue()
} }
px, py := bbs.InnerSeries.GetValue(index) px, py := bbs.InnerSeries.GetValue(index)
@ -86,14 +83,14 @@ func (bbs *BollingerBandsSeries) GetLastBoundedValue() (x, y1, y2 float64) {
if bbs.InnerSeries == nil { if bbs.InnerSeries == nil {
return return
} }
windowSize := bbs.GetWindowSize() period := bbs.GetPeriod()
seriesLength := bbs.InnerSeries.Len() seriesLength := bbs.InnerSeries.Len()
startAt := seriesLength - windowSize startAt := seriesLength - period
if startAt < 0 { if startAt < 0 {
startAt = 0 startAt = 0
} }
vb := NewRingBufferWithCapacity(windowSize) vb := NewRingBufferWithCapacity(period)
for index := startAt; index < seriesLength; index++ { for index := startAt; index < seriesLength; index++ {
xn, yn := bbs.InnerSeries.GetValue(index) xn, yn := bbs.InnerSeries.GetValue(index)
vb.Enqueue(yn) vb.Enqueue(yn)
@ -117,7 +114,7 @@ func (bbs *BollingerBandsSeries) Render(r Renderer, canvasBox Box, xrange, yrang
FillColor: DefaultAxisColor.WithAlpha(32), FillColor: DefaultAxisColor.WithAlpha(32),
})) }))
DrawBoundedSeries(r, canvasBox, xrange, yrange, s, bbs, bbs.GetWindowSize()) DrawBoundedSeries(r, canvasBox, xrange, yrange, s, bbs, bbs.GetPeriod())
} }
func (bbs BollingerBandsSeries) getAverage(valueBuffer *RingBuffer) float64 { func (bbs BollingerBandsSeries) getAverage(valueBuffer *RingBuffer) float64 {