Exemple #1
0
        // Infrastructure Authority get street crowd by day weeek month , determent what city needs a new street
        static List <CrowedPerDayDto> GetStreetDataPerCity(City city)
        {
            var CurrentStreetStatus = new List <CrowedPerDayDto>()
            {
            };
            var    carsCount   = 0;
            double cityCapcity = 0;

            foreach (var street in city.Streets)
            {
                var CameraCounts = street.Cameras.Count;

                var AtThebegaining = street.Cameras.Where(c => c.IsInStreetBegaining == true).FirstOrDefault();
                var AtTheEnd       = street.Cameras.Where(c => c.IsInStreetBegaining == false).FirstOrDefault();

                if (CameraCounts > 0 && AtThebegaining.CameraRequests.Count > 0 && AtTheEnd.CameraRequests.Count > 0)
                {
                    int hourin           = AtThebegaining.CameraRequests.FirstOrDefault().Date.Value.Date.Month;
                    var datyein          = AtThebegaining.CameraRequests.FirstOrDefault().Date.Value.Date;
                    var dateTime         = DateTime.Now.Date;
                    var inCountBegaining = AtThebegaining.CameraRequests.Sum(s => s.InCount) ?? 0;
                    var outCountEnd      = AtTheEnd.CameraRequests.Sum(s => s.OutCount) ?? 0;
                    var goResuilt        = inCountBegaining - outCountEnd;

                    var inCountEnd        = AtTheEnd.CameraRequests.Sum(s => s.InCount) ?? 0;
                    var outCountBegaining = AtThebegaining.CameraRequests.Sum(s => s.OutCount) ?? 0;
                    var backResuilt       = inCountEnd - outCountBegaining;

                    carsCount   += goResuilt + backResuilt;
                    cityCapcity += street.Capacity;
                }
            }
            double trafficJam = 0;

            if (carsCount != 0)
            {
                trafficJam = ((double)carsCount / cityCapcity) * 100;
            }
            CrowedPerDayDto todayHour = new CrowedPerDayDto
            {
                Value      = city.Name,
                carsCount  = carsCount,
                TrafficJam = trafficJam,
                streetId   = city.Id
            };

            CurrentStreetStatus.Add(todayHour);
            return(CurrentStreetStatus);
        }
Exemple #2
0
        //get day crowd by hours / week crowd by day / year crowd by months for traffic man / street crowd
        /// <summary>
        /// 7 steen carscount in 7 am an dcroud percent 7 80%
        /// get cars count 7in - 7out
        /// </summary>
        /// <param name="street"></param>
        /// <returns></returns>
        static List <CrowedPerDayDto> GetStreetDataPerDay(Street street)
        {
            var CurrentStreetStatus = new List <CrowedPerDayDto>()
            {
            };

            var CameraCounts = street.Cameras.Count;

            var AtThebegaining = street.Cameras.Where(c => c.IsInStreetBegaining == true).FirstOrDefault();
            var AtTheEnd       = street.Cameras.Where(c => c.IsInStreetBegaining == false).FirstOrDefault();

            for (int i = 0; i < 24; i++)
            {
                if (CameraCounts > 0 && AtThebegaining.CameraRequests.Count > 0 && AtTheEnd.CameraRequests.Count > 0)
                {
                    // DayOfWeek week = DayOfWeek.
                    var hourin           = AtThebegaining.CameraRequests.FirstOrDefault().Date.Value.DayOfWeek;
                    var datyein          = AtThebegaining.CameraRequests.FirstOrDefault().Date.Value.Date;
                    var dateTime         = DateTime.Now.Date;
                    var inCountBegaining = AtThebegaining.CameraRequests.Where(w => w.Date.Value.Date == DateTime.Now.Date && w.Date.Value.Hour == i).Sum(s => s.InCount) ?? 0;
                    var outCountEnd      = AtTheEnd.CameraRequests.Where(w => w.Date.Value.Date == DateTime.Now.Date && w.Date.Value.Hour == i).Sum(s => s.OutCount) ?? 0;
                    var goResuilt        = inCountBegaining - outCountEnd;

                    var inCountEnd        = AtTheEnd.CameraRequests.Where(w => w.Date.Value.Date == DateTime.Now.Date && w.Date.Value.Hour == i).Sum(s => s.InCount) ?? 0;
                    var outCountBegaining = AtThebegaining.CameraRequests.Where(w => w.Date.Value.Date == DateTime.Now.Date && w.Date.Value.Hour == i).Sum(s => s.OutCount) ?? 0;
                    var backResuilt       = inCountEnd - outCountBegaining;

                    var carsCount = goResuilt + backResuilt;

                    CrowedPerDayDto todayHour = new CrowedPerDayDto
                    {
                        Value      = i.ToString(),
                        carsCount  = carsCount,
                        TrafficJam = ((double)carsCount / (double)street.Capacity) * 100,
                        streetId   = street.Id
                    };
                    CurrentStreetStatus.Add(todayHour);
                }
            }
            return(CurrentStreetStatus);
        }