41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
namespace bts.BlueOrb {
|
|
using BCG;
|
|
|
|
using System;
|
|
|
|
[DataStreamUserRespresentation("MultiRowRollingMathStream")]
|
|
public class MultiRowRollingMathStream : ViewStream {
|
|
private ViewStream _sorted_parent_str;
|
|
private MultiRowOpHelper _op;
|
|
private int _rolling_window_sz;
|
|
public MultiRowRollingMathStream(ViewStream parent_str, string op_txt, string sort_exp, int rolling_window_sz) {
|
|
_sorted_parent_str = new SortStream(parent_str, sort_exp);
|
|
_op = MultiRowOpHelper.parse_ops(op_txt);
|
|
_rolling_window_sz = rolling_window_sz;
|
|
}
|
|
|
|
protected override void myOnFirstSubscriber() {
|
|
_sorted_parent_str.onChange += _parent_str_onchange;
|
|
}
|
|
|
|
protected override void myOnLastSubscriber() {
|
|
_sorted_parent_str.onChange -= _parent_str_onchange;
|
|
}
|
|
|
|
private void _parent_str_onchange(object dp_obj) {
|
|
var dp = (IDataPacket)dp_obj;
|
|
var rows = dp.newRows.to_list();
|
|
BlueTable? out_table = null;
|
|
for (int i = 0; i < rows.Count; i++) {
|
|
var out_r = MultiRowOpHelper.group_by_compute(rows, i, _rolling_window_sz, _op)
|
|
?? throw new InvalidOperationException("group_by_compute returned null row");
|
|
if (out_table == null)
|
|
out_table = new BlueTable(out_r.schema);
|
|
out_table.addRow(out_r);
|
|
}
|
|
var dp_out = BlueDataUtility.build_dp_inc(out_table, myLastValue as DataPacket, true);
|
|
myFireEvent(dp_out);
|
|
}
|
|
}
|
|
}
|