@@ -25,7 +25,10 @@ TGenerator = class(TObject)
25
25
FStationNames: TStringList;
26
26
27
27
procedure BuildStationNames ;
28
- function GenerateProgressBar (APosition, AMax, ALength:Int64):String;
28
+ function GenerateProgressBar (
29
+ APBPosition, APBMax, APBWIdth, AFileSize:Int64;
30
+ ATimeElapsed: TDateTime
31
+ ):String;
29
32
protected
30
33
public
31
34
constructor Create(AInputFile, AOutputFile: String; ALineCount: Int64);
@@ -119,28 +122,37 @@ procedure TGenerator.BuildStationNames;
119
122
WriteLn;
120
123
end ;
121
124
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;
124
129
var
125
130
percentDone: Double;
126
131
filled: Integer;
127
132
begin
128
- percentDone:= (100 * APosition ) / AMax ;
129
- filled:= (ALength * APosition ) div AMax ;
133
+ percentDone:= (100 * APBPosition ) / APBMax ;
134
+ filled:= (APBWIdth * APBPosition ) div APBMax ;
130
135
Result:= ' [' ;
131
136
Result:= Result + StringOfChar(' #' , filled);
132
- Result:= Result + StringOfChar(' -' , ALength - filled);
137
+ Result:= Result + StringOfChar(' -' , APBWIdth - filled);
133
138
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
+ ]);
134
144
end ;
135
145
136
146
procedure TGenerator.Generate ;
137
147
var
138
148
index, progressBatch: Int64;
139
149
stationId: Int64;
140
- randomTemp: Double;
150
+ randomTemp: Integer;
151
+ randomTempStr: String[4 ];
141
152
outputFileStream: TFileStream;
142
153
outputBufWriter: TWriteBufStream;
143
- line: String;
154
+ line, randomTempFinal: String;
155
+ start: TDateTime;
144
156
begin
145
157
// Randomize sets this variable depending on the current time
146
158
// We just set it to our own value
@@ -157,32 +169,61 @@ procedure TGenerator.Generate;
157
169
// outputBufWriter:= TWriteBufStream.Create(outputFileStream, 4*1024);
158
170
outputBufWriter:= TWriteBufStream.Create(outputFileStream, 64 *1024 );
159
171
try
160
- Write(GenerateProgressBar(1 , FLineCount, 50 ), #13 );
172
+ start:= Now;
173
+ Write(GenerateProgressBar(1 , FLineCount, 50 , 0 , Now - start), #13 );
161
174
// Generate the file
162
175
for index:= 1 to FLineCount do
163
176
begin
164
177
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 ;
170
191
// 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
172
198
Dec(progressBatch);
173
199
if progressBatch = 0 then
174
200
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 );
176
208
progressBatch:= floor(FLineCount * (batchPercent / 100 ));
177
209
end ;
178
210
end ;
211
+ if line <> ' ' then
212
+ begin
213
+ outputFileStream.WriteBuffer(line[1 ], Length(line));
214
+ end ;
179
215
finally
180
216
outputBufWriter.Free;
181
217
end ;
182
218
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
+ ]));
183
225
outputFileStream.Free;
184
226
end ;
185
- WriteLn;
186
227
end ;
187
228
188
229
end .
0 commit comments