From 86c063caeef88519cf49cd19f95cb2559228f43f Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Sun, 17 Feb 2019 17:56:42 +0100 Subject: [PATCH] ReasultsBrowser : Histograms added, ver. 2.18.1146 --- .../Forms/HistogramCtrl.Designer.cs | 76 +++++++++ ResultsBrowser/Forms/HistogramCtrl.cs | 42 +++++ ResultsBrowser/Forms/HistogramCtrl.resx | 120 ++++++++++++++ ResultsBrowser/Forms/HistogramDlg.Designer.cs | 150 +++++++++++++++++ ResultsBrowser/Forms/HistogramDlg.cs | 152 ++++++++++++++++++ ResultsBrowser/Forms/HistogramDlg.resx | 120 ++++++++++++++ .../Forms/HistogramOptionsDlg.Designer.cs | 91 +++++++++++ ResultsBrowser/Forms/HistogramOptionsDlg.cs | 67 ++++++++ ResultsBrowser/Forms/HistogramOptionsDlg.resx | 120 ++++++++++++++ ResultsBrowser/Forms/StatisticsDlg.cs | 95 ++++------- ResultsBrowser/Forms/StatisticsOptionsDlg.cs | 5 +- ResultsBrowser/Properties/AssemblyInfo.cs | 4 +- ResultsBrowser/Resources/Strings.cs.resx | 3 + ResultsBrowser/Resources/Strings.resx | 3 + ResultsBrowser/Resources/Strings1.Designer.cs | 9 ++ ResultsBrowser/ResultsBrowser.csproj | 28 ++++ ResultsBrowser/ResultsBrowserWnd.Designer.cs | 111 +++++++++---- ResultsBrowser/ResultsBrowserWnd.cs | 34 +++- 18 files changed, 1116 insertions(+), 114 deletions(-) create mode 100644 ResultsBrowser/Forms/HistogramCtrl.Designer.cs create mode 100644 ResultsBrowser/Forms/HistogramCtrl.cs create mode 100644 ResultsBrowser/Forms/HistogramCtrl.resx create mode 100644 ResultsBrowser/Forms/HistogramDlg.Designer.cs create mode 100644 ResultsBrowser/Forms/HistogramDlg.cs create mode 100644 ResultsBrowser/Forms/HistogramDlg.resx create mode 100644 ResultsBrowser/Forms/HistogramOptionsDlg.Designer.cs create mode 100644 ResultsBrowser/Forms/HistogramOptionsDlg.cs create mode 100644 ResultsBrowser/Forms/HistogramOptionsDlg.resx diff --git a/ResultsBrowser/Forms/HistogramCtrl.Designer.cs b/ResultsBrowser/Forms/HistogramCtrl.Designer.cs new file mode 100644 index 000000000..63b659824 --- /dev/null +++ b/ResultsBrowser/Forms/HistogramCtrl.Designer.cs @@ -0,0 +1,76 @@ +namespace ResultsBrowser.Forms +{ + partial class HistogramCtrl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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.Title title1 = new System.Windows.Forms.DataVisualization.Charting.Title(); + this.myChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + ((System.ComponentModel.ISupportInitialize)(this.myChart)).BeginInit(); + this.SuspendLayout(); + // + // myChart + // + chartArea1.Name = "ChartArea1"; + this.myChart.ChartAreas.Add(chartArea1); + this.myChart.Dock = System.Windows.Forms.DockStyle.Fill; + legend1.Name = "Legend1"; + this.myChart.Legends.Add(legend1); + this.myChart.Location = new System.Drawing.Point(0, 0); + this.myChart.Name = "myChart"; + this.myChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Bright; + series1.ChartArea = "ChartArea1"; + series1.Legend = "Legend1"; + series1.Name = "Series1"; + this.myChart.Series.Add(series1); + this.myChart.Size = new System.Drawing.Size(400, 300); + this.myChart.TabIndex = 0; + this.myChart.Text = "chart1"; + title1.Name = "Title1"; + title1.Text = "Title1"; + this.myChart.Titles.Add(title1); + // + // HistogramCtrl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.myChart); + this.Name = "HistogramCtrl"; + this.Size = new System.Drawing.Size(400, 300); + ((System.ComponentModel.ISupportInitialize)(this.myChart)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart myChart; + } +} diff --git a/ResultsBrowser/Forms/HistogramCtrl.cs b/ResultsBrowser/Forms/HistogramCtrl.cs new file mode 100644 index 000000000..d0d88f0e8 --- /dev/null +++ b/ResultsBrowser/Forms/HistogramCtrl.cs @@ -0,0 +1,42 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using System.Drawing; +using System.Windows.Forms; +using System.Windows.Forms.DataVisualization.Charting; + +namespace ResultsBrowser.Forms +{ + public partial class HistogramCtrl : UserControl + { + /// + /// Create user control that displays a bar chart iwth custom X-axis labels. + /// + /// Title of the chart displayed at the top + /// Values = bar lengths + /// Labels for the X-axis + public HistogramCtrl(string title, double[] values, string[] labels) + { + InitializeComponent(); + + if (myChart.Titles.Count > 0) myChart.Titles[0].Text = title; + + if ((myChart.Series.Count > 0) && (values != null)) + { + int startOffset = -1; + int endOffset = 1; + for (int i = 0; i < Math.Min(values.Length + 1, labels.Length); i++) + { + if (i < values.Length) myChart.Series[0].Points.Add(values[i]); + if (!string.IsNullOrEmpty(labels[i])) + { + myChart.ChartAreas[0].AxisX.CustomLabels.Add(new System.Windows.Forms.DataVisualization.Charting.CustomLabel(startOffset, endOffset, labels[i], 0, LabelMarkStyle.None)); + } + startOffset = startOffset + 1; + endOffset = endOffset + 1; + } + } + } + } +} diff --git a/ResultsBrowser/Forms/HistogramCtrl.resx b/ResultsBrowser/Forms/HistogramCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/ResultsBrowser/Forms/HistogramCtrl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ResultsBrowser/Forms/HistogramDlg.Designer.cs b/ResultsBrowser/Forms/HistogramDlg.Designer.cs new file mode 100644 index 000000000..4388afcba --- /dev/null +++ b/ResultsBrowser/Forms/HistogramDlg.Designer.cs @@ -0,0 +1,150 @@ +namespace ResultsBrowser.Forms +{ + partial class HistogramDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.exportButton = new System.Windows.Forms.Button(); + this.printButton = new System.Windows.Forms.Button(); + this.closeButton = new System.Windows.Forms.Button(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.flowLayoutPanel1); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.splitContainer2); + this.splitContainer1.Size = new System.Drawing.Size(572, 409); + this.splitContainer1.SplitterDistance = 320; + this.splitContainer1.TabIndex = 0; + // + // splitContainer2 + // + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; + this.splitContainer2.Location = new System.Drawing.Point(0, 0); + this.splitContainer2.Name = "splitContainer2"; + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.exportButton); + this.splitContainer2.Panel2.Controls.Add(this.printButton); + this.splitContainer2.Panel2.Controls.Add(this.closeButton); + this.splitContainer2.Size = new System.Drawing.Size(572, 85); + this.splitContainer2.SplitterDistance = 249; + this.splitContainer2.TabIndex = 0; + // + // exportButton + // + this.exportButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.exportButton.Location = new System.Drawing.Point(103, 21); + this.exportButton.Name = "exportButton"; + this.exportButton.Size = new System.Drawing.Size(94, 41); + this.exportButton.TabIndex = 1; + this.exportButton.Text = "Export"; + this.exportButton.UseVisualStyleBackColor = true; + // + // printButton + // + this.printButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.printButton.Location = new System.Drawing.Point(4, 21); + this.printButton.Name = "printButton"; + this.printButton.Size = new System.Drawing.Size(94, 41); + this.printButton.TabIndex = 0; + this.printButton.Text = "Print"; + this.printButton.UseVisualStyleBackColor = true; + // + // closeButton + // + this.closeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.closeButton.Location = new System.Drawing.Point(203, 21); + this.closeButton.Name = "closeButton"; + this.closeButton.Size = new System.Drawing.Size(94, 41); + this.closeButton.TabIndex = 2; + this.closeButton.Text = "Close"; + this.closeButton.UseVisualStyleBackColor = true; + this.closeButton.Click += new System.EventHandler(this.closeButton_Click); + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(572, 320); + this.flowLayoutPanel1.TabIndex = 0; + // + // HistogramDlg + // + this.AcceptButton = this.closeButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(572, 409); + this.Controls.Add(this.splitContainer1); + this.Name = "HistogramDlg"; + this.Text = "HistogramDlg"; + this.Load += new System.EventHandler(this.HistogramDlg_Load); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.splitContainer2.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.Button closeButton; + private System.Windows.Forms.Button printButton; + private System.Windows.Forms.Button exportButton; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + } +} \ No newline at end of file diff --git a/ResultsBrowser/Forms/HistogramDlg.cs b/ResultsBrowser/Forms/HistogramDlg.cs new file mode 100644 index 000000000..f59bcdca8 --- /dev/null +++ b/ResultsBrowser/Forms/HistogramDlg.cs @@ -0,0 +1,152 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Globalization; +using System.IO; +using System.Windows.Forms; +using System.Windows.Forms.DataVisualization.Charting; +using Results.Entities; +using ResultsBrowser.Resources; +using ResultsBrowser.Output.Printers.Statistics; + +namespace ResultsBrowser.Forms +{ + public partial class HistogramDlg : Form + { + const int NrBins = 11; + + IList waterMeters; + HistogramOptionsDlg options; + + public HistogramDlg(IList waterMeters, HistogramOptionsDlg options, string title) + { + InitializeComponent(); + + this.waterMeters = waterMeters; + this.options = options; + Text = title; + + closeButton.Text = Strings.OkBtnText; + printButton.Text = Strings.Print; + } + + private void HistogramDlg_Load(object sender, EventArgs e) + { + CalculateAndDraw(); + } + + void CalculateAndDraw() + { + for (int i = 0; i < options.SelectedItems.Count; i++) + { + Results.WMeterRsltItemSpec item = options.SelectedItems[i]; + + try + { + /// Find minimum and maximum + double min = Double.MaxValue; + double max = Double.MinValue; + double sum = 0; + int count = 0; + foreach (var wm in waterMeters) + { + string strValue = item.Print(wm); + double value; + if (!double.TryParse(strValue, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.CurrentCulture, out value) && + !double.TryParse(strValue, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out value)) + { + throw new Exception(string.Format("{0} is not a number, cannot calculate histogram", item.Caption)); + } + + sum += value; + count++; + if (min > value) min = value; + if (max < value) max = value; + } + + double mean = (count != 0) ? (sum / count) : 0; /// Prevent division by zero + + /// + /// Determine limits for bins + /// + double[] binHiLim; + string[] labels; + if ((-0.55 <= min) && (max <= 0.55)) + { + labels = new string[] { "-0.6", "", "-0.4", "", "-0.2", "", "0", "", "0.2", "", "0.4", "", "0.6" }; + binHiLim = new double[] { -0.45, -0.35, -0.25, -0.15, -0.05, 0.05, 0.15, 0.25, 0.35, 0.45, 0.55 }; + } + else if ((-1.1 <= min) && (max <= 1.1)) + { + labels = new string[] { "-1.2", "", "-0.8", "", "-0.4", "", "0", "", "0.4", "", "0.8", "", "1.2" }; + binHiLim = new double[] { -0.9, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.7, 0.9, 1.1 }; + } + else if ((-2.2 <= min) && (max <= 2.2)) + { + labels = new string[] { "-2.4", "", "-1.6", "", "-0.8", "", "0", "", "0.8", "", "1.6", "", "2.4" }; + binHiLim = new double[] { -1.8, -1.4, -1.0, -0.6, -0.2, 0.2, 0.6, 1.0, 1.4, 1.8, 2.2 }; + } + else if ((-4.4 <= min) && (max <= 4.4)) + { + labels = new string[] { "-4.8", "", "-3.2", "", "-1.6", "", "0", "", "1.6", "", "3.2", "", "4.8" }; + binHiLim = new double[] { -3.6, -2.8, -2.0, -1.2, -0.4, 0.4, 1.2, 2.0, 2.8, 3.6, 4.4 }; + } + else + { + labels = new string[] { "-9.6", "", "-6.4", "", "-3.2", "", "0", "", "3.2", "", "6.4", "", "9.6" }; + binHiLim = new double[] { -7.2, -5.6, -4.0, -2.4, -0.8, 0.8, 2.4, 4.0, 5.6, 7.2, 8.8 }; + } + + int nrBins = Math.Min(labels.Length - 1, binHiLim.Length + 1); + + double[] bins = new double[nrBins]; + for (int j = 0; j < nrBins; j++) bins[j] = 0; + + /// Calculate bins + foreach (var wm in waterMeters) + { + string strValue = item.Print(wm); + double value; + if (!double.TryParse(strValue, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.CurrentCulture, out value) && + !double.TryParse(strValue, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out value)) + { + throw new Exception(string.Format("{0} is not a number, cannot calculate histogram", item.Caption)); + } + + for (int j = 0; j < nrBins - 1; j++) + { + if (value < binHiLim[j]) + { + bins[j] += 1.0; + break; + } + } + if (value >= binHiLim[nrBins - 2]) + { + bins[nrBins - 1] += 1.0; + } + } + + /// + /// Draw + /// + HistogramCtrl histo = new HistogramCtrl(string.Format("{0} mean = {1}", item.Caption, mean.ToString("F3")), bins, labels); + flowLayoutPanel1.Controls.Add(histo); + } + catch (Exception exc) + { + string msg = exc.Message; + } + } + } + + private void closeButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + Close(); + } + } +} diff --git a/ResultsBrowser/Forms/HistogramDlg.resx b/ResultsBrowser/Forms/HistogramDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/ResultsBrowser/Forms/HistogramDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ResultsBrowser/Forms/HistogramOptionsDlg.Designer.cs b/ResultsBrowser/Forms/HistogramOptionsDlg.Designer.cs new file mode 100644 index 000000000..2fccbcade --- /dev/null +++ b/ResultsBrowser/Forms/HistogramOptionsDlg.Designer.cs @@ -0,0 +1,91 @@ +namespace ResultsBrowser.Forms +{ + partial class HistogramOptionsDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.cancelButton = new System.Windows.Forms.Button(); + this.okButton = new System.Windows.Forms.Button(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.SuspendLayout(); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(380, 302); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(95, 38); + this.cancelButton.TabIndex = 9; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // 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(269, 302); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(95, 38); + this.okButton.TabIndex = 8; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + this.flowLayoutPanel1.Location = new System.Drawing.Point(12, 12); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(479, 271); + this.flowLayoutPanel1.TabIndex = 10; + // + // HistogramOptionsDlg + // + this.AcceptButton = this.okButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(503, 355); + this.Controls.Add(this.flowLayoutPanel1); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.okButton); + this.Name = "HistogramOptionsDlg"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "HistogramOptionsDlg"; + this.Load += new System.EventHandler(this.HistogramOptionsDlg_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + } +} \ No newline at end of file diff --git a/ResultsBrowser/Forms/HistogramOptionsDlg.cs b/ResultsBrowser/Forms/HistogramOptionsDlg.cs new file mode 100644 index 000000000..1c6ce7309 --- /dev/null +++ b/ResultsBrowser/Forms/HistogramOptionsDlg.cs @@ -0,0 +1,67 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using ResultsBrowser.Resources; + +namespace ResultsBrowser.Forms +{ + public partial class HistogramOptionsDlg : Form + { + IList items; + public IList SelectedItems; + + IList checkBoxes; + + public HistogramOptionsDlg(IList items) + { + InitializeComponent(); + this.items = items; + + checkBoxes = new List(); + } + + private void HistogramOptionsDlg_Load(object sender, EventArgs e) + { + Localize(); + + foreach (var item in items) + { + CheckBox cb = new CheckBox(); + cb.Text = item.Caption; + cb.Checked = false; + flowLayoutPanel1.Controls.Add(cb); + checkBoxes.Add(cb); + } + } + + void Localize() + { + Text = Strings.Statistics; + okButton.Text = Strings.OkBtnText; + cancelButton.Text = Strings.CancelBtnText; + } + + private void okButton_Click(object sender, EventArgs e) + { + SelectedItems = new List(); + for (int i = 0; i < items.Count; i++) + { + if (checkBoxes[i].Checked) SelectedItems.Add(items[i]); + } + + //Program.LocalSettings.RowItemCaption = RowItem.Caption; + // ... + //Program.LocalSettings.Save(); + + DialogResult = DialogResult.OK; + Close(); + } + + private void cancelButton_Click(object sender, EventArgs e) + { + } + } +} diff --git a/ResultsBrowser/Forms/HistogramOptionsDlg.resx b/ResultsBrowser/Forms/HistogramOptionsDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/ResultsBrowser/Forms/HistogramOptionsDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ResultsBrowser/Forms/StatisticsDlg.cs b/ResultsBrowser/Forms/StatisticsDlg.cs index 272e1c8bf..92d669a16 100644 --- a/ResultsBrowser/Forms/StatisticsDlg.cs +++ b/ResultsBrowser/Forms/StatisticsDlg.cs @@ -1,4 +1,7 @@ -using System; +/// +/// Copyright (c) 2016-2019 Sensus Slovensko a.s. +/// +using System; using System.Collections.Generic; using System.Windows.Forms; using Results.Entities; @@ -11,22 +14,7 @@ namespace ResultsBrowser.Forms public partial class StatisticsDlg : Form { IList waterMeters; - - bool twoDim; - - Results.WMeterRsltItemSpec rowItem; - Results.WMeterRsltItemSpec rowItem2; - Results.WMeterRsltItemSpec rowItem3; - Results.WMeterRsltItemSpec columnItem; - Results.WMeterRsltItemSpec columnItem2; - Results.WMeterRsltItemSpec columnItem3; - - string rowTestSpec; - string rowTestSpec2; - string rowTestSpec3; - string columnTestSpec; - string columnTestSpec2; - string columnTestSpec3; + StatisticsOptionsDlg options; IList rowValues; IList columnValues; @@ -36,23 +24,14 @@ namespace ResultsBrowser.Forms string title; - public StatisticsDlg(IList waterMeters, bool twoDim, - Results.WMeterRsltItemSpec rowItem, - Results.WMeterRsltItemSpec rowItem2, - Results.WMeterRsltItemSpec rowItem3, - Results.WMeterRsltItemSpec columnItem, - Results.WMeterRsltItemSpec columnItem2, - Results.WMeterRsltItemSpec columnItem3, - string rowTestSpec, - string rowTestSpec2, - string rowTestSpec3, - string columnTestSpec, - string columnTestSpec2, - string columnTestSpec3, + public StatisticsDlg(IList waterMeters, StatisticsOptionsDlg options, DateTime startDate, DateTime endDate) { InitializeComponent(); + this.waterMeters = waterMeters; + this.options = options; + if (!string.IsNullOrEmpty(Program.LocalSettings.TimePeriodFormat) && (startDate != new DateTime(0)) && (endDate != new DateTime(0))) { title = string.Format(Program.LocalSettings.TimePeriodFormat, startDate, endDate); @@ -66,26 +45,6 @@ namespace ResultsBrowser.Forms closeButton.Text = Strings.OkBtnText; printButton.Text = Strings.Print; - - this.waterMeters = waterMeters; - - this.twoDim = twoDim; - - this.rowItem = rowItem; - this.rowItem2 = rowItem2; - this.rowItem3 = rowItem3; - - this.columnItem = columnItem; - this.columnItem2 = columnItem2; - this.columnItem3 = columnItem3; - - this.rowTestSpec = rowTestSpec; - this.rowTestSpec2 = rowTestSpec2; - this.rowTestSpec3 = rowTestSpec3; - - this.columnTestSpec = columnTestSpec; - this.columnTestSpec2 = columnTestSpec2; - this.columnTestSpec3 = columnTestSpec3; } private void StatisticsDlg_Load(object sender, EventArgs e) @@ -105,16 +64,16 @@ namespace ResultsBrowser.Forms /// foreach (var wm in waterMeters) { - string value = rowItem.Print(wm); - if (rowItem2 != null) value = value + " | " + rowItem2.Print(wm); - if (rowItem3 != null) value = value + " | " + rowItem3.Print(wm); + string value = options.RowItem.Print(wm); + if (options.RowItem2 != null) value = value + " | " + options.RowItem2.Print(wm); + if (options.RowItem3 != null) value = value + " | " + options.RowItem3.Print(wm); if (!rowValues.Contains(value)) rowValues.Add(value); - if (twoDim) + if (options.TwoDim) { - value = columnItem.Print(wm); - if (columnItem2 != null) value = value + " | " + columnItem2.Print(wm); - if (columnItem3 != null) value = value + " | " + columnItem3.Print(wm); + value = options.ColumnItem.Print(wm); + if (options.ColumnItem2 != null) value = value + " | " + options.ColumnItem2.Print(wm); + if (options.ColumnItem3 != null) value = value + " | " + options.ColumnItem3.Print(wm); if (!columnValues.Contains(value)) columnValues.Add(value); } } @@ -129,17 +88,17 @@ namespace ResultsBrowser.Forms { for (int row = 0; row < rowValues.Count; row++) { - string rowValue = rowItem.Print(wm); - if (rowItem2 != null) rowValue = rowValue + " | " + rowItem2.Print(wm); - if (rowItem3 != null) rowValue = rowValue + " | " + rowItem3.Print(wm); + string rowValue = options.RowItem.Print(wm); + if (options.RowItem2 != null) rowValue = rowValue + " | " + options.RowItem2.Print(wm); + if (options.RowItem3 != null) rowValue = rowValue + " | " + options.RowItem3.Print(wm); - if (twoDim) + if (options.TwoDim) { for (int column = 0; column < columnsCount; column++) { - string columnValue = columnItem.Print(wm); - if (columnItem2 != null) columnValue = columnValue + " | " + columnItem2.Print(wm); - if (columnItem3 != null) columnValue = columnValue + " | " + columnItem3.Print(wm); + string columnValue = options.ColumnItem.Print(wm); + if (options.ColumnItem2 != null) columnValue = columnValue + " | " + options.ColumnItem2.Print(wm); + if (options.ColumnItem3 != null) columnValue = columnValue + " | " + options.ColumnItem3.Print(wm); if (rowValue == rowValues[row] && columnValue == columnValues[column]) { @@ -164,7 +123,7 @@ namespace ResultsBrowser.Forms statisticsListView.Columns.Add(" ", 200); for (int column = 0; column < columnsCount; column++) { - statisticsListView.Columns.Add((twoDim ? columnValues[column] : Strings.Count), 70); + statisticsListView.Columns.Add((options.TwoDim ? columnValues[column] : Strings.Count), 70); } for (int row = 0; row < rowValues.Count; row++) @@ -197,7 +156,7 @@ namespace ResultsBrowser.Forms table[0, 0] = string.Empty; for (int column = 0; column < columnsCount; column++) { - table[0, column + 1] = (twoDim ? columnValues[column] : Strings.Count); + table[0, column + 1] = (options.TwoDim ? columnValues[column] : Strings.Count); } for (int row = 0; row < rowValues.Count; row++) @@ -234,7 +193,7 @@ namespace ResultsBrowser.Forms { using (TextWriter writer = new StreamWriter(dlg.FileName, false, System.Text.Encoding.UTF8)) { - if (twoDim) + if (options.TwoDim) { /// Write column headers for (int i = 0; i < columnValues.Count; i++) @@ -245,7 +204,7 @@ namespace ResultsBrowser.Forms } else { - writer.WriteLine(string.Format("\"{0}\";\"{1}\"", rowItem.Caption, Strings.Count)); + writer.WriteLine(string.Format("\"{0}\";\"{1}\"", options.RowItem.Caption, Strings.Count)); } int nrColumns = Math.Max(1, columnValues.Count); diff --git a/ResultsBrowser/Forms/StatisticsOptionsDlg.cs b/ResultsBrowser/Forms/StatisticsOptionsDlg.cs index 400943673..b0b3a2a1b 100644 --- a/ResultsBrowser/Forms/StatisticsOptionsDlg.cs +++ b/ResultsBrowser/Forms/StatisticsOptionsDlg.cs @@ -1,4 +1,7 @@ -using System; +/// +/// Copyright (c) 2016-2019 Sensus Slovensko a.s. +/// +using System; using System.Collections.Generic; using System.Windows.Forms; using ResultsBrowser.Resources; diff --git a/ResultsBrowser/Properties/AssemblyInfo.cs b/ResultsBrowser/Properties/AssemblyInfo.cs index 3a4ad442c..dcf6d8325 100644 --- a/ResultsBrowser/Properties/AssemblyInfo.cs +++ b/ResultsBrowser/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.18.1140.0")] -[assembly: AssemblyFileVersion("2.18.1140.0")] +[assembly: AssemblyVersion("2.18.1146.0")] +[assembly: AssemblyFileVersion("2.18.1146.0")] diff --git a/ResultsBrowser/Resources/Strings.cs.resx b/ResultsBrowser/Resources/Strings.cs.resx index d07906a4f..3f3e80c5c 100644 --- a/ResultsBrowser/Resources/Strings.cs.resx +++ b/ResultsBrowser/Resources/Strings.cs.resx @@ -240,4 +240,7 @@ Dohledej údaje z Oracle + + Histogramy + \ No newline at end of file diff --git a/ResultsBrowser/Resources/Strings.resx b/ResultsBrowser/Resources/Strings.resx index 1db4d4442..faa7f805f 100644 --- a/ResultsBrowser/Resources/Strings.resx +++ b/ResultsBrowser/Resources/Strings.resx @@ -828,4 +828,7 @@ Add data from Oracle + + Histograms + \ No newline at end of file diff --git a/ResultsBrowser/Resources/Strings1.Designer.cs b/ResultsBrowser/Resources/Strings1.Designer.cs index 613bb6dcc..11b65bcf3 100644 --- a/ResultsBrowser/Resources/Strings1.Designer.cs +++ b/ResultsBrowser/Resources/Strings1.Designer.cs @@ -1257,6 +1257,15 @@ namespace ResultsBrowser.Resources { } } + /// + /// Looks up a localized string similar to Histograms. + /// + internal static string Histograms { + get { + return ResourceManager.GetString("Histograms", resourceCulture); + } + } + /// /// Looks up a localized string similar to Horizontally. /// diff --git a/ResultsBrowser/ResultsBrowser.csproj b/ResultsBrowser/ResultsBrowser.csproj index a82dcc4d4..519c95367 100644 --- a/ResultsBrowser/ResultsBrowser.csproj +++ b/ResultsBrowser/ResultsBrowser.csproj @@ -60,6 +60,7 @@ + @@ -133,6 +134,24 @@ DatabaseSettingsDlg.cs + + UserControl + + + HistogramCtrl.cs + + + Form + + + HistogramDlg.cs + + + Form + + + HistogramOptionsDlg.cs + Form @@ -202,6 +221,15 @@ DatabaseSettingsDlg.cs + + HistogramCtrl.cs + + + HistogramDlg.cs + + + HistogramOptionsDlg.cs + NoBenchOrDatabaseDlg.cs diff --git a/ResultsBrowser/ResultsBrowserWnd.Designer.cs b/ResultsBrowser/ResultsBrowserWnd.Designer.cs index a2c98f09d..6162aa981 100644 --- a/ResultsBrowser/ResultsBrowserWnd.Designer.cs +++ b/ResultsBrowser/ResultsBrowserWnd.Designer.cs @@ -34,10 +34,13 @@ this.filtersFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); this.resultsGroupBox = new System.Windows.Forms.GroupBox(); this.resultsListView = new System.Windows.Forms.ListView(); - this.printerConfigBtn = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.histogramBtn = new System.Windows.Forms.Button(); this.statisticsBtn = new System.Windows.Forms.Button(); - this.printQueryResultsBtn = new System.Windows.Forms.Button(); + this.outputGroupBox = new System.Windows.Forms.GroupBox(); this.exportQueryResultsBtn = new System.Windows.Forms.Button(); + this.printQueryResultsBtn = new System.Windows.Forms.Button(); + this.printerConfigBtn = new System.Windows.Forms.Button(); this.formatOfResultsBtn = new System.Windows.Forms.Button(); this.clearFiltersBtn = new System.Windows.Forms.Button(); this.settingsBtn = new System.Windows.Forms.Button(); @@ -62,6 +65,8 @@ this.hSplitContainer.SuspendLayout(); this.filtersGroupBox.SuspendLayout(); this.resultsGroupBox.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.outputGroupBox.SuspendLayout(); this.testBenchesGroupBox.SuspendLayout(); this.SuspendLayout(); // @@ -79,10 +84,9 @@ // // vSplitContainer.Panel2 // + this.vSplitContainer.Panel2.Controls.Add(this.groupBox1); + this.vSplitContainer.Panel2.Controls.Add(this.outputGroupBox); this.vSplitContainer.Panel2.Controls.Add(this.printerConfigBtn); - this.vSplitContainer.Panel2.Controls.Add(this.statisticsBtn); - this.vSplitContainer.Panel2.Controls.Add(this.printQueryResultsBtn); - this.vSplitContainer.Panel2.Controls.Add(this.exportQueryResultsBtn); this.vSplitContainer.Panel2.Controls.Add(this.formatOfResultsBtn); this.vSplitContainer.Panel2.Controls.Add(this.clearFiltersBtn); this.vSplitContainer.Panel2.Controls.Add(this.settingsBtn); @@ -154,6 +158,68 @@ this.resultsListView.UseCompatibleStateImageBehavior = false; this.resultsListView.View = System.Windows.Forms.View.Details; // + // groupBox1 + // + this.groupBox1.Controls.Add(this.histogramBtn); + this.groupBox1.Controls.Add(this.statisticsBtn); + this.groupBox1.Location = new System.Drawing.Point(8, 608); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(125, 93); + this.groupBox1.TabIndex = 13; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Analysis"; + // + // histogramBtn + // + this.histogramBtn.Location = new System.Drawing.Point(5, 55); + this.histogramBtn.Name = "histogramBtn"; + this.histogramBtn.Size = new System.Drawing.Size(114, 32); + this.histogramBtn.TabIndex = 11; + this.histogramBtn.Text = "Histograms"; + this.histogramBtn.UseVisualStyleBackColor = true; + this.histogramBtn.Click += new System.EventHandler(this.histogramBtn_Click); + // + // statisticsBtn + // + this.statisticsBtn.Location = new System.Drawing.Point(5, 18); + this.statisticsBtn.Name = "statisticsBtn"; + this.statisticsBtn.Size = new System.Drawing.Size(114, 32); + this.statisticsBtn.TabIndex = 10; + this.statisticsBtn.Text = "Statistics"; + this.statisticsBtn.UseVisualStyleBackColor = true; + this.statisticsBtn.Click += new System.EventHandler(this.statisticsBtn_Click); + // + // outputGroupBox + // + this.outputGroupBox.Controls.Add(this.exportQueryResultsBtn); + this.outputGroupBox.Controls.Add(this.printQueryResultsBtn); + this.outputGroupBox.Location = new System.Drawing.Point(8, 509); + this.outputGroupBox.Name = "outputGroupBox"; + this.outputGroupBox.Size = new System.Drawing.Size(125, 93); + this.outputGroupBox.TabIndex = 12; + this.outputGroupBox.TabStop = false; + this.outputGroupBox.Text = "Output"; + // + // exportQueryResultsBtn + // + this.exportQueryResultsBtn.Location = new System.Drawing.Point(5, 18); + this.exportQueryResultsBtn.Name = "exportQueryResultsBtn"; + this.exportQueryResultsBtn.Size = new System.Drawing.Size(114, 32); + this.exportQueryResultsBtn.TabIndex = 8; + this.exportQueryResultsBtn.Text = "Export query results"; + this.exportQueryResultsBtn.UseVisualStyleBackColor = true; + this.exportQueryResultsBtn.Click += new System.EventHandler(this.exportQueryResultsBtn_Click); + // + // printQueryResultsBtn + // + this.printQueryResultsBtn.Location = new System.Drawing.Point(5, 55); + this.printQueryResultsBtn.Name = "printQueryResultsBtn"; + this.printQueryResultsBtn.Size = new System.Drawing.Size(113, 32); + this.printQueryResultsBtn.TabIndex = 9; + this.printQueryResultsBtn.Text = "Print query results"; + this.printQueryResultsBtn.UseVisualStyleBackColor = true; + this.printQueryResultsBtn.Click += new System.EventHandler(this.printQueryResultsBtn_Click); + // // printerConfigBtn // this.printerConfigBtn.Location = new System.Drawing.Point(8, 316); @@ -164,36 +230,6 @@ this.printerConfigBtn.UseVisualStyleBackColor = true; this.printerConfigBtn.Click += new System.EventHandler(this.printerConfigBtn_Click); // - // statisticsBtn - // - this.statisticsBtn.Location = new System.Drawing.Point(8, 621); - this.statisticsBtn.Name = "statisticsBtn"; - this.statisticsBtn.Size = new System.Drawing.Size(125, 35); - this.statisticsBtn.TabIndex = 10; - this.statisticsBtn.Text = "Statistics"; - this.statisticsBtn.UseVisualStyleBackColor = true; - this.statisticsBtn.Click += new System.EventHandler(this.statisticsBtn_Click); - // - // printQueryResultsBtn - // - this.printQueryResultsBtn.Location = new System.Drawing.Point(8, 548); - this.printQueryResultsBtn.Name = "printQueryResultsBtn"; - this.printQueryResultsBtn.Size = new System.Drawing.Size(125, 35); - this.printQueryResultsBtn.TabIndex = 9; - this.printQueryResultsBtn.Text = "Print query results"; - this.printQueryResultsBtn.UseVisualStyleBackColor = true; - this.printQueryResultsBtn.Click += new System.EventHandler(this.printQueryResultsBtn_Click); - // - // exportQueryResultsBtn - // - this.exportQueryResultsBtn.Location = new System.Drawing.Point(8, 508); - this.exportQueryResultsBtn.Name = "exportQueryResultsBtn"; - this.exportQueryResultsBtn.Size = new System.Drawing.Size(125, 35); - this.exportQueryResultsBtn.TabIndex = 8; - this.exportQueryResultsBtn.Text = "Export query results"; - this.exportQueryResultsBtn.UseVisualStyleBackColor = true; - this.exportQueryResultsBtn.Click += new System.EventHandler(this.exportQueryResultsBtn_Click); - // // formatOfResultsBtn // this.formatOfResultsBtn.Location = new System.Drawing.Point(8, 276); @@ -370,6 +406,8 @@ this.hSplitContainer.ResumeLayout(false); this.filtersGroupBox.ResumeLayout(false); this.resultsGroupBox.ResumeLayout(false); + this.groupBox1.ResumeLayout(false); + this.outputGroupBox.ResumeLayout(false); this.testBenchesGroupBox.ResumeLayout(false); this.testBenchesGroupBox.PerformLayout(); this.ResumeLayout(false); @@ -402,5 +440,8 @@ private System.Windows.Forms.RadioButton checkBox4; private System.Windows.Forms.Button printerConfigBtn; private System.Windows.Forms.RadioButton checkBox6; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox outputGroupBox; + private System.Windows.Forms.Button histogramBtn; } } \ No newline at end of file diff --git a/ResultsBrowser/ResultsBrowserWnd.cs b/ResultsBrowser/ResultsBrowserWnd.cs index b91ed8572..fbd347288 100644 --- a/ResultsBrowser/ResultsBrowserWnd.cs +++ b/ResultsBrowser/ResultsBrowserWnd.cs @@ -1,4 +1,7 @@ -using System; +/// +/// Copyright (c) 2016-2019 Sensus Slovensko a.s. +/// +using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; @@ -489,7 +492,7 @@ namespace ResultsBrowser IList items = Results.WMeterRsltItemSpec.FromStrArray(filtersConfig.ResultItems); /// - /// Enter options + /// Statistics options /// Forms.StatisticsOptionsDlg optionsDlg = new Forms.StatisticsOptionsDlg(items); if (optionsDlg.ShowDialog() != DialogResult.OK) return; @@ -497,16 +500,31 @@ namespace ResultsBrowser /// /// Calculate statistics /// - Forms.StatisticsDlg statisticsDlg = new Forms.StatisticsDlg(waterMeters, optionsDlg.TwoDim, - optionsDlg.RowItem, optionsDlg.RowItem2, optionsDlg.RowItem3, - optionsDlg.ColumnItem, optionsDlg.ColumnItem2, optionsDlg.ColumnItem3, - optionsDlg.RowTestSpecifier, optionsDlg.RowTestSpecifier2, optionsDlg.RowTestSpecifier3, - optionsDlg.ColumnTestSpecifier, optionsDlg.ColumnTestSpecifier2, optionsDlg.ColumnTestSpecifier3, - timePeriodStart, timePeriodEnd); + Forms.StatisticsDlg statisticsDlg = new Forms.StatisticsDlg(waterMeters, optionsDlg, timePeriodStart, timePeriodEnd); statisticsDlg.ShowDialog(); } + private void histogramBtn_Click(object sender, EventArgs e) + { + if (waterMeters == null || waterMeters.Count == 0) return; + + IList items = Results.WMeterRsltItemSpec.FromStrArray(filtersConfig.ResultItems); + + /// + /// Histogram options + /// + Forms.HistogramOptionsDlg optionsDlg = new Forms.HistogramOptionsDlg(items); + if (optionsDlg.ShowDialog() != DialogResult.OK) return; + + /// + /// Calculate and display histograms + /// + Forms.HistogramDlg histogramDlg = new Forms.HistogramDlg(waterMeters, optionsDlg, "Histogramy"); + histogramDlg.ShowDialog(); + } + + /// /// Updates component factory ///