Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions generator/Common/generate.common.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TGenerator = class(TObject)

{$IFNDEF FPC}
TStringArray = array of string;
TWriteBufStream = TBufferedFileStream;
TWriteBufStream = TFileStream;
{$ENDIF}

implementation
Expand Down Expand Up @@ -161,11 +161,11 @@ function TGenerator.GenerateProgressBar(APBPosition, APBMax, APBWIdth, AFileSize

procedure TGenerator.Generate;
var
index, progressBatch: Int64;
index, progressCount, progressBatch: Int64;
stationId: Int64;
randomTemp: Integer;
randomTempStr: String[4];
outputFileStream: TBufferedFileStream;
outputFileStream: TFileStream;
chunkLine, randomTempFinal: String;
stationArray, temperatureArray: TStringArray;
LenStationArray, LenTemperatureArray: Array of Integer;
Expand All @@ -179,7 +179,7 @@ procedure TGenerator.Generate;
// Build list of station names
BuildStationNames;

outputFileStream := TBufferedFileStream.Create(FOutPutFile, fmCreate);
outputFileStream := TFileStream.Create(FOutPutFile, fmCreate);

progressBatch := floor(FLineCount * (linesPercent / 100));
start := Now;
Expand Down Expand Up @@ -224,6 +224,7 @@ procedure TGenerator.Generate;
chunkCount := chunkBatch;
chunkLen := 0;
SetLength(chunkLine, chunkCapacity);
progressCount := progressBatch;
// To here

try
Expand Down Expand Up @@ -251,23 +252,18 @@ procedure TGenerator.Generate;
chunkLen := 0;
end;
// To here
Dec(progressBatch);
if progressBatch = 0 then
Dec(progressCount);
if progressCount = 0 then
begin
Write(GenerateProgressBar(index, FLineCount, 50, outputFileStream.Size,
Now - start), lineBreak);
progressBatch := floor(FLineCount * (linesPercent / 100));
progressCount := progressBatch;
end;
end;

if chunkCount > 0 then
begin
outputFileStream.WriteBuffer(chunkLine[1], chunkLen);
{$IFDEF FPC}
outputFileStream.Flush;
{$ELSE}
outputFileStream.FlushBuffer;
{$ENDIF}
end;
finally
WriteLn;
Expand Down