summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2017-06-05 17:44:31 +0200
committerArne Schwabe <arne@rfc2549.org>2017-06-05 17:44:31 +0200
commit407796ae7d121613ab8633437e557b430e83fa84 (patch)
tree03d485b3429cdd919478c65f4114a84167452d62 /main/src
parentc42ca589361afc8a703edaef5f2bca7c81142952 (diff)
Graph fixes
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java9
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java34
2 files changed, 28 insertions, 15 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java b/main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java
index 019f58be..6ba35066 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/TrafficHistory.java
@@ -20,6 +20,9 @@ import static java.lang.Math.max;
public class TrafficHistory implements Parcelable {
+ public static final long PERIODS_TO_KEEP = 5;
+ public static final int TIME_PERIOD_MINTUES = 60 * 1000;
+ public static final int TIME_PERIOD_HOURS = 3600 * 1000;
private LinkedList<TrafficDatapoint> trafficHistorySeconds = new LinkedList<>();
private LinkedList<TrafficDatapoint> trafficHistoryMinutes = new LinkedList<>();
private LinkedList<TrafficDatapoint> trafficHistoryHours = new LinkedList<>();
@@ -179,12 +182,12 @@ public class TrafficHistory implements Parcelable {
TrafficDatapoint lastTsPeriod;
if (seconds) {
- timePeriod = 60 * 1000;
+ timePeriod = TIME_PERIOD_MINTUES;
tpList = trafficHistorySeconds;
nextList = trafficHistoryMinutes;
lastTsPeriod = lastSecondUsedForMinute;
} else {
- timePeriod = 3600 * 1000;
+ timePeriod = TIME_PERIOD_HOURS;
tpList = trafficHistoryMinutes;
nextList = trafficHistoryHours;
lastTsPeriod = lastMinuteUsedForHours;
@@ -201,7 +204,7 @@ public class TrafficHistory implements Parcelable {
for (TrafficDatapoint tph : tpList) {
// List is iteratered from oldest to newest, remembert first one that we did not
- if ((newTdp.timestamp - tph.timestamp) / timePeriod > 4)
+ if ((newTdp.timestamp - tph.timestamp) / timePeriod >= PERIODS_TO_KEEP)
toRemove.add(tph);
}
tpList.removeAll(toRemove);
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java b/main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java
index 8273ca9b..3942285f 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java
@@ -274,20 +274,25 @@ public class GraphFragment extends Fragment implements VpnStatus.ByteCountListen
LinkedList<Entry> dataOut = new LinkedList<>();
long interval;
+ long totalInterval;
LinkedList<TrafficHistory.TrafficDatapoint> list;
switch (timeperiod) {
case TIME_PERIOD_HOURS:
list = VpnStatus.trafficHistory.getHours();
- interval = 3600 ;
+ interval = TrafficHistory.TIME_PERIOD_HOURS;
+ totalInterval = 0;
break;
case TIME_PERIOD_MINUTES:
list = VpnStatus.trafficHistory.getMinutes();
- interval = 60;
+ interval = TrafficHistory.TIME_PERIOD_MINTUES;
+ totalInterval = TrafficHistory.TIME_PERIOD_HOURS * TrafficHistory.PERIODS_TO_KEEP;;
+
break;
default:
list = VpnStatus.trafficHistory.getSeconds();
- interval = OpenVPNManagement.mBytecountInterval ;
+ interval = OpenVPNManagement.mBytecountInterval * 1000;
+ totalInterval = TrafficHistory.TIME_PERIOD_MINTUES * TrafficHistory.PERIODS_TO_KEEP;
break;
}
if (list.size()==0) {
@@ -305,11 +310,17 @@ public class GraphFragment extends Fragment implements VpnStatus.ByteCountListen
else
zeroValue=0;
+ long now = System.currentTimeMillis();
+
+
for (TrafficHistory.TrafficDatapoint tdp: list){
+ if (totalInterval !=0 && (now - tdp.timestamp) > totalInterval)
+ continue;
+
float t = (tdp.timestamp - firstTimestamp) / 100f;
- float in = (tdp.in - lastBytecountIn)/ (float) interval;
- float out = (tdp.out - lastBytecountOut) / (float) interval;
+ float in = (tdp.in - lastBytecountIn)/ (float) (interval/1000);
+ float out = (tdp.out - lastBytecountOut) / (float) (interval/1000);
lastBytecountIn = tdp.in;
lastBytecountOut = tdp.out;
@@ -319,12 +330,12 @@ public class GraphFragment extends Fragment implements VpnStatus.ByteCountListen
out = max(2f, (float) Math.log10(out* 8));
}
- if (lastts > 0 && ( tdp.timestamp -lastts> 2 * interval*1000)){
- dataIn.add(new Entry((lastts- firstTimestamp + interval*1000)/100f, zeroValue));
- dataOut.add(new Entry((lastts- firstTimestamp + interval*1000)/100f, zeroValue));
+ if (lastts > 0 && ( tdp.timestamp -lastts> 2 * interval)){
+ dataIn.add(new Entry((lastts- firstTimestamp + interval)/100f, zeroValue));
+ dataOut.add(new Entry((lastts- firstTimestamp + interval)/100f, zeroValue));
- dataIn.add(new Entry(t - interval*10f, zeroValue));
- dataOut.add(new Entry(t - interval*10f, zeroValue));
+ dataIn.add(new Entry(t - interval/100f, zeroValue));
+ dataOut.add(new Entry(t - interval/100f, zeroValue));
}
lastts = tdp.timestamp;
@@ -333,8 +344,7 @@ public class GraphFragment extends Fragment implements VpnStatus.ByteCountListen
dataOut.add(new Entry(t,out));
}
- long now = System.currentTimeMillis();
- if (lastts < now-interval* 1000L) {
+ if (lastts < now-interval) {
if (now -lastts > 2 * interval*1000) {
dataIn.add(new Entry((lastts- firstTimestamp+ interval*1000)/100f, zeroValue));