File src/algs.cpp changed (mode: 100644) (index 5b54826..4f218e8) |
... |
... |
FirefoxAlg::reset() |
376 |
376 |
lastEta = 0; |
lastEta = 0; |
377 |
377 |
lastProgress = 0; |
lastProgress = 0; |
378 |
378 |
lastTime = 0; |
lastTime = 0; |
|
379 |
|
speed = 0; |
379 |
380 |
} |
} |
380 |
381 |
|
|
381 |
382 |
int |
int |
382 |
383 |
FirefoxAlg::estimate(int current, int total, int time) |
FirefoxAlg::estimate(int current, int total, int time) |
383 |
384 |
{ |
{ |
384 |
385 |
float v = float(current - lastProgress)/(time - lastTime); |
float v = float(current - lastProgress)/(time - lastTime); |
385 |
|
speed = v*0.1f + speed*0.9f; |
|
|
386 |
|
if (lastTime == 0) |
|
387 |
|
speed = v; |
|
388 |
|
else |
|
389 |
|
speed = v*0.1f + speed*0.9f; |
386 |
390 |
|
|
387 |
391 |
float eta = (total - current)/speed; |
float eta = (total - current)/speed; |
388 |
392 |
|
|
389 |
393 |
// Apply hysteresis to favor downward over upward swings 30% of down and 10% |
// Apply hysteresis to favor downward over upward swings 30% of down and 10% |
390 |
394 |
// of up (exponential smoothing). |
// of up (exponential smoothing). |
391 |
395 |
float etaDiff = eta - lastEta; |
float etaDiff = eta - lastEta; |
392 |
|
eta = lastEta + (etaDiff < 0 ? 0.3 : (lastTime == 0 ? 0.4 : 0.1))*etaDiff; |
|
|
396 |
|
eta = lastEta + (lastTime == 0 ? 1.0f : etaDiff < 0 ? 0.3f : 0.1f)*etaDiff; |
393 |
397 |
|
|
394 |
398 |
// If the new ETA is similar, reuse something close to the last ETA, but |
// If the new ETA is similar, reuse something close to the last ETA, but |
395 |
399 |
// subtract a little to provide forward progress. |
// subtract a little to provide forward progress. |