コード例 #1
0
        public static Item FindPotentialNewOwner(
            LocationReport lr,
            Item luggageItem)
        {
            // for a given luggage find the owner that is nearest to it
            Item passenger = null;
            double distanceMin = int.MaxValue;
            foreach (var item in lr.Items) {
                if (item.Type.Equals("P")) {
                    var who = item.AssetId;
                    if (luggageItem.AssetIdPassenger.Equals(who)) {
                        continue;
                    }

                    var distance = LRUtil.Distance(
                        luggageItem.Location.X,
                        luggageItem.Location.Y,
                        item.Location.X,
                        item.Location.Y);

                    if (passenger == null || distance < distanceMin) {
                        passenger = item;
                        distanceMin = distance;
                    }
                }
            }

            return passenger;
        }
コード例 #2
0
        /// <summary>
        ///     Return all luggages separated from the owner.
        /// </summary>
        /// <param name="lr">event</param>
        /// <returns>list</returns>
        public static IList<Item> FindSeparatedLuggage(LocationReport lr)
        {
            // loop over all luggages
            // find the location of the owner of the luggage
            // compute distance luggage to owner
            // if distance > 10 add original-owner

            IList<Item> result = new List<Item>();
            foreach (var item in lr.Items) {
                if (item.Type.Equals("L")) {
                    var belongTo = item.AssetIdPassenger;

                    Item owner = null;
                    foreach (var ownerItem in lr.Items) {
                        if (ownerItem.Type.Equals("P")) {
                            if (ownerItem.AssetId.Equals(belongTo)) {
                                owner = ownerItem;
                            }
                        }
                    }

                    if (owner == null) {
                        continue;
                    }

                    var distanceOwner = LRUtil.Distance(
                        owner.Location.X,
                        owner.Location.Y,
                        item.Location.X,
                        item.Location.Y);
                    if (distanceOwner > 20) {
                        result.Add(item);
                    }
                }
            }

            return result;
        }