parallel PathData creation
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<ProjectVersion>20.3</ProjectVersion>
|
||||
<FrameworkType>FMX</FrameworkType>
|
||||
<Base>True</Base>
|
||||
<Config Condition="'$(Config)'==''">Release</Config>
|
||||
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||
<Platform Condition="'$(Platform)'==''">Win64</Platform>
|
||||
<ProjectName Condition="'$(ProjectName)'==''">AuraTrader</ProjectName>
|
||||
<TargetedPlatforms>3</TargetedPlatforms>
|
||||
|
||||
+33
-2
@@ -88,10 +88,14 @@ begin
|
||||
if SymbolsComboBox.ItemIndex < 0 then
|
||||
exit;
|
||||
|
||||
var arr := TDataSeries<TAskBidItem>.CreateArray(3000);
|
||||
var curr := TWriteable<TDataSeries<TAskBidItem>>.CreateProtected;
|
||||
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 :=
|
||||
FServer.ProcessData(
|
||||
Symbol,
|
||||
@@ -100,12 +104,36 @@ begin
|
||||
begin
|
||||
arr.Add(Values);
|
||||
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
|
||||
);
|
||||
|
||||
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(
|
||||
curr.Changed,
|
||||
@@ -120,13 +148,16 @@ begin
|
||||
Path1.Data.Clear;
|
||||
Path1.Data.MoveTo(PointF(Path1.Width - 1, Prices[0].Data.Ask));
|
||||
for var i := 1 to Prices.Count - 1 do
|
||||
begin
|
||||
Path1.Data.LineTo(PointF(Path1.Width - i - 1, Prices[i].Data.Ask));
|
||||
end;
|
||||
finally
|
||||
Path1.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
);
|
||||
*)
|
||||
end;
|
||||
|
||||
procedure TForm1.Button2Click(Sender: TObject);
|
||||
|
||||
@@ -59,6 +59,22 @@ type
|
||||
property Value: T read GetValue;
|
||||
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
|
||||
|
||||
uses
|
||||
@@ -144,4 +160,27 @@ begin
|
||||
Dest.FFuture := FNull;
|
||||
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.
|
||||
|
||||
@@ -101,7 +101,7 @@ type
|
||||
// Used by cache to actually load an uncached file.
|
||||
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
|
||||
class var
|
||||
@@ -400,19 +400,19 @@ begin
|
||||
Result := FCachedFiles.GetOrAdd(DataFile.GetFullFileName);
|
||||
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
|
||||
if not currFile.IsValid or Terminated.IsSet then
|
||||
if not DataFile.IsValid or Terminated.IsSet then
|
||||
exit(TState.Null);
|
||||
|
||||
var data := FCachedFiles.GetOrAdd(currFile.GetFullFileName);
|
||||
var data := FCachedFiles.GetOrAdd(DataFile.GetFullFileName);
|
||||
|
||||
Result :=
|
||||
data.Chain(
|
||||
function(const Data: TArray<TDataPoint<T>>): TState
|
||||
begin
|
||||
Proc(Data, Terminated);
|
||||
Result := LoadFile(currFile.GetNextFile, Terminated, Proc);
|
||||
Result := LoadFile(DataFile.GetNextFile, Terminated, Proc);
|
||||
end
|
||||
);
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user