如何检查某些值是否超过阈值超过 n 天?

How to check if some values have been above a threshold for more than n days?

我有以下 table:

t:([]date:.z.d+neg til 100; region:100#(`us`eu`asia`au); product:100#(`car`insurance`loan`other); qty:100?1f);

date       region product   qty        
---------------------------------------
2019.11.28 us     car       0.3998898  
2019.11.27 eu     insurance 0.592308   
2019.11.26 asia   loan      0.9796166  
...

我想要的是检查 qty 是否高于给定阈值,比如 0.5,超过 n 天,比如 3 天。这里days其实可以只是连续观察的次数。

我想按地区检查我拥有的 4 种产品中的每一种。

我想在 n 天内应用滚动功能,并应用以下功能:

myfunc:{[l]
    :all l>0.5;
    };

其中 0.5 是我的阈值,但它并没有真正起作用...

一种使用 fby 的方法:

q)consec:{s in(s:sums[differ y])where(x-1){x&prev x}/y};
q)`region`product`date xdesc select from t where (consec[3];0.5<qty)fby([]region;product)
date       region product   qty
-------------------------------------
2019.11.04 us     car       0.949975
2019.10.31 us     car       0.8481567
2019.10.27 us     car       0.9367503
2019.09.28 eu     insurance 0.6884756
2019.09.24 eu     insurance 0.9598964
2019.09.20 eu     insurance 0.6789082
2019.09.16 eu     insurance 0.726781
2019.09.12 eu     insurance 0.5830262
2019.09.08 eu     insurance 0.7750292
2019.11.21 au     other     0.5347096
2019.11.17 au     other     0.5785203
2019.11.13 au     other     0.6137452
2019.11.09 au     other     0.6919531
2019.09.30 au     other     0.7278528
2019.09.26 au     other     0.7520102
2019.09.22 au     other     0.6430982
2019.09.18 au     other     0.9877844
2019.09.14 au     other     0.8355065
2019.09.10 au     other     0.9149882
2019.09.06 au     other     0.6324114

/to make it a sequence of 5 consecutive
`region`product`date xdesc select from t where (consec[5];0.5<qty)fby([]region;product)

/to make the threshold >0.6
`region`product`date xdesc select from t where (consec[5];0.6<qty)fby([]region;product)