public string GetTrip(Int16 carid, Int64 tripid) { try { DBController dbc = new DBController(); Trip trip = dbc.GetTripByCarIdAndTripId(carid, tripid); dbc.Close(); return JsonConvert.SerializeObject(trip); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetTrip?carid={carid}&tripid={tripid}", carid, tripid, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), ""); dbc.Close(); } return ""; }
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(); }