improvement: Lookup timestamp col by index rather than name
This commit is contained in:
1 parent
0b64bd6544
commit
4fd2073b63
1 file changed
+10
-4
+10
-4
@@ -6,6 +6,7 @@
|
||||
using BCG;
|
||||
|
||||
using Bts.DataStream;
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
@@ -26,6 +27,8 @@
|
||||
readonly ViewStream source;
|
||||
private RowsWithPointer _rows = new RowsWithPointer();
|
||||
IDisposable? sourceSub;
|
||||
// The index of the 'ts_event' column (it's resolved on the first update).
|
||||
int timestampIndex = -1;
|
||||
|
||||
public ReplayFutureLiveBBOStream(string continous_contract) {
|
||||
Func<string> iso_8601_now = () => {
|
||||
@@ -79,7 +82,10 @@
|
||||
_rows.rows = new List<IBlueRow>(0);
|
||||
return;
|
||||
}
|
||||
_rows.rows = source.rows.Cast<IBlueRow>().OrderBy(r => r.GetDateTime("ts_event")).ToList();
|
||||
if (timestampIndex == -1) {
|
||||
timestampIndex = source.rows.schema.ResolveIndices("ts_event");
|
||||
}
|
||||
_rows.rows = source.rows.Cast<IBlueRow>().OrderBy(r => r.GetDateTime(timestampIndex)).ToList();
|
||||
}
|
||||
|
||||
void OnSourceChanged(object obj) =>
|
||||
@@ -92,12 +98,12 @@
|
||||
}
|
||||
|
||||
public void doWork() {
|
||||
if (_rows.rows is null || _rows.rows.Count == 0) {
|
||||
if (_rows.rows is null || _rows.rows.Count == 0 || timestampIndex == -1) {
|
||||
return;
|
||||
}
|
||||
IBlueRow cand_row = _rows.rows[_rows.pointer];
|
||||
string cand_ts_event = cand_row.get<string>("ts_event");
|
||||
DateTime cand_ts_event_dt = DateTime.Parse(cand_ts_event, null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
var cand_ts_event_dt = cand_row.GetDateTime(timestampIndex)
|
||||
?? throw new InvalidOperationException("Failed to get timestamp from row");
|
||||
TimeSpan cand_ts_span_file = cand_ts_event_dt - _last_fire_time.last_fireitme_file;
|
||||
TimeSpan ts_clock = DateTime.Now - _last_fire_time.last_firetime_clock;
|
||||
if (ts_clock >= cand_ts_span_file) {
|
||||
|
||||
Reference in new issue
Block a user