/// <summary> /// обновление всех элементов в соответствии с выбранными параметрами /// </summary> private void refreshInfo() { RawRange tempr = range.GetRange( radioButtonSelectPeriod.Checked, radioButtonSelectYearMonth.Checked, dateTimePickerFrom.Value, dateTimePickerTo.Value, comboBoxYear.SelectedItem, comboBoxMonth.SelectedItem ); if (tempr == null) { throw new Exception("что-то совсем не так!!"); } //расчет параметров try { range_info = StatisticEngine.ProcessRange(tempr, range); stat_speeds = StatisticEngine.GetExpectancy(tempr, Vars.Options.CurrentSpeedGradation); stat_directions = StatisticEngine.GetDirectionExpectancy(tempr, GradationInfo <WindDirections16> .Rhumb16Gradations); exp_info = StatisticEngine.ProcessRange(stat_speeds); } catch (Exception ex) { _ = MessageBox.Show(this, ex.Message, "Расчёт энергетических характеристик", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (range_info == null || exp_info == null) { _ = MessageBox.Show(this, "Для заданного ряда невозможно расчитать характеристики на выбранном интервале", "Расчёт энергетических характеристик", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //вывод параметров labelEnergyDensity.Text = (range_info.EnergyDensity / 1000).ToString("0.00") + " кВт*ч/м^2"; labelPowerDensity.Text = range_info.PowerDensity.ToString("0.00") + " Вт/м^2"; labelCv.Text = range_info.Cv.ToString("0.000"); labelV0.Text = range_info.V0.ToString("0.0") + " м/с"; labelExtremalSpeed.Text = range_info.ExtremalSpeed.ToString("0.0") + " м/с"; labelVmax.Text = range_info.Vmax.ToString("0.0") + " м/с"; labelVmin.Text = range_info.Vmin.ToString("0.0") + " м/с"; labelStandardDeviationSpeed.Text = range_info.StandardDeviationSpeed.ToString("0.000") + " м/с"; labelGamma.Text = range_info.VeybullGamma.ToString("0.000"); labelBeta.Text = range_info.VeybullBeta.ToString("0.000") + " м/с"; labelAirDensity.Text = tempr.AirDensity.ToString("0.000") + " кг/м^3" + (Vars.Options.CalculateAirDensity ? " (расчёт)" : ""); labelEnergyDensityTV.Text = (exp_info.EnergyDensity / 1000).ToString("0.00") + " кВт*ч/м^2"; labelPowerDensityTV.Text = exp_info.PowerDensity.ToString("0.00") + " Вт/м^2"; labelCvTV.Text = exp_info.Cv.ToString("0.000"); labelV0TV.Text = exp_info.V0.ToString("0.0") + " м/с"; labelGammaTV.Text = exp_info.VeybullGamma.ToString("0.000"); labelBetaTV.Text = exp_info.VeybullBeta.ToString("0.000") + " м/с"; }
/// <summary> /// сохранение ВЭК /// </summary> /// <param name="filename"></param> /// <param name="range"></param> public override void SaveEnergyInfo(string filename, RawRange range) { using (ExcelPackage excelPackage = new ExcelPackage()) { //Set some properties of the Excel document excelPackage.Workbook.Properties.Author = "Wind Energy"; excelPackage.Workbook.Properties.Title = range.Name; excelPackage.Workbook.Properties.Created = DateTime.Now; //Create the WorkSheet ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Лист 1"); List <object> years = new List <object>(); foreach (RawItem item in range) { if (!years.Contains(item.Date.Year)) { years.Add(item.Date.Year); } } double totalAverageSpeed = range.Average((t) => t.Speed); //формирование заголовка List <string> cap = new List <string>() { "Год", "Месяц", "Кол-во измерений" }; foreach (GradationItem grad in Vars.Options.CurrentSpeedGradation.Items) { cap.Add(grad.Average.ToString("0.00")); } cap.AddRange(new string[] { "Vmin, м/с", "Vmax, м/с", "Vср, м/с", "Vэкстр.50, м/с", "δ(P)", "Cv(V)", "𝜎(V)", "γ", "β", "Nвал уд., Вт/м^2", "Эвал уд., Вт*ч/м^2" }); foreach (WindDirections16 wd in WindDirections16.Calm.GetEnumItems().GetRange(0, 17)) { cap.Add(wd.Description()); } //ЗАПИСЬ ФАЙЛА //запись заголовка for (int j = 1; j <= cap.Count; j++) { worksheet.Cells[1, j].Value = cap[j - 1]; } worksheet.Cells[1, 1, 1, cap.Count].Style.Font.Bold = true; worksheet.Cells[1, 1, 1, cap.Count].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[1, 1, 1, cap.Count].Style.Fill.BackgroundColor.SetColor(Color.Gray); worksheet.View.FreezePanes(2, 3); //запись данных обо всём периоде EnergyInfo ri1 = StatisticEngine.ProcessRange(range); StatisticalRange <WindDirections16> sd1 = StatisticEngine.GetDirectionExpectancy(range, GradationInfo <WindDirections16> .Rhumb16Gradations); StatisticalRange <GradationItem> ss1 = StatisticEngine.GetExpectancy(range, Vars.Options.CurrentSpeedGradation); EnergyInfo ei1 = StatisticEngine.ProcessRange(ss1); int cells = saveEnergyInfoLine(worksheet, 2, ri1, ei1, sd1, ss1, "Все года", "Все месяцы", range.Count); worksheet.Cells[2, 1, 2, cells].Style.Font.Bold = true; worksheet.Cells[2, 1, 2, cells].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[2, 1, 2, cells].Style.Fill.BackgroundColor.SetColor(Color.LightGray); //запись данных для каждого года int line = 3; foreach (int year in years) //цикл по годам { //для каждого месяца в году for (int mt = 0; mt <= 12; mt++) //по месяцам, начиная со всех { Months month = (Months)mt; RawRange rn = range.GetRange(false, true, DateTime.Now, DateTime.Now, year, month.Description()); if (rn == null || rn.Count == 0) { continue; } EnergyInfo ri = StatisticEngine.ProcessRange(rn, range); StatisticalRange <WindDirections16> sd = StatisticEngine.GetDirectionExpectancy(rn, GradationInfo <WindDirections16> .Rhumb16Gradations); StatisticalRange <GradationItem> ss = StatisticEngine.GetExpectancy(rn, Vars.Options.CurrentSpeedGradation); EnergyInfo ei = StatisticEngine.ProcessRange(ss); cells = saveEnergyInfoLine(worksheet, line, ri, ei, sd, ss, year.ToString(), month.Description(), rn.Count); if (Math.IEEERemainder(mt + 1, 2) == 0 || mt == 0) //на нечетных строках добавляем серый фон { worksheet.Cells[line, 1, line, cells].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[line, 1, line, cells].Style.Fill.BackgroundColor.SetColor(Color.LightGray); } if (month == Months.All) //для суммарной информации по году выделение жирным { worksheet.Cells[line, 1, line, cells].Style.Font.Bold = true; } line++; } } //запись данных для каждого месяца отдельно line += 3; //для каждого месяца в году for (int mt = 1; mt <= 12; mt++) //по месяцам { Months month = (Months)mt; RawRange rn = range.GetRange(false, true, DateTime.Now, DateTime.Now, "Все", month.Description()); if (rn == null || rn.Count == 0) { continue; } EnergyInfo ri = StatisticEngine.ProcessRange(rn, range); StatisticalRange <WindDirections16> sd = StatisticEngine.GetDirectionExpectancy(rn, GradationInfo <WindDirections16> .Rhumb16Gradations); StatisticalRange <GradationItem> ss = StatisticEngine.GetExpectancy(rn, Vars.Options.CurrentSpeedGradation); EnergyInfo ei = StatisticEngine.ProcessRange(ss); cells = saveEnergyInfoLine(worksheet, line, ri, ei, sd, ss, "Все года", month.Description(), rn.Count); if (Math.IEEERemainder(mt + 1, 2) == 0 || mt == 0) //на нечетных строках добавляем серый фон { worksheet.Cells[line, 1, line, cells].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[line, 1, line, cells].Style.Fill.BackgroundColor.SetColor(Color.LightGray); } line++; } //Save your file FileInfo fi = new FileInfo(filename); excelPackage.SaveAs(fi); } }
/// <summary> /// Сохранение ВЭК в формате CSV /// </summary> /// <param name="filename"></param> /// <param name="range"></param> public override void SaveEnergyInfo(string filename, RawRange range) { List <object> years = new List <object>(); foreach (RawItem item in range) { if (!years.Contains(item.Date.Year)) { years.Add(item.Date.Year); } } //формирование заголовка string cap = "Год;Месяц;кол-во изм"; foreach (GradationItem grad in Vars.Options.CurrentSpeedGradation.Items) { cap += ";" + grad.Average.ToString("0.00"); } cap += ";Vmin, м/с;Vmax, м/с;Vср, м/с;Vэкст50,м/с;Cv(V);𝜎(V);параметр γ;параметр β;Nвал уд., Вт/м^2;Эвал уд., Вт*ч/м^2"; foreach (WindDirections16 wd in WindDirections16.Calm.GetEnumItems().GetRange(0, 17)) { cap += ";" + wd.Description(); } //запись в файл saveEnergyInfoLine(filename, null, null, null, null, cap, "", "", 0, false); //запись заголовка //запись данных обо всём периоде EnergyInfo ri1 = StatisticEngine.ProcessRange(range); StatisticalRange <WindDirections16> sd1 = StatisticEngine.GetDirectionExpectancy(range, GradationInfo <WindDirections16> .Rhumb16Gradations); StatisticalRange <GradationItem> ss1 = StatisticEngine.GetExpectancy(range, Vars.Options.CurrentSpeedGradation); EnergyInfo ei1 = StatisticEngine.ProcessRange(ss1); saveEnergyInfoLine(filename, ri1, ei1, sd1, ss1, null, "Все года", "Все месяцы", range.Count, true); //запись данных для каждого года foreach (int year in years) //цикл по годам { //для каждого месяца в году for (int mt = 0; mt <= 12; mt++)//по месяцам, начиная со всех { Months month = (Months)mt; RawRange rn = range.GetRange(false, true, DateTime.Now, DateTime.Now, year, month.Description()); if (rn == null || rn.Count == 0) { continue; } EnergyInfo ri = StatisticEngine.ProcessRange(rn, range); StatisticalRange <WindDirections16> sd = StatisticEngine.GetDirectionExpectancy(rn, GradationInfo <WindDirections16> .Rhumb16Gradations); StatisticalRange <GradationItem> ss = StatisticEngine.GetExpectancy(rn, Vars.Options.CurrentSpeedGradation); EnergyInfo ei = StatisticEngine.ProcessRange(ss); saveEnergyInfoLine(filename, ri, ei, sd, ss, null, year.ToString(), month.Description(), rn.Count, true); } } //запись данных по месяцам saveEnergyInfoLine(filename, null, null, null, null, ";", "", "", 0, true); saveEnergyInfoLine(filename, null, null, null, null, ";", "", "", 0, true); saveEnergyInfoLine(filename, null, null, null, null, ";", "", "", 0, true); for (int mt = 1; mt <= 12; mt++)//по месяцам, начиная со всех { Months month = (Months)mt; RawRange rn = range.GetRange(false, true, DateTime.Now, DateTime.Now, "Все", month.Description()); if (rn == null || rn.Count == 0) { continue; } EnergyInfo ri = StatisticEngine.ProcessRange(rn, range); StatisticalRange <WindDirections16> sd = StatisticEngine.GetDirectionExpectancy(rn, GradationInfo <WindDirections16> .Rhumb16Gradations); StatisticalRange <GradationItem> ss = StatisticEngine.GetExpectancy(rn, Vars.Options.CurrentSpeedGradation); EnergyInfo ei = StatisticEngine.ProcessRange(ss); saveEnergyInfoLine(filename, ri, ei, sd, ss, null, "Все года", month.Description(), rn.Count, true); } }