parallel PathData creation
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<ProjectVersion>20.3</ProjectVersion>
|
<ProjectVersion>20.3</ProjectVersion>
|
||||||
<FrameworkType>FMX</FrameworkType>
|
<FrameworkType>FMX</FrameworkType>
|
||||||
<Base>True</Base>
|
<Base>True</Base>
|
||||||
<Config Condition="'$(Config)'==''">Release</Config>
|
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||||
<Platform Condition="'$(Platform)'==''">Win64</Platform>
|
<Platform Condition="'$(Platform)'==''">Win64</Platform>
|
||||||
<ProjectName Condition="'$(ProjectName)'==''">AuraTrader</ProjectName>
|
<ProjectName Condition="'$(ProjectName)'==''">AuraTrader</ProjectName>
|
||||||
<TargetedPlatforms>3</TargetedPlatforms>
|
<TargetedPlatforms>3</TargetedPlatforms>
|
||||||
|
|||||||
+33
-2
@@ -88,10 +88,14 @@ begin
|
|||||||
if SymbolsComboBox.ItemIndex < 0 then
|
if SymbolsComboBox.ItemIndex < 0 then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
var arr := TDataSeries<TAskBidItem>.CreateArray(3000);
|
|
||||||
var curr := TWriteable<TDataSeries<TAskBidItem>>.CreateProtected;
|
var curr := TWriteable<TDataSeries<TAskBidItem>>.CreateProtected;
|
||||||
var Symbol := FSymbols.WaitFor[SymbolsComboBox.ItemIndex];
|
var Symbol := FSymbols.WaitFor[SymbolsComboBox.ItemIndex];
|
||||||
|
|
||||||
|
var currPathData := TWriteable<IObjectRef<TPathData>>.CreateProtected;
|
||||||
|
|
||||||
|
LogMemo.AddIdleHandler(curr.Changed, procedure begin LogMemo.Lines.Add(Symbol + ': ' + curr.Value.TotalCount.ToString); end);
|
||||||
|
|
||||||
|
var arr := TDataSeries<TAskBidItem>.CreateArray(3000);
|
||||||
var done :=
|
var done :=
|
||||||
FServer.ProcessData(
|
FServer.ProcessData(
|
||||||
Symbol,
|
Symbol,
|
||||||
@@ -100,12 +104,36 @@ begin
|
|||||||
begin
|
begin
|
||||||
arr.Add(Values);
|
arr.Add(Values);
|
||||||
curr.Value := arr.Copy;
|
curr.Value := arr.Copy;
|
||||||
|
|
||||||
|
var PathData := TPathData.Create;
|
||||||
|
var Prices := arr;
|
||||||
|
if Prices.Count > 0 then
|
||||||
|
begin
|
||||||
|
PathData.MoveTo(PointF(Prices.Count - 1, Prices[0].Data.Ask));
|
||||||
|
for var i := 1 to Prices.Count - 1 do
|
||||||
|
PathData.LineTo(PointF(Prices.Count - i - 1, Prices[i].Data.Ask));
|
||||||
|
end;
|
||||||
|
|
||||||
|
currPathData.Value := TObjectRef<TPathData>.Create(PathData);
|
||||||
end
|
end
|
||||||
);
|
);
|
||||||
|
|
||||||
FLoadDone := TState.All([FLoadDone, done]);
|
FLoadDone := TState.All([FLoadDone, done]);
|
||||||
|
|
||||||
LogMemo.AddIdleHandler(curr.Changed, procedure begin LogMemo.Lines.Add(Symbol + ': ' + curr.Value.TotalCount.ToString); end);
|
Path1.AddIdleHandler(
|
||||||
|
currPathData.Changed,
|
||||||
|
procedure
|
||||||
|
begin
|
||||||
|
if currPathData.Value<>nil then
|
||||||
|
begin
|
||||||
|
Path1.Data.Assign( currPathData.Value.Obj );
|
||||||
|
currPathData.Value := nil;
|
||||||
|
end;
|
||||||
|
end );
|
||||||
|
|
||||||
|
|
||||||
|
(*
|
||||||
|
FLoadDone := TState.All([FLoadDone, done]);
|
||||||
|
|
||||||
Path1.AddIdleHandler(
|
Path1.AddIdleHandler(
|
||||||
curr.Changed,
|
curr.Changed,
|
||||||
@@ -120,13 +148,16 @@ begin
|
|||||||
Path1.Data.Clear;
|
Path1.Data.Clear;
|
||||||
Path1.Data.MoveTo(PointF(Path1.Width - 1, Prices[0].Data.Ask));
|
Path1.Data.MoveTo(PointF(Path1.Width - 1, Prices[0].Data.Ask));
|
||||||
for var i := 1 to Prices.Count - 1 do
|
for var i := 1 to Prices.Count - 1 do
|
||||||
|
begin
|
||||||
Path1.Data.LineTo(PointF(Path1.Width - i - 1, Prices[i].Data.Ask));
|
Path1.Data.LineTo(PointF(Path1.Width - i - 1, Prices[i].Data.Ask));
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
Path1.EndUpdate;
|
Path1.EndUpdate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
);
|
);
|
||||||
|
*)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.Button2Click(Sender: TObject);
|
procedure TForm1.Button2Click(Sender: TObject);
|
||||||
|
|||||||
@@ -59,6 +59,22 @@ type
|
|||||||
property Value: T read GetValue;
|
property Value: T read GetValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
IObjectRef<T: class> = interface
|
||||||
|
function GetObj: T;
|
||||||
|
function Pop: T;
|
||||||
|
property Obj: T read GetObj;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TObjectRef<T: class> = class(TInterfacedObject, IObjectRef<T>)
|
||||||
|
private
|
||||||
|
FObj: T;
|
||||||
|
function GetObj: T;
|
||||||
|
public
|
||||||
|
constructor Create(const ARef: T);
|
||||||
|
destructor Destroy; override;
|
||||||
|
function Pop: T;
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@@ -144,4 +160,27 @@ begin
|
|||||||
Dest.FFuture := FNull;
|
Dest.FFuture := FNull;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TObjectRef<T>.Create(const ARef: T);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
FObj := ARef;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TObjectRef<T>.Destroy;
|
||||||
|
begin
|
||||||
|
FObj.Free;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TObjectRef<T>.GetObj: T;
|
||||||
|
begin
|
||||||
|
Result := FObj;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TObjectRef<T>.Pop: T;
|
||||||
|
begin
|
||||||
|
Result := FObj;
|
||||||
|
FreeAndNil( FObj );
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ type
|
|||||||
// Used by cache to actually load an uncached file.
|
// Used by cache to actually load an uncached file.
|
||||||
function DoLoad(const FileName: string): TFuture<TArray<TDataPoint<T>>>;
|
function DoLoad(const FileName: string): TFuture<TArray<TDataPoint<T>>>;
|
||||||
|
|
||||||
function LoadFile(currFile: TAuraDataFile; Terminated: TState; Proc: TDataProc<T>): TState;
|
function LoadFile(DataFile: TAuraDataFile; Terminated: TState; Proc: TDataProc<T>): TState;
|
||||||
|
|
||||||
strict private
|
strict private
|
||||||
class var
|
class var
|
||||||
@@ -400,19 +400,19 @@ begin
|
|||||||
Result := FCachedFiles.GetOrAdd(DataFile.GetFullFileName);
|
Result := FCachedFiles.GetOrAdd(DataFile.GetFullFileName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TAuraDataServer<T>.LoadFile(currFile: TAuraDataFile; Terminated: TState; Proc: TDataProc<T>): TState;
|
function TAuraDataServer<T>.LoadFile(DataFile: TAuraDataFile; Terminated: TState; Proc: TDataProc<T>): TState;
|
||||||
begin
|
begin
|
||||||
if not currFile.IsValid or Terminated.IsSet then
|
if not DataFile.IsValid or Terminated.IsSet then
|
||||||
exit(TState.Null);
|
exit(TState.Null);
|
||||||
|
|
||||||
var data := FCachedFiles.GetOrAdd(currFile.GetFullFileName);
|
var data := FCachedFiles.GetOrAdd(DataFile.GetFullFileName);
|
||||||
|
|
||||||
Result :=
|
Result :=
|
||||||
data.Chain(
|
data.Chain(
|
||||||
function(const Data: TArray<TDataPoint<T>>): TState
|
function(const Data: TArray<TDataPoint<T>>): TState
|
||||||
begin
|
begin
|
||||||
Proc(Data, Terminated);
|
Proc(Data, Terminated);
|
||||||
Result := LoadFile(currFile.GetNextFile, Terminated, Proc);
|
Result := LoadFile(DataFile.GetNextFile, Terminated, Proc);
|
||||||
end
|
end
|
||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
|
|||||||
Reference in New Issue
Block a user