private void Node_ComBox_Changed_Graph_2(object sender, SelectionChangedEventArgs e)
        {
            List <string> Tech = this.nirPlotData.AsEnumerable().Where(row => (string)row[1] == (string)siteListBox_2.SelectedItem).Select(col => (string)col[3]).Distinct().ToList <string>();

            techListBox_2.ItemsSource  = Tech;
            techListBox_2.SelectedItem = Tech[Tech.Count - 1];

            var cells2Plot = nirPlotData.AsEnumerable()
                             .Where(row => (string)row[1] == (string)siteListBox_2.SelectedItem && (string)row[3] == (string)techListBox_2.SelectedItem)
                             .Select(col => (string)col[2]).Distinct();

            List <SectorListItem> sectors = new List <SectorListItem>();

            foreach (var cell in cells2Plot)
            {
                sectors.Add(new SectorListItem()
                {
                    Enabled = true, Sector = TECH_NUM.GetSectorFromLNCEL(cell)
                });
            }
            this.Sectors = sectors;

            Binding codeBinding = new Binding("Sectors");

            codeBinding.Source = this;
            sectorListBox.SetBinding(ListBox.ItemsSourceProperty, codeBinding);
            UpdateGraph_2();
        }
Beispiel #2
0
        public NIR48H(string[] lnBtsInputs, string path)
        {
            data = new DataTable();
            try
            {
                using (StreamReader reader = new StreamReader(path))
                {
                    //Establecer Columnas
                    string[] aux = reader.ReadLine().Split(';'); //Linea de titulo
                    for (int i = 0; i < dataColumns.Length; i++)
                    {
                        data.Columns.Add(dataColumns[i], dataTypes[i]);
                    }

                    while (!reader.EndOfStream)
                    {
                        aux = reader.ReadLine().Split(';');


                        if (aux.Length > 4)
                        {
                            foreach (string lnBts in lnBtsInputs)
                            {
                                if (aux[2].Equals(lnBts))
                                {
                                    object[] line = new object[data.Columns.Count];

                                    line[0] = change_fecha(aux[0]);                                //Fecha

                                    line[1] = aux[2];                                              //Lnbts

                                    line[2] = aux[3].Replace("=", String.Empty);                   //Lncel
                                    line[3] = TECH_NUM.GetName(TECH_NUM.GetTechFromLNCEL(aux[3])); //Tecnología

                                    double?value;
                                    Conversion.ToDouble(aux[11], out value); //Intentos Inter
                                    line[4] = value;

                                    Conversion.ToDouble(aux[12], out value); // Exitos Inter
                                    line[5] = value;

                                    Conversion.ToDouble(aux[9], out value); //Intentos Intra
                                    line[8] = value;

                                    Conversion.ToDouble(aux[10], out value); //Exitos Intra
                                    line[9] = value;

                                    if (line[4] == null && line[5] == null && line[8] == null && line[9] == null)
                                    {
                                        continue;
                                    }

                                    else
                                    {
                                        if (line[4] != null && line[5] != null)
                                        {
                                            line[6] = Math.Round((double)line[5] * (double)line[4] / 100.0, 0); //Exito Inter
                                            line[7] = (double)line[5] - (double)line[6];
                                        }
                                        else
                                        {
                                            line[4] = 0;
                                            line[5] = 0;
                                            line[6] = 0;
                                            line[7] = 0;
                                        }

                                        if (line[9] != null && line[8] != null)
                                        {
                                            line[10] = Math.Round((double)line[8] * (double)line[9] / 100.0, 0); //Exito Intra
                                            line[11] = (double)line[9] - (double)line[10];                       // Errores Intra
                                        }
                                        else
                                        {
                                            line[8]  = 0;
                                            line[9]  = 0;
                                            line[10] = 0;
                                            line[11] = 0;
                                        }
                                    }
                                    data.Rows.Add(line);
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }

                ProcessData();
            }
            catch (FileNotFoundException)
            {
                throw new FileNotFoundException("No se ha podido encontrar la NIR 48h en " + path);
            }
        }
Beispiel #3
0
        // Analiza los errores de los datos guardados y añade las conclusiones como columnas al dataset
        private void ProcessData()
        {
            DataView dv = data.DefaultView;

            dv.Sort = "PERIOD_START_TIME ASC, [LNCEL name] ASC";
            data    = dv.ToTable();

            errors = new DataTable();
            for (int j = 0; j < errorColumns.Length; j++)
            {
                errors.Columns.Add(errorColumns[j], types[j]);
            }

            int i = 0;

            while (i < data.Rows.Count)
            {
                double[,] currentData = new double[5, 4]; //Una matriz que contiene una fila por cada tecnología y 4 columnas de datos( 2 inter y 2 intra)

                do
                {
                    try
                    {
                        byte tech = TECH_NUM.GetTechFromLNCEL((string)data.Rows[i]["LNCEL name"]);
                        if (data.Rows[i]["Intentos Inter"] != DBNull.Value)
                        {
                            currentData[tech, 0] += (int)data.Rows[i]["Intentos Inter"];
                        }
                        if (data.Rows[i]["Exitos HO INTER"] != DBNull.Value)
                        {
                            currentData[tech, 1] += (double)data.Rows[i]["Exitos HO INTER"];
                        }
                        if (data.Rows[i]["Intentos Intra"] != DBNull.Value)
                        {
                            currentData[tech, 2] += (int)data.Rows[i]["Intentos Intra"];
                        }
                        if (data.Rows[i]["Exitos HO INTRA"] != DBNull.Value)
                        {
                            currentData[tech, 3] += (double)data.Rows[i]["Exitos HO INTRA"];
                        }
                    }
                    catch (FormatException fe)
                    {
                        Console.WriteLine("BlackListingAndOffset->AnalisisPrevio->Nir48.cs: Una de las celdas de la NIR no tiene el formato deseado. Detalles:\n " + fe.StackTrace);
                    }
                    i++;
                } while (i < data.Rows.Count && (string)data.Rows[i]["PERIOD_START_TIME"] == (string)data.Rows[i - 1]["PERIOD_START_TIME"] && (string)data.Rows[i]["LNBTS name"] == (string)data.Rows[i - 1]["LNBTS name"]);

                for (byte tech_i = 0; tech_i < 5; tech_i++) // para cada nodo y fecha se saca una linea para cada tecnologia que tenga datos
                {
                    double successInter      = 0;
                    double errInter          = 0;
                    double err2ImproveInter  = 0;
                    double successInterIntra = 0;

                    if (currentData[tech_i, 0] <= 0 && currentData[tech_i, 2] <= 0)
                    {
                        continue;                                                             //Si no hubiera datos ni de inter ni de intra se salta la linea
                    }
                    if (currentData[tech_i, 0] > 0)
                    {
                        successInter = Math.Round(currentData[tech_i, 1] / currentData[tech_i, 0] * 100.0, 2); //Redondear
                        errInter     = currentData[tech_i, 0] - currentData[tech_i, 1];
                        double MaxErr = currentData[tech_i, 0] - (CONSTANTS.U_INTER.PER[tech_i] * currentData[tech_i, 0] / 100.0);
                        err2ImproveInter = 0;
                        if (errInter > MaxErr)
                        {
                            err2ImproveInter = (errInter - Math.Round(MaxErr, 0)) + 1;
                        }
                    }

                    double successIntra     = 0;
                    double errIntra         = 0;
                    double err2ImproveIntra = 0;
                    if (currentData[tech_i, 2] > 0)
                    {
                        successIntra = Math.Round(currentData[tech_i, 3] / currentData[tech_i, 2] * 100, 2); //Redondear
                        errIntra     = currentData[tech_i, 2] - currentData[tech_i, 3];
                        double MaxErr = currentData[tech_i, 2] - (CONSTANTS.U_INTRA.PER[tech_i] * currentData[tech_i, 2] / 100);
                        err2ImproveIntra = 0;
                        if (errIntra > MaxErr)
                        {
                            err2ImproveIntra = (errIntra - Math.Round(MaxErr, 0)) + 1;
                        }
                    }


                    double errInterPlusIntra = 0;
                    errInterPlusIntra = currentData[tech_i, 2] + currentData[tech_i, 0] - (currentData[tech_i, 3] + currentData[tech_i, 1]);
                    successInterIntra = (currentData[tech_i, 1] + currentData[tech_i, 3]) / (currentData[tech_i, 0] + currentData[tech_i, 2]) * 100;
                    successInterIntra = Math.Round(successInterIntra, 2);



                    object[] aux = new object[16] {
                        data.Rows[i - 1]["PERIOD_START_TIME"], data.Rows[i - 1]["LNBTS name"], TECH_NUM.GetName(tech_i), currentData[tech_i, 0], currentData[tech_i, 1], successInter, errInter, err2ImproveInter, currentData[tech_i, 2], currentData[tech_i, 3], successIntra, errIntra, err2ImproveIntra, currentData[tech_i, 0] + currentData[tech_i, 2], successInterIntra, errInterPlusIntra
                    };
                    errors.Rows.Add(aux);
                }
            }
        }
        private void UpdateGraph_2()
        {
            var xAxis = nirPlotData.AsEnumerable()
                        .Where(row => (string)row[1] == (string)siteListBox_2.SelectedItem && (string)row[3] == (string)techListBox_2.SelectedItem)
                        .Select(col => (string)col[0]).Distinct();



            InsertEmpty();

            List <string> xAxis2 = xAxis.ToList();

            xAxis2 = sort_fechas(xAxis2);


            var cells2Plot = nirPlotData.AsEnumerable()
                             .Where(row => (string)row[1] == (string)siteListBox_2.SelectedItem && (string)row[3] == (string)techListBox_2.SelectedItem)
                             .Select(col => (string)col[2]);



            SeriesCollection data = new SeriesCollection();

            var plotSectors = Sectors.Where(item => item.Enabled).ToList();



            if ((bool)checkInter.IsChecked)
            {
                for (int i = 0; i < plotSectors.Count; i++)         // Intentos
                {
                    try
                    {
                        data.Add(new StackedColumnSeries
                        {
                            Values = new ChartValues <int>(nirPlotData.AsEnumerable().Where(row => TECH_NUM.GetSectorFromLNCEL((string)row["LNCEL name"]) == (byte)plotSectors[i].Sector && (string)row[1] == (string)siteListBox_2.SelectedItem &&
                                                                                            (string)row[3] == (string)techListBox_2.SelectedItem).Select(col => (int)col[4]).ToList <int>()),
                            StackMode  = StackMode.Values,
                            DataLabels = true,
                            Fill       = (SolidColorBrush)(new BrushConverter().ConvertFrom("#AA" + interColorsLines[i])),
                            ScalesYAt  = 0,
                            Title      = "Intentos HO Inter s" + plotSectors[i].Sector
                        });
                    }

                    catch (InvalidCastException ice)
                    {
                        Console.WriteLine("HAY VALORES VACIOS " + ice.StackTrace);
                    }
                }
            }
            if ((bool)checkIntra.IsChecked)
            {
                for (int i = 0; i < plotSectors.Count; i++)         // Intentos
                {
                    try
                    {
                        data.Add(new StackedColumnSeries
                        {
                            Values = new ChartValues <int>(nirPlotData.AsEnumerable().Where(row => TECH_NUM.GetSectorFromLNCEL((string)row["LNCEL name"]) == (byte)plotSectors[i].Sector && (string)row[1] == (string)siteListBox_2.SelectedItem &&
                                                                                            (string)row[3] == (string)techListBox_2.SelectedItem).Select(col => (int)col[8]).ToList <int>()),
                            StackMode  = StackMode.Values,
                            DataLabels = true,
                            Fill       = (SolidColorBrush)(new BrushConverter().ConvertFrom("#AA" + intraColorsLines[i])),
                            ScalesYAt  = 0,

                            Title = "Intentos HO Intra s" + plotSectors[i].Sector
                        });
                    }
                    catch (InvalidCastException ice)
                    {
                        Console.WriteLine("HAY VALORES VACIOS " + ice.StackTrace);
                    }
                }
            }
            if ((bool)checkInter.IsChecked)
            {
                for (int i = 0; i < plotSectors.Count; i++)         //Tasa de Exito
                {
                    try
                    {
                        data.Add(new LineSeries
                        {
                            Values = new ChartValues <double>(nirPlotData.AsEnumerable().Where(row => TECH_NUM.GetSectorFromLNCEL((string)row["LNCEL name"]) == (byte)plotSectors[i].Sector && (string)row[1] == (string)siteListBox_2.SelectedItem &&
                                                                                               (string)row[3] == (string)techListBox_2.SelectedItem).Select(col => (double)col[5]).ToList <double>()),
                            ScalesYAt       = 1,
                            StrokeThickness = 2.5,
                            Stroke          = (SolidColorBrush)(new BrushConverter().ConvertFrom("#" + interColorsLines[i])),
                            Fill            = Brushes.Transparent,
                            Title           = " % Exitos HO Inter s" + plotSectors[i].Sector
                        });
                    }
                    catch (InvalidCastException ice)
                    {
                        Console.WriteLine("HAY VALORES VACIOS " + ice.StackTrace);
                    }
                }
            }
            if ((bool)checkIntra.IsChecked)
            {
                for (int i = 0; i < plotSectors.Count; i++)         //Tasa de Exito
                {
                    try
                    {
                        data.Add(new LineSeries
                        {
                            Values = new ChartValues <double>(nirPlotData.AsEnumerable().Where(row => TECH_NUM.GetSectorFromLNCEL((string)row["LNCEL name"]) == (byte)plotSectors[i].Sector && (string)row[1] == (string)siteListBox_2.SelectedItem &&
                                                                                               (string)row[3] == (string)techListBox_2.SelectedItem).Select(col => (double)col[9]).ToList <double>()),
                            ScalesYAt       = 1,
                            StrokeThickness = 2.5,
                            Stroke          = (SolidColorBrush)(new BrushConverter().ConvertFrom("#" + intraColorsLines[i])),
                            Fill            = Brushes.Transparent,
                            Title           = " % Exitos HO Intra s" + plotSectors[i].Sector,
                        });
                    }
                    catch (InvalidCastException ice)
                    {
                        Console.WriteLine("HAY VALORES VACIOS " + ice.StackTrace);
                    }
                }
            }

            //arreglar lo de los ejes, te puedes inspirar en UpdateGraph_1(), y la ordenacion de las fechas, buena suerte, y pregunta cosas a la gente
            graphObject_2.DrawGraph(data, 50000, xAxis2);
        }
        //tras acabar el procesado en segundo plano se actualiza la interfaz con ellos
        private void BackGround_Completed(object sender, RunWorkerCompletedEventArgs e)
        {
            // Progress_Bar.Value = 100;
            if (e.Error == null)
            {
                //Paramos de girar el cursor
                Cursor = Cursors.Arrow;

                plotNodo.Visibility   = Visibility;
                plotceldas.Visibility = Visibility;


                bgwBlnOffResult output = (bgwBlnOffResult)e.Result;
                Copiaoutput = output;
                if (output.colindancias != null)
                {
                    colinGrid.WorkingData = output.colindancias;
                    WPFForms.FindParent <TabItem>(colinGrid).Visibility = Visibility.Visible;
                    tabColindancias.IsSelected = true;



                    //fc = new formColindancias(output.colindancias);

                    //fc.Show();
                }

                if (output.siteCoordErrors != "" && (bool)Is_BlnOFF_Enabled.IsChecked)
                {
                    WPFForms.ShowError("Faltan las coordenadas de los siguientes emplazamientos", output.siteCoordErrors);
                }

                if (output.candBl != null)
                {
                    candBLGrid.WorkingData = output.candBl;
                    WPFForms.FindParent <TabItem>(candBLGrid).Visibility = Visibility.Visible;
                }
                if (output.candOff != null)
                {
                    candOFFGrid.WorkingData = output.candOff;
                    WPFForms.FindParent <TabItem>(candOFFGrid).Visibility = Visibility.Visible;
                }
                if (output.error != null)
                {   //se genera la tabla de analis previo
                    errGrid.WorkingData = output.error;
                    WPFForms.FindParent <TabItem>(errGrid).Visibility = Visibility.Visible;

                    //se genera la gárafica por nodos
                    this.erroresAMejorar = output.error;

                    List <string> sites = erroresAMejorar.AsEnumerable().Select(col => (string)col[1]).Distinct().ToList();
                    siteListBox_1.ItemsSource  = sites;
                    siteListBox_1.SelectedItem = sites[0];

                    List <string> Tech = this.erroresAMejorar.AsEnumerable().Where(row => (string)row[1] == (string)siteListBox_1.SelectedItem).Select(col => (string)col[2]).Distinct().ToList <string>();
                    techListBox_1.ItemsSource  = Tech;
                    techListBox_1.SelectedItem = Tech[0];

                    UpdateGraph_1();
                }
                if (output.nirPlotData != null)
                {
                    this.nirPlotData = output.nirPlotData;

                    List <string> sites = erroresAMejorar.AsEnumerable().Select(col => (string)col[1]).Distinct().ToList();
                    siteListBox_2.ItemsSource  = sites;
                    siteListBox_2.SelectedItem = sites[0];

                    List <string> tech = this.nirPlotData.AsEnumerable().Where(row => (string)row[1] == (string)siteListBox_2.SelectedItem).Select(col => (string)col[3]).Distinct().ToList <string>();
                    techListBox_2.ItemsSource  = tech;
                    techListBox_2.SelectedItem = tech[0];

                    var cells2Plot = nirPlotData.AsEnumerable()
                                     .Where(row => (string)row[1] == (string)siteListBox_2.SelectedItem && (string)row[3] == (string)techListBox_2.SelectedItem)
                                     .Select(col => (string)col[2]).Distinct().Where(item => !item.Contains("="));

                    List <SectorListItem> sectors = new List <SectorListItem>();
                    foreach (var cell in cells2Plot)
                    {
                        sectors.Add(new SectorListItem()
                        {
                            Enabled = true, Sector = TECH_NUM.GetSectorFromLNCEL(cell)
                        });
                    }
                    this.Sectors = sectors;

                    Binding codeBinding = new Binding("Sectors");
                    codeBinding.Source = this;
                    sectorListBox.SetBinding(ListBox.ItemsSourceProperty, codeBinding);

                    UpdateGraph_2();
                }
            }
            else
            {
                //Paramos de girar el cursor
                Cursor = Cursors.Arrow;

                //control de errores en BackGround
                switch (e.Error.GetType().Name)
                {
                case "FileNotFoundException":
                    WPFForms.ShowError("Falta un archivo", e.Error.Message);
                    break;

                case "InvalidOperationException":
                    WPFForms.ShowError("Error critico", e.Error.Message);
                    break;

                case "ArgumentException":
                    WPFForms.ShowError("Error en los datos", e.Error.Message);
                    break;

                default:
                    WPFForms.ShowError("No controlado", e.Error.Message);
                    break;
                }
            }
        }