예제 #1
0
      protected override void OnPeriodicElapsed(object sender, System.Timers.ElapsedEventArgs e) {
         var messages = _reader.TMC.Messages;
         if (messages == null || messages.Count == 0)
            return;

         BplLanguage.RuntimeMode = BplRuntimeMode.Batch;
         var res = new List<TrafficEvent>();
         foreach (var msg in messages) {

            var origin = new TrafficLocation {
               CountryCode = msg.CC,
               LocationTableNumber = msg.LTN,
               LocationCode = msg.LocationCode
            };

            var evt = new TrafficEvent {
               //Age = new TimeFrame(DateTime.Now, DateTime.Now.AddMinutes(msg.Duration)),
               Direction = msg.DirectionFlag ? 1 : 0,
               Extent = msg.Extent,
               IsTwoWay = msg.IsTwoWay,
               LastUpdate = DateTime.Now,
               Origin = origin
            };            
            
            evt.Codes = new BplArray<int>(msg.EventCodes);

            if (evt.Codes.Count > 0) {
               res.Add(evt);
            }
         }
         UpdateTrafficEvents(res.ToArray());
      }
예제 #2
0
 /// <summary>Checks two traffic locations for memberwise equality.</summary>
 public static bool MemberwiseEquals(TrafficLocation first, TrafficLocation second) {
    if (first == second) return true;
    if (first == null || second == null) return false;
    return first.LocationCode == second.LocationCode &&
       first.CountryCode == second.CountryCode &&
       first.LocationTableNumber == second.LocationTableNumber &&
       first.Location == second.Location;
 }
예제 #3
0
      private void _sendTrafficState() {
         if (_reader == null || _reader.TMC == null) {
            Log.Info("No TMC data");
            return;
         }

         var messages = _reader.TMC.Messages;
         if (messages == null || messages.Count == 0) {
            Log.Info("No traffic events");
            return;
         }

         var res = new List<TrafficEvent>();
         foreach (var msg in messages) {

            var origin = new TrafficLocation {
               CountryCode = msg.CC,
               LocationTableNumber = msg.LTN,
               LocationCode = msg.LocationCode
            };

            var evt = new TrafficEvent {
               //Age = new TimeFrame(DateTime.Now, DateTime.Now.AddMinutes(msg.Duration)),
               Direction = msg.DirectionFlag ? 1 : 0,
               Extent = msg.Extent,
               IsTwoWay = msg.IsTwoWay,
               LastUpdate = DateTime.Now,
               Origin = origin
            };

            evt.Codes = new BplArray<int>(msg.EventCodes);

            if (evt.Codes.Count > 0) {
               res.Add(evt);
            }
         }

         Log.Info("Provider name: {0}", _reader.TMC.ProviderName);
         Log.Info("-------------------- Traffic Events List ----------");
         var fmtr = new Mpcr.Core.Persistence.BplXmlFormatter();
         var cnt = 1;
         foreach (var evt in res) {
            if (fmtr.Format(evt)) {
               Log.Info("\tEvent #{0}: {1}", cnt++, fmtr.Output);
            } else
               Log.Info("Cannot format event: {0}", evt);
         }
         Log.Info("===================================================");
      }
예제 #4
0
      private void _processTraffic(XmlDocument data) {
         BplLanguage.RuntimeMode = BplRuntimeMode.Batch;
         var res = new List<TrafficEvent>();
         var nodes = data.SelectNodes("/Inrix/Incidents/Incident");
         foreach (XmlNode node in nodes) {

            try {

               var rdsNode = node.SelectSingleNode("RDS");

               var destination = new TrafficLocation {
                  CountryCode = int.Parse(rdsNode.SelectSingleNode("@tmcCountry").Value),
                  LocationTableNumber = int.Parse(rdsNode.SelectSingleNode("@tmcRegion").Value),
                  LocationCode = int.Parse(rdsNode.SelectSingleNode("@tmcLocation").Value)
               };

               var originTmc = node.SelectSingleNode("TMCs/TMC[last()]/@code").Value;
               var origin = new TrafficLocation {
                  CountryCode = int.Parse(originTmc.At(0)),
                  LocationTableNumber = int.Parse(originTmc.Between(1, 2)),
                  LocationCode = int.Parse(originTmc.Between(4, 8))
               };

               var e = new TrafficEvent {
                  ApproximatedDelay = TimeSpan.FromMinutes(float.Parse(node.SelectSingleNode("DelayImpact/@fromFreeFlowMinutes").Value)),
                  ApproximatedSpeed = Speed.Undefined,
                  Destination = destination,
                  Direction = int.Parse(rdsNode.SelectSingleNode("@direction").Value),
                  Extent = int.Parse(rdsNode.SelectSingleNode("@extent").Value),
                  IsTwoWay = node.SelectNodes(@"ParameterizedDescription/Direction[. = ""BOTH""]").Count > 0,
                  LastUpdate = DateTime.Now,
                  Length = Distance.FromMeters(1000.0 * float.Parse(node.SelectSingleNode("DelayImpact/@distance").Value)),
                  Load = new Percent(int.Parse(node.SelectSingleNode("@severity").Value) / 4d),
                  Origin = origin
               };

               var eventCodes = rdsNode.SelectNodes("EventCodes/EventCode/@value");
               var codes = new int[eventCodes.Count];
               for (var i = 0; i < eventCodes.Count; i++) codes[i] = int.Parse(eventCodes[i].Value);
               e.Codes = new BplArray<int>(codes);

               var parts = e.Codes.Select(c => c.ToString()).ToList();
               parts.AddRange(
                     e.Origin.LocationCode.ToString(),
                     e.Destination.LocationCode.ToString(),
                     e.Origin.LocationTableNumber.ToString(),
                     e.Destination.LocationTableNumber.ToString(),
                     e.Extent.ToString(),
                     e.Direction.ToString()
                     );
               e.Id = parts.ToArray().Join("-");

               if (e.Codes.Count > 0) {
                  res.Add(e);
               }
            } catch (Exception) {
               //Skip <Incident> with empty <TMCs> or any other ill-formed incident
            }
         }
         UpdateTrafficEvents(res.ToArray());
      }