Example #1
0
        void ShowParameterData(string parameterName)
        {
            if (Calculation.stringName != parameterName)
            {
                Calculation.stringName  = parameterName;
                TextBoxColumnCount.Text = "";
                TextBoxMax.Text         = "";
                TextBoxMin.Text         = "";
            }
            List <KeyValuePair <DateTime, double> > data;

            int parameterID = XMLWork.FindIDWithName(parameterName, Properties.Settings.Default.Languages);
            var scadaName   = XMLWork.FindScadaNameWithID(parameterID);

            if (scadaName.StartsWith("Def"))
            {
                data = (from row in TrainData.Train
                        select new KeyValuePair <DateTime, double>(row.Date, (double)row.Output[parameterID])).ToList();
            }
            else
            {
                data = (from row in TrainData.Train
                        select new KeyValuePair <DateTime, double>(row.Date, (double)row.Input[parameterID])).ToList();
            }

            /* double min, max;
             * min = String.IsNullOrWhiteSpace(TextBoxMin.Text) ? data.Min(item => item.Value) : double.Parse(TextBoxMin.Text);
             * TextBoxMin.Text = min.ToString();
             * max = String.IsNullOrWhiteSpace(TextBoxMax.Text) ? data.Max(item => item.Value) : double.Parse(TextBoxMax.Text);
             * TextBoxMax.Text = max.ToString();*/

            if (options.log)
            {
                data = data.Where(item => item.Value != 0).ToList();
                List <KeyValuePair <DateTime, double> > keyValuePairs = new List <KeyValuePair <DateTime, double> >();
                foreach (var d in data)
                {
                    keyValuePairs.Add(new KeyValuePair <DateTime, double>(d.Key, Math.Round(Math.Log(d.Value), 2)));
                }
                data = keyValuePairs;
                if (!String.IsNullOrWhiteSpace(TextBoxMin.Text) || !String.IsNullOrWhiteSpace(TextBoxMin.Text))
                {
                    if (data.Max(n => n.Value) < Convert.ToDouble(TextBoxMax.Text) || data.Min(n => n.Value) > Convert.ToDouble(TextBoxMin.Text))
                    {
                        TextBoxMin.Text = "";
                        TextBoxMax.Text = "";
                    }
                }
            }
            if (options.unlog)
            {
                List <KeyValuePair <DateTime, double> > keyValuePairs = new List <KeyValuePair <DateTime, double> >();
                foreach (var d in data)
                {
                    keyValuePairs.Add(new KeyValuePair <DateTime, double>(d.Key, Math.Round(Math.Exp(d.Value), 2)));
                }
                data            = keyValuePairs;
                TextBoxMin.Text = "";
                TextBoxMax.Text = "";
            }
            if (options.sigma)
            {
                List <KeyValuePair <DateTime, double> > dataControl;
                double expectedValue     = data.Sum(item => item.Value) / data.Count;
                double standartDeviation = Math.Sqrt(data.Sum(item => Math.Pow(item.Value - expectedValue, 2)) / (data.Count - 1));
                do
                {
                    data              = data.Where(item => item.Value > (expectedValue - 3 * standartDeviation) && item.Value < (expectedValue + 3 * standartDeviation)).ToList();
                    expectedValue     = data.Sum(item => item.Value) / data.Count;
                    standartDeviation = Math.Sqrt(data.Sum(item => Math.Pow(item.Value - expectedValue, 2)) / (data.Count - 1));
                    double a = expectedValue - 3 * standartDeviation;
                    double b = expectedValue + 3 * standartDeviation;
                    dataControl = data.Where(item => item.Value <= a || item.Value >= b).ToList();
                } while (dataControl.Count() > 0);
            }
            double min, max;

            if (options.language)
            {
                TextBoxMin.Text = TextBoxMin.Text.Replace(".", ",");
                TextBoxMax.Text = TextBoxMax.Text.Replace(".", ",");
            }
            else
            {
                TextBoxMin.Text = TextBoxMin.Text.Replace(",", ".");
                TextBoxMax.Text = TextBoxMax.Text.Replace(",", ".");
            }
            min             = String.IsNullOrWhiteSpace(TextBoxMin.Text) ? data.Min(item => item.Value) : double.Parse(TextBoxMin.Text);
            TextBoxMin.Text = min.ToString();
            max             = String.IsNullOrWhiteSpace(TextBoxMax.Text) ? data.Max(item => item.Value) : double.Parse(TextBoxMax.Text);
            TextBoxMax.Text = max.ToString();

            if (options.minmax)
            {
                data = data.Where(item => item.Value >= min && item.Value <= max).ToList();
            }
            dataResult = data;
            ShowChart1(data, parameterName);
            ShowChart2(data, parameterName);
        }