public void TestTryGet()
        {
            var dict = new Dictionary<int, string>
            {
                { 1, string.Empty },
                { 2, string.Empty },
                { 4, string.Empty },
            };

            var val1 = dict.TryGet(1);
            var val2 = dict.TryGet(2);
            var val3 = dict.TryGet(3);
            var val4 = dict.TryGet(4);

            Assert.IsNotNull(val1);
            Assert.IsNotNull(val2);
            Assert.IsNull(val3);
            Assert.IsNotNull(val4);
        }
Example #2
0
 protected void ReadDvbData(SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, Dictionary<long, string> providers)
 {
     this.ShortName = DbSerializer.ReadUtf16(r, 16);
       this.RecordOrder = r.GetInt32(field["major"]);
       int serviceType = r.GetInt32(field["srvType"]);
       this.ServiceType = serviceType;
       this.SignalSource |= LookupData.Instance.IsRadioOrTv(serviceType);
       this.OriginalNetworkId = r.GetInt32(field["onid"]);
       this.TransportStreamId = r.GetInt32(field["tsid"]);
       this.ServiceId = r.GetInt32(field["progNum"]);
       this.VideoPid = r.GetInt32(field["vidPid"]);
       if (!r.IsDBNull(field["provId"]))
     this.Provider = providers.TryGet(r.GetInt64(field["provId"]));
 }
Example #3
0
        private void ReadAnalogChannels(ZipFile zip, string fileName, ChannelList list, out byte[] data, Dictionary<int,decimal> freq)
        {
            data = null;
              int entrySize = c.avbtChannelLength;
              if (entrySize == 0)
            return;

              data = ReadFileContent(zip, fileName);
              if (data == null)
            return;

              this.DataRoot.AddChannelList(list);
              var rawChannel = analogMappings.GetMapping(entrySize);
              list.MaxChannelNameLength = rawChannel.Settings.GetInt("lenName")/2;
              rawChannel.SetDataPtr(data, 0);
              int count = data.Length / entrySize;

              for (int slotIndex = 0; slotIndex < count; slotIndex++)
              {
            MapAnalogChannel(rawChannel, slotIndex, list, freq.TryGet(slotIndex));
            rawChannel.BaseOffset += entrySize;
              }
        }
Example #4
0
      private void btnExtract_Click(object sender, EventArgs e) {
         this.DispatchToBackground(() => {
            var A = new List<AnalyzedActivity>();
            using (var dbConn = DatabaseManager.DbConn()) {

               A.AddRange(dbConn.ExecuteBpl(new TelemetryVehicleActivityGetAll()).Select(a => new AnalyzedActivity { Activity = a }));
               _report("Activities: {0}", A.Count);

               for (var i = 0; i < A.Count; i++) {
                  var a = A[i];
                  a.StartMeters = dbConn.ExecuteBpl(new TelemetryVehicleActivityMetersGetByActivityIdType { ActivityId = a.Activity.ActivityId, RecordType = VehicleMetersRecordType.StartMeters });
                  a.FinishMeters = dbConn.ExecuteBpl(new TelemetryVehicleActivityMetersGetByActivityIdType { ActivityId = a.Activity.ActivityId, RecordType = VehicleMetersRecordType.FinishMeters });
               }
               A.RemoveAll(a => a.Activity.ActivityType != VehicleMode.Driving || (a.FinishMeters.Odometer - a.StartMeters.Odometer) < (Distance)10);
               _report("Usable driving activities: {0}", A.Count);

               var AA = A.ToDictionary(a => a.Activity.ActivityId.ToString(false));

               var T = dbConn.ExecuteBpl(new TelemetryGetAll());
               _report("Records: {0}", T.Count);

               var TT = new Dictionary<string, VehicleTelemetry>();
               for (var i = 0; i < T.Count; i++) {
                  var dbt = T[i];
                  if (!dbt.Telemetry.IsManaged) continue;

                  var a = AA.TryGet(dbt.Telemetry.ActivityId.ToString(false));
                  if (a == null) continue;

                  var t = TT.TryGet(dbt.TelemetryId.ToString(false));
                  if (t == null) {
                     t = dbt.Telemetry;
                     a.Telemetry.Add(t);
                     TT.Add(dbt.TelemetryId.ToString(false), t);
                  }
                  t.FutureDrivingSteps.Add(dbt.Step);
               }
            }
            A.RemoveAll(a => a.Telemetry.Count == 0);
            _report("Usable planned driving Activities: {0}", A.Count);

            // fix: all key in DB are 0 due to client bug in 2.9.7 (fixed in 2.9.8)
            foreach (var a in A) {
               // Log.Info("Activity: {0}, {1} records", a.Activity.ActivityId, a.Telemetry.Count);
               var lastDta = Distance.Undefined;
               var lastIndex = -1;
               var firstStepKey = -1;
               foreach (var t in a.Telemetry) {
                  // Log.Info("     #{0} | {1} | Planned:{2} | {3} - O:{4}, S:{5}, i:{6}", t.RecordNo, t.TimeStamp, t.IsManaged, t.RecordType, t.Odometer, t.Battery.Soc, t.DrivingSegmentIndex);
                  var stepCount = t.FutureDrivingSteps.Count;
                  if (stepCount == 0) {
                     lastDta = Distance.Undefined;
                     lastIndex = -1;
                     firstStepKey = -1;
                     continue;
                  }

                  if (t.RecordType == TelemetryRecordType.DrivingPlanChanged || firstStepKey == -1 || lastIndex == -1) {
                     lastDta = t.FutureDrivingSteps[0].Dta;
                     lastIndex = t.DrivingSegmentIndex;
                     firstStepKey = (int)Distance.ToMeters(t.FutureDrivingSteps[0].Dta);
                  }

                  // fix rule is: 
                  // - if index is 0, plan may change, so unless dDistance is 0 or very small - assume plan change
                  // - if index dropped (from X to 0) - assume plan change
                  // - some times index is dropped, but a bit later, so look at large dDistance change, as a fallback
                  //   (this is heuristics, but this is the best possible one, even though it's not precise - it's helpful sometimes)
                  // - distance in meters used as a key, to fight cases with round-trip route where two steps have very similar distance (in meters - it will be different)
                  //
                  var dta = t.FutureDrivingSteps[0].Dta;
                  var index = t.DrivingSegmentIndex;
                  var ddta = (dta - lastDta).Abs();
                  var dindex = (index - lastIndex);
                  if ((index == 0 && ddta < (Distance)0.5) || dindex < 0 || ddta > (Distance)2) {
                     firstStepKey = (int)Distance.ToMeters(t.FutureDrivingSteps[0].Dta);
                  }
                  lastDta = dta;
                  lastIndex = index;

                  t.FutureDrivingSteps[0].Key = firstStepKey;
                  for (var i = 1; i < t.FutureDrivingSteps.Count; i++) {
                     t.FutureDrivingSteps[i].Key = (int)Distance.ToMeters(t.FutureDrivingSteps[i].Dta);
                  }
                  /*
                  var str = "";
                  foreach (var s in t.FutureDrivingSteps) {
                     str += "{0,7:#.000} | {1,6}, ".Substitute((double)s.Dta, s.Key);
                  }
                  Log.Info("         {0}", str);
                  */
               }
            }
            _report("Key fix applied");

            _report("Saving extracted activities");
            _activitiesList = new AnalyzedActivityList();
            _activitiesList.Activities.AddRange(A);
            var formatter = BplXmlFormatter.Minimal;
            formatter.Format(_activitiesList);
            var xml = formatter.Output;
            File.WriteAllText("extracted.bpl", xml);
            _report("Extracting done");
         });
      }