forked from leafgray/pysonar2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Progress.java
82 lines (61 loc) · 1.95 KB
/
Progress.java
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
79
80
81
82
package org.python.indexer;
public class Progress {
long startTime;
long total;
long dotInterval;
long reportInterval;
long count;
long mark;
public Progress(long dotInterval, long width, long total) {
this.startTime = System.currentTimeMillis();
this.dotInterval = dotInterval;
this.reportInterval = width * dotInterval;
this.total = total; // for calculating ETA
this.count = 0;
this.mark = reportInterval;
}
public Progress(long dotInterval, long width) {
this.startTime = System.currentTimeMillis();
this.dotInterval = dotInterval;
this.reportInterval = width * dotInterval;
this.total = -1;
this.count = 0;
this.mark = reportInterval;
}
public void tick(int n) {
long oldCount = count;
count += n;
if (count % dotInterval == 0) {
System.out.print(".");
}
// if the count goes cross the mark, report interval speed etc.
if (oldCount < mark && count >= mark) {
mark += reportInterval;
intervalReport();
}
}
public void tick() {
tick(1);
}
public void end() {
intervalReport();
System.out.println();
}
public void intervalReport() {
if (count % reportInterval == 0) {
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
long seconds = totalTime / 1000;
if (seconds == 0) { seconds = 1; }
long rate = count / seconds;
Util.msg("\n" + count + " items processed" +
", time: " + Util.timeString(totalTime) +
", rate: " + count / seconds);
if (total > 0) {
long rest = total - count;
long eta = rest / rate;
Util.msg("ETA: " + Util.timeString(eta * 1000));
}
}
}
}