File src/algs.cpp changed (mode: 100644) (index 49fe0ba..1fae56c) |
... |
... |
SwitchAlg::estimate(int current, int total, int time) |
300 |
300 |
return time - it->second; |
return time - it->second; |
301 |
301 |
} |
} |
302 |
302 |
|
|
|
303 |
|
GravityAlg::GravityAlg() : speeds(-1, &indexWeight) |
|
304 |
|
{ } |
|
305 |
|
|
303 |
306 |
void |
void |
304 |
307 |
GravityAlg::reset() |
GravityAlg::reset() |
305 |
308 |
{ |
{ |
|
... |
... |
GravityAlg::estimate(int current, int total, int time) |
319 |
322 |
|
|
320 |
323 |
int lastTimeElapsed = time - lastTime; |
int lastTimeElapsed = time - lastTime; |
321 |
324 |
|
|
322 |
|
speeds.push_back(float(current - lastProgress)/lastTimeElapsed); |
|
323 |
|
|
|
324 |
|
// Scales are 1/s, 2/s, ..., speeds.size()/s |
|
325 |
|
// Where s = 1 + 2 + ... speeds.size() |
|
326 |
|
// They sum to 1. |
|
327 |
|
float scaleDiv = (1 + speeds.size())*speeds.size()/2.0f; |
|
328 |
|
|
|
329 |
|
float v = 0; |
|
330 |
|
for (int i = 0; i < (int)speeds.size(); ++i) { |
|
331 |
|
float scaleFactor = (i + 1)/scaleDiv; |
|
332 |
|
v += scaleFactor*speeds[i]; |
|
333 |
|
} |
|
|
325 |
|
float v = speeds.update(float(current - lastProgress)/lastTimeElapsed); |
334 |
326 |
|
|
335 |
327 |
const float mass = (lastTime == 0 ? 1.0f : 4.0f); |
const float mass = (lastTime == 0 ? 1.0f : 4.0f); |
336 |
328 |
const float maxSpeedCoeff = 0.25f; |
const float maxSpeedCoeff = 0.25f; |
File src/algs.hpp changed (mode: 100644) (index 9ab7ed0..8b10a13) |
... |
... |
class Window |
30 |
30 |
using weight_f = std::function<float(int idx, float lastWeight)>; |
using weight_f = std::function<float(int idx, float lastWeight)>; |
31 |
31 |
|
|
32 |
32 |
public: |
public: |
|
33 |
|
// Pass in negative size for unlimited window size. |
33 |
34 |
Window(int size, weight_f weight) : size(size), weight(weight) |
Window(int size, weight_f weight) : size(size), weight(weight) |
34 |
35 |
{ } |
{ } |
35 |
36 |
|
|
|
... |
... |
public: |
41 |
42 |
{ |
{ |
42 |
43 |
// Emulating circular buffer. |
// Emulating circular buffer. |
43 |
44 |
data.push_back(datum); |
data.push_back(datum); |
44 |
|
if ((int)data.size() > size) { |
|
|
45 |
|
if ((int)data.size() == size) { |
45 |
46 |
data.erase(data.cbegin()); |
data.erase(data.cbegin()); |
46 |
47 |
} |
} |
47 |
48 |
} |
} |
|
... |
... |
private: |
212 |
213 |
|
|
213 |
214 |
class GravityAlg : public EtaAlg |
class GravityAlg : public EtaAlg |
214 |
215 |
{ |
{ |
|
216 |
|
public: |
|
217 |
|
GravityAlg(); |
|
218 |
|
|
215 |
219 |
public: |
public: |
216 |
220 |
virtual std::string getName() const override |
virtual std::string getName() const override |
217 |
221 |
{ return "Gravity"; } |
{ return "Gravity"; } |
|
... |
... |
private: |
225 |
229 |
int lastTime; |
int lastTime; |
226 |
230 |
float avgProgressRate; |
float avgProgressRate; |
227 |
231 |
float avgSeekRate; |
float avgSeekRate; |
228 |
|
std::vector<float> speeds; |
|
|
232 |
|
Window speeds; |
229 |
233 |
}; |
}; |
230 |
234 |
|
|
231 |
235 |
class FirefoxAlg : public EtaAlg |
class FirefoxAlg : public EtaAlg |