From 8f175c481ebf1adbf7e9e06afb13c93c1b4c54a3 Mon Sep 17 00:00:00 2001 From: icylogic Date: Tue, 1 Mar 2016 22:25:32 +0800 Subject: [PATCH] filter out meanless data. --- shadowsocks-csharp/Model/StatisticsRecord.cs | 27 ++++++++++--------- .../StatisticsStrategyConfigurationForm.cs | 4 +-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/shadowsocks-csharp/Model/StatisticsRecord.cs b/shadowsocks-csharp/Model/StatisticsRecord.cs index 47015f75..5c1051a4 100644 --- a/shadowsocks-csharp/Model/StatisticsRecord.cs +++ b/shadowsocks-csharp/Model/StatisticsRecord.cs @@ -52,23 +52,26 @@ namespace Shadowsocks.Model public StatisticsRecord(string identifier, ICollection inboundSpeedRecords, ICollection outboundSpeedRecords, ICollection latencyRecords) { ServerIdentifier = identifier; - if (inboundSpeedRecords != null && inboundSpeedRecords.Any()) + var inbound = inboundSpeedRecords?.Where(s => s > 0).ToList(); + if (inbound != null && inbound.Any()) { - AverageInboundSpeed = (int) inboundSpeedRecords.Average(); - MinInboundSpeed = inboundSpeedRecords.Min(); - MaxInboundSpeed = inboundSpeedRecords.Max(); + AverageInboundSpeed = (int) inbound.Average(); + MinInboundSpeed = inbound.Min(); + MaxInboundSpeed = inbound.Max(); } - if (outboundSpeedRecords != null && outboundSpeedRecords.Any()) + var outbound = outboundSpeedRecords?.Where(s => s > 0).ToList(); + if (outbound!= null && outbound.Any()) { - AverageOutboundSpeed = (int) outboundSpeedRecords.Average(); - MinOutboundSpeed = outboundSpeedRecords.Min(); - MaxOutboundSpeed = outboundSpeedRecords.Max(); + AverageOutboundSpeed = (int) outbound.Average(); + MinOutboundSpeed = outbound.Min(); + MaxOutboundSpeed = outbound.Max(); } - if (latencyRecords != null && latencyRecords.Any()) + var latency = latencyRecords?.Where(s => s > 0).ToList(); + if (latency!= null && latency.Any()) { - AverageLatency = (int) latencyRecords.Average(); - MinLatency = latencyRecords.Min(); - MaxLatency = latencyRecords.Max(); + AverageLatency = (int) latency.Average(); + MinLatency = latency.Min(); + MaxLatency = latency.Max(); } } diff --git a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs index 42f8ee87..4f1b95ae 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs @@ -125,9 +125,9 @@ namespace Shadowsocks.View dataGroup.First().Timestamp, Speed = dataGroup.Max(data => data.MaxInboundSpeed) ?? 0, Ping = (int) (dataGroup.Average(data => data.AverageResponse) ?? 0), - PackageLossPercentage = (dataGroup.Average(data => data.PackageLoss) ?? 0) * 100 + PackageLossPercentage = (int) (dataGroup.Average(data => data.PackageLoss) ?? 0) * 100 }; - foreach (var data in finalData) + foreach (var data in finalData.Where(data => data.Speed != 0 || data.PackageLossPercentage != 0 || data.Ping != 0)) { _dataTable.Rows.Add(data.Timestamp, data.Speed, data.PackageLossPercentage, data.Ping); }