Exemplo n.º 1
0
 public static Tuple<IEnumerable<Site>, IEnumerable<BplIdentity>> GetTmpSites() {
    var resp = "<autos_cc:SitesUpdateResponse id=\"575bc45b-c8c7-44dd-b3a5-78ed9c171972\" timeStamp=\"2010-08-12T19:15:01-00:00\" sessionId=\"4ace66b6-a5bf-42d9-b3fc-cd0d2369eaa1\" correlatedId=\"4ace66b6-a5bf-42d9-b3fc-cd0d2369eaa1\" oldVersion=\"1.0\" newVersion=\"1.1\" xmlns:autos_cc=\"urn:Mpcr.Messages.AutOS_CC?version=1.60.10319\" xmlns:bpl=\"urn:Mpcr.Model?version=1.60.10319\">  <addedSites>    <bpl:ParkingSite id=\"972.0.4.314.20\" name=\"Rosh ha-Ayin-Amal-1000\">      <address>        <bpl:Address addressDetails=\"Amal\" cityName=\"Rosh ha-Ayin\" countryCode=\"ISR\" stateCode=\"0\" streetName=\"Amal\" />      </address>    </bpl:ParkingSite>    <bpl:ParkingSite id=\"972.0.4.314.21\" name=\"Rosh ha-Ayin-Amal-1001\">      <address>        <bpl:Address addressDetails=\"Amal\" cityName=\"Rosh ha-Ayin\" countryCode=\"ISR\" stateCode=\"0\" streetName=\"Amal\" />      </address>    </bpl:ParkingSite>    <bpl:ParkingSite id=\"972.0.4.314.5\" name=\"Rosh ha-Ayin-Amal-1003\">      <address>        <bpl:Address addressDetails=\"Amal\" cityName=\"Rosh ha-Ayin\" countryCode=\"ISR\" stateCode=\"0\" streetName=\"Amal\" />      </address>    </bpl:ParkingSite>    <bpl:ParkingSite id=\"972.0.4.314.24\" name=\"Rosh ha-Ayin-Ha-Melakha-6\">      <address>        <bpl:Address addressDetails=\"Ha-Melakha\" cityName=\"Rosh ha-Ayin\" countryCode=\"ISR\" stateCode=\"0\" streetName=\"Ha-Melakha\" />      </address>    </bpl:ParkingSite>    <bpl:ParkingSite id=\"972.0.4.314.25\" name=\"Rosh ha-Ayin-Amal-10\">      <address>        <bpl:Address addressDetails=\"Amal\" cityName=\"Rosh ha-Ayin\" countryCode=\"ISR\" stateCode=\"0\" streetName=\"Amal\" />      </address>    </bpl:ParkingSite>    <bpl:ParkingSite id=\"972.0.4.315.1\" name=\"Rishon le-Tsiyon-Mivtsa Kadesh-11\">      <address>        <bpl:Address addressDetails=\"Mivtsa Kadesh\" cityName=\"Rishon le-Tsiyon\" countryCode=\"ISR\" stateCode=\"0\" streetName=\"Mivtsa Kadesh\" />      </address>    </bpl:ParkingSite>    <bpl:ParkingSite id=\"972.0.6.98.29\" name=\"Netivot-Ha-Ari-2\">      <address>        <bpl:Address addressDetails=\"Ha-Ari\" cityName=\"Netivot\" countryCode=\"ISR\" stateCode=\"0\" streetName=\"Ha-Ari\" zipCode=\"3\" />      </address>    </bpl:ParkingSite>    <bpl:ParkingSite id=\"972.0.2.22.2\" name=\"Haifa-Herzl-14\">      <address>        <bpl:Address addressDetails=\"Herzl\" cityName=\"Haifa\" countryCode=\"ISR\" stateCode=\"0\" streetName=\"Herzl\" zipCode=\"5\" />      </address>    </bpl:ParkingSite>    <bpl:ParkingSite id=\"972.0.5.14.2\" name=\"Tel Aviv-Yafo-Ibn Gabirol-12\">      <address>        <bpl:Address addressDetails=\"Ibn Gabirol\" cityName=\"Tel Aviv-Yafo\" countryCode=\"ISR\" stateCode=\"0\" streetName=\"Ibn Gabirol\" />      </address>    </bpl:ParkingSite>  </addedSites></autos_cc:SitesUpdateResponse>";
    var parser = new BplXmlParser();
    parser.Parse<SitesUpdateResponse>(resp);
    if (parser.Success) {
       var r = (SitesUpdateResponse)parser.Output;
       return new Tuple<IEnumerable<Site>, IEnumerable<BplIdentity>>(r.AddedSites, r.RemovedSites);
    } else {
       return null;
    }
 }
Exemplo n.º 2
0
      private void btnAnalyze_Click(object sender, EventArgs e) {
         this.DispatchToBackground(() => {
            if (_activitiesList == null) {
               _report("Reading extracted activities");
               var xml = File.ReadAllText("extracted.bpl");
               var parser = new BplXmlParser();
               parser.Parse(xml);
               _activitiesList = parser.Output as AnalyzedActivityList;
            }
            var A = _activitiesList.Activities;

            // create list of activities with telemetry segments longer than 10km of driving without structured plan changes
            _report("Start Analyzing. Total activities {0}", A.Count);
            var partSize = (Distance)20;
            var activities = new List<AnalyzedActivity>();
            foreach (var a in A) {
               var telemetry = new List<VehicleTelemetry>();

               Action tryAdd = () => {
                  // plan change - measure part size, and if too short - clear and ignore
                  var t0 = telemetry.FirstOrDefault();
                  var t1 = telemetry.LastOrDefault();
                  if (t0 == null || t1 == null) return;
                  var d = t1.Odometer - t0.Odometer;
                  if (d < partSize) {
                     telemetry.Clear();
                     return;
                  }

                  var anew = new AnalyzedActivity { Activity = a.Activity.Clone() };
                  anew.Telemetry.AddRange(telemetry);
                  activities.Add(anew);
                  telemetry.Clear();
               };

               var tryadded = false;
               var partStarted = false;
               var lastKey = -1;
               for (var i = 0; i < a.Telemetry.Count; i++) {
                  var t = a.Telemetry[i];
                  if (t.RecordType != TelemetryRecordType.DrivingPlanChanged && t.RecordType != TelemetryRecordType.DrivingRoadSegmentPassed) continue;

                  // skip anything before first plan creation
                  if (!partStarted) {
                     if (t.RecordType == TelemetryRecordType.DrivingPlanChanged) partStarted = true;
                     continue;
                  }

                  if (lastKey == -1) {
                     var s = t.FutureDrivingSteps.FirstOrDefault();
                     if (s == null) continue;
                     lastKey = s.Key;
                  }

                  // aggregate telemetry (with nearest destination only) as long as there's no plan change
                  if (t.RecordType == TelemetryRecordType.DrivingRoadSegmentPassed) {
                     var tnew = t.Clone();
                     if (tnew.OriginalDrivingSegmentEstimates.Eea.IsUndefined) continue;
                     var snew = tnew.FutureDrivingSteps.FirstOrDefault().Clone();
                     if (snew == null) continue;

                     if (snew.Key == lastKey) {
                        tnew.FutureDrivingSteps.Clear();
                        tnew.FutureDrivingSteps.Add(snew);
                        telemetry.Add(tnew);
                        continue;
                     }
                     lastKey = snew.Key;
                  } else if (t.RecordType == TelemetryRecordType.DrivingPlanChanged) {
                     var s = t.FutureDrivingSteps.FirstOrDefault();
                     if (s == null) continue;
                     lastKey = s.Key;
                  }

                  tryAdd();
                  tryadded = true;
               }
               if (!tryadded) tryAdd(); // try add remainings
            }
            _report("Done Analyzing. {0} - long usable planned driving activities: {1}", partSize, activities.Count);

            foreach (var a in activities) {
               var t0 = a.Telemetry.First();
               var t1 = a.Telemetry.Last();

               var slopeU = 0.0;
               var slenU = 0.0;
               var slopeD = 0.0;
               var slenD = 0.0;
               a.Telemetry.Apply(t => {
                  var s = t.Segment;
                  if (s.Slope > (Percent)0.04) {
                     slopeU = (slopeU * slenU + (double)s.Slope * (double)s.Length) / (slenU + (double)s.Length);
                     slenU += (double)s.Length;
                  } else if (s.Slope < (Percent)(-0.04)) {
                     slopeD = (slopeD * slenD + (double)s.Slope * (double)s.Length) / (slenD + (double)s.Length);
                     slenD += (double)s.Length;
                  }
               });
               slopeU = (slopeU * 100.0).Round(1);
               slenU = slenU.Round(3);
               slopeD = (slopeD * 100.0).Round(1);
               slenD = slenD.Round(3);

               var o0 = t0.Odometer;
               var e0 = t0.Battery.Energy;
               var s0 = t0.Battery.Soc;
               // var a0 = t0.Gps.Location.Altitude;

               var o1 = t1.Odometer;
               var e1 = t1.Battery.Energy;
               var s1 = t1.Battery.Soc;
               // var a1 = t1.Gps.Location.Altitude;

               var dOdo = ((double)(o1 - o0)).Round(0);
               // var dAlt = ((double)(a1 - a0) * 1000).Round(0);
               var eest = ((double)t1.OriginalDrivingSegmentEstimates.Eea).Round(1);
               var eact = ((double)e1).Round(1);

               Debug.WriteLine("Distance: {0}, SlopeU: {1}, SlenU: {2}, SlopeD: {3}, SlenD: {4}, Eea: {5} ({6}%), E.actual: {7} ({8}%), Err: {9}%, ActivityId: {10}, Device: {11}, TimeStamp: {12}".Substitute(
                  dOdo,
                  slopeU, slenU,
                  slopeD, slenD,
                  eest, ((eest * 100) / 21.0).Round(0),
                  eact, ((eact * 100) / 21.0).Round(0),
                  ((eact * 100) / 21.0).Round(0) - ((eest * 100) / 21.0).Round(0),
                  a.Activity.ActivityId,
                  a.Activity.DeviceId,
                  t1.TimeStamp
                  ));
            }
            _report("Done Reporting");

         });
      }