Ejemplo n.º 1
0
        public static List <double> AgruparSegmentacion(Segmentacion segmentacion, List <Evento> eventos)
        {
            if (eventos != null && eventos.Count > 0)
            {
                double cantEventos = (double)eventos.Count;
                switch (segmentacion)
                {
                case Segmentacion.DIA:
                    return(eventos.Select(x => new { Mes = x.fecha.Month, Anio = x.fecha.Year, Dia = x.fecha.Day })
                           .GroupBy(x => new { x.Mes, x.Anio, x.Dia }).Select(x => Convert.ToDouble(x.Count())).ToList());

                case Segmentacion.HORA:
                    return(eventos.Select(x => new { Mes = x.fecha.Month, Anio = x.fecha.Year, Dia = x.fecha.Day, Hora = x.fecha.Hour })
                           .GroupBy(x => new { x.Anio, x.Mes, x.Dia, x.Hora }).Select(x => Convert.ToDouble(x.Count())).ToList());

                case Segmentacion.MINUTO:
                    return(eventos.Select(x => new { Mes = x.fecha.Month, Anio = x.fecha.Year, Dia = x.fecha.Day, Hora = x.fecha.Hour, Minuto = x.fecha.Minute })
                           .GroupBy(x => new { x.Anio, x.Mes, x.Dia, x.Hora, x.Minuto }).Select(x => Convert.ToDouble(x.Count())).ToList());

                case Segmentacion.SEGUNDO:
                    return(eventos.Select(x => new { Mes = x.fecha.Month, Anio = x.fecha.Year, Dia = x.fecha.Day, Hora = x.fecha.Hour, Minuto = x.fecha.Minute, Segundo = x.fecha.Second })
                           .GroupBy(x => new { x.Anio, x.Mes, x.Dia, x.Hora, x.Minuto, x.Segundo }).Select(x => Convert.ToDouble(x.Count())).ToList());

                default:
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
 public FrmAjusteFunciones(MetodologiaAjuste metodologia, Segmentacion segmentacion, List <Double> intervalos, int flagIntervalos, Origen proyecto)
 {
     InitializeComponent();
     this.metodologia    = metodologia;
     this.segmentacion   = segmentacion;
     this.intervalos     = intervalos;
     this.flagIntervalos = flagIntervalos;
     this.proyecto       = proyecto;
 }
Ejemplo n.º 3
0
        public static void nuevoPorIntervalo(int cantidad, Segmentacion segm, int idOrigen)
        {
            DateTime fechaAAgregar = DateTime.Now;

            using (var db = new EventoContexto())
            {
                DateTime maxFecha;
                if (db.Eventos.Where(x => x.idOrigen == idOrigen).Count() > 0)
                {
                    maxFecha = db.Eventos.Where(x => x.idOrigen == idOrigen).Max(x => x.fecha);
                }
                else
                {
                    maxFecha = DateTime.Now;
                }

                switch (segm)
                {
                case Segmentacion.DIA:
                    fechaAAgregar = maxFecha.AddDays(cantidad);
                    break;

                case Segmentacion.HORA:
                    fechaAAgregar = maxFecha.AddHours(cantidad);
                    break;

                case Segmentacion.MINUTO:
                    fechaAAgregar = maxFecha.AddMinutes(cantidad);
                    break;

                case Segmentacion.SEGUNDO:
                    fechaAAgregar = maxFecha.AddSeconds(cantidad);
                    break;

                default:
                    break;
                }
                db.Eventos.Add(entity: new Evento {
                    fecha = fechaAAgregar, idOrigen = idOrigen, activo = true
                });
                db.SaveChanges();
            }
        }
        private void btnCalcularFDP_Click(object sender, EventArgs e)
        {
            if (eventos.Count() >= 15)
            {
                try
                {
                    MetodologiaAjuste metodologia  = MetodologiaAjuste.EVENTO_A_EVENTO;
                    Segmentacion      segmentacion = Segmentacion.SEGUNDO;
                    int flagIntervalos             = 0;

                    if (rbFecha.Checked)
                    {
                        metodologia  = rbEventoAEvento.Checked ? MetodologiaAjuste.EVENTO_A_EVENTO : MetodologiaAjuste.DT_CONSTANTE;
                        segmentacion = rbDia.Checked ? Segmentacion.DIA : (rbHora.Checked ? Segmentacion.HORA : (rbMinuto.Checked ? Segmentacion.MINUTO : Segmentacion.SEGUNDO));
                        FrmAjusteFunciones frm = new FrmAjusteFunciones(metodologia, segmentacion, eventos, flagIntervalos, this.proyecto);
                        this.Visible = false;
                        frm.ShowDialog();
                        this.Visible = true;
                    }
                    else if (rbIntervalos.Checked)
                    {
                        metodologia    = MetodologiaAjuste.EVENTO_A_EVENTO;
                        flagIntervalos = 1;
                        FrmAjusteFunciones frm = new FrmAjusteFunciones(metodologia, segmentacion, intervalosParciales, flagIntervalos, this.proyecto);
                        this.Visible = false;
                        frm.ShowDialog();
                        this.Visible = true;
                    }
                }
                catch
                {
                    mostrarMensaje("Error al calcular funciones", Color.FromArgb(255, 89, 89));
                }
            }
            else
            {
                mostrarMensaje("Debe haber al menos 15 eventos en el proyecto", Color.FromArgb(255, 255, 0));
            }
        }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            DateTime     fecha;
            Segmentacion segmentacion = Segmentacion.SEGUNDO;

            switch (tipoAccion)
            {
            case TipoAccionProcesamiento.AGREGAR_REGISTRO:
                if (rbAgregarPorFechaYHora.Checked)
                {
                    fecha = new DateTime(dtp1.Value.Year, dtp1.Value.Month, dtp1.Value.Day, dtp2.Value.Hour, dtp2.Value.Minute, dtp2.Value.Second);
                    EventoService.nuevo(fecha, this.proyecto.Id);
                }
                else if (rbAgregarPorIntervalo.Checked)
                {
                    switch (cbAgregarPorIntervalo.SelectedItem)
                    {
                    case "Segundos":
                        segmentacion = Segmentacion.SEGUNDO;
                        break;

                    case "Minutos":
                        segmentacion = Segmentacion.MINUTO;
                        break;

                    case "Horas":
                        segmentacion = Segmentacion.HORA;
                        break;

                    case "Dias":
                        segmentacion = Segmentacion.DIA;
                        break;

                    default:
                        break;
                    }
                    EventoService.nuevoPorIntervalo(Convert.ToInt32(nudAgregarPorIntervalo.Value), segmentacion, this.proyecto.Id);
                }
                mostrarMensaje("Registro agregado correctamente", Color.FromArgb(128, 255, 128));
                cargarEventos();
                actualizarEstadisticas();

                break;

            case TipoAccionProcesamiento.MODIFICAR_REGISTRO:
                fecha = new DateTime(dtp1.Value.Year, dtp1.Value.Month, dtp1.Value.Day, dtp2.Value.Hour, dtp2.Value.Minute, dtp2.Value.Second);
                if (eventosSeleccionados.Count == 1)
                {
                    EventoService.modificar(eventosSeleccionados[0].Id, fecha);
                    cargarEventos();
                    mostrarMensaje("Registro modificado correctamente", Color.FromArgb(128, 255, 128));
                    actualizarEstadisticas();
                }
                else
                {
                    mostrarMensaje("Seleccione solo un registro", Color.FromArgb(255, 89, 89));
                }
                break;

            case TipoAccionProcesamiento.FILTRAR:
                agregarFiltro();
                filtrar();
                mostrarMensaje("Filtro aplicado correctamente", Color.FromArgb(128, 255, 128));
                actualizarEstadisticas();
                break;

            default:
                break;
            }
        }