Exemplo n.º 1
0
        public void AssignAverageWaitTime()
        {
            if (Waypoints.Count < 2 || Waypoints.All(x => x.WaitTime != 0))
            {
                return;
            }

            var order = Waypoints.OrderBy(x => x.Index).ThenBy(x => x.Time).GroupBy(x => x.Time);

            var waittimes = new List <int>();

            var array = order.Select(x => x.First()).ToArray();

            for (var i = 0; i < array.Length; i++)
            {
                if (i + 1 < array.Length)
                {
                    var ms = (int)(array[i + 1].Time - array[i].Time).TotalMilliseconds;
                    waittimes.Add(ms);
                    array[i + 1].WaitTime = ms;
                }
            }

            var average = waittimes.Sum() / waittimes.Count;

            for (var i = 0; i < array.Length; i++)
            {
                if (i + 1 < array.Length)
                {
                    array[i + 1].WaitTime = average;
                }
            }
        }