From b9632f8636b1a5eab2b71737be9c2c16a1a2f09b Mon Sep 17 00:00:00 2001 From: icylogic Date: Wed, 30 Sep 2015 23:54:36 +0800 Subject: [PATCH] basic statistics form UI --- .../Service/AvailabilityStatistics.cs | 35 ++- .../View/CalculationControl.Designer.cs | 14 +- ...sticsStrategyConfigurationForm.Designer.cs | 256 +++++++++--------- .../StatisticsStrategyConfigurationForm.cs | 55 +++- .../StatisticsStrategyConfigurationForm.resx | 5 +- 5 files changed, 211 insertions(+), 154 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs index 97afc477..7bc2500e 100644 --- a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs +++ b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs @@ -82,32 +82,41 @@ namespace Shadowsocks.Controller public static async Task GetGeolocationAndIsp() { Logging.Debug("Retrive information of geolocation and isp"); - const string api = "http://ip-api.com/json"; - var ret = new DataList + const string API = "http://ip-api.com/json"; + const string alternativeAPI = "http://www.telize.com/geoip"; //must be compatible with current API + var result = await GetInfoFromAPI(API); + if (result != null) return result; + result = await GetInfoFromAPI(alternativeAPI); + if (result != null) return result; + return new DataList { new DataUnit(State.Geolocation, State.Unknown), new DataUnit(State.ISP, State.Unknown) }; + } + + private static async Task GetInfoFromAPI(string API) + { string jsonString; try { - jsonString = await new HttpClient().GetStringAsync(api); + jsonString = await new HttpClient().GetStringAsync(API); } catch (HttpRequestException e) { Logging.LogUsefulException(e); - return ret; + return null; } dynamic obj; - if (!SimpleJson.SimpleJson.TryDeserializeObject(jsonString, out obj)) return ret; + if (!SimpleJson.SimpleJson.TryDeserializeObject(jsonString, out obj)) return null; string country = obj["country"]; string city = obj["city"]; string isp = obj["isp"]; - string regionName = obj["regionName"]; - if (country == null || city == null || isp == null || regionName == null) return ret; - ret[0] = new DataUnit(State.Geolocation, $"{country} | {regionName} | {city}"); - ret[1] = new DataUnit(State.ISP, isp); - return ret; + if (country == null || city == null || isp == null) return null; + return new DataList { + new DataUnit(State.Geolocation, $"{country} {city}"), + new DataUnit(State.ISP, isp) + }; } private async Task> ICMPTest(Server server) @@ -195,7 +204,7 @@ namespace Shadowsocks.Controller _servers = config.configs; } - private void FilterRawStatistics() + private async void FilterRawStatistics() { if (FilteredStatistics == null) { @@ -206,7 +215,7 @@ namespace Shadowsocks.Controller var filteredData = rawData; if (_config.ByIsp) { - var current = GetGeolocationAndIsp().Result; + var current = await GetGeolocationAndIsp(); filteredData = filteredData.Where( data => @@ -230,7 +239,7 @@ namespace Shadowsocks.Controller FilteredStatistics[serverName] = dataList; } } - + private void LoadRawStatistics() { try diff --git a/shadowsocks-csharp/View/CalculationControl.Designer.cs b/shadowsocks-csharp/View/CalculationControl.Designer.cs index 19b9d222..b5a9bfab 100644 --- a/shadowsocks-csharp/View/CalculationControl.Designer.cs +++ b/shadowsocks-csharp/View/CalculationControl.Designer.cs @@ -44,7 +44,7 @@ 0, 0, 131072}); - this.factorNum.Location = new System.Drawing.Point(320, 7); + this.factorNum.Location = new System.Drawing.Point(285, 5); this.factorNum.Minimum = new decimal(new int[] { 1000, 0, @@ -58,7 +58,7 @@ // this.multiply.AutoSize = true; this.multiply.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.multiply.Location = new System.Drawing.Point(286, 9); + this.multiply.Location = new System.Drawing.Point(251, 7); this.multiply.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.multiply.Name = "multiply"; this.multiply.Size = new System.Drawing.Size(26, 28); @@ -69,7 +69,7 @@ // this.plus.AutoSize = true; this.plus.Font = new System.Drawing.Font("Segoe UI", 10F); - this.plus.Location = new System.Drawing.Point(5, 9); + this.plus.Location = new System.Drawing.Point(5, 7); this.plus.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.plus.Name = "plus"; this.plus.Size = new System.Drawing.Size(26, 28); @@ -79,10 +79,12 @@ // valueLabel // this.valueLabel.AutoSize = true; - this.valueLabel.Location = new System.Drawing.Point(39, 17); + this.valueLabel.Font = new System.Drawing.Font("Microsoft YaHei", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.valueLabel.Location = new System.Drawing.Point(39, 11); this.valueLabel.Name = "valueLabel"; - this.valueLabel.Size = new System.Drawing.Size(0, 18); + this.valueLabel.Size = new System.Drawing.Size(118, 24); this.valueLabel.TabIndex = 7; + this.valueLabel.Text = "PackageLoss"; // // CalculationControl // @@ -93,7 +95,7 @@ this.Controls.Add(this.multiply); this.Controls.Add(this.plus); this.Name = "CalculationControl"; - this.Size = new System.Drawing.Size(425, 46); + this.Size = new System.Drawing.Size(380, 46); ((System.ComponentModel.ISupportInitialize)(this.factorNum)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs index 44c8a872..b1200e32 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs @@ -29,18 +29,18 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.StatisticsChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.byISPCheckBox = new System.Windows.Forms.CheckBox(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); - this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.radioButton2 = new System.Windows.Forms.RadioButton(); - this.radioButton1 = new System.Windows.Forms.RadioButton(); + this.chartModeSelector = new System.Windows.Forms.GroupBox(); + this.allMode = new System.Windows.Forms.RadioButton(); + this.dayMode = new System.Windows.Forms.RadioButton(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.label9 = new System.Windows.Forms.Label(); @@ -54,12 +54,12 @@ this.splitContainer3 = new System.Windows.Forms.SplitContainer(); this.label1 = new System.Windows.Forms.Label(); this.calculationContainer = new System.Windows.Forms.FlowLayoutPanel(); + this.serverSelector = new System.Windows.Forms.ComboBox(); this.CancelButton = new System.Windows.Forms.Button(); this.OKButton = new System.Windows.Forms.Button(); this.bindingConfiguration = new System.Windows.Forms.BindingSource(this.components); - this.serverSelector = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.StatisticsChart)).BeginInit(); - this.groupBox1.SuspendLayout(); + this.chartModeSelector.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -81,45 +81,47 @@ // StatisticsChart // this.StatisticsChart.BackColor = System.Drawing.Color.Transparent; - chartArea3.AxisX.MajorGrid.Enabled = false; - chartArea3.AxisY.MajorGrid.Enabled = false; - chartArea3.AxisY2.MajorGrid.Enabled = false; - chartArea3.BackColor = System.Drawing.Color.Transparent; - chartArea3.Name = "ChartArea"; - this.StatisticsChart.ChartAreas.Add(chartArea3); + chartArea1.AxisX.MajorGrid.Enabled = false; + chartArea1.AxisY.MajorGrid.Enabled = false; + chartArea1.AxisY2.MajorGrid.Enabled = false; + chartArea1.BackColor = System.Drawing.Color.Transparent; + chartArea1.Name = "DataArea"; + this.StatisticsChart.ChartAreas.Add(chartArea1); this.StatisticsChart.Dock = System.Windows.Forms.DockStyle.Fill; - legend3.BackColor = System.Drawing.Color.Transparent; - legend3.Name = "ChartLegend"; - this.StatisticsChart.Legends.Add(legend3); + legend1.BackColor = System.Drawing.Color.Transparent; + legend1.Name = "ChartLegend"; + this.StatisticsChart.Legends.Add(legend1); this.StatisticsChart.Location = new System.Drawing.Point(0, 0); this.StatisticsChart.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.StatisticsChart.Name = "StatisticsChart"; this.StatisticsChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Pastel; - series5.ChartArea = "ChartArea"; - series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; - series5.Color = System.Drawing.Color.FromArgb(((int)(((byte)(221)))), ((int)(((byte)(88)))), ((int)(((byte)(0))))); - series5.Legend = "ChartLegend"; - series5.Name = "Package Loss"; - series5.YValuesPerPoint = 4; - series6.BorderWidth = 4; - series6.ChartArea = "ChartArea"; - series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series6.Color = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(77)))), ((int)(((byte)(150))))); - series6.Legend = "ChartLegend"; - series6.Name = "Ping"; - this.StatisticsChart.Series.Add(series5); - this.StatisticsChart.Series.Add(series6); - this.StatisticsChart.Size = new System.Drawing.Size(1061, 314); + series1.ChartArea = "DataArea"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; + series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(221)))), ((int)(((byte)(88)))), ((int)(((byte)(0))))); + series1.Legend = "ChartLegend"; + series1.Name = "Package Loss"; + series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime; + series1.YValuesPerPoint = 2; + series2.BorderWidth = 4; + series2.ChartArea = "DataArea"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(77)))), ((int)(((byte)(150))))); + series2.Legend = "ChartLegend"; + series2.Name = "Ping"; + series2.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime; + this.StatisticsChart.Series.Add(series1); + this.StatisticsChart.Series.Add(series2); + this.StatisticsChart.Size = new System.Drawing.Size(1077, 303); this.StatisticsChart.TabIndex = 2; // // byISPCheckBox // this.byISPCheckBox.AutoSize = true; this.byISPCheckBox.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.bindingConfiguration, "ByIsp", true)); - this.byISPCheckBox.Location = new System.Drawing.Point(12, 56); + this.byISPCheckBox.Location = new System.Drawing.Point(13, 54); this.byISPCheckBox.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.byISPCheckBox.Name = "byISPCheckBox"; - this.byISPCheckBox.Size = new System.Drawing.Size(204, 32); + this.byISPCheckBox.Size = new System.Drawing.Size(220, 31); this.byISPCheckBox.TabIndex = 5; this.byISPCheckBox.Text = "By ISP/geolocation"; this.byISPCheckBox.UseVisualStyleBackColor = true; @@ -127,70 +129,73 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(7, 141); + this.label2.Location = new System.Drawing.Point(8, 136); this.label2.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(152, 28); + this.label2.Size = new System.Drawing.Size(167, 27); this.label2.TabIndex = 8; this.label2.Text = "Keep choice for "; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(261, 141); + this.label3.Location = new System.Drawing.Point(285, 136); this.label3.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(81, 28); + this.label3.Size = new System.Drawing.Size(87, 27); this.label3.TabIndex = 9; this.label3.Text = "minutes"; // // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(7, 226); + this.label4.Location = new System.Drawing.Point(8, 218); this.label4.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(51, 28); + this.label4.Size = new System.Drawing.Size(54, 27); this.label4.TabIndex = 10; this.label4.Text = "Ping"; // - // groupBox1 - // - this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.groupBox1.Controls.Add(this.radioButton2); - this.groupBox1.Controls.Add(this.radioButton1); - this.groupBox1.Location = new System.Drawing.Point(808, 114); - this.groupBox1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Padding = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.groupBox1.Size = new System.Drawing.Size(239, 107); - this.groupBox1.TabIndex = 3; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "Chart Mode"; - // - // radioButton2 - // - this.radioButton2.AutoSize = true; - this.radioButton2.Checked = true; - this.radioButton2.Location = new System.Drawing.Point(10, 63); - this.radioButton2.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.radioButton2.Name = "radioButton2"; - this.radioButton2.Size = new System.Drawing.Size(57, 32); - this.radioButton2.TabIndex = 1; - this.radioButton2.TabStop = true; - this.radioButton2.Text = "all"; - this.radioButton2.UseVisualStyleBackColor = true; - // - // radioButton1 - // - this.radioButton1.AutoSize = true; - this.radioButton1.Location = new System.Drawing.Point(10, 30); - this.radioButton1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.radioButton1.Name = "radioButton1"; - this.radioButton1.Size = new System.Drawing.Size(70, 32); - this.radioButton1.TabIndex = 0; - this.radioButton1.Text = "24h"; - this.radioButton1.UseVisualStyleBackColor = true; + // chartModeSelector + // + this.chartModeSelector.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.chartModeSelector.Controls.Add(this.allMode); + this.chartModeSelector.Controls.Add(this.dayMode); + this.chartModeSelector.Location = new System.Drawing.Point(801, 104); + this.chartModeSelector.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.chartModeSelector.Name = "chartModeSelector"; + this.chartModeSelector.Padding = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.chartModeSelector.Size = new System.Drawing.Size(261, 103); + this.chartModeSelector.TabIndex = 3; + this.chartModeSelector.TabStop = false; + this.chartModeSelector.Text = "Chart Mode"; + this.chartModeSelector.Enter += new System.EventHandler(this.chartModeSelector_Enter); + // + // allMode + // + this.allMode.AutoSize = true; + this.allMode.Checked = true; + this.allMode.Location = new System.Drawing.Point(11, 61); + this.allMode.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.allMode.Name = "allMode"; + this.allMode.Size = new System.Drawing.Size(58, 31); + this.allMode.TabIndex = 1; + this.allMode.TabStop = true; + this.allMode.Text = "all"; + this.allMode.UseVisualStyleBackColor = true; + this.allMode.CheckedChanged += new System.EventHandler(this.allMode_CheckedChanged); + // + // dayMode + // + this.dayMode.AutoSize = true; + this.dayMode.Location = new System.Drawing.Point(11, 29); + this.dayMode.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.dayMode.Name = "dayMode"; + this.dayMode.Size = new System.Drawing.Size(73, 31); + this.dayMode.TabIndex = 0; + this.dayMode.Text = "24h"; + this.dayMode.UseVisualStyleBackColor = true; + this.dayMode.CheckedChanged += new System.EventHandler(this.dayMode_CheckedChanged); // // splitContainer1 // @@ -210,10 +215,10 @@ this.splitContainer1.Panel2.Controls.Add(this.serverSelector); this.splitContainer1.Panel2.Controls.Add(this.CancelButton); this.splitContainer1.Panel2.Controls.Add(this.OKButton); - this.splitContainer1.Panel2.Controls.Add(this.groupBox1); + this.splitContainer1.Panel2.Controls.Add(this.chartModeSelector); this.splitContainer1.Panel2.Controls.Add(this.StatisticsChart); - this.splitContainer1.Size = new System.Drawing.Size(1061, 637); - this.splitContainer1.SplitterDistance = 313; + this.splitContainer1.Size = new System.Drawing.Size(1077, 614); + this.splitContainer1.SplitterDistance = 301; this.splitContainer1.SplitterWidth = 10; this.splitContainer1.TabIndex = 12; // @@ -244,28 +249,29 @@ // splitContainer2.Panel2 // this.splitContainer2.Panel2.Controls.Add(this.splitContainer3); - this.splitContainer2.Size = new System.Drawing.Size(1061, 313); - this.splitContainer2.SplitterDistance = 365; + this.splitContainer2.Size = new System.Drawing.Size(1077, 301); + this.splitContainer2.SplitterDistance = 384; this.splitContainer2.SplitterWidth = 5; this.splitContainer2.TabIndex = 7; // // label9 // this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(7, 181); + this.label9.Location = new System.Drawing.Point(8, 175); this.label9.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(152, 28); + this.label9.Size = new System.Drawing.Size(164, 27); this.label9.TabIndex = 20; this.label9.Text = "Collect Data per"; // // label8 // this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(261, 183); + this.label8.Font = new System.Drawing.Font("Microsoft YaHei", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label8.Location = new System.Drawing.Point(285, 176); this.label8.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(81, 28); + this.label8.Size = new System.Drawing.Size(87, 27); this.label8.TabIndex = 19; this.label8.Text = "minutes"; // @@ -277,7 +283,7 @@ 0, 0, 0}); - this.dataCollectionMinutesNum.Location = new System.Drawing.Point(161, 179); + this.dataCollectionMinutesNum.Location = new System.Drawing.Point(176, 173); this.dataCollectionMinutesNum.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.dataCollectionMinutesNum.Maximum = new decimal(new int[] { 120, @@ -290,7 +296,7 @@ 0, 0}); this.dataCollectionMinutesNum.Name = "dataCollectionMinutesNum"; - this.dataCollectionMinutesNum.Size = new System.Drawing.Size(92, 34); + this.dataCollectionMinutesNum.Size = new System.Drawing.Size(100, 34); this.dataCollectionMinutesNum.TabIndex = 18; this.dataCollectionMinutesNum.Value = new decimal(new int[] { 10, @@ -302,10 +308,10 @@ // this.StatisticsEnabledCheckBox.AutoSize = true; this.StatisticsEnabledCheckBox.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.bindingConfiguration, "StatisticsEnabled", true)); - this.StatisticsEnabledCheckBox.Location = new System.Drawing.Point(12, 12); + this.StatisticsEnabledCheckBox.Location = new System.Drawing.Point(13, 12); this.StatisticsEnabledCheckBox.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.StatisticsEnabledCheckBox.Name = "StatisticsEnabledCheckBox"; - this.StatisticsEnabledCheckBox.Size = new System.Drawing.Size(177, 32); + this.StatisticsEnabledCheckBox.Size = new System.Drawing.Size(189, 31); this.StatisticsEnabledCheckBox.TabIndex = 17; this.StatisticsEnabledCheckBox.Text = "Enable Statistics"; this.StatisticsEnabledCheckBox.UseVisualStyleBackColor = true; @@ -318,7 +324,7 @@ 0, 0, 0}); - this.choiceKeptMinutesNum.Location = new System.Drawing.Point(161, 139); + this.choiceKeptMinutesNum.Location = new System.Drawing.Point(176, 134); this.choiceKeptMinutesNum.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.choiceKeptMinutesNum.Maximum = new decimal(new int[] { 120, @@ -331,7 +337,7 @@ 0, 0}); this.choiceKeptMinutesNum.Name = "choiceKeptMinutesNum"; - this.choiceKeptMinutesNum.Size = new System.Drawing.Size(92, 34); + this.choiceKeptMinutesNum.Size = new System.Drawing.Size(100, 34); this.choiceKeptMinutesNum.TabIndex = 16; this.choiceKeptMinutesNum.Value = new decimal(new int[] { 10, @@ -343,10 +349,10 @@ // this.byHourOfDayCheckBox.AutoSize = true; this.byHourOfDayCheckBox.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.bindingConfiguration, "ByHourOfDay", true)); - this.byHourOfDayCheckBox.Location = new System.Drawing.Point(12, 98); + this.byHourOfDayCheckBox.Location = new System.Drawing.Point(13, 95); this.byHourOfDayCheckBox.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.byHourOfDayCheckBox.Name = "byHourOfDayCheckBox"; - this.byHourOfDayCheckBox.Size = new System.Drawing.Size(165, 32); + this.byHourOfDayCheckBox.Size = new System.Drawing.Size(180, 31); this.byHourOfDayCheckBox.TabIndex = 15; this.byHourOfDayCheckBox.Text = "By hour of day"; this.byHourOfDayCheckBox.UseVisualStyleBackColor = true; @@ -354,7 +360,7 @@ // repeatTimesNum // this.repeatTimesNum.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingConfiguration, "RepeatTimesNum", true)); - this.repeatTimesNum.Location = new System.Drawing.Point(66, 224); + this.repeatTimesNum.Location = new System.Drawing.Point(72, 216); this.repeatTimesNum.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.repeatTimesNum.Maximum = new decimal(new int[] { 10, @@ -362,7 +368,7 @@ 0, 0}); this.repeatTimesNum.Name = "repeatTimesNum"; - this.repeatTimesNum.Size = new System.Drawing.Size(91, 34); + this.repeatTimesNum.Size = new System.Drawing.Size(99, 34); this.repeatTimesNum.TabIndex = 14; this.repeatTimesNum.Value = new decimal(new int[] { 4, @@ -373,9 +379,10 @@ // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(163, 226); + this.label6.Font = new System.Drawing.Font("Microsoft YaHei", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label6.Location = new System.Drawing.Point(178, 218); this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(184, 28); + this.label6.Size = new System.Drawing.Size(201, 27); this.label6.TabIndex = 13; this.label6.Text = "packages everytime"; // @@ -396,7 +403,7 @@ // splitContainer3.Panel2 // this.splitContainer3.Panel2.Controls.Add(this.calculationContainer); - this.splitContainer3.Size = new System.Drawing.Size(691, 313); + this.splitContainer3.Size = new System.Drawing.Size(688, 301); this.splitContainer3.SplitterDistance = 46; this.splitContainer3.SplitterWidth = 10; this.splitContainer3.TabIndex = 6; @@ -407,7 +414,7 @@ this.label1.Location = new System.Drawing.Point(5, 12); this.label1.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(242, 28); + this.label1.Size = new System.Drawing.Size(262, 27); this.label1.TabIndex = 0; this.label1.Text = "Design evaluation method"; // @@ -418,15 +425,25 @@ this.calculationContainer.Location = new System.Drawing.Point(0, 0); this.calculationContainer.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.calculationContainer.Name = "calculationContainer"; - this.calculationContainer.Size = new System.Drawing.Size(691, 257); + this.calculationContainer.Size = new System.Drawing.Size(688, 245); this.calculationContainer.TabIndex = 1; // + // serverSelector + // + this.serverSelector.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.serverSelector.FormattingEnabled = true; + this.serverSelector.Location = new System.Drawing.Point(801, 67); + this.serverSelector.Name = "serverSelector"; + this.serverSelector.Size = new System.Drawing.Size(260, 35); + this.serverSelector.TabIndex = 6; + this.serverSelector.SelectedIndexChanged += new System.EventHandler(this.serverSelector_SelectedIndexChanged); + // // CancelButton // this.CancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.CancelButton.Location = new System.Drawing.Point(954, 234); + this.CancelButton.Location = new System.Drawing.Point(960, 220); this.CancelButton.Name = "CancelButton"; - this.CancelButton.Size = new System.Drawing.Size(93, 43); + this.CancelButton.Size = new System.Drawing.Size(101, 41); this.CancelButton.TabIndex = 5; this.CancelButton.Text = "Cancel"; this.CancelButton.UseVisualStyleBackColor = true; @@ -435,9 +452,9 @@ // OKButton // this.OKButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.OKButton.Location = new System.Drawing.Point(855, 234); + this.OKButton.Location = new System.Drawing.Point(852, 220); this.OKButton.Name = "OKButton"; - this.OKButton.Size = new System.Drawing.Size(93, 43); + this.OKButton.Size = new System.Drawing.Size(101, 41); this.OKButton.TabIndex = 4; this.OKButton.Text = "OK"; this.OKButton.UseVisualStyleBackColor = true; @@ -447,30 +464,21 @@ // this.bindingConfiguration.DataSource = typeof(Shadowsocks.Model.StatisticsStrategyConfiguration); // - // serverSelector - // - this.serverSelector.FormattingEnabled = true; - this.serverSelector.Location = new System.Drawing.Point(808, 75); - this.serverSelector.Name = "serverSelector"; - this.serverSelector.Size = new System.Drawing.Size(239, 36); - this.serverSelector.TabIndex = 6; - this.serverSelector.SelectedIndexChanged += new System.EventHandler(this.serverSelector_SelectedIndexChanged); - // // StatisticsStrategyConfigurationForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 28F); + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 27F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSize = true; - this.ClientSize = new System.Drawing.Size(1061, 637); + this.ClientSize = new System.Drawing.Size(1077, 614); this.Controls.Add(this.splitContainer1); - this.Font = new System.Drawing.Font("Segoe UI", 10F); + this.Font = new System.Drawing.Font("Microsoft YaHei", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.MinimumSize = new System.Drawing.Size(973, 514); + this.MinimumSize = new System.Drawing.Size(1059, 498); this.Name = "StatisticsStrategyConfigurationForm"; this.Text = "StatisticsStrategyConfigurationForm"; ((System.ComponentModel.ISupportInitialize)(this.StatisticsChart)).EndInit(); - this.groupBox1.ResumeLayout(false); - this.groupBox1.PerformLayout(); + this.chartModeSelector.ResumeLayout(false); + this.chartModeSelector.PerformLayout(); this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); @@ -499,9 +507,9 @@ private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; - private System.Windows.Forms.GroupBox groupBox1; - private System.Windows.Forms.RadioButton radioButton2; - private System.Windows.Forms.RadioButton radioButton1; + private System.Windows.Forms.GroupBox chartModeSelector; + private System.Windows.Forms.RadioButton allMode; + private System.Windows.Forms.RadioButton dayMode; private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.Label label1; private System.Windows.Forms.SplitContainer splitContainer2; diff --git a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs index 936cf719..88e32309 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs @@ -7,6 +7,7 @@ using System.Windows.Forms.DataVisualization.Charting; using Shadowsocks.Controller; using Shadowsocks.Model; using SimpleJson; +using System.Net.NetworkInformation; namespace Shadowsocks.View { @@ -15,7 +16,7 @@ namespace Shadowsocks.View private readonly ShadowsocksController _controller; private StatisticsStrategyConfiguration _configuration; private DataTable _dataTable = new DataTable(); - private List _servers; + private List _servers; public StatisticsStrategyConfigurationForm(ShadowsocksController controller) { @@ -55,11 +56,11 @@ namespace Shadowsocks.View _dataTable.Columns.Add("Ping", typeof (int)); StatisticsChart.Series["Package Loss"].XValueMember = "Timestamp"; - StatisticsChart.Series["Package Loss"].YValueMembers = "PackageLoss"; + StatisticsChart.Series["Package Loss"].YValueMembers = "Package Loss"; StatisticsChart.Series["Ping"].XValueMember = "Timestamp"; StatisticsChart.Series["Ping"].YValueMembers = "Ping"; StatisticsChart.DataSource = _dataTable; - loadChartData(serverSelector.SelectedText); + loadChartData(); StatisticsChart.DataBind(); } @@ -80,20 +81,60 @@ namespace Shadowsocks.View Close(); } - private void loadChartData(string serverName) + private void loadChartData() { + string serverName = _servers[serverSelector.SelectedIndex]; _dataTable.Rows.Clear(); List statistics; if (!_controller.availabilityStatistics.FilteredStatistics.TryGetValue(serverName, out statistics)) return; - foreach (var data in statistics) + IEnumerable> dataGroups; + if (allMode.Checked) { - _dataTable.Rows.Add(data.Timestamp, (float) new Random().Next() % 50, new Random().Next() % 200); + dataGroups = statistics.GroupBy(data => data.Timestamp.DayOfYear); + StatisticsChart.ChartAreas["DataArea"].AxisX.LabelStyle.Format = "MM/dd/yyyy"; + StatisticsChart.ChartAreas["DataArea"].AxisX2.LabelStyle.Format = "MM/dd/yyyy"; } + else + { + dataGroups = statistics.GroupBy(data => data.Timestamp.Hour); + StatisticsChart.ChartAreas["DataArea"].AxisX.LabelStyle.Format = "HH:00"; + StatisticsChart.ChartAreas["DataArea"].AxisX2.LabelStyle.Format = "HH:00"; + } + var finalData = from dataGroup in dataGroups + orderby dataGroup.Key + select new + { + Timestamp = dataGroup.First().Timestamp, + Ping = (int)dataGroup.Average(data => data.RoundtripTime), + PackageLoss = (int) + (dataGroup.Count(data => data.ICMPStatus.Equals(IPStatus.TimedOut.ToString())) + / (float)dataGroup.Count() * 100) + }; + foreach (var data in finalData) + { + _dataTable.Rows.Add(data.Timestamp, data.PackageLoss, data.Ping); + } + StatisticsChart.DataBind(); } private void serverSelector_SelectedIndexChanged(object sender, EventArgs e) { - loadChartData(_servers[serverSelector.SelectedIndex]); + loadChartData(); + } + + private void chartModeSelector_Enter(object sender, EventArgs e) + { + + } + + private void dayMode_CheckedChanged(object sender, EventArgs e) + { + loadChartData(); + } + + private void allMode_CheckedChanged(object sender, EventArgs e) + { + loadChartData(); } } } diff --git a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx index 73aff71e..df14f52d 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx @@ -120,10 +120,7 @@ 1, 30 - - 1, 30 - - 63 + 56 \ No newline at end of file