DataFeed-Producer

This commit is contained in:
Michael Schimmel
2025-12-08 20:25:54 +01:00
parent 59692bc211
commit 9a4f477cfd
7 changed files with 817 additions and 14 deletions
+27 -8
View File
@@ -3,11 +3,11 @@ unit Myc.Data.Scalar;
interface
uses
system.sysutils,
system.generics.collections,
system.generics.defaults,
system.math,
system.dateutils,
System.SysUtils,
System.Generics.Collections,
System.Generics.Defaults,
System.Math,
System.DateUtils,
Myc.Utils,
Myc.Data.Decimal,
Myc.Data.Series,
@@ -24,6 +24,7 @@ type
TKind = (Ordinal, Float, Keyword, Boolean, DateTime);
// The 8-byte storage for the scalar value
PValue = ^TValue;
TValue = record
case TKind of
TKind.Ordinal, TKind.Keyword, TKind.Boolean: (AsInt64: Int64);
@@ -157,7 +158,7 @@ type
strict private
FDef: IScalarRecordDefinition;
FFields: TArray<TScalar.TValue>;
end;
end deprecated;
ISeries = interface
{$region 'private'}
@@ -174,7 +175,7 @@ type
procedure Add(const Item: TScalar.TValue; Lookback: Int64 = -1);
end;
// A time series of scalar records, optimized for memory and access speed.
// A series of scalar records, optimized for memory and access speed.
TScalarSeries = class(TInterfacedObject, ISeries, IWriteableSeries)
private
FKind: TScalar.TKind;
@@ -196,13 +197,14 @@ type
function GetFields(const Key: IKeyword): ISeries;
{$endregion}
procedure Add(const Item: TScalarRecord; Lookback: Int64 = -1);
procedure AddRaw(const Data; Lookback: Int64 = -1);
property Count: Int64 read GetCount;
property Def: IScalarRecordDefinition read GetDef;
property Fields[const Key: IKeyword]: ISeries read GetFields; default;
property TotalCount: Int64 read GetTotalCount;
end;
// A time series of scalar records, optimized for memory and access speed.
// A series of scalar records, optimized for memory and access speed.
TScalarRecordSeries = class(TInterfacedObject, IRecordSeries)
type
TMemberSeries = class(TGenericContainedObject<TScalarRecordSeries>, ISeries)
@@ -231,6 +233,10 @@ type
constructor Create(const ADef: IScalarRecordDefinition);
destructor Destroy; override;
procedure Add(const Item: TScalarRecord; Lookback: Int64 = -1);
// Copies data directly from the Data reference (zero-copy wrapper)
procedure AddRaw(const Data; Lookback: Int64 = -1);
property Count: Int64 read GetCount;
property Fields[const Key: IKeyword]: ISeries read GetFields; default;
property Def: IScalarRecordDefinition read GetDef;
@@ -849,6 +855,19 @@ begin
inc(FTotalCount);
end;
procedure TScalarRecordSeries.AddRaw(const Data; Lookback: Int64 = -1);
type
TValueArr = array[0..MaxInt div SizeOf(TScalar.TValue) - 1] of TScalar.TValue;
PValueArr = ^TValueArr;
var
len: Integer;
begin
len := Length(FDef.Fields);
// Use Slice to pass the raw data as an open array without copying.
FArray.Add(Slice(PValueArr(@Data)^, len), len * Integer(Lookback));
inc(FTotalCount);
end;
function TScalarRecordSeries.GetFields(const Key: IKeyword): ISeries;
begin
var elem := FDef.IndexOf(Key);