private void AddGpsPoints(TrackedRideDocument trackedRide)
 {
     var rnd = new Random();
     var randomKey = _routesGps.Keys.ToArray()[rnd.Next(0, _routesGps.Keys.Count - 1)];
     var gps = _routesGps[randomKey];
     trackedRide.Gps = gps;
     if (gps.Length > 1)
     {
         var total = 0.0;
         for (var idx = 0; idx < gps.Length - 1; idx++)
         {
             total += gps[idx + 1].DistanceFrom(gps[idx]);
         }
         trackedRide.Miles = total;
         // Create a random avg speed betwwen 10 and 90
         trackedRide.GpsAverageSpeed = 10.0 + (rnd.NextDouble() * 90.0);
         // Update EndTime accordly to the avg speed
         var hours = trackedRide.Miles / trackedRide.GpsAverageSpeed;
         trackedRide.EndTime = trackedRide.StartTime + TimeSpan.FromSeconds(hours * 3600.0);
     }
 }
        private TrackedRideDocument CreateTrackedRideForRide(Ride ride)
        {
            var tr = new TrackedRideDocument();
            tr.Device = ride.Vehicle.DeviceId;
            tr.StartTime = ride.StartDateTime;
            tr.EndTime = ride.EndDateTime;
            tr.DriverId = ride.DriverId;
            AddGpsPoints(tr);
            AddObds(tr);

            return tr;
        }
 private void AddObds(TrackedRideDocument tr)
 {
     int iter = 0;
     var rideObds = _obds.Where(o => o.DriverId == tr.DriverId && o.DeviceId == tr.Device &&
         tr.StartTime <= o.Date && tr.EndTime >= o.Date).ToList();
     if (!rideObds.Any())
     {
         rideObds = _obds.ToList();
     }
     tr.Obds = rideObds.Select(og => new ObdData()
     {
         Code = og.Code,
         Date = tr.StartTime  + TimeSpan.FromMinutes(++iter)
     }).Where(o => o.Date < tr.EndTime).ToArray();
 }