Exemplo n.º 1
0
        public static List <T> FilterErrorPoints <T>(List <T> posInfoList) where T : IPosInfo
        {
            var errorPoints = new List <T>();

            if (posInfoList == null)
            {
                return(errorPoints);
            }
            var maxSpeed = AppContext.MoveMaxSpeed;

            if (maxSpeed <= 0)
            {
                return(errorPoints);
            }

            DateTime start = DateTime.Now;

            posInfoList.Sort((a, b) =>
            {
                return(a.DateTimeStamp.CompareTo(b.DateTimeStamp));
            });

            var disList      = new List <PosDistance>();
            var errorDisList = new List <PosDistance>();

            //string txt = "";

            for (int i = 0; i < posInfoList.Count - 1; i++)
            {
                var p1  = posInfoList[i];
                var p2  = posInfoList[i + 1];
                var dis = new PosDistance(p1, p2);
                //txt += dis + "\n";
                if (dis.speed > maxSpeed)
                {
                    errorDisList.Add(dis);

                    errorPoints.Add(p2);
                    posInfoList.RemoveAt(i);
                    i--;
                }
                else
                {
                    disList.Add(dis);
                }
            }
            disList.Sort();
            errorDisList.Sort();

            var         time  = DateTime.Now - start;
            PosDistance first = null;

            if (disList.Count > 0)
            {
                first = disList.First();
            }
            Log.Info(LogTags.HisPos, string.Format("maxSpeed:{0},allCount:{1},errorCount:{2},time:{3}ms,first:{4}", maxSpeed, posInfoList.Count, errorPoints.Count, time.TotalMilliseconds, first));

            //Log.Info(LogTags.HisPos, txt);
            return(errorPoints);
        }
Exemplo n.º 2
0
        private int errorCount = 0;                                                  //测试用

        private void EditTagPositionListOP(List <Position> positions)
        {
            //1.获取列表
            if (tagPosDic == null)
            {
                tagPosDic = LocationCardPositions.ToDictionary();
            }
            //var tagPosList = LocationCardPositions.ToDictionary();
            List <LocationCardPosition> changedTagPosList = new List <LocationCardPosition>();
            //Dictionary<string, LocationCard> dict = LocationCards.ToDictionaryByCode();//放在TagRelationBuffer中
            List <LocationCardPosition> newTagPosList = new List <LocationCardPosition>();

            List <LocationCard> editCardList       = new List <LocationCard>();
            Dictionary <string, LocationCard> dict = TagRelationBuffer.Instance().GetLocationCardDic();

            var maxSpeed = AppContext.MoveMaxSpeed;

            //maxSpeed = 0;//测试用

            //2.修改数据
            for (int i = 0; i < positions.Count; i++)
            {
                Position position = positions[i];
                if (position == null)
                {
                    continue;                  //位置信息可能有null
                }
                //LocationCard lc = LocationCards.Where(p=>p.Code == position.Code).FirstOrDefault();
                LocationCard lc = GetChangedCard(dict, position);
                if (lc != null)
                {
                    editCardList.Add(lc);
                }

                if (tagPosDic.ContainsKey(position.Code))
                {
                    var tagPos = tagPosDic[position.Code];

                    if (maxSpeed > 0)
                    {
                        var speed = PosDistanceUtil.GetSpeed(tagPos, position);

                        //PosDistance dis1 = new PosDistance(tagPos, position);
                        //posDistanceList.Add(dis1);

                        if (speed > maxSpeed)  //判断错误点
                        {
                            errorCount++;
                            PosDistance dis = new PosDistance(tagPos, position);
                            //这个点就不用来修改实时位置了
                            string tagPos1 = tagPos.GetText();
                            string tagPos2 = position.GetText();
                            Log.Info("ErrorPos", string.Format("发现错误点:TagPos:{0} Position:{1} ErrorCount:{2} Distance:{3}", tagPos1, tagPos2, errorCount, dis));
                            positions.RemoveAt(i);
                            i--;
                        }
                        else
                        {
                            tagPos.Edit(position);                   //修改实时位置数据
                            if (!changedTagPosList.Contains(tagPos)) //修改部分
                            {
                                changedTagPosList.Add(tagPos);
                            }
                        }
                    }
                    else
                    {
                        tagPos.Edit(position);                   //修改实时位置数据
                        if (!changedTagPosList.Contains(tagPos)) //修改部分
                        {
                            changedTagPosList.Add(tagPos);
                        }
                    }
                }
                else
                {
                    LocationCardPosition newTagPos = new LocationCardPosition(position);
                    newTagPosList.Add(newTagPos);
                    tagPosDic.Add(newTagPos.Id, newTagPos);//更新缓存
                }
            }

            //List<LocationCardPosition> noChangedTagPosList = new List<LocationCardPosition>();//没有移动的位置信息
            //foreach (var tag1 in tagPosList)
            //{
            //    if (!changedTagPosList.Contains(tag1))
            //    {
            //        noChangedTagPosList.Add(tag1);
            //    }
            //}

            ////设置实时位置的移动状态
            //foreach (var tag1 in noChangedTagPosList)
            //{
            //    TimeSpan time = DateTime.Now - tag1.DateTime;
            //    if (time.TotalSeconds > 30)
            //    {
            //        if (tag1.Flag == "0:0:0:0:1")
            //        {
            //            tag1.MoveState = 1;
            //        }
            //        else
            //        {
            //            tag1.MoveState = 2;
            //        }
            //    }
            //}

            LocationCards.EditRange(editCardList);              //修改定位卡信息

            LocationCardPositions.EditRange(changedTagPosList); //修改位置信息

            LocationCardPositions.AddRange(newTagPosList);      //增加位置信息
        }