Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
6.6 kB
1
Indexable
Never
private static void Create_Report_By_Nodes(ExcelPackage excelPackage, List<Node> Nodes, ThreePhDevice BaseDevice, List<I_ByPh> I_values)
        {
            var sheet = excelPackage.Workbook.Worksheets.Add("Фаза А_NEW");

            sheet.Cells[1, 1].Value = "Момент времени";
            sheet.Cells[1, 2].Value = $"Напряжение фазы A базового ПУ";
            sheet.Cells[1, 3].Value = $"∑I(A) ср для узла";
            sheet.Cells[1, 4].Value = $"Тип напряжения U";
            int row = 2;
            for (int i = 0; i < BaseDevice.ThreePhDatas.Count; i++, row += 2)
            {
                sheet.Cells[row, 1].Value = BaseDevice.ThreePhDatas[i].DateTime.ToString();
                sheet.Cells[row + 1, 1].Value = BaseDevice.ThreePhDatas[i].DateTime.ToString();
                sheet.Cells[row, 2].Value = BaseDevice.ThreePhDatas[i].phA_Voltage;
                sheet.Cells[row + 1, 2].Value = BaseDevice.ThreePhDatas[i].phA_Voltage;
                sheet.Cells[row, 3].Value = I_values[i].Value_I;
                sheet.Cells[row + 1, 3].Value = I_values[i].Value_I;
            }
            int column_Index = 5;
            for (int i = 0; i < Nodes.Count; i++, column_Index++)
            {
                row = 2;
                sheet.Cells[1, column_Index].Value = $"Узел {Nodes[i].Ident}";

                if(Nodes[i].Devices_phA is not null && Nodes[i].Devices_phA.Count != 0)
                {
                    for (int j = 0; j < I_values.Count; j++, row += 2)
                    {
                        Tuple<double, double> avgValues = Get222(Nodes[i].Devices_phA, I_values[j].DateTime);
                        sheet.Cells[row, 4].Value = "Фактическое";
                        sheet.Cells[row + 1, 4].Value = "Расчетное";
                        sheet.Cells[row, column_Index].Value = Math.Round(avgValues.Item1, 2);
                        sheet.Cells[row + 1, column_Index].Value = Math.Round(avgValues.Item2, 2);
                    }
                }
            }

            sheet = excelPackage.Workbook.Worksheets.Add("Фаза B_NEW");

            sheet.Cells[1, 1].Value = "Момент времени";
            sheet.Cells[1, 2].Value = $"Напряжение фазы B базового ПУ";
            sheet.Cells[1, 3].Value = $"∑I(B) ср для узла";
            sheet.Cells[1, 4].Value = $"Тип напряжения U";
            row = 2;
            for (int i = 0; i < BaseDevice.ThreePhDatas.Count; i++, row += 2)
            {
                sheet.Cells[row, 1].Value = BaseDevice.ThreePhDatas[i].DateTime.ToString();
                sheet.Cells[row + 1, 1].Value = BaseDevice.ThreePhDatas[i].DateTime.ToString();
                sheet.Cells[row, 2].Value = BaseDevice.ThreePhDatas[i].phB_Voltage;
                sheet.Cells[row + 1, 2].Value = BaseDevice.ThreePhDatas[i].phB_Voltage;
                sheet.Cells[row, 3].Value = I_values[i].Value_I;
                sheet.Cells[row + 1, 3].Value = I_values[i].Value_I;
            }
            column_Index = 5;
            for (int i = 0; i < Nodes.Count; i++, column_Index++)
            {
                row = 2;
                sheet.Cells[1, column_Index].Value = $"Узел {Nodes[i].Ident}";

                if (Nodes[i].Devices_phB is not null && Nodes[i].Devices_phB.Count != 0)
                {
                    for (int j = 0; j < I_values.Count; j++, row += 2)
                    {
                        Tuple<double, double> avgValues = Get222(Nodes[i].Devices_phB, I_values[j].DateTime);
                        sheet.Cells[row, 4].Value = "Фактическое";
                        sheet.Cells[row + 1, 4].Value = "Расчетное";
                        sheet.Cells[row, column_Index].Value = Math.Round(avgValues.Item1, 2);
                        sheet.Cells[row + 1, column_Index].Value = Math.Round(avgValues.Item2, 2);
                    }
                }
            }

            sheet = excelPackage.Workbook.Worksheets.Add("Фаза C_NEW");

            sheet.Cells[1, 1].Value = "Момент времени";
            sheet.Cells[1, 2].Value = $"Напряжение фазы C базового ПУ";
            sheet.Cells[1, 3].Value = $"∑I(C) ср для узла";
            sheet.Cells[1, 4].Value = $"Тип напряжения U";
            row = 2;
            for (int i = 0; i < BaseDevice.ThreePhDatas.Count; i++, row += 2)
            {
                sheet.Cells[row, 1].Value = BaseDevice.ThreePhDatas[i].DateTime.ToString();
                sheet.Cells[row + 1, 1].Value = BaseDevice.ThreePhDatas[i].DateTime.ToString();
                sheet.Cells[row, 2].Value = BaseDevice.ThreePhDatas[i].phC_Voltage;
                sheet.Cells[row + 1, 2].Value = BaseDevice.ThreePhDatas[i].phC_Voltage;
                sheet.Cells[row, 3].Value = I_values[i].Value_I;
                sheet.Cells[row + 1, 3].Value = I_values[i].Value_I;
            }
            column_Index = 5;
            for (int i = 0; i < Nodes.Count; i++, column_Index++)
            {
                row = 2;
                sheet.Cells[1, column_Index].Value = $"Узел {Nodes[i].Ident}";

                if (Nodes[i].Devices_phC is not null && Nodes[i].Devices_phC.Count != 0)
                {
                    for (int j = 0; j < I_values.Count; j++, row += 2)
                    {
                        Tuple<double, double> avgValues = Get222(Nodes[i].Devices_phC, I_values[j].DateTime);
                        sheet.Cells[row, 4].Value = "Фактическое";
                        sheet.Cells[row + 1, 4].Value = "Расчетное";
                        sheet.Cells[row, column_Index].Value = Math.Round(avgValues.Item1, 2);
                        sheet.Cells[row + 1, column_Index].Value = Math.Round(avgValues.Item2, 2);
                    }
                }
            }
        }
        private static Tuple<double,double> Get222(List<OnePhDevice> onePhDevices, DateTime dateTime)
        {
            double avg_Voltage = 0;
            double avg_CurrentVoltage = 0;
            var datas = onePhDevices.SelectMany(x => x.OnePhData).ToList().Where(dt => dt.DateTime == dateTime);

            avg_Voltage = datas.Average(a => a.VoltageU);
            avg_CurrentVoltage = datas.Average(a => a.CurrentU);

            return new Tuple<double, double>(avg_Voltage, avg_CurrentVoltage);
        }