2018-12-21 07:14:42 +00:00
|
|
|
|
///
|
2020-10-30 07:23:59 +00:00
|
|
|
|
/// Copyright (c) 2018-2020 Sensus Slovensko a.s.
|
2018-12-21 07:14:42 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2018-12-10 20:17:00 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-10-30 07:23:59 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text;
|
2018-12-10 20:17:00 +00:00
|
|
|
|
using System.Windows.Forms;
|
2018-12-19 11:23:41 +00:00
|
|
|
|
using System.Windows.Forms.DataVisualization.Charting;
|
|
|
|
|
|
using Results.Entities;
|
2018-12-21 07:14:42 +00:00
|
|
|
|
using Statistics.Resources;
|
2018-12-10 20:17:00 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Statistics.UserControls
|
|
|
|
|
|
{
|
2020-10-30 07:23:59 +00:00
|
|
|
|
class DataPoint
|
|
|
|
|
|
{
|
|
|
|
|
|
public DateTime StartTime;
|
|
|
|
|
|
public double RefError;
|
|
|
|
|
|
|
|
|
|
|
|
public DataPoint(DateTime startTime, double refError)
|
|
|
|
|
|
{
|
|
|
|
|
|
StartTime = startTime;
|
|
|
|
|
|
RefError = refError;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-10 20:17:00 +00:00
|
|
|
|
public partial class StatisticsCtrl : UserControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public int Id; /// Index of the tab page
|
2018-12-21 07:14:42 +00:00
|
|
|
|
public MidOrWaterMetersCtrl MidCtrl; /// Reference to the parent control
|
2020-10-30 07:23:59 +00:00
|
|
|
|
IList<DataPoint> currentData;
|
2018-12-10 20:17:00 +00:00
|
|
|
|
|
|
|
|
|
|
public StatisticsCtrl()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2018-12-19 11:23:41 +00:00
|
|
|
|
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "dd.MM.yy";
|
|
|
|
|
|
chart1.ChartAreas[0].AxisX.Interval = 1;
|
|
|
|
|
|
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;
|
2020-10-30 07:23:59 +00:00
|
|
|
|
currentData = new List<DataPoint>();
|
2018-12-10 20:17:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2018-12-21 07:14:42 +00:00
|
|
|
|
if (MidCtrl != null)
|
2018-12-19 11:23:41 +00:00
|
|
|
|
{
|
2018-12-21 07:14:42 +00:00
|
|
|
|
for (int i = 1; i <= 5; i++)
|
|
|
|
|
|
{
|
2018-12-31 22:13:47 +00:00
|
|
|
|
chart1.Series[string.Format("Flow {0}", i)].Points.Clear();
|
2018-12-21 07:14:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IList<TestRslt> results = MidCtrl.UpdateRequest(Id);
|
2018-12-19 11:23:41 +00:00
|
|
|
|
|
|
|
|
|
|
if (results != null)
|
|
|
|
|
|
{
|
2020-10-30 07:23:59 +00:00
|
|
|
|
currentData.Clear();
|
|
|
|
|
|
|
2018-12-19 11:23:41 +00:00
|
|
|
|
foreach (var r in results)
|
|
|
|
|
|
{
|
2018-12-21 07:14:42 +00:00
|
|
|
|
if (r.ErrorMaster != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 1; i <= 5; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (MidCtrl.IsFlowEnabled(i) && (MidCtrl.FlowFrom(i) <= r.FlowMean) && (r.FlowMean <= MidCtrl.FlowTo(i)))
|
|
|
|
|
|
{
|
2018-12-31 22:13:47 +00:00
|
|
|
|
chart1.Series[string.Format("Flow {0}", i)].Points.AddXY(r.StartTime, r.ErrorMaster);
|
2020-10-30 07:23:59 +00:00
|
|
|
|
currentData.Add(new DataPoint(r.StartTime, r.ErrorMaster));
|
2018-12-21 07:14:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-19 11:23:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void exportButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2020-10-30 07:23:59 +00:00
|
|
|
|
SaveFileDialog dlg = new SaveFileDialog();
|
|
|
|
|
|
dlg.Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
|
2018-12-19 11:23:41 +00:00
|
|
|
|
|
2020-10-30 07:23:59 +00:00
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (TextWriter writer = new StreamWriter(dlg.FileName))
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var d in currentData)
|
|
|
|
|
|
{
|
|
|
|
|
|
writer.WriteLine("{0:dd.MM.yyyy HH:mm}; {1}", d.StartTime, d.RefError);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MessageBox.Show(string.Format("Data written to file {0}", dlg.FileName));
|
|
|
|
|
|
}
|
2018-12-10 20:17:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|