Exemplo n.º 1
0
        private IEnumerable <ITerm> Method1(DateTime start, DateTime end, IList <RtaaSlicedTerm> blocks, IList <IAgentStatus> statuses, DateTime watchPoint)
        {
            List <ITerm> results            = new List <ITerm>();
            var          agentAdherenceList = GetACDEvents(statuses, start, end, 0, watchPoint);
            int          minAbnormalBufferSeconds;

            if (Application.Current == null)
            {
                // 晚下班
                DelayOffLineBuffer = LanguageReader.GetValue <int>("OffLineLaterBufferSeconds");
                // 早上線
                PrematureOnLineBuffer = LanguageReader.GetValue <int>("OnLineEarlierBufferSeconds");
                // 晚上線
                DelayOnLineBuffer = LanguageReader.GetValue <int>("OnLineLaterBufferSeconds");
                // 早下線
                PrematureOffLineBuffer = LanguageReader.GetValue <int>("OffLineEarlierBufferSeconds");
                // 通用
                minAbnormalBufferSeconds = LanguageReader.GetValue <int>("MinAbnormalBufferSeconds");
            }
            else
            {
                // 晚下班
                DelayOffLineBuffer = Convert.ToInt32(Application.Current.Resources["OffLineLaterBufferSeconds"]);
                // 早上線
                PrematureOnLineBuffer = Convert.ToInt32(Application.Current.Resources["OnLineEarlierBufferSeconds"]);
                // 晚上線
                DelayOnLineBuffer = Convert.ToInt32(Application.Current.Resources["OnLineLaterBufferSeconds"]);
                // 早下線
                PrematureOffLineBuffer = Convert.ToInt32(Application.Current.Resources["OffLineEarlierBufferSeconds"]);
                // 通用
                minAbnormalBufferSeconds = Convert.ToInt32(Application.Current.Resources["MinAbnormalBufferSeconds"]);
            }

            int j = 0;

            for (int i = 0; i < agentAdherenceList.Count; i++)
            {
                //并交行走
                for (; j < blocks.Count && i < agentAdherenceList.Count; j++)
                {//两个相交才确定
                    if (blocks[j].Start <= agentAdherenceList[i].End && agentAdherenceList[i].Start <= blocks[j].End)
                    {
                        #region CrossOver

                        // if 相交部分OnService的情況相同 Or 這個班塊是Ignore
                        if (blocks[j].OnService == agentAdherenceList[i].OnService || blocks[j].Ignore)
                        {
                            //               i
                            //  Adh    |===========|----------
                            //  Block      |===========|------
                            //                   j
                            // Block 已經比 Adh 更晚了
                            // Block idx不變 Adh 換到下一個
                            if (agentAdherenceList[i].End <= blocks[j].End)
                            {
                                j--;
                                i++;
                            }
                            continue;
                        }

                        DateRangeRef centerDateRange = new DateRangeRef();

                        // 找出相交部分的區域
                        centerDateRange.Start = blocks[j].Start < agentAdherenceList[i].Start ? agentAdherenceList[i].Start : blocks[j].Start;
                        centerDateRange.End   = blocks[j].End > agentAdherenceList[i].End ? agentAdherenceList[i].End : blocks[j].End;


                        //if (exceptionBlock.End.Subtract(exceptionBlock.Start).TotalMinutes < unitmin) continue;

                        #region 找出leftBlock, leftDateRange, rightBlock, rightDateRange
                        // 找出前一個Block  如果是第一個(inx = 0)Block ,建立一個Gap,時間是從DateTime.Min~第一個Block的開始
                        RtaaSlicedTerm leftBlock = j > 0 ? blocks[j - 1] :
                                                   new RtaaSlicedTerm()
                        {
                            Start     = DateTime.MinValue,
                            End       = blocks[j].Start,
                            OnService = false,
                            Text      = "Gap"
                        };    //Gap
                        DateRangeRef leftDateRange = new DateRangeRef(leftBlock.Start, leftBlock.End);
                        if (j > 0)
                        {
                            leftDateRange.Start = blocks[j - 1].Start;
                            leftDateRange.End   = blocks[j - 1].End;
                        }

                        // 找出下一個Block 如果是最後一個Block ,建立一個Gap,時間是最後一個Block結束~DateTime.Max
                        RtaaSlicedTerm rightBlock = j < (blocks.Count - 1) ? blocks[j + 1] :
                                                    new RtaaSlicedTerm()
                        {
                            Start     = blocks[j].End,
                            End       = DateTime.MaxValue,
                            OnService = false,
                            Text      = "Gap"
                        };    //Gap
                        DateRangeRef rightDateRange = new DateRangeRef(rightBlock.Start, rightBlock.End);
                        if (j < (blocks.Count - 1))
                        {
                            rightDateRange.Start = blocks[j + 1].Start;
                            rightDateRange.End   = blocks[j + 1].End;
                        }
                        #endregion

                        // 決定這個相交段是 "LateToWork"(應上未上) Or "LateToLeave"(應下未下) Or ""(被Buff忽略)
                        string style = ShiftCheckAdherence(leftBlock, blocks[j], rightBlock, leftDateRange, centerDateRange, rightDateRange);

                        // if 是 "LateToWork"(應上未上) Or "LateToLeave"(應下未下)
                        if (style.Length > 0)
                        {
                            // 如果是不在start~end間, 換看下一個Block
                            if (centerDateRange.End <= start || centerDateRange.Start >= end)
                            {
                                //               i          i+1
                                //  Adh    |===========|----------|
                                //  Block      |===========|-------
                                //                   j
                                // Block 已經比 Adh 更晚了
                                // Block idx不變 Adh 換到下一個
                                if (agentAdherenceList[i].End <= blocks[j].End)
                                {
                                    j--;
                                    i++;
                                }
                                //                          i          i+1
                                //  Adh               |===========|----------|
                                //  Block      |===========|---------|--------
                                //                   j         J+1
                                // Adh 已經比 Block 更晚了
                                // Adh idx不變 Block 換到下一個
                                //else { }
                                continue;
                            }


                            var exceptionBlock = new AdherenceTerm(centerDateRange.Start, centerDateRange.End, new DateRange(start, end))
                            {
                                Text = style
                            };
                            //exceptionBlock.BackgroundColor = blockBrushColors[style];

                            // 檢查產生的長度是否大過 minAbnormalBufferSeconds,否則就不加入Result
                            if (exceptionBlock.End.Subtract(exceptionBlock.Start).TotalSeconds >= minAbnormalBufferSeconds)
                            {
                                results.Add(exceptionBlock);
                            }
                        }

                        //               i          i+1
                        //  Adh    |===========|----------|
                        //  Block      |===========|-------
                        //                   j
                        // Block 已經比 Adh 更晚了
                        // Block idx不變 Adh 換到下一個
                        if (agentAdherenceList[i].End <= blocks[j].End)
                        {
                            j--;
                            i++;
                        }
                        //                          i          i+1
                        //  Adh               |===========|----------|
                        //  Block      |===========|---------|--------
                        //                   j         J+1
                        // Adh 已經比 Block 更晚了
                        // Adh idx不變 Block 換到下一個
                        //else { }
                        #endregion
                    }
                    else
                    {
                        //               i            i+1
                        //  Adh    |===========|--------------------|
                        //  Block                |===========|------
                        //                             j
                        // Block 已經比 Adh 更晚了
                        // Block idx不變 Adh 換到下一個
                        if (blocks[j].Start > agentAdherenceList[i].End)
                        {
                            if (j > 0)
                            {
                                j--;
                            }
                            break;
                        }
                        //                                 i
                        //  Adh                      |===========|----------
                        //  Block      |===========|------------|------------
                        //                   j           j+1
                        // Adh 已經比 Block 更晚了
                        // Adh idx不變 Block 換到下一個
                        //else { }
                    }
                }
            }


            // 切掉超出start和end之外的片段
            if (results.Count > 0 && results[0].Start < start) //Henry: modified @ 2010/3/31 13:50 if (results.Count > 0 && results[0].Start <= start)
            {
                results.RemoveAt(0);
            }

            if (results.Count > 0 && results[results.Count - 1].End > end)
            {
                results[results.Count - 1].SaftyInvoke <AdherenceTerm>(o =>
                {
                    o.End = end;
                    if (o.End.Subtract(o.Start).TotalSeconds < minAbnormalBufferSeconds)
                    {
                        results.Remove(o);
                    }
                });
            }

            return(results);
        }
Exemplo n.º 2
0
        private IEnumerable<ITerm> Method1(DateTime start, DateTime end, IList<RtaaSlicedTerm> blocks, IList<IAgentStatus> statuses, DateTime watchPoint)
        {
            List<ITerm> results = new List<ITerm>();
            var agentAdherenceList = GetACDEvents(statuses, start, end, 0, watchPoint);
            int minAbnormalBufferSeconds;

            if (Application.Current == null)
            {
                // 晚下班
                DelayOffLineBuffer = LanguageReader.GetValue<int>("OffLineLaterBufferSeconds");
                // 早上線
                PrematureOnLineBuffer = LanguageReader.GetValue<int>("OnLineEarlierBufferSeconds");
                // 晚上線
                DelayOnLineBuffer = LanguageReader.GetValue<int>("OnLineLaterBufferSeconds");
                // 早下線
                PrematureOffLineBuffer = LanguageReader.GetValue<int>("OffLineEarlierBufferSeconds");
                // 通用
                minAbnormalBufferSeconds = LanguageReader.GetValue<int>("MinAbnormalBufferSeconds");
            }
            else
            {
                // 晚下班
                DelayOffLineBuffer = Convert.ToInt32(Application.Current.Resources["OffLineLaterBufferSeconds"]);
                // 早上線
                PrematureOnLineBuffer = Convert.ToInt32(Application.Current.Resources["OnLineEarlierBufferSeconds"]);
                // 晚上線
                DelayOnLineBuffer = Convert.ToInt32(Application.Current.Resources["OnLineLaterBufferSeconds"]);
                // 早下線
                PrematureOffLineBuffer = Convert.ToInt32(Application.Current.Resources["OffLineEarlierBufferSeconds"]);
                // 通用
                minAbnormalBufferSeconds = Convert.ToInt32(Application.Current.Resources["MinAbnormalBufferSeconds"]);
            }

            int j = 0;
            for (int i = 0; i < agentAdherenceList.Count; i++)
            {
                //并交行走
                for (; j < blocks.Count && i < agentAdherenceList.Count; j++)
                {//两个相交才确定
                    if (blocks[j].Start <= agentAdherenceList[i].End && agentAdherenceList[i].Start <= blocks[j].End)
                    {
                        #region CrossOver

                        // if 相交部分OnService的情況相同 Or 這個班塊是Ignore
                        if (blocks[j].OnService == agentAdherenceList[i].OnService || blocks[j].Ignore)
                        {
                            //               i
                            //  Adh    |===========|----------
                            //  Block      |===========|------
                            //                   j
                            // Block 已經比 Adh 更晚了
                            // Block idx不變 Adh 換到下一個
                            if (agentAdherenceList[i].End <= blocks[j].End)
                            {
                                j--;
                                i++;
                            }
                            continue;
                        }

                        DateRangeRef centerDateRange = new DateRangeRef();

                        // 找出相交部分的區域
                        centerDateRange.Start = blocks[j].Start < agentAdherenceList[i].Start ? agentAdherenceList[i].Start : blocks[j].Start;
                        centerDateRange.End = blocks[j].End > agentAdherenceList[i].End ? agentAdherenceList[i].End : blocks[j].End;


                        //if (exceptionBlock.End.Subtract(exceptionBlock.Start).TotalMinutes < unitmin) continue;

                        #region 找出leftBlock, leftDateRange, rightBlock, rightDateRange
                        // 找出前一個Block  如果是第一個(inx = 0)Block ,建立一個Gap,時間是從DateTime.Min~第一個Block的開始
                        RtaaSlicedTerm leftBlock = j > 0 ? blocks[j - 1] :
                            new RtaaSlicedTerm()
                            {
                                Start = DateTime.MinValue,
                                End = blocks[j].Start,
                                OnService = false,
                                Text = "Gap"
                            };//Gap
                        DateRangeRef leftDateRange = new DateRangeRef(leftBlock.Start, leftBlock.End);
                        if (j > 0)
                        {
                            leftDateRange.Start = blocks[j - 1].Start;
                            leftDateRange.End = blocks[j - 1].End;
                        }

                        // 找出下一個Block 如果是最後一個Block ,建立一個Gap,時間是最後一個Block結束~DateTime.Max
                        RtaaSlicedTerm rightBlock = j < (blocks.Count - 1) ? blocks[j + 1] :
                            new RtaaSlicedTerm()
                            {
                                Start = blocks[j].End,
                                End = DateTime.MaxValue,
                                OnService = false,
                                Text = "Gap"
                            };//Gap
                        DateRangeRef rightDateRange = new DateRangeRef(rightBlock.Start, rightBlock.End);
                        if (j < (blocks.Count - 1))
                        {
                            rightDateRange.Start = blocks[j + 1].Start;
                            rightDateRange.End = blocks[j + 1].End;
                        }
                        #endregion

                        // 決定這個相交段是 "LateToWork"(應上未上) Or "LateToLeave"(應下未下) Or ""(被Buff忽略)
                        string style = ShiftCheckAdherence(leftBlock, blocks[j], rightBlock, leftDateRange, centerDateRange, rightDateRange);

                        // if 是 "LateToWork"(應上未上) Or "LateToLeave"(應下未下)
                        if (style.Length > 0)
                        {
                            // 如果是不在start~end間, 換看下一個Block
                            if (centerDateRange.End <= start || centerDateRange.Start >= end)
                            {
                                //               i          i+1
                                //  Adh    |===========|----------|
                                //  Block      |===========|-------
                                //                   j
                                // Block 已經比 Adh 更晚了
                                // Block idx不變 Adh 換到下一個
                                if (agentAdherenceList[i].End <= blocks[j].End)
                                {
                                    j--;
                                    i++;
                                }
                                //                          i          i+1
                                //  Adh               |===========|----------|
                                //  Block      |===========|---------|--------
                                //                   j         J+1
                                // Adh 已經比 Block 更晚了
                                // Adh idx不變 Block 換到下一個
                                //else { }
                                continue;
                            }


                            var exceptionBlock = new AdherenceTerm(centerDateRange.Start, centerDateRange.End, new DateRange(start, end)) { Text = style };
                            //exceptionBlock.BackgroundColor = blockBrushColors[style];

                            // 檢查產生的長度是否大過 minAbnormalBufferSeconds,否則就不加入Result
                            if (exceptionBlock.End.Subtract(exceptionBlock.Start).TotalSeconds >= minAbnormalBufferSeconds)
                                results.Add(exceptionBlock);
                        }

                        //               i          i+1
                        //  Adh    |===========|----------|
                        //  Block      |===========|-------
                        //                   j
                        // Block 已經比 Adh 更晚了
                        // Block idx不變 Adh 換到下一個
                        if (agentAdherenceList[i].End <= blocks[j].End)
                        {
                            j--;
                            i++;
                        }
                        //                          i          i+1
                        //  Adh               |===========|----------|
                        //  Block      |===========|---------|--------
                        //                   j         J+1
                        // Adh 已經比 Block 更晚了
                        // Adh idx不變 Block 換到下一個
                        //else { }
                        #endregion
                    }
                    else
                    {
                        //               i            i+1
                        //  Adh    |===========|--------------------|
                        //  Block                |===========|------
                        //                             j
                        // Block 已經比 Adh 更晚了
                        // Block idx不變 Adh 換到下一個
                        if (blocks[j].Start > agentAdherenceList[i].End)
                        {
                            if (j > 0)
                                j--;
                            break;
                        }
                        //                                 i
                        //  Adh                      |===========|----------
                        //  Block      |===========|------------|------------
                        //                   j           j+1
                        // Adh 已經比 Block 更晚了
                        // Adh idx不變 Block 換到下一個
                        //else { }
                    }
                }
            }


            // 切掉超出start和end之外的片段
            if (results.Count > 0 && results[0].Start < start) //Henry: modified @ 2010/3/31 13:50 if (results.Count > 0 && results[0].Start <= start)
            {
                results.RemoveAt(0);
            }

            if (results.Count > 0 && results[results.Count - 1].End > end)
            {
                results[results.Count - 1].SaftyInvoke<AdherenceTerm>(o =>
                {
                    o.End = end;
                    if (o.End.Subtract(o.Start).TotalSeconds < minAbnormalBufferSeconds)
                        results.Remove(o);
                });
            }

            return results;
        }