Better guard against negative ping values

This commit is contained in:
Rsl1122 2018-07-16 17:24:44 +03:00
parent 6f11dc33ac
commit a836b7a362
6 changed files with 40 additions and 11 deletions

View File

@ -26,7 +26,7 @@ public class PingMutator {
public PingMutator filterBy(Predicate<Ping> predicate) { public PingMutator filterBy(Predicate<Ping> predicate) {
return new PingMutator(pings.stream().filter(predicate).collect(Collectors.toList())); return new PingMutator(pings.stream().filter(predicate).collect(Collectors.toList()));
} }
public PingMutator filterByServer(UUID serverUUID) { public PingMutator filterByServer(UUID serverUUID) {
return filterBy(ping -> serverUUID.equals(ping.getServerUUID())); return filterBy(ping -> serverUUID.equals(ping.getServerUUID()));
} }
@ -52,6 +52,9 @@ public class PingMutator {
int max = -1; int max = -1;
for (Ping ping : pings) { for (Ping ping : pings) {
Integer value = ping.getMax(); Integer value = ping.getMax();
if (value < 0) {
continue;
}
if (value > max) { if (value > max) {
max = value; max = value;
} }
@ -64,6 +67,9 @@ public class PingMutator {
int min = -1; int min = -1;
for (Ping ping : pings) { for (Ping ping : pings) {
Integer value = ping.getMin(); Integer value = ping.getMin();
if (value < 0) {
continue;
}
if (value < min || min == -1) { if (value < min || min == -1) {
min = value; min = value;
} }
@ -73,6 +79,8 @@ public class PingMutator {
} }
public double average() { public double average() {
return pings.stream().mapToDouble(Ping::getAverage).average().orElse(-1); return pings.stream().mapToDouble(Ping::getAverage)
.filter(value -> value >= 0)
.average().orElse(-1);
} }
} }

View File

@ -56,7 +56,8 @@ public class PingTable extends UserIDTable {
public void clean() { public void clean() {
String sql = "DELETE FROM " + tableName + String sql = "DELETE FROM " + tableName +
" WHERE (" + Col.DATE + "<?)"; " WHERE (" + Col.DATE + "<?)" +
" OR (" + Col.MIN_PING + "<0)";
execute(new ExecStatement(sql) { execute(new ExecStatement(sql) {
@Override @Override

View File

@ -37,7 +37,7 @@ public class PingInsertProcessor implements CriticalRunnable {
long lastDate = history.get(history.size() - 1).getDate(); long lastDate = history.get(history.size() - 1).getDate();
OptionalInt max = history.stream() OptionalInt max = history.stream()
.mapToInt(DateObj::getValue) .mapToInt(DateObj::getValue)
.filter(i -> i != -1) .filter(i -> i >= 0)
.max(); .max();
if (!max.isPresent()) { if (!max.isPresent()) {
@ -46,12 +46,12 @@ public class PingInsertProcessor implements CriticalRunnable {
int minValue = history.stream() int minValue = history.stream()
.mapToInt(DateObj::getValue) .mapToInt(DateObj::getValue)
.filter(i -> i != -1) .filter(i -> i >= 0)
.min().orElse(-1); .min().orElse(-1);
double avgValue = history.stream() double avgValue = history.stream()
.mapToInt(DateObj::getValue) .mapToInt(DateObj::getValue)
.filter(i -> i != -1) .filter(i -> i >= 0)
.average().orElse(-1); .average().orElse(-1);
int maxValue = max.getAsInt(); int maxValue = max.getAsInt();

View File

@ -155,7 +155,7 @@ public class PingCountTimer extends AbsRunnable implements Listener {
addPlayer(player); addPlayer(player);
} }
} }
}).runTaskLater(PING_INTERVAL); }).runTaskLater(PING_INTERVAL * 2);
} }
@EventHandler @EventHandler

View File

@ -14,8 +14,8 @@ public class PingTable extends TableContainer {
super( super(
Icon.called("globe") + " Country", Icon.called("globe") + " Country",
Icon.called("signal") + " Average Ping", Icon.called("signal") + " Average Ping",
Icon.called("signal") + " Maximum Ping", Icon.called("signal") + " Worst Ping",
Icon.called("signal") + " Minimum Ping" Icon.called("signal") + " Best Ping"
); );
setColor("amber"); setColor("amber");

View File

@ -1064,7 +1064,27 @@
</div> </div>
<div class="row clearfix"> <div class="row clearfix">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
${tablePing} <div class="card">
<div class="header">
<div class="row clearfix">
<div class="col-xs-8 col-sm-8 col-lg-8">
<h2><i class="fa fa-wifi"></i> Connection Information</h2>
</div>
<div class="col-xs-4 col-sm-4 col-lg-4">
<a href="javascript:void(0)" class="help material-icons pull-right"
tabindex="0" data-trigger="focus" data-toggle="popover" data-placement="left"
data-container="body" data-html="true"
data-original-title="Connection Information"
data-content="Ping gathered by Ping task - Ping data is stored for 2 weeks.<br><br>
Geolocations are not directly linked to ping data, so player's ping is placed under the most recent login location."
>help_outline</a>
</div>
</div>
</div>
<div class="panel panel-default">
${tablePing}
</div>
</div>
</div> </div>
</div> </div>
<!-- #END# Geolocations --> <!-- #END# Geolocations -->
@ -1436,7 +1456,7 @@
healthGauge('healthGauge', [v.data.healthIndex]); healthGauge('healthGauge', [v.data.healthIndex]);
onlineActivityCalendar('#calendar', v.data.calendar, v.values.firstDay); onlineActivityCalendar('#calendar', v.data.calendar, v.values.firstDay);
horizontalBarChart('countryBarChart', v.data.countryCategories, [series.country], 'Players'); horizontalBarChart('countryBarChart', v.data.countryCategories, [series.country], 'Players');
lineChart('pingGraph', [series.playersOnline, series.avgPing, series.maxPing, series.minPing]); lineChart('pingGraph', [series.avgPing, series.maxPing, series.minPing]);
${sessionTabGraphViewFunctions} ${sessionTabGraphViewFunctions}
/**/ /**/