public NormalDistribution() { if (Properties.Settings.Default.Languages == System.Globalization.CultureInfo.GetCultureInfo("en-US").Name) { options.language = false; } else { options.language = true; } if (!string.IsNullOrEmpty(Properties.Settings.Default.Languages)) { System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Languages); System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Languages); } InitializeComponent(); if (options.language) { SelectedRussianLanguage(); } else { SelectedEnglishLanguage(); } TrainData.GetData(); }
public RegressionAnalysisNew() { if (!string.IsNullOrEmpty(Properties.Settings.Default.Languages)) { System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Languages); System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Languages); } InitializeComponent(); TrainData.GetData(); }
//Сбор данных private void dataAcq_Click(object sender, EventArgs e) { if (ListDelete.Items.Count != 0) { Stopwatch sw = new Stopwatch(); sw.Start(); TrainData.Train.Clear(); measurementses.Clear(); Dictionary <string, int> newElements = new Dictionary <string, int>(); if (ListDelete.Items.Count != 0) { //Сохранения имен параметров и их ID в справочник newElements foreach (var item in ListDelete.Items) { string t = item.ToString(); int j = elements.Where(s => s.Key == t).Single().Value; newElements.Add(t, j); //Работа с локальной базой данных(сохранения данных туда) XMLWork.AddRow(j, t); } } var stream = File.Open(path.Text, FileMode.Open, FileAccess.Read); var eReader = ExcelReaderFactory.CreateOpenXmlReader(stream); bool check = true; try { _counter = 0; while (eReader.Read()) // Одну строку пропускаем с общей информацией { ++_counter; break; } DateTime lastTime = new DateTime(); while (eReader.Read()) // Считывание информации с EXCEL файла { var date = eReader.GetDateTime(0); var time = eReader.GetDateTime(1); TimeSpan ts = new TimeSpan(time.Hour, time.Minute, time.Second); date = date + ts; if (_counter == 1) { lastTime = date; } else { if (lastTime == date) { continue; } lastTime = date; } Measurements measurements; foreach (var value in newElements) { Decimal parValue; var val = Convert.ToString(eReader.GetValue(value.Value)); val = val.Trim(); if (val == "") { parValue = -1; } else { var extA = Convert.ToString(eReader.GetValue(value.Value)).Replace(",", "."); try { parValue = Decimal.Parse(extA, NumberStyles.Float, _formatProvider); } catch (Exception exe) { throw new Exception("Invalid value format in row " + _counter, exe); } measurements = new Measurements(parValue, date, value.Key, value.Value); // созеания измерения measurementses.Add(measurements); // и добавление его в коллекцию } } ++_counter; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { eReader.Close(); } try { List <OneRow> dataSet = new List <OneRow>(); var uniqueTimestamp = measurementses.OrderBy(o => o.TimeStamp).Select(o => o.TimeStamp).Distinct(); OneRow lastRow = new OneRow(); // Отделение технологических параметров от показателей качество. //TODO: сделать отдельную колонку в бд, в которой хранить краткую информацию о расположении датчика относительно производственной линии foreach (DateTime dateTime in uniqueTimestamp) { var moveData = measurementses.Where( o => ((dateTime == o.TimeStamp) && (!o.ParameterName.StartsWith("Def")))) .ToDictionary(o => o.ParID, s => s.Value); // Добавление технологических параметров в дикшионари //температуры для усадки var temperatureData = measurementses.Where(o => ((dateTime == o.TimeStamp) && (o.ParameterName.Contains("XT")))) .ToDictionary(o => o.ParameterName, s => s.Value); //скорости для усадки var velocityData = measurementses.Where(o => ((dateTime == o.TimeStamp) && (o.ParameterName.Contains("XV")))) .ToDictionary(o => o.ParameterName, s => s.Value); OneRow row = new OneRow(); row.Input = moveData; row.Temperatures = temperatureData; row.Velocities = velocityData; if (row.Input.Count >= 1) { row.Date = dateTime; var dataOutput = measurementses.Where( o => ((dateTime == o.TimeStamp) && (o.ParameterName.StartsWith("Def")))) .ToDictionary(o => o.ParID, s => s.Value); row.Output = dataOutput; dataSet.Add(row); // Добавление показателя качества в ОЗУ } lastRow = row; } var datas = measurementses.Where(o => dataSet.First().Date == o.TimeStamp) .ToDictionary(o => o.ParID, s => s.ParameterName); TrainData.GetData(); foreach (KeyValuePair <int, string> keyValuePair in datas) { if (!TrainData.Pairs.ContainsKey(keyValuePair.Value)) { TrainData.Pairs.Add(keyValuePair.Value, keyValuePair.Value); } } TrainData.nameParameter = datas; TrainData.Train = dataSet; // Присвоение статической переменной данных } catch (InvalidOperationException iex) { var parameters = measurementses.Where(o => !o.ParameterName.StartsWith("Def")).ToArray(); if (parameters.Count() == 0) { MessageBox.Show( Localization.MyStrings.QualityParameters); } else { MessageBox.Show(iex.ToString()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } sw.Stop(); var parametersInput = measurementses.Where(o => o.ParameterName.StartsWith("Def")).ToArray(); if (parametersInput.Count() == 0) { MessageBox.Show( Localization.MyStrings.RegimeParameters, Localization.MyStrings.Warning); } MessageBox.Show(Localization.MyStrings.TimeParameters + sw.Elapsed); string pathToShrinkage = System.AppDomain.CurrentDomain.BaseDirectory + "\\Shrinkage.xml"; if (File.Exists(pathToShrinkage)) { File.Delete(pathToShrinkage); } } else { MessageBox.Show(Localization.MyStrings.SelectedParameters); } }
public Diagramm(List <DM.DecisionTree.TreeNode> rndForests) { if (!string.IsNullOrEmpty(Properties.Settings.Default.Languages)) { System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Languages); System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Languages); } InitializeComponent(); TrainData.GetData(); List <string> dictForestsSort = new List <string>(); List <string> secForestsSort = new List <string>(); Dictionary <string, int> dictForests = new Dictionary <string, int>(); Dictionary <string, int> secondForests = new Dictionary <string, int>(); foreach (DM.DecisionTree.TreeNode rndForest in rndForests) { if (!dictForests.ContainsKey(rndForest.attributeName)) { dictForests.Add(rndForest.attributeName, 1); } else { dictForests[rndForest.attributeName]++; } } dictForestsSort = dictForests.Keys.ToList(); InsertionSort(dictForestsSort, dictForests); this.chart1.Series.Clear(); this.chart1.Titles.Clear(); // Set palette. this.chart1.Palette = ChartColorPalette.SeaGreen; // Set title. this.chart1.Titles.Add("1st Node"); double numberOfParameters = 1.0; foreach (var item in dictForestsSort) { //TODO Russian name if ((item != "False") && (item != "True")) { var name = TrainData.nameParameter.SingleOrDefault(parameter => parameter.Value == item).Value; // Add series. Series series = this.chart1.Series.Add(XMLWork.FindNameWithScada(item, Properties.Settings.Default.Languages)); // Add point. //series.Points.Add(Convert.ToDouble(item.Value)); series.Points.Add(dictForests[item]); } } foreach (var rndForest in rndForests) { foreach (var treeNode in rndForest.MChilds) { if ((treeNode != null) && (treeNode.attributeName != "False") && ((treeNode.attributeName != "True"))) { if (!secondForests.ContainsKey(treeNode.attributeName)) { secondForests.Add(treeNode.attributeName, 1); } else { secondForests[treeNode.attributeName]++; } } } } secForestsSort = secondForests.Keys.ToList(); InsertionSort(secForestsSort, secondForests); this.chart2.Series.Clear(); this.chart2.Titles.Clear(); // Set palette. this.chart2.Palette = ChartColorPalette.SeaGreen; // Set title. this.chart2.Titles.Add("2nd Node"); foreach (var item in secForestsSort) { //TODO Russian name var name = TrainData.nameParameter.Single(parameter => parameter.Value == item).Value; // Add series. Series series = this.chart2.Series.Add(XMLWork.FindNameWithScada(item, Properties.Settings.Default.Languages)); // Add point. series.Points.Add(secondForests[item]); } }