forked from etotheipi/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgress.cpp
More file actions
78 lines (63 loc) · 2.01 KB
/
Progress.cpp
File metadata and controls
78 lines (63 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2011-2015, Armory Technologies, Inc. //
// Distributed under the GNU Affero General Public License (AGPL v3) //
// See LICENSE or http://www.gnu.org/licenses/agpl.html //
// //
////////////////////////////////////////////////////////////////////////////////
#include "Progress.h"
ProgressCalculator::ProgressCalculator(uint64_t total)
: total_(total)
{
then_ = 0;
}
void ProgressCalculator::advance(uint64_t to)
{
static const double smoothingFactor=.10;
if (to == lastSample_) return;
const time_t now = time(0);
if (then_ == 0)
{
then_ = now;
lastSample_ = to;
}
if (now == then_) return;
if (now < then_+10) return;
double speed = (to-lastSample_)/double(now-then_);
if (lastSample_ == 0)
avgSpeed_ = speed;
lastSample_ = to;
avgSpeed_ = smoothingFactor*speed + (1-smoothingFactor)*avgSpeed_;
then_ = now;
}
ProgressReporterFilter::ProgressReporterFilter(ProgressReporter *to)
: to_(to)
{ }
void ProgressReporterFilter::progress(
double progress, unsigned secondsRemaining
)
{
secondsRemaining_ = secondsRemaining;
progress_ = progress;
to_->progress(progress, secondsRemaining);
}
ProgressFilter::ProgressFilter(ProgressReporter *to, int64_t offset, uint64_t total)
: ProgressReporterFilter(to), calc_(total), offset_(offset)
{
advance(0);
}
ProgressFilter::ProgressFilter(ProgressReporter *to, uint64_t total)
: ProgressReporterFilter(to), calc_(total)
{
advance(0);
}
ProgressFilter::~ProgressFilter()
{
advance(calc_.total());
}
void ProgressFilter::advance(uint64_t to)
{
calc_.advance(to+offset_);
progress(calc_.fractionCompleted(), calc_.remainingSeconds());
}
// kate: indent-width 3; replace-tabs on;