Exemplo n.º 1
0
 public static void Debug(string msg)
 {
     if (m_Logger != null)
     {
         m_Logger.Debug(msg);
     }
 }
Exemplo n.º 2
0
 public static void Debug(string msg)
 {
     if (m_Logger != null)
     {
         m_Logger.Debug(msg);
     }
     TryToSendLogToGui("[DEBUG] " + msg);
 }
Exemplo n.º 3
0
        protected Trip ProcessTrip(Trip trip)
        {
            _logger.Debug($"Started processing trip {trip.TripId}");

            var currentDistanceTraveled = trip.DistanceTraveled ?? 0;

            if (trip.Status == TripStatus.Processed)
            {
                // Trip has already been processed. Clean up anything that was done previously
                RemovePossiblePlacesFromTrip(trip);
            }

            var readings = _db.Readings.Where(x => x.TripId == trip.TripId)
                           .OrderBy(x => x.ReadDate)
                           .ToList();

            if (readings.Any())
            {
                NormalizeStartEndLocations(readings);

                double maxSpeed       = 0;
                double totalSpeed     = 0;
                double totalDistance  = 0;
                double maxEngineRpm   = 0;
                double totalEngineRpm = 0;

                TimeSpan idleTime = new TimeSpan(); //ticks

                Reading previousReading = null;

                for (int i = 0; i < readings.Count; i++)
                {
                    var reading = readings[i];
                    if (reading.Speed.HasValue && reading.Speed.Value > maxSpeed)
                    {
                        maxSpeed = reading.Speed.Value;
                    }

                    if (reading.EngineRpm.HasValue && reading.EngineRpm.Value > maxEngineRpm)
                    {
                        maxEngineRpm = reading.EngineRpm.Value;
                    }

                    totalSpeed     += reading.Speed ?? 0;
                    totalEngineRpm += reading.EngineRpm ?? 0;

                    if (null != previousReading)
                    {
                        totalDistance += CalculateDistanceBetweenReadings(previousReading, reading);

                        if ((previousReading.Speed ?? 0) == 0 && (reading.Speed ?? 0) == 0)
                        {
                            idleTime = idleTime.Add(reading.ReadDate - previousReading.ReadDate);
                        }
                    }

                    previousReading = reading;
                }

                trip.AverageSpeed     = totalSpeed / (readings.Count * 1.0);
                trip.AverageEngineRpm = totalEngineRpm / (readings.Count * 1.0);

                trip.MaxEngineRpm     = maxEngineRpm;
                trip.MaximumSpeed     = maxSpeed;
                trip.DistanceTraveled = totalDistance;
                trip.IdleTime         = Convert.ToInt64(idleTime.TotalMilliseconds);

                //if the end date of the trip is null, set its end date to the read date of the
                //  last reading
                if (!trip.EndDate.HasValue)
                {
                    trip.EndDate = readings.Last().ReadDate;
                }

                var car = _db.Cars.FirstOrDefault(c => c.CarId == trip.CarId);
                if (null != car &&
                    (!car.MileageLastUserSet.HasValue || car.MileageLastUserSet < trip.EndDate))
                {
                    car.Mileage += trip.DistanceTraveled - currentDistanceTraveled;
                }

                _db.SaveChanges();

                AddPossiblePlacesToTrip(trip, readings);
                AddGuessedPlacesToTrip(trip);
            }

            trip.Status = TripStatus.Processed;
            _db.SaveChanges();

            _logger.Debug($"Finished processing trip {trip.TripId}");

            return(trip);
        }