Пример #1
0
        private Intercalado CalcularDirections(Intercalado intercalado, PuntoEntrega nuevoPunto)
        {
            var i = CalcularDirectionsOriginal(intercalado);

            i = CalcularDirectionsIntercalado(i, nuevoPunto);
            return(i);
        }
Пример #2
0
        private bool IsInHoras(Intercalado intercalado)
        {
            if (Horas.Count() != 24)
            {
                return(true);
            }
            var h = intercalado.Hora.Hour;

            return(Horas[h]);
        }
Пример #3
0
        private Intercalado CalcularDirectionsOriginal(Intercalado intercalado)
        {
            var viaje      = Viajes.FirstOrDefault(v => v.Id == intercalado.Id);
            var first      = viaje.Detalles.First().ReferenciaGeografica;
            var last       = viaje.Detalles.Last().ReferenciaGeografica;
            var origen     = new LatLon(first.Latitude, first.Longitude);
            var destino    = new LatLon(last.Latitude, last.Longitude);
            var waypoints  = viaje.Detalles.Skip(1).Take(viaje.Detalles.Count - 2).Select(w => new LatLon(w.ReferenciaGeografica.Latitude, w.ReferenciaGeografica.Longitude)).ToList();
            var directions = GoogleDirections.GetDirections(origen, destino, GoogleDirections.Modes.Driving,
                                                            string.Empty, waypoints.ToArray());

            intercalado.ViajeAnterior = directions;
            if (directions != null)
            {
                intercalado.CostoKmOld = directions.Distance;
            }
            var duracionAnterior = viaje.Detalles.Last().Programado.Subtract(viaje.Detalles.First().Programado);

            intercalado.CostoMinOld = duracionAnterior.TotalMinutes;

            return(intercalado);
        }
Пример #4
0
        private Intercalado CalcularDirectionsIntercalado(Intercalado intercalado, PuntoEntrega nuevoPunto)
        {
            var viaje = Viajes.FirstOrDefault(v => v.Id == intercalado.Id);

            var first  = viaje.Detalles.First().ReferenciaGeografica;
            var origen = new LatLon(first.Latitude, first.Longitude);

            var last    = viaje.Detalles.Last().ReferenciaGeografica;
            var destino = new LatLon(last.Latitude, last.Longitude);

            var waypoints = viaje.Detalles.Skip(1).Take(viaje.Detalles.Count - 2).Select(w => new LatLon(w.ReferenciaGeografica.Latitude, w.ReferenciaGeografica.Longitude)).ToList();

            var nuevaLatLon = new LatLon(nuevoPunto.ReferenciaGeografica.Latitude,
                                         nuevoPunto.ReferenciaGeografica.Longitude);

            if (intercalado.Index == 0)
            {
                waypoints.Insert(0, origen);
                origen = nuevaLatLon;
            }
            else if (intercalado.Index >= viaje.Detalles.Count)
            {
                waypoints.Add(destino);
                destino = nuevaLatLon;
            }
            else if (intercalado.Index == viaje.Detalles.Count - 1)
            {
                waypoints.Add(nuevaLatLon);
            }
            else
            {
                waypoints.Insert(intercalado.Index, nuevaLatLon);
            }

            var directions = GoogleDirections.GetDirections(origen, destino, GoogleDirections.Modes.Driving,
                                                            string.Empty, waypoints.ToArray());

            intercalado.ViajeIntercalado = directions;
            if (directions != null)
            {
                intercalado.CostoKm = directions.Distance;
            }

            var nuevoDetalle = new EntregaDistribucion
            {
                PuntoEntrega = nuevoPunto,
                Cliente      = nuevoPunto.Cliente,
                Descripcion  = nuevoPunto.Descripcion
            };

            viaje.InsertarEntrega(intercalado.Index, nuevoDetalle);
            if (intercalado.Index > 0)
            {
                viaje.CalcularHorario(intercalado.Index, intercalado.ViajeIntercalado);
            }
            if (intercalado.Index < viaje.Detalles.Count)
            {
                viaje.CalcularHorario(intercalado.Index, intercalado.ViajeIntercalado);
            }

            var duracionNueva = viaje.Detalles.Last().Programado.Subtract(viaje.Detalles.First().Programado);

            intercalado.CostoMin = duracionNueva.TotalMinutes;

            intercalado.Hora = nuevoDetalle.Programado;

            viaje.RemoverEntrega(intercalado.Index);

            return(intercalado);
        }