Example #1
0
 public DbRecord Clone() {
    var copy = new DbRecord();
    copy.Length = Length;
    copy.Names = new Dictionary<string, int>(Names);
    copy.Values = new object[Length];
    Values.CopyTo(copy.Values, 0);
    return copy;
 }
Example #2
0
      private void _processActivityRecords(SqlConnection conn, string activityId) {
         string queryString =
            " SELECT V.ActivityId, V.VehicleKey, V.DriverId, V.BatteryKey, V.Odometer, V.Bat_Energy," +
            "        V.Seg_Curvature, V.Seg_Length, V.Seg_Slope, V.DrivingSegmentIndex, V.DrvEst_Eea, V.TimeStamp," +
            "        (SELECT TOP(1) ISNULL(CAST(S.Eta AS VARCHAR(50)),'') + ';' + ISNULL(CAST(S.Eea AS VARCHAR(32)),'') + ';' + ISNULL(CAST(S.Dta AS VARCHAR(32)),'')" +
            "        FROM dbo.T_TELEMETRY_DRIVING_STEPS AS S" +
            "        WHERE V.TelemetryId = S.TelemetryId" +
            "        ORDER BY S.Eta) AS EndEstimations" +       
            " FROM dbo.T_TELEMETRY_VEHICLE AS V" +
            " WHERE V.ActivityId = '" + activityId + "'" +
            " AND V.IsManaged = 1 AND (V.RecordType = " + (int)TelemetryRecordType.DrivingPlanChanged +
            " OR V.RecordType = " + (int)TelemetryRecordType.DrivingRoadSegmentPassed + ")" +
            " ORDER BY V.RecordNo;";

         var command = new SqlCommand(queryString, conn);
         var reader = command.ExecuteReader();
         var counter = 0;
         var lastIndex = -1;
         TrackInfo trackInfo = null;
         DbRecord lastRecord = null;

         try {
            var record = new DbRecord(reader);
            while (reader.Read()) {
               record.Fetch(reader);
               var currIndex = record.GetInt("DrivingSegmentIndex");

               if (currIndex == lastIndex) continue;
               if (currIndex < lastIndex) {
                  _finalizeTrackInfo(trackInfo,lastRecord,counter);
                  _trackList.Add(trackInfo);
                  trackInfo = _initializeTrackInfo(record);
                  counter = 1;
               } else {
                  if (lastIndex == -1) trackInfo = _initializeTrackInfo(record);
                  lastRecord = record.Clone();
                  counter++;
               }

               lastIndex = currIndex;
               _aggregateTrackInfo(trackInfo, record);
            }
         } finally {
            // Always call Close when done reading.
            reader.Close();
         }
      }
Example #3
0
 private TrackInfo _initializeTrackInfo(DbRecord record) {
    var newTrackInfo = new TrackInfo();
    newTrackInfo.ActivityId = record.GetString("ActivityId");
    newTrackInfo.VehicleKey = record.GetString("VehicleKey");
    newTrackInfo.DriverId = record.GetString("DriverId");
    newTrackInfo.BatteryKey = record.GetString("BatteryKey");
    newTrackInfo.OdometerStart = record.GetDouble("Odometer");
    newTrackInfo.ActualStartEnergy = record.GetDouble("Bat_Energy");
    newTrackInfo.ActualStartTime = record.GetDateTime("TimeStamp");
    var estimations = record.GetString("EndEstimations");
    _extractEstimations(newTrackInfo, estimations);
    return newTrackInfo;
 }
Example #4
0
 private void _finalizeTrackInfo(TrackInfo trackInfo, DbRecord record, int SegmentCount) {
    trackInfo.OdometerEnd = record.GetDouble("Odometer");
    trackInfo.ActualEndEnergy = record.GetDouble("Bat_Energy");
    trackInfo.EstimatedEndEnergy = record.GetDouble("DrvEst_Eea");
    trackInfo.ActualEndTime = record.GetDateTime("TimeStamp");
    trackInfo.SegmentCount = SegmentCount;
 }
Example #5
0
 private void _aggregateTrackInfo(TrackInfo trackInfo, DbRecord record) {
    var length = record.GetDouble("Seg_Length");
    trackInfo.TrackDistance += length;
    if (!(record.IsNull("Seg_Slope"))) {
       var slope = record.GetDouble("Seg_Slope");
       var index = (int)(Math.Round(Math.Atan(slope).ToDegrees().Limit(-10, 10) / 1.0)) + 10;
       trackInfo.Elevations[index] += length;
    }
 }