how to get previous value of output column ?

Hi,

I want to perform similar calculation for parabolic SAR which requires previous values ​​of output like the example shown below. How to achieve this ?

input = table(100:0, `id`val1`val2, [INT,DOUBLE,DOUBLE])

output = table(100:0, `id`f1`f2 , [INT,DOUBLE,DOUBLE])

prev_rs=createReactiveStateEngine(name="prev_rs",metrics=<[ iif(val1>prev(f1),val1,prev(val1)),iif(val2<prev(f2),iif(prev(f2)>val1,val1,prev(f2)),iif(prev(f1)> val2,val2,prev(f1)))]>,dummyTable=input,outputTable=output ,keyColumn=`id)

I need help in values of previous output like prev(f1) and prev(f2) please help me.

Please help me.

attachments-2022-02-n9l0IWP56207b85187133.png

请先 登录 后评论

最佳答案 2022-04-01 13:05

currently, this can only be done by handler:

login("admin","123456");
share streamTable(100:0, `id`val1`val2, [INT,DOUBLE,DOUBLE]) as input;
output = table(100:0, `id`f1`f2 , [INT,DOUBLE,DOUBLE]);
pre_v1v2f1f2_count = (double(0),double(0),double(0),double(0), int(0));
def handler(mutable data, mutable out, msg){
    id = msg[0]
    current_v1 = msg[1]
    current_v2 = msg[2]
    prev_v1 = data[0]
    prev_v2 = data[1]
    prev_f1 = data[2]
    prev_f2 = data[3]
    data[4] += 1 //counter
    data[0] = current_v1
    data[1] = current_v2
    if (data[4] <= 1) return
    res_f1 = double(0)
    if (current_v1 > prev_f1) res_f1 = current_v1
    else res_f1 = prev_v1
    prev_f1 = res_f1
    tableInsert(out, (id, res_f1,0))
};
subscribeTable(tableName="input",  handler=handler{pre_v1v2f1f2_count, output});
请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 0 收藏,1002 浏览
  • Vishvesh Upadhyay 提出于 2022-02-12 21:40

相似问题