//Updates trip without PreviousTripId, localtripId and Secondstolag public static void UpdateExistingTrip(Int16 carId, Int64 tripId) { DBController dbc = new DBController(); Trip trip = new Trip(tripId, carId); List<Fact> facts = dbc.GetFactsByTripIdNoQuality(tripId); //Calc the trip updates trip = UpdateTrip(trip, facts, dbc); //Compute the scores trip.OptimalScore = FinalScore.CalculateOptimalScore(trip); List<double> fullscores = FinalScore.CalculateTripScores(trip); trip.RoadTypeScore = fullscores[0]; trip.CriticalTimeScore = fullscores[1]; trip.SpeedingScore = fullscores[2]; trip.AccelerationScore = fullscores[3]; trip.BrakeScore = fullscores[4]; trip.JerkScore = fullscores[5]; trip.TripScore = fullscores[6]; //Update the trip in the database dbc.UpdateTripFactWithMeasures(trip); dbc.Close(); }
public static void Update(Int16 carId) { DBController dbc = new DBController(); List<Int64> tripIds = dbc.GetTripIdsByCarId(carId); List<Fact> facts; Trip trip; Int64 previousTripId = 0; DateTime previousEndTimestamp = new DateTime(); for (int i = 0; i < tripIds.Count; i++) { trip = dbc.GetTripByTripId(tripIds[i]); facts = dbc.GetFactsByTripId(tripIds[i]); //If a previous trip exists, save ID and the time passed between them if (i > 0) { trip.PreviousTripId = previousTripId; trip.SecondsToLag = MeasureCalculator.SecondsToLag(facts[0].Temporal.Timestamp, previousEndTimestamp); } //Remember variables for next iteration previousTripId = trip.TripId; previousEndTimestamp = trip.EndTemporal.Timestamp; Console.WriteLine("Updating car {0}, trip {1} ({2} facts)", carId, trip.TripId, facts.Count); trip = UpdateTrip(trip, facts, dbc); trip.OptimalScore = FinalScore.CalculateOptimalScore(trip); List<double> fullscores = FinalScore.CalculateTripScores(trip); trip.RoadTypeScore = fullscores[0]; trip.CriticalTimeScore = fullscores[1]; trip.SpeedingScore = fullscores[2]; trip.AccelerationScore = fullscores[3]; trip.BrakeScore = fullscores[4]; trip.JerkScore = fullscores[5]; trip.TripScore = fullscores[6]; dbc.UpdateTripFactWithMeasures(trip); } dbc.Close(); }
public static void UpdateTrip(Int16 carId, Int64 tripId) { DBController dbc = new DBController(); Trip trip = new Trip(tripId, carId); List<Fact> facts = dbc.GetFactsByTripIdNoQuality(tripId); //Getting the previous tripid and seconds to previous trip List<Int64> tripIds = dbc.GetTripIdsByCarId(carId); //In case this is the first trip - ignore computing measures for previous trip if (tripIds.Count > 1) { Int64 latestTrip = tripIds[tripIds.Count() - 2]; Trip previousTrip = dbc.GetTripByCarIdAndTripId(carId, latestTrip); trip.SecondsToLag = MeasureCalculator.SecondsToLag(facts[0].Temporal.Timestamp, previousTrip.EndTemporal.Timestamp); } else { trip.SecondsToLag = new TimeSpan(0, 0, -1); } //Calc the trip updates trip = UpdateTrip(trip, facts, dbc); //Compute the scores trip.OptimalScore = FinalScore.CalculateOptimalScore(trip); List<double> fullscores = FinalScore.CalculateTripScores(trip); trip.RoadTypeScore = fullscores[0]; trip.CriticalTimeScore = fullscores[1]; trip.SpeedingScore = fullscores[2]; trip.AccelerationScore = fullscores[3]; trip.BrakeScore = fullscores[4]; trip.JerkScore = fullscores[5]; trip.TripScore = fullscores[6]; //Update the trip in the database dbc.UpdateTripFactWithMeasures(trip); dbc.Close(); }