/// <summary>
    /// 根据进度值,获取当前需要执行的点的索引
    /// </summary>
    /// <param name="f"></param>
    /// <param name="accuracy">精确度:时间相差accuracy秒</param>
    public override int GetCompareTime(double f, float accuracy = 0.1f)
    {
        DateTime startTimeT = HistoryPlayUI.Instance.GetStartTime();

        //相匹配的第一个元素,结果为-1表示没找到
        return(PosInfoList.FindIndexByTime(startTimeT, f, accuracy));
    }
    /// <summary>
    /// 获取离它最近的下一个播放点
    /// </summary>
    public override int GetNextPoint(float value)
    {
        DateTime startTimeT = HistoryPlayUI.Instance.GetStartTime();
        double   f          = timeLength * value;

        //相匹配的第一个元素,结果为-1表示没找到
        return(PosInfoList.FindIndex((item) =>
        {
            double timeT = (item.Time - startTimeT).TotalSeconds;
            if (timeT > f)
            {
                return true;
            }
            else
            {
                return false;
            }
        }));
    }
    /// <summary>
    /// 根据进度时间值,获取当前需要执行的点的索引
    /// </summary>
    /// <param name="f"></param>
    /// <param name="accuracy">精确度:时间相差accuracy秒</param>
    public override int GetCompareTime(double f, float accuracy = 0.1f)
    {
        DateTime startTimeT = LocationHistoryUITool.GetStartTime();

        ////相匹配的第一个元素,结果为-1表示没找到
        //return PosInfoList.FindIndex((item) =>
        //{
        //    double timeT = (item.Time - startTimeT).TotalSeconds;
        //    if (Math.Abs(f - timeT) < accuracy)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //});

        return(PosInfoList.FindIndexByTime(startTimeT, f, accuracy));
    }
Ejemplo n.º 4
0
    /// <summary>
    /// 执行轨迹演变
    /// </summary>
    protected PositionInfo ExcuteHistoryPath(int currentIndex, float rateT = 1f, bool isLerp = true)
    {
        HisPosInfo info = new HisPosInfo();

        info.PreHisInfo         = hisPosInfo;
        hisPosInfo              = info;
        hisPosInfo.currentIndex = currentIndex;

        //Debug.Log("ExcuteHistoryPath:"+ currentIndex);
        HighlightTestPoint(currentIndex);

        //if (!MultHistoryPlayUI.Instance.isNewWalkPath)
        //{

        #region 用画线插件来设置人员在轨迹上的位置

        //ExcuteHistoryPathOP(currentIndex, isLerp);

        #endregion

        //}
        //else
        //{

        #region 自己计算设置人员在轨迹上的位置


        if (rateChanged)
        {
            previousPos = transform.position;
            SetRateChanged(false);
            timesub = timesub - timesum * rateT;
            timesum = 0;
        }

        if (previousCurrentPointIndex != currentIndex)
        {
            count   = 0;
            timesum = 0;
            previousCurrentPointIndex = currentIndex;
            if (currentIndex - 1 >= 0 && currentIndex - 1 < PosCount)
            {
                hisPosInfo.PrePosInfo = PosInfoList[currentIndex - 1];
                previousPos           = PosInfoList[currentIndex - 1].Vec;
                timesub = (float)PosInfoList.GetTimeSpane(currentPointIndex);
            }
        }

        count++;
        timesum += Time.deltaTime;
        PositionInfo posInfo = PosInfoList[currentIndex];
        hisPosInfo.CurrentPosInfo = posInfo;


        Vector3 targetPos = posInfo.Vec;
        Vector3 showPos   = targetPos;
        if (isLerp && currentIndex > 0)
        {
            //showPos = Vector3.Lerp(previousPos, targetPos, count * speed * rateT * Time.fixedDeltaTime);//speed小的话会导致计算出来的演变点比实际要演变的点慢很多(两个位置点差距比较大)
            if (timesub == 0)
            {
                showPos = Vector3.Lerp(transform.position, targetPos, count * speed * rateT * Time.deltaTime);
                //Debug.LogError("timesub == 0!!!!!");
            }
            else
            {
                showPos = Vector3.Lerp(previousPos, targetPos, timesum * rateT / timesub);
            }
        }
        else
        {
            showPos = targetPos;
        }

        //Debug.LogError("显示位置:" + showPos + ",索引:" + currentIndex + ",起始点:" + previousPos + ",计数:" + count + ",系数:" + count * speed * rateT * Time.deltaTime + ",speed:" + speed + ",Time.fixedDeltaTime" + Time.fixedDeltaTime);
        //Debug.LogError("timesum / timesub:" + timesum / timesub);

        SetRotaion(targetPos); //设置旋转角度
        //transform.position = new Vector3(showPos.x, showPos.y - historyOffsetY, showPos.z);//减去0.4是为了让人员高度贴近地面,通常为人的一半高度

        if (LocationHistoryManager.Instance.isSetPersonHeightByRay)
        {
            showPos = SetPersonHeightByRay(showPos);
        }
        else
        {
            showPos = new Vector3(showPos.x, showPos.y - heightOffset, showPos.z); //卡拿着的大约高度
        }
        //transform.position = showPos;

        hisPosInfo.TargetPos  = targetPos;
        hisPosInfo.ShowPos    = showPos;
        hisPosInfo.CurrentPos = transform.position;
        SetPosition(hisPosInfo, rateT);

        #endregion

        //}
        return(posInfo);
    }
    protected override void Update()
    {
        //if (MultHistoryPlayUINew.Instance.istest)
        //{
        //    int i= 0;
        //}
        base.Update();
        if (MultHistoryPlayUINew.Instance.isPlay)
        {
            if (!isCreatePathComplete)
            {
                return;
            }
            if (!LocationHistoryUITool.GetIsPlaying())
            {
                return;
            }
            if (isNeedHide)
            {
                isNeedHide = false;
                Hide();
                return;
            }
            float valuet = 1;
            valuet = LocationHistoryUITool.GetProcessSliderValue();
            if (valuet < 1)
            {
                //double timesum = MultHistoryPlayUI.Instance.timeSum;
                //DateTime showPointTime = MultHistoryPlayUI.Instance.GetStartTime().AddSeconds(timesum);
                MultHistoryTimeStamp timeStamp = LocationHistoryUITool.GetTimeStamp();
                double   timesum       = timeStamp.timeSum;
                DateTime showPointTime = timeStamp.showPointTime;
                float    currentSpeedT = timeStamp.currentSpeed;
                if (currentPointIndex < PosCount && currentPointIndex > -1)
                {
                    //Debug.LogErrorFormat("timelist[currentPointIndex]:{0},showPointTime:{1}", timelist[currentPointIndex], showPointTime);
                    if (PosInfoList[currentPointIndex].Time < showPointTime)
                    {
                        //double timesum2 = (timelist[currentPointIndex] - HistoryPlayUI.Instance.GetStartTime()).TotalSeconds;
                        //Debug.Log("timesum2:" + timesum2);
                        //progressTargetValue = (double)timesum2 / HistoryPlayUI.Instance.timeLength;
                        //if (MultHistoryPlayUI.Instance.isNewWalkPath)
                        //{
                        if (currentPointIndex - 1 >= 0)
                        {
                            double temp = PosInfoList.GetTimeSpane(currentPointIndex);
                            if (temp > 2f)
                            {
                                //ExcuteHistoryPath(currentPointIndex,1f, false);
                                ExcuteHistoryPath(currentPointIndex, currentSpeedT);
                                currentPointIndex++;
                                return;
                            }
                            else
                            {
                                ExcuteHistoryPath(currentPointIndex, currentSpeedT);
                            }
                        }
                        else
                        {
                            ExcuteHistoryPath(currentPointIndex, currentSpeedT);
                        }
                        //}
                        //else
                        //{
                        //    ExcuteHistoryPath(currentPointIndex, MultHistoryPlayUI.Instance.CurrentSpeed);
                        //}
                        //Debug.LogError("currentPointIndex111:" + currentPointIndex);
                        currentPointIndex++;
                        Show();
                    }
                    else//如果当前点的时间超过了当前进度时间
                    {
                        //if (currentPointIndex - 1 >= 0)
                        //{
                        //    ExcuteHistoryPath(currentPointIndex - 1, MultHistoryPlayUI.Instance.CurrentSpeed);
                        //}

                        ExcuteHistoryPath(currentPointIndex, currentSpeedT);

                        //Debug.LogError("currentPointIndex222:" + currentPointIndex);
                        //if (MultHistoryPlayUI.Instance.isNewWalkPath)
                        //{
                        if (currentPointIndex - 1 >= 0)
                        {
                            double temp = (PosInfoList[currentPointIndex].Time - PosInfoList[currentPointIndex - 1].Time).TotalSeconds;
                            if (temp > 2f)//如果当前要执行历史点的值,超过播放时间值5秒,就认为这超过5秒时间里,没历史轨迹数据,则让人员消失
                            {
                                //Hide();
                            }
                        }
                        else
                        {
                            //Hide();
                        }
                        //}
                        //else
                        //{
                        //    double temp = (timelist[currentPointIndex] - showPointTime).TotalSeconds;
                        //    if (temp > 5f)//如果当前要执行历史点的值,超过播放时间值5秒,就认为这超过5秒时间里,没历史轨迹数据,则让人员消失
                        //    {
                        //        Hide();
                        //    }
                        //}
                    }
                    //progressValue = Mathf.Lerp((float)progressValue, (float)progressTargetValue, 2 * Time.deltaTime);
                    //transform.position = line.GetPoint3D01((float)progressValue);
                    //ExcuteHistoryPath(currentPointIndex);
                }
                else
                {
                    Hide();
                }
            }
            else
            {
                progressValue       = 0;
                progressTargetValue = 0;
                currentPointIndex   = 0;
            }
        }
        //else
        //{
        ShowArea();
        //}

        if (depnode != null)
        {
            if (LocationHistoryManager.Instance && LocationHistoryManager.Instance.IsFocus)//对焦状态时才可以加载设备
            {
                BuildingController buillding = depnode.GetParentNode <BuildingController>();
                if (buillding && !buillding.IsDevCreate)//加载设备
                {
                    buillding.IsDevCreate = true;
                    buillding.LoadDevices(() =>
                    {
                        RoomFactory.Instance.CreateDepDev(buillding, true);//todo:是否可以不加载动态设备
                    });
                }
            }
        }
    }
Ejemplo n.º 6
0
        public int RemoveRepeatData(string tag, bool isDelete, List <PosInfoList> list, string preProgress = "")
        {
            int removeCount = 0;

            Log.Info(tag, "RemoveRepeatData Start");
            for (int i = 0; i < list.Count; i++)
            {
                PosInfoList posList = list[i];


                var groupby = posList.Items.GroupBy(p => new { p.DateTimeStamp, p.Code }).Select(p => new
                {
                    p.Key.DateTimeStamp,
                    p.Key.Code,
                    Id    = p.First(w => true).Id,
                    list  = p.Select(w => w.Id).ToList(),
                    total = p.Count()
                });
                var groupList = groupby.Where(k => k.total > 1).ToList();
                if (groupList.Count == 0)
                {
                    continue;
                }

                string progress1 = string.Format("{4} Progress1>>Name:{0},Count:{1:N} ({2}/{3})", posList.Name,
                                                 posList.Count, (i + 1), list.Count, preProgress);
                Log.Info(tag, progress1);

                var groupList1 = groupby.Where(k => k.total == 2).ToList();
                var groupList2 = groupby.Where(k => k.total == 3).ToList();
                var groupList3 = groupby.Where(k => k.total == 4).ToList();
                var groupList4 = groupby.Where(k => k.total > 1 && k.total <= 10).ToList();
                var groupList5 = groupby.Where(k => k.total > 10).ToList();

                Log.Info(tag, string.Format("groupList:{0}", groupList.Count));

                posList.Items.Clear();
                //GC.Collect();
                //return 0;

                List <Position> removeListTemp = new List <Position>();
                int             maxPageCount   = 4000;
                int             packageCount   = maxPageCount;
                List <long>     timestampList  = new List <long>();
                List <int>      idList         = new List <int>();
                List <string>   wheres         = new List <string>();
                for (int k = 0; k < groupList.Count; k++)
                {
                    var item = groupList[k];
                    if (item.total > 1)
                    {
                        item.list.Remove(item.Id);
                        timestampList.Add(item.DateTimeStamp);
                        idList.AddRange(item.list);

                        string where = string.Format("(DateTimeStamp = {0} and Code = '{1}' and Id != {2})", item.DateTimeStamp, item.Code, item.Id);
                        wheres.Add(where);
                    }
                    if (idList.Count >= packageCount ||
                        (k == groupList.Count - 1 && idList.Count > 0)//最后一组
                        )
                    {
                        try
                        {
                            //var query =this.DbSet.Where(j => idList.Contains(j.Id));
                            //var sql = query.ToString();
                            var count2 = idList.Count();
                            if (isDelete)
                            {
                                //query.DeleteFromQuery();
                                //this.RemovePoints(query, false);
                                //this.RemovePoints(idList);
                                //this.RemovePoints(tag,wheres, idList);
                                var temp  = new List <string>(wheres);
                                var temp2 = new List <int>(idList);
                                //ThreadPool.QueueUserWorkItem((data) =>
                                //{
                                using (LocationHistoryDb db = new LocationHistoryDb())    //using必须有
                                {
                                    PositionBll.RemovePoints(tag, db, temp, temp2);
                                }
                                //});
                            }
                            removeCount += count2;
                            Log.Info(tag, string.Format("{6}{5} || Progress2>>where:{7},count:{0},total:{1:N} ({2}/{3},{4:F3})", count2, removeCount, (k + 1), groupList.Count, (k + 1.0) / groupList.Count, progress1, preProgress, wheres.Count));
                            timestampList = new List <long>();
                            idList        = new List <int>();
                            wheres        = new List <string>();

                            if (packageCount < maxPageCount)
                            {
                                packageCount *= 2;
                                if (packageCount > maxPageCount)
                                {
                                    packageCount = maxPageCount;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            //Log.Info(tag, string.Format("{5} || Progress2 》》 count:{0},total:{1:N} ({2}/{3},{4:F3})", "NULL", removeCount, (k + 1), groupList.Count, (k + 1.0) / groupList.Count, progress1));

                            Log.Info(tag, string.Format("Progress2 Error:{0}", e));
                            //return -1;//暂停

                            Thread.Sleep(50);
                            packageCount /= 2;
                            k--;//将包的大小减少 重新尝试
                            timestampList = new List <long>();
                            idList        = new List <int>();
                        }
                        //Log.Info(tag, string.Format("removeGroupCount:{0}", timestampList.Count));
                    }
                }
            }
            Log.Info(tag, "RemoveRepeatData End TotolCount:" + removeCount);
            return(removeCount);
        }