Esempio n. 1
0
        public double GetRunningHours(int coche, DateTime inicio, DateTime fin)
        {
            var time = 0.0;

            if (fin < DateTime.Today.ToDataBaseDateTime())
            {
                var dmDAO = new DatamartDAO();
                var dm    = dmDAO.GetMobilesTimes(inicio, fin, new List <int> {
                    coche
                }).FirstOrDefault();
                return(dm != null ? dm.ElapsedTime : 0.0);
            }

            var lpDAO   = new LogPosicionDAO();
            var results = lpDAO.GetPositionsBetweenDates(coche, inicio, fin);

            //if (results.Count.Equals(0))
            //    results = Session.Query<LogPosicionHistorica>()
            //        .Where(position => position.Coche.Id == coche && position.FechaMensaje >= inicio && position.FechaMensaje <= fin)
            //        .Cast<LogPosicionBase>()
            //        .ToList();

            for (var i = 0; i < results.Count - 1; i++)
            {
                var x = results[i];
                var y = results[i + 1];

                if (x.MotorOn.HasValue && x.MotorOn.Value)
                {
                    time += y.FechaMensaje.Subtract(x.FechaMensaje).TotalHours;
                }
            }

            return(time);
        }
Esempio n. 2
0
        public List <MobilePoi> GetVehiculosCercanos(IEnumerable <int> empresas, IEnumerable <int> lineas, int referencia)
        {
            var posDao   = new LogPosicionDAO();
            var cocheDao = new CocheDAO();

            var r = FindById(referencia);

            var lat = r.Direccion != null ? r.Direccion.Latitud : r.Poligono.Centro.Y;
            var lon = r.Direccion != null ? r.Direccion.Longitud : r.Poligono.Centro.X;

            var coches = cocheDao.GetList(empresas, lineas);

            if (!coches.Any())
            {
                return(new List <MobilePoi>());
            }

            return(posDao.GetLastVehiclesPositions(coches).Values
                   .Where(position => position != null)
                   .Select(lup => new MobilePoi
            {
                IdVehiculo = lup.IdCoche,
                PuntoDeInteres = r.Descripcion,
                Distancia = Distancias.Loxodromica(lup.Latitud, lup.Longitud, lat, lon),
                Interno = lup.Coche,
                Latitud = lup.Latitud,
                Longitud = lup.Longitud,
                TipoVehiculo = lup.TipoCoche,
                Velocidad = lup.Velocidad
            })
                   .OrderBy(mp => mp.Distancia)
                   .ToList());
        }
Esempio n. 3
0
        /// <summary>
        /// Gets datamart regeneration periods.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="refference"></param>
        /// <returns></returns>
        public List <RegenerateDatamart> GetDaysToRegenerate(Coche vehicle, DateTime from, DateTime to, DateTime refference)
        {
            var posicionesDao = new LogPosicionDAO();

            int maxMonths;

            try
            {
                maxMonths = vehicle != null && vehicle.Empresa != null ? vehicle.Empresa.MesesConsultaPosiciones : 3;
            }
            catch (Exception)
            {
                maxMonths = 3;
            }

            var te    = new TimeElapsed();
            var start = posicionesDao.GetRegenerationStartDate(vehicle.Id, from, to, refference, maxMonths);
            var ts    = te.getTimeElapsed().TotalSeconds;

            if (ts > 1)
            {
                STrace.Error("Logictracker.Scheduler.Tasks.Mantenimiento.DatamartGeneration", string.Format("GetRegenerationStartDate en {0} segundos", ts));
            }

            if (!start.HasValue)
            {
                return(new List <RegenerateDatamart>());
            }

            var startDate = start.Value;

            te.Restart();
            var endDate = posicionesDao.GetRegenerationEndDate(vehicle.Id, from, to, maxMonths);

            ts = te.getTimeElapsed().TotalSeconds;
            if (ts > 1)
            {
                STrace.Error("Logictracker.Scheduler.Tasks.Mantenimiento.DatamartGeneration", string.Format("GetRegenerationEndDate en {0} segundos", ts));
            }

            var result = new List <RegenerateDatamart>();

            while (startDate < endDate)
            {
                var period = new RegenerateDatamart(startDate);
                result.Add(period);
                startDate = startDate.AddDays(1);
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the last datamart update for the specified vehicle.
        /// </summary>
        /// <param name="coche"></param>
        /// <returns></returns>
        public DateTime GetLastDatamartUpdate(int coche)
        {
            DetachedCriteria dc   = GetDatamartDetachedCriteria(coche);
            ICriteria        crit = GetDatamartCriteria(1, dc, Order.Desc("Begin"));

            var data = crit.UniqueResult <Datamart>();

            //Adds a minute to avoid regenerating the last hour.
            if (data != null)
            {
                return(data.End.AddMinutes(1));
            }

            var posicionesDao = new LogPosicionDAO();

            LogPosicion firtPosition = posicionesDao.GetFirtPosition(coche);

            DateTime result = firtPosition == null ? DateTime.MinValue : firtPosition.FechaMensaje;

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the distance traveled by the mobile in the specified time span.
        /// </summary>
        /// <param name="coche"></param>
        /// <param name="inicio"></param>
        /// <param name="fin"></param>
        /// <returns></returns>
        public double GetDistance(int coche, DateTime inicio, DateTime fin)
        {
            var distance = 0.0;

            if (fin < DateTime.Today.ToDataBaseDateTime())
            {
                var dmDAO = new DatamartDAO();
                var dm    = dmDAO.GetMobilesKilometers(inicio, fin, new List <int> {
                    coche
                }).FirstOrDefault();
                return(dm != null ? dm.Kilometers : 0.0);
            }

            //var sqlQ = Session.CreateSQLQuery("SELECT dbo.fn_getVehicleKm(?, ?, ?);");
            //sqlQ.SetInt32(0, coche);
            //sqlQ.SetDateTime(1, inicio);
            //sqlQ.SetDateTime(2, fin);
            //distance = sqlQ.UniqueResult<double>();
            //return distance;

            var lpDAO   = new LogPosicionDAO();
            var results = lpDAO.GetPositionsBetweenDates(coche, inicio, fin);

            //if (results.Count.Equals(0))
            //    results = Session.Query<LogPosicionHistorica>()
            //        .Where(position => position.Coche.Id == coche && position.FechaMensaje >= inicio && position.FechaMensaje <= fin)
            //        .Cast<LogPosicionBase>()
            //        .ToList();

            for (var i = 0; i < results.Count - 1; i++)
            {
                var x = results[i];
                var y = results[i + 1];

                distance += Distancias.Loxodromica(x.Latitud, x.Longitud, y.Latitud, y.Longitud);
            }

            return(distance / 1000.0);
        }
Esempio n. 6
0
        public XmlDocument ObtenerEstadoEntrega(String Distrito, String Base, String Entrega, String Cliente)
        {
            var address = HttpContext.Current.Request.UserHostAddress;

            try
            {
                using (StreamWriter sw = File.AppendText(Directory.GetCurrentDirectory() + @"\LOGIP.txt"))
                {
                    sw.WriteLine(address.ToString() + "\t" + DateTime.Now.ToString("ddMMyyyyHHmmssfff"));
                }
            }
            catch (Exception)
            {
            }

            if (!String.IsNullOrEmpty(Distrito) &&
                !String.IsNullOrEmpty(Base) &&
                (!String.IsNullOrEmpty(Entrega) ||
                 !String.IsNullOrEmpty(Cliente)))
            {
                var EstadoActual            = "";
                var TiempoLlegada           = "";
                var DistanciakmtsLlegada    = "";
                var linkGoogleMaps          = "https://www.google.com.ar/maps/dir/-34.598198,-58.3841437/-34.5972089,-58.3780497";
                ViajeDistribucionDAO dao    = new ViajeDistribucionDAO();
                LogPosicionDAO       daopos = new LogPosicionDAO();
                var sinbase = dao.FindAll().Where(x => x.Inicio.Day.Equals(DateTime.Now.Day) &&
                                                  x.Inicio.Month.Equals(DateTime.Now.Month) &&
                                                  x.Inicio.Year.Equals(DateTime.Now.Year) && x.Empresa.RazonSocial.ToString().Trim().ToUpper().Contains(Distrito.Trim().ToUpper()));
                if (!String.IsNullOrEmpty(Base))
                {
                    sinbase = sinbase.Where(x => x.Linea == null ||
                                            x.Linea != null &&
                                            x.Linea.Descripcion.ToString().Trim().ToUpper().Contains(Base.Trim().ToUpper()));
                }
                bool closeLoop = false;
                foreach (var item in sinbase)
                {
                    foreach (EntregaDistribucion detalle in item.Detalles.Where(x => x.PuntoEntrega != null))
                    {
                        //codigo = entrega
                        //descripcion cliente
                        if (detalle.PuntoEntrega.Codigo.Trim().ToUpper().Equals(Entrega.Trim().ToUpper()) ||
                            detalle.PuntoEntrega.Descripcion.Trim().ToUpper().Equals(Cliente.Trim().ToUpper()))
                        {
                            switch (detalle.Estado)
                            {
                            case EntregaDistribucion.Estados.EnSitio:
                            {
                                EstadoActual = "EnSitio";
                                break;
                            }

                            case EntregaDistribucion.Estados.Completado:
                            {
                                EstadoActual = "Completado";
                                break;
                            }

                            case EntregaDistribucion.Estados.Cancelado:
                            {
                                EstadoActual = "Cancelado";
                                break;
                            }

                            case EntregaDistribucion.Estados.EnZona:
                            {
                                EstadoActual = "EnZona";
                                break;
                            }

                            case EntregaDistribucion.Estados.NoCompletado:
                            {
                                EstadoActual = "NoCompletado";
                                break;
                            }

                            case EntregaDistribucion.Estados.Pendiente:
                            {
                                EstadoActual = "Pendiente";
                                break;
                            }

                            case EntregaDistribucion.Estados.Restaurado:
                            {
                                EstadoActual = "Restaurado";
                                break;
                            }

                            case EntregaDistribucion.Estados.SinVisitar:
                            {
                                EstadoActual = "SinVisitar";
                                break;
                            }

                            case EntregaDistribucion.Estados.Visitado:
                            {
                                EstadoActual = "Visitado";
                                break;
                            }

                            default:
                                break;
                            }

                            LogUltimaPosicionVo ult = daopos.GetLastVehiclePosition(item.Vehiculo);
                            if (ult == null)
                            {
                                ult = daopos.GetLastOnlineVehiclePosition(item.Vehiculo);
                            }
                            LatLon origen  = new LatLon(ult.Latitud, ult.Longitud);
                            LatLon destino = new LatLon(detalle.PuntoEntrega.ReferenciaGeografica.Latitude, detalle.PuntoEntrega.ReferenciaGeografica.Longitude);

                            linkGoogleMaps = "https://www.google.com.ar/maps/dir/" + origen.Latitud.ToString().Replace(',', '.') + "," + origen.Longitud.ToString().Replace(',', '.') + "/" + destino.Latitud.ToString().Replace(',', '.') + "," + destino.Longitud.ToString().Replace(',', '.');

                            var waypoints = new List <LatLon>();
                            waypoints.Add(origen);
                            waypoints.Add(destino);
                            var directions = GoogleDirections.GetDirections(origen, destino, GoogleDirections.Modes.Driving, string.Empty, waypoints.ToArray());
                            int reintentos = 0;
                            while (directions == null && reintentos < 4)
                            {
                                reintentos++;
                                Thread.Sleep(2000);
                                directions = GoogleDirections.GetDirections(origen, destino, GoogleDirections.Modes.Driving, string.Empty, waypoints.ToArray());
                            }
                            if (directions != null)
                            {
                                TiempoLlegada        = new DateTime(directions.Duration.Ticks).ToString("HH:mm:ss");
                                DistanciakmtsLlegada = (directions.Distance / 1000).ToString();
                            }
                            closeLoop = true;
                            break;
                        }
                    }
                    if (closeLoop)
                    {
                        break;
                    }
                }
                XmlDocument    doc            = new XmlDocument();
                XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                XmlElement     root           = doc.DocumentElement;
                doc.InsertBefore(xmlDeclaration, root);

                //(2) string.Empty makes cleaner code
                XmlElement element1 = doc.CreateElement(string.Empty, "body", string.Empty);
                doc.AppendChild(element1);

                XmlElement element2 = doc.CreateElement(string.Empty, "EstadoActual", string.Empty);
                XmlText    text1    = doc.CreateTextNode(EstadoActual);
                element2.AppendChild(text1);
                element1.AppendChild(element2);

                XmlElement element3 = doc.CreateElement(string.Empty, "TiempoLlegadaHHMMSS", string.Empty);
                XmlText    text2    = doc.CreateTextNode(TiempoLlegada);
                element3.AppendChild(text2);
                element1.AppendChild(element3);

                XmlElement element4 = doc.CreateElement(string.Empty, "DistanciakmtsLlegada", string.Empty);
                XmlText    text3    = doc.CreateTextNode(DistanciakmtsLlegada);
                element4.AppendChild(text3);
                element1.AppendChild(element4);

                XmlElement element5 = doc.CreateElement(string.Empty, "linkGoogleMaps", string.Empty);
                XmlText    text4    = doc.CreateTextNode(linkGoogleMaps);
                element5.AppendChild(text4);
                element1.AppendChild(element5);

                return(doc);
            }
            else
            {
                return(new XmlDocument());
            }
        }