Hi,
I am using influx cloud and this query returns inconsistent results when run on influx cloud and when run using the JS/ node library.
Why is that?
import “math”
import “strings”
data_1 = from(bucket: “returns”)
|> range(start: 1609439400, stop: 1614448943)
|> filter(fn: ® => r["_measurement"] == “returns-daily”)
|> filter(fn: ® => r["_field"] == “supervised_return_gof_pre_tax” or r["_field"] == “supervised_return_gof_post_tax”)
|> filter(fn: ® => r[“account_number”] == “939888955”)
|> map(fn: ® => ({
_value: r._value + 1.00000 ,
_time: r._time,
_field: r._field
}))
|> reduce(fn: (r, accumulator) => ({
pre_tax: if r._field == “supervised_return_gof_pre_tax” then r._value * accumulator.pre_tax else accumulator.pre_tax ,
post_tax: if r._field == “supervised_return_gof_post_tax” then r._value * accumulator.post_tax else accumulator.post_tax,
}),
identity: {pre_tax: -1.0, post_tax: -1.0})
|> drop(columns: ["_field", “_measurement”])
|> reduce(fn: (r, accumulator) => ({
pre_tax: math.abs(x: r.pre_tax * accumulator.pre_tax) ,
post_tax: math.abs(x: r.post_tax * accumulator.post_tax),
tax_alpha: (r.post_tax * accumulator.post_tax) - (r.pre_tax * accumulator.pre_tax)
}),
identity: {pre_tax: 1.0, post_tax: 1.0, tax_alpha: 0.0})
|> yield()