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 <RankingTransportistas> GetRanking(List <Int32> distritos, List <Int32> bases, List <Int32> transportistas, DateTime from, DateTime to)
        {
            var ranking = new List <RankingTransportistas>();

            var vehicles     = DAOFactory.CocheDAO.GetList(distritos, bases, new[] { -1 }, transportistas, new[] { -1 });
            var infracciones = DAOFactory.InfraccionDAO.GetByVehiculos(vehicles.Select(v => v.Id), from, to);

            var kms   = new List <MobilesKilometers>();
            var times = new List <MobilesTime>();

            if (to < DateTime.Today.ToDataBaseDateTime())
            {
                var dmDAO = new DatamartDAO();
                kms   = dmDAO.GetMobilesKilometers(from, to, vehicles.Select(v => v.Id).ToList()).ToList();
                times = dmDAO.GetMobilesTimes(from, to, vehicles.Select(v => v.Id).ToList()).ToList();
            }

            foreach (var vehicle in vehicles)
            {
                var dmKm   = kms.FirstOrDefault(dm => dm.Movil == vehicle.Id);
                var dmTime = times.FirstOrDefault(dm => dm.Movil == vehicle.Id);

                var km = dmKm != null ? dmKm.Kilometers : DAOFactory.CocheDAO.GetDistance(vehicle.Id, from, to);
                var hs = dmTime != null ? dmTime.ElapsedTime : DAOFactory.CocheDAO.GetRunningHours(vehicle.Id, from, to);

                var idTransportista      = vehicle.Transportista != null ? vehicle.Transportista.Id : 0;
                var rankingTransportista = ranking.FirstOrDefault(d => d.IdTransportista == idTransportista);

                if (rankingTransportista != null)
                {
                    ranking.Remove(rankingTransportista);

                    rankingTransportista.Vehiculos++;
                    rankingTransportista.Kilometros += km;
                    rankingTransportista.Hours      += hs;
                }
                else
                {
                    rankingTransportista = new RankingTransportistas
                    {
                        IdTransportista = idTransportista,
                        Transportista   = vehicle.Transportista != null ? vehicle.Transportista.Descripcion : "Sin Transportista",
                        Kilometros      = km,
                        Hours           = hs,
                        Vehiculos       = 1
                    };
                }

                var messages = infracciones.Where(message => message.Vehiculo.Id.Equals(vehicle.Id)).ToList();

                foreach (var infraction in messages)
                {
                    var gravedad = GetGravedadInfraccion(infraction);

                    if (gravedad.Equals(0))
                    {
                        continue;
                    }

                    if (gravedad.Equals(1))
                    {
                        rankingTransportista.InfraccionesLeves++;
                    }
                    else if (gravedad.Equals(2))
                    {
                        rankingTransportista.InfraccionesMedias++;
                    }
                    else
                    {
                        rankingTransportista.InfraccionesGraves++;
                    }

                    rankingTransportista.Puntaje += GetPonderacionInfraccion(infraction);
                }

                ranking.Add(rankingTransportista);
            }

            return(ranking);
        }