ObjFW  Check-in [65681d0342]

Overview
Comment:utils/ofhttp: Show ETA
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 65681d03424b1035bc31287de00bd5694e7945a6a89fadb2d25eaeb11a2e14f9
User & Date: js on 2015-05-16 23:59:39
Other Links: manifest | tags
Context
2015-05-17
01:42
utils/ofhttp: Make sure bar width is >= 0 check-in: e4b34278f5 user: js tags: trunk
2015-05-16
23:59
utils/ofhttp: Show ETA check-in: 65681d0342 user: js tags: trunk
20:29
Rename OFDeflateStream -> OFInflateStream check-in: 2e9336b1ef user: js tags: trunk
Changes

Modified utils/ofhttp/ProgressBar.h from [41e4a8fdbc] to [88c7d2589b].

22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
@interface ProgressBar: OFObject
{
	intmax_t _received, _lastReceived, _length, _resumedFrom;
	OFDate *_startDate, *_lastReceivedDate;
	OFTimer *_drawTimer, *_BPSTimer;
	bool _stopped;
	float _BPS;

}

- initWithLength: (intmax_t)length
     resumedFrom: (intmax_t)resumedFrom;
- (void)setReceived: (intmax_t)received;
- (void)draw;
- (void)calculateBPS;
- (void)stop;
@end







>






|


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@interface ProgressBar: OFObject
{
	intmax_t _received, _lastReceived, _length, _resumedFrom;
	OFDate *_startDate, *_lastReceivedDate;
	OFTimer *_drawTimer, *_BPSTimer;
	bool _stopped;
	float _BPS;
	double _ETA;
}

- initWithLength: (intmax_t)length
     resumedFrom: (intmax_t)resumedFrom;
- (void)setReceived: (intmax_t)received;
- (void)draw;
- (void)calculateBPSAndETA;
- (void)stop;
@end

Modified utils/ofhttp/ProgressBar.m from [54fb752c1d] to [258ce39ec5].

51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
		    scheduledTimerWithTimeInterval: UPDATE_INTERVAL
					    target: self
					  selector: @selector(draw)
					   repeats: true] retain];
		_BPSTimer = [[OFTimer
		    scheduledTimerWithTimeInterval: 1.0
					    target: self
					  selector: @selector(calculateBPS)

					   repeats: true] retain];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}







|
>







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
		    scheduledTimerWithTimeInterval: UPDATE_INTERVAL
					    target: self
					  selector: @selector(draw)
					   repeats: true] retain];
		_BPSTimer = [[OFTimer
		    scheduledTimerWithTimeInterval: 1.0
					    target: self
					  selector: @selector(
							calculateBPSAndETA)
					   repeats: true] retain];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	uint_fast8_t i;
	float bars, percent;
	unsigned short barWidth;
#ifdef HAVE_SYS_IOCTL_H
	struct winsize ws;

	if (ioctl(0, TIOCGWINSZ, &ws) == 0)
		barWidth = ws.ws_col - 28;
	else
#endif
		barWidth = 52;

	bars = (float)(_resumedFrom + _received) /
	    (_resumedFrom + _length) * barWidth;
	percent = (float)(_resumedFrom + _received) /
	    (_resumedFrom + _length) * 100;

	[of_stdout writeString: @"\r  ▕"];







|


|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
	uint_fast8_t i;
	float bars, percent;
	unsigned short barWidth;
#ifdef HAVE_SYS_IOCTL_H
	struct winsize ws;

	if (ioctl(0, TIOCGWINSZ, &ws) == 0)
		barWidth = ws.ws_col - 37;
	else
#endif
		barWidth = 43;

	bars = (float)(_resumedFrom + _received) /
	    (_resumedFrom + _length) * barWidth;
	percent = (float)(_resumedFrom + _received) /
	    (_resumedFrom + _length) * 100;

	[of_stdout writeString: @"\r  ▕"];
127
128
129
130
131
132
133
134


135












136
137
138
139
140
141
142

		for (i = 0; i < barWidth - (uint_fast8_t)bars - 1; i++)
			[of_stdout writeString: @" "];
	}

	[of_stdout writeFormat: @"▏ %6.2f%% ", percent];

	if (percent == 100)


		_BPS = (float)_received / -[_startDate timeIntervalSinceNow];













	if (_BPS >= GIBIBYTE)
		[of_stdout writeFormat: @"%7.2f GiB/s", _BPS / GIBIBYTE];
	else if (_BPS >= MEBIBYTE)
		[of_stdout writeFormat: @"%7.2f MiB/s", _BPS / MEBIBYTE];
	else if (_BPS >= KIBIBYTE)
		[of_stdout writeFormat: @"%7.2f KiB/s", _BPS / KIBIBYTE];







|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

		for (i = 0; i < barWidth - (uint_fast8_t)bars - 1; i++)
			[of_stdout writeString: @" "];
	}

	[of_stdout writeFormat: @"▏ %6.2f%% ", percent];

	if (percent == 100) {
		double timeInterval = -[_startDate timeIntervalSinceNow];

		_BPS = (float)_received / timeInterval;
		_ETA = timeInterval;
	}

	if (isinf(_ETA))
		[of_stdout writeString: @"--:--:-- "];
	else if (_ETA >= 99 * 3600)
		[of_stdout writeFormat: @"%4.2f d ", _ETA / (24 * 3600)];
	else
		[of_stdout writeFormat: @"%2u:%02u:%02u ",
		    (unsigned char)(_ETA / 3600),
		    (unsigned char)(_ETA / 60) % 60,
		    (unsigned char)_ETA % 60];

	if (_BPS >= GIBIBYTE)
		[of_stdout writeFormat: @"%7.2f GiB/s", _BPS / GIBIBYTE];
	else if (_BPS >= MEBIBYTE)
		[of_stdout writeFormat: @"%7.2f MiB/s", _BPS / MEBIBYTE];
	else if (_BPS >= KIBIBYTE)
		[of_stdout writeFormat: @"%7.2f KiB/s", _BPS / KIBIBYTE];
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
{
	if (_length > 0)
		[self _drawProgress];
	else
		[self _drawReceived];
}

- (void)calculateBPS
{
	_BPS = (float)(_received - _lastReceived) /
	    -[_lastReceivedDate timeIntervalSinceNow];;


	_lastReceived = _received;
	[_lastReceivedDate release];
	_lastReceivedDate = [[OFDate alloc] init];
}

- (void)stop







|



>







194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
{
	if (_length > 0)
		[self _drawProgress];
	else
		[self _drawReceived];
}

- (void)calculateBPSAndETA
{
	_BPS = (float)(_received - _lastReceived) /
	    -[_lastReceivedDate timeIntervalSinceNow];;
	_ETA = (double)(_length - _resumedFrom - _resumedFrom) / _BPS;

	_lastReceived = _received;
	[_lastReceivedDate release];
	_lastReceivedDate = [[OFDate alloc] init];
}

- (void)stop