47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
namespace bts.SilverPine {
|
|
using BCG;
|
|
|
|
using System;
|
|
using System.CodeDom;
|
|
using System.Configuration;
|
|
using System.Reactive.Disposables;
|
|
|
|
public class TimeProximityJoinStream : ViewStream {
|
|
private int _id = 0;
|
|
|
|
public TimeProximityJoinStream(ViewStream ls, string l_time_col, ViewStream rs, string r_time_col,
|
|
string pre_join_period, string post_join_period) :
|
|
this(ls, l_time_col, rs, r_time_col, TimeBasedFilter.parse_duration(pre_join_period),
|
|
TimeBasedFilter.parse_duration(post_join_period)) { }
|
|
|
|
|
|
public TimeProximityJoinStream(ViewStream ls, string l_time_col, ViewStream rs, string r_time_col,
|
|
TimeSpan pre_join_period, TimeSpan post_join_period) {
|
|
Func<IBlueRow, IBlueRow, IBlueRow> create_row = (lr, rr) => {
|
|
var id = 0;
|
|
lock (this) {
|
|
id = _id++;
|
|
}
|
|
IBlueRow rv = BlueDataUtility.create_composite_row(lr, rr, id);
|
|
return rv;
|
|
};
|
|
Func<IBlueRow, IBlueRow, IBlueRow> join_func = (lr, rr) => {
|
|
DateTime ldt = lr.get_datetime(l_time_col);
|
|
DateTime rdt = rr.get_datetime(r_time_col);
|
|
TimeSpan diff = ldt - rdt;
|
|
if (ldt < rdt) {
|
|
if (diff.Duration() > pre_join_period) {
|
|
return null;
|
|
}
|
|
} else {
|
|
if (diff > post_join_period)
|
|
return null;
|
|
}
|
|
return create_row(lr, rr);
|
|
};
|
|
|
|
ViewStream rstr = new ProximityJoinStream(ls, rs, join_func);
|
|
mySetRealSource(rstr);
|
|
}
|
|
}
|
|
} |