/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonForecast_Click(object sender, EventArgs e) { try { ModelDiagnosticTest mdt = new ModelDiagnosticTest(); var forecast = mdt.GetForecast(_parentId); MessageBox.Show(string.Format("Результат: {0}", forecast), "Прогноз", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Прогноз", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonForecast_Click(object sender, EventArgs e) { try { if (dataGridView.SelectedRows.Count > 0) { StringBuilder sb = new StringBuilder(); ModelDiagnosticTest mdt = new ModelDiagnosticTest(); for (int i = 0; i < dataGridView.SelectedRows.Count; ++i) { var forecast = mdt.GetForecast(Convert.ToInt32(dataGridView.SelectedRows[i].Cells[0].Value)); sb.AppendLine(forecast.ToString()); } MessageBox.Show(string.Format("Результат: {0}", sb.ToString()), "Прогноз", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Прогноз", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool MakeTest(FileInfo file) { using (var _context = new DissertationDbContext()) { try { var entity = ModelConvector.ToSeriesDescription(new SeriesDescriptionBindingModel { SeriesName = file.Name, NeedForecast = true }); _context.SeriesDescriptions.Add(entity); _context.SaveChanges(); #region Временной ряд var res = CreateFuzzyLabel(file.FullName, entity.Id); if (!res) { return(false); } _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} нечеткие метки получены", file.Name) }); res = CreateFuzzyTrend(file.FullName, entity.Id); if (!res) { return(false); } _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} нечеткие тенденции получены", file.Name) }); res = CreateRuleTrend(file.FullName, entity.Id); if (!res) { return(false); } _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} правила для тенденций получены", file.Name) }); res = CreatePointTrend(file.FullName, entity.Id); if (!res) { return(false); } _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} точки для тенденций получены", file.Name) }); res = GenerateSituationsByEntropy(file.FullName, entity.Id); if (!res) { return(false); } _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} ситуации по энтропии получены", file.Name) }); res = GenerateSituationsByFuzzy(file.FullName, entity.Id); if (!res) { return(false); } _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} ситуации по нечеткости получены", file.Name) }); #endregion lock (runForecast) { _countPoints = 0; _points = new List <PointInfo>(); var test = ModelConvector.ToDiagnosticTest(new DiagnosticTestBindingModel { TestNumber = "1", FileName = file.FullName, TypeFile = TypeFile.Текстовый, DatasInFile = new List <TypeDataInFile> { TypeDataInFile.ЧисловоеЗначение }, SeriesDiscriptionId = entity.Id, CountPointsForMemmory = 5 }); test.DateTest = DateTime.Now; test.Count = 0; _context.DiagnosticTests.Add(test); _context.SaveChanges(); _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} создали тест", file.Name) }); var values = LoadFromTxt(file.FullName); if (values != null && values.Count > 1) { _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} загрузили данные", file.Name) }); for (int i = 0; i < values.Count - 1; ++i) { AddNewPoint(new PointInfo { SeriesDiscriptionId = entity.Id, DiagnosticTestId = test.Id, Value = values[i] }, entity.Id); } _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} обработали данные", file.Name) }); test.Count = _countPoints; var lastPoint = _points[_points.Count - 1]; lastPoint.IsLast = true; ClearPoint(lastPoint); _context.PointInfos.Add(lastPoint); _context.SaveChanges(); var preLastPoint = _points[_points.Count - 2]; ClearPoint(preLastPoint); _context.PointInfos.Add(preLastPoint); _context.SaveChanges(); _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} сохранили последние точки", file.Name) }); _context.SaveChanges(); var forecast = mdt.GetForecast(test.Id); var forecasts = string.Join(";", mdt.GetForecastByPointTrend(test.Id)); _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} получили прогноз", file.Name) }); var realValue = values[values.Count - 1]; _context.ExperimentFileResults.Add(new ExperimentFileResult { DateExperiment = DateTime.Now, Forecast = forecast, ForecastsByPoint = forecasts, RealValue = realValue, FileName = file.Name }); _context.SaveChanges(); _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Info", MessageLogTitle = file.Name, MessageLog = string.Format("{0} сохранили прогноз", file.FullName) }); _context.SaveChanges(); } else { _context.SaveChanges(); _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLogType = "Error", MessageLogTitle = file.Name, MessageLog = string.Format("{0} не получили точек", file.FullName) }); _context.SaveChanges(); } } return(true); } catch (Exception ex) { _context.LogDatas.Add(new LogData { DateLog = DateTime.Now, MessageLog = string.Format("MakeTest {0}: {1}", file.FullName, ex.Message), MessageLogType = "Error" }); _context.SaveChanges(); return(false); } } }