@@ -25,7 +25,10 @@ TGenerator = class(TObject)
2525 FStationNames: TStringList;
2626
2727 procedure BuildStationNames ;
28- function GenerateProgressBar (APosition, AMax, ALength:Int64):String;
28+ function GenerateProgressBar (
29+ APBPosition, APBMax, APBWIdth, AFileSize:Int64;
30+ ATimeElapsed: TDateTime
31+ ):String;
2932 protected
3033 public
3134 constructor Create(AInputFile, AOutputFile: String; ALineCount: Int64);
@@ -119,28 +122,37 @@ procedure TGenerator.BuildStationNames;
119122 WriteLn;
120123end ;
121124
122- function TGenerator.GenerateProgressBar (APosition, AMax, ALength: Int64
123- ): String;
125+ function TGenerator.GenerateProgressBar (
126+ APBPosition, APBMax, APBWIdth, AFileSize: Int64;
127+ ATimeElapsed: TDateTime
128+ ): String;
124129var
125130 percentDone: Double;
126131 filled: Integer;
127132begin
128- percentDone:= (100 * APosition ) / AMax ;
129- filled:= (ALength * APosition ) div AMax ;
133+ percentDone:= (100 * APBPosition ) / APBMax ;
134+ filled:= (APBWIdth * APBPosition ) div APBMax ;
130135 Result:= ' [' ;
131136 Result:= Result + StringOfChar(' #' , filled);
132- Result:= Result + StringOfChar(' -' , ALength - filled);
137+ Result:= Result + StringOfChar(' -' , APBWIdth - filled);
133138 Result:= Result + Format(' ] %5.2f %%' , [ percentDone ]);
139+ Result:= Result + Format(' lines: %.n, file size: %.n, elapsed: %s ' , [
140+ Double(APBPosition),
141+ Double(AFileSize),
142+ FormatDateTime(' n" min, "s" sec"' , ATimeElapsed)
143+ ]);
134144end ;
135145
136146procedure TGenerator.Generate ;
137147var
138148 index, progressBatch: Int64;
139149 stationId: Int64;
140- randomTemp: Double;
150+ randomTemp: Integer;
151+ randomTempStr: String[4 ];
141152 outputFileStream: TFileStream;
142153 outputBufWriter: TWriteBufStream;
143- line: String;
154+ line, randomTempFinal: String;
155+ start: TDateTime;
144156begin
145157 // Randomize sets this variable depending on the current time
146158 // We just set it to our own value
@@ -157,32 +169,61 @@ procedure TGenerator.Generate;
157169 // outputBufWriter:= TWriteBufStream.Create(outputFileStream, 4*1024);
158170 outputBufWriter:= TWriteBufStream.Create(outputFileStream, 64 *1024 );
159171 try
160- Write(GenerateProgressBar(1 , FLineCount, 50 ), #13 );
172+ start:= Now;
173+ Write(GenerateProgressBar(1 , FLineCount, 50 , 0 , Now - start), #13 );
161174 // Generate the file
162175 for index:= 1 to FLineCount do
163176 begin
164177 stationId:= Random(FStationNames.Count);
165- randomTemp:= Random * (2 * cHottestTemp) - cHottestTemp;
166- line:= Format(' %s;%s' #13 #10 , [
167- FStationNames[stationId],
168- FormatFloat(' #0.0' , randomTemp)
169- ]);
178+ // This is all paweld magic:
179+ // From here
180+ randomTemp:= Random(1000 );
181+ randomTempStr:= IntToStr(randomTemp);
182+ case Ord(randomTempStr[0 ]) of
183+ 1 : randomTempFinal := ' 0.' + randomTempStr;
184+ 2 : randomTempFinal := randomTempStr[1 ] + ' .' + randomTempStr[2 ];
185+ 3 : randomTempFinal := randomTempStr[1 ] + randomTempStr[2 ] + ' .' + randomTempStr[3 ];
186+ 4 : randomTempFinal := randomTempStr[1 ] + randomTempStr[2 ] + randomTempStr[3 ] + ' .' + randomTempStr[4 ];
187+ end ;
188+ if (randomTemp <> 0 ) and (Random(2 ) = 1 ) then
189+ randomTempFinal := ' -' + randomTempFinal;
190+ line := line + FStationNames[stationId] + ' ;' + randomTempFinal + #13 #10 ;
170191 // Write(line);
171- outputBufWriter.WriteBuffer(line[1 ], Length(line));
192+ if index mod 10000 = 0 then
193+ begin
194+ outputFileStream.WriteBuffer(line[1 ], Length(line));
195+ line := ' ' ;
196+ end ;
197+ // To here
172198 Dec(progressBatch);
173199 if progressBatch = 0 then
174200 begin
175- Write(GenerateProgressBar(index, FLineCount, 50 ), #13 );
201+ Write(GenerateProgressBar(
202+ index,
203+ FLineCount,
204+ 50 ,
205+ outputFileStream.Size,
206+ Now - start
207+ ), #13 );
176208 progressBatch:= floor(FLineCount * (batchPercent / 100 ));
177209 end ;
178210 end ;
211+ if line <> ' ' then
212+ begin
213+ outputFileStream.WriteBuffer(line[1 ], Length(line));
214+ end ;
179215 finally
180216 outputBufWriter.Free;
181217 end ;
182218 finally
219+ WriteLn;
220+ WriteLn;
221+ WriteLn(Format(' Done: file size: %.n, elapsed: %s' , [
222+ Double(outputFileStream.Size),
223+ FormatDateTime(' n" min, "s" sec"' , Now - start)
224+ ]));
183225 outputFileStream.Free;
184226 end ;
185- WriteLn;
186227end ;
187228
188229end .
0 commit comments