File src/algs.cpp changed (mode: 100644) (index 68957f4..49fe0ba) |
29 |
29 |
#include "utils/float.hpp" |
#include "utils/float.hpp" |
30 |
30 |
#include "core.hpp" |
#include "core.hpp" |
31 |
31 |
|
|
|
32 |
|
struct FactorWeight |
|
33 |
|
{ |
|
34 |
|
float factor; |
|
35 |
|
|
|
36 |
|
FactorWeight(float factor) : factor(factor) |
|
37 |
|
{ } |
|
38 |
|
|
|
39 |
|
float operator()(int idx, float lastWeight) const |
|
40 |
|
{ |
|
41 |
|
return (idx == 0 ? 1.0f : lastWeight*factor); |
|
42 |
|
} |
|
43 |
|
}; |
|
44 |
|
|
32 |
45 |
template <float factor> |
template <float factor> |
33 |
46 |
float |
float |
34 |
47 |
factorWeight(int idx, float lastWeight) |
factorWeight(int idx, float lastWeight) |
35 |
|
{ return (idx == 0 ? 1.0f : lastWeight*factor); } |
|
|
48 |
|
{ return FactorWeight(factor)(idx, lastWeight); } |
36 |
49 |
|
|
37 |
50 |
static float |
static float |
38 |
51 |
indexWeight(int idx, float lastWeight) |
indexWeight(int idx, float lastWeight) |
|
... |
... |
SlownessAlg::estimate(int current, int total, int time) |
465 |
478 |
} |
} |
466 |
479 |
|
|
467 |
480 |
WindowAlg::WindowAlg(int windowSize, float alpha) : |
WindowAlg::WindowAlg(int windowSize, float alpha) : |
468 |
|
windowSize(windowSize), alpha(alpha) |
|
|
481 |
|
windowSize(windowSize), |
|
482 |
|
alpha(alpha), |
|
483 |
|
speeds(windowSize, FactorWeight(alpha)) |
469 |
484 |
{ } |
{ } |
470 |
485 |
|
|
471 |
486 |
std::string |
std::string |
|
... |
... |
WindowAlg::estimate(int current, int total, int time) |
488 |
503 |
return 0; |
return 0; |
489 |
504 |
} |
} |
490 |
505 |
|
|
491 |
|
speeds.push_back(float(current - lastProgress)/(time - lastTime)); |
|
492 |
|
|
|
493 |
|
if ((int)speeds.size() > windowSize) { |
|
494 |
|
speeds.erase(speeds.cbegin()); |
|
495 |
|
} |
|
496 |
|
|
|
497 |
|
float v = 0; |
|
498 |
|
float totalWeight = 0; |
|
499 |
|
float weight = alpha; |
|
500 |
|
for (int i = 0; i < (int)speeds.size(); ++i) { |
|
501 |
|
v += weight*speeds[i]; |
|
502 |
|
totalWeight += weight; |
|
503 |
|
weight *= alpha; |
|
504 |
|
} |
|
505 |
|
|
|
506 |
|
v /= totalWeight; |
|
507 |
|
|
|
|
506 |
|
float v = speeds.update(float(current - lastProgress)/(time - lastTime)); |
508 |
507 |
if (floatEq(v, 0)) { |
if (floatEq(v, 0)) { |
509 |
508 |
return lastEta + time - lastTime; |
return lastEta + time - lastTime; |
510 |
509 |
} |
} |
File src/algs.hpp changed (mode: 100644) (index bead426..9ab7ed0) |
18 |
18 |
#ifndef ETABENCH__ALGS_HPP__ |
#ifndef ETABENCH__ALGS_HPP__ |
19 |
19 |
#define ETABENCH__ALGS_HPP__ |
#define ETABENCH__ALGS_HPP__ |
20 |
20 |
|
|
|
21 |
|
#include <functional> |
21 |
22 |
#include <map> |
#include <map> |
22 |
23 |
#include <memory> |
#include <memory> |
23 |
24 |
#include <vector> |
#include <vector> |
|
26 |
27 |
|
|
27 |
28 |
class Window |
class Window |
28 |
29 |
{ |
{ |
29 |
|
using weight_f = float (*)(int idx, float lastWeight); |
|
|
30 |
|
using weight_f = std::function<float(int idx, float lastWeight)>; |
30 |
31 |
|
|
31 |
32 |
public: |
public: |
32 |
33 |
Window(int size, weight_f weight) : size(size), weight(weight) |
Window(int size, weight_f weight) : size(size), weight(weight) |
|
... |
... |
private: |
306 |
307 |
int lastTime; |
int lastTime; |
307 |
308 |
int lastProgress; |
int lastProgress; |
308 |
309 |
int lastEta; |
int lastEta; |
309 |
|
std::vector<int> speeds; |
|
|
310 |
|
Window speeds; |
310 |
311 |
}; |
}; |
311 |
312 |
|
|
312 |
313 |
class ExponentialAlg : public EtaAlg |
class ExponentialAlg : public EtaAlg |