Skip to content

Commit b67fb7d

Browse files
committed
use step gaps for smoothins
1 parent a9f4c75 commit b67fb7d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

app/ui/src/components/charts/smoothing/two_sided_exponential_average.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,38 @@ export class TwoSidedExponentialAverage extends SeriesSmoothing {
2121

2222
let last_sum = 0
2323
let last_weight = 0
24+
let last_step = ind.series[0].step
2425
for (let j = 0; j < ind.series.length; j++) {
25-
f_sum.push(last_sum * smoothingFactor + ind.series[j].value)
26-
f_weights.push(last_weight * smoothingFactor + 1)
26+
let smooth_gap = Math.pow(smoothingFactor, Math.abs(ind.series[j].step - last_step))
27+
f_sum.push(last_sum * smooth_gap + ind.series[j].value)
28+
f_weights.push(last_weight * smooth_gap + 1)
2729

2830
last_sum = f_sum[j]
2931
last_weight = f_weights[j]
32+
last_step = ind.series[j].step
3033
}
3134

3235
last_sum = 0
3336
last_weight = 0
37+
last_step = ind.series[ind.series.length - 1].step
3438
for (let j = ind.series.length - 1; j >= 0; j--) {
35-
b_sum.push(last_sum * smoothingFactor + ind.series[j].value)
36-
b_weights.push(last_weight * smoothingFactor + 1)
39+
let smooth_gap = Math.pow(smoothingFactor, Math.abs(ind.series[j].step - last_step))
40+
b_sum.push(last_sum * smooth_gap + ind.series[j].value)
41+
b_weights.push(last_weight * smooth_gap + 1)
3742

3843
last_sum = b_sum[b_sum.length - 1]
3944
last_weight = b_weights[b_weights.length - 1]
45+
last_step = ind.series[j].step
4046
}
4147
b_weights.reverse()
4248
b_sum.reverse()
4349

44-
for (let j = 0; j < ind.series.length-1; j++) {
45-
let smoothed = (f_sum[j] + smoothingFactor * b_sum[j+1]) /
46-
(f_weights[j] + smoothingFactor * b_weights[j+1])
50+
for (let j = 0; j < ind.series.length; j++) {
51+
let smoothed = (f_sum[j] + b_sum[j] - ind.series[j].value) /
52+
(f_weights[j] + b_weights[j] - 1)
4753
result.push({step: ind.series[j].step, value: ind.series[j].value,
4854
smoothed: smoothed, lastStep: ind.series[j].lastStep})
4955
}
50-
result.push({step: ind.series[ind.series.length-1].step, value: ind.series[ind.series.length-1].value,
51-
smoothed: f_sum[ind.series.length-1] / f_weights[ind.series.length-1],
52-
lastStep: ind.series[ind.series.length-1].lastStep})
53-
54-
5556

5657
ind.series = result
5758
}

0 commit comments

Comments
 (0)