Ejemplo n.º 1
0
 public RankingTransportistasVo(RankingTransportistas ranking)
 {
     IdTransportista     = ranking.IdTransportista;
     Transportista       = ranking.Transportista;
     Vehiculos           = ranking.Vehiculos;
     Kilometros          = ranking.Kilometros;
     HorasMovimiento     = ranking.HorasMovimiento;
     Puntaje             = ranking.Puntaje;
     InfraccionesLeves   = ranking.InfraccionesLeves;
     InfraccionesMedias  = ranking.InfraccionesMedias;
     InfraccionesGraves  = ranking.InfraccionesGraves;
     InfraccionesTotales = ranking.InfraccionesTotales;
 }
Ejemplo 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);
        }