TimeSeries and TimeBucketStreams, Stream offloading etc

This commit is contained in:
Taha committed 2023-10-23 14:18:31 -04:00
1 parent 33030b1212
commit 88bf04e5f1
31 files changed
+1823 -836

No files matched your search

@@ -1,10 +1,9 @@
using System;
using BCG.Utilities.General;
namespace BCG
{
public abstract class TimeUnitStream : ViewStream, IWorker
{
namespace BCG {
public abstract class TimeUnitStream : ViewStream, IWorker {
protected TimeSpan myOffset;
protected DateTime myConstructionTime;
protected int mySizeOfStream;
@@ -13,87 +12,80 @@ namespace BCG
protected ViewStreamDatabase myDb;
protected int myId = 0;
public TimeUnitStream (DateTime zeroTime, TimeSpan offSet, int sizeOfStream, ViewStreamDatabase db)
{
public TimeUnitStream(DateTime zeroTime, TimeSpan offSet, int sizeOfStream, ViewStreamDatabase db) {
myConstructionTime = DateTime.Now;
myZeroTime = zeroTime;
myOffset = offSet;
mySizeOfStream = sizeOfStream;
myDb = db;
myCollection = new CircularRowCollection (
new BlueTableSchema ("Time",
new ColumnInfo ("id", 0, typeof(Int32)), new ColumnInfo ("time", 1, typeof(DateTime))),
myCollection = new CircularRowCollection(
new BlueTableSchema("Time",
new ColumnInfo("id", 0, typeof(Int32)), new ColumnInfo("time", 1, typeof(DateTime))),
mySizeOfStream);
}
}
#region ViewStream overriden methods
protected override void myOnFirstSubscriber()
{
myDb.addWorker (this);
myInit ();
protected override void myOnFirstSubscriber() {
myDb.addWorker(this);
myInit();
}
protected override void myOnLastSubscriber()
{
myDb.removeWorker (this);
protected override void myOnLastSubscriber() {
myDb.removeWorker(this);
}
#endregion
protected virtual void myInit ()
{
protected virtual void myInit() {
int periods = (int)
(DateTime.Now - myConstructionTime).TotalMilliseconds / (int) myOffset.TotalMilliseconds;
(DateTime.Now - myConstructionTime).TotalMilliseconds / (int)myOffset.TotalMilliseconds;
DateTime dt = myGetLatestRow() == null ? myRoundTime(myZeroTime) :
myRoundTime (myZeroTime + new TimeSpan(myOffset.Ticks * periods));
DateTime dt = myGetLatestRow() == null ? myRoundTime(myZeroTime) :
myRoundTime(myZeroTime + new TimeSpan(myOffset.Ticks * periods));
if (myGetLatestRow() == null ||
!myGetLatestRow()["time"].Equals(dt))
{
IBlueRow ar = new BlueRow (myCollection.schema,
!myGetLatestRow()["time"].Equals(dt)) {
IBlueRow ar = new BlueRow(myCollection.schema,
myId++, dt);
IBlueRow dr = myCollection.addRowWithReturn (ar);
myFireEvent (new DataPacket (myCollection,
myConvertToCollection (ar),
myConvertToCollection (dr)));
IBlueRow dr = myCollection.addRowWithReturn(ar);
if (n_updates <= 3000)
myFireEvent(new DataPacket(myCollection,
myConvertToCollection(ar),
myConvertToCollection(dr)));
}
}
#region IWorker methods
public void doWork ()
{
myInit ();
public void doWork() {
myInit();
}
#endregion
protected abstract DateTime myRoundTime (DateTime dt);
protected abstract DateTime myRoundTime(DateTime dt);
#region Private Helper methods
private IBlueRow myGetLatestRow ()
{
private IBlueRow myGetLatestRow() {
return myCollection.Count == 0 ?
null :
BlueDataUtility.extractRow (myCollection, myCollection.Count - 1);
BlueDataUtility.extractRow(myCollection, myCollection.Count - 1);
}
private IBlueRowCollection myConvertToCollection (IBlueRow r)
{
BlueTable retVal = new BlueTable (myCollection.schema);
private IBlueRowCollection myConvertToCollection(IBlueRow r) {
BlueTable retVal = new BlueTable(myCollection.schema);
if (r != null)
retVal.addRow (r);
retVal.addRow(r);
return retVal;
}
#endregion
}
}
}