コード例 #1
0
 public void AddGetTrendPoint(int l_iAutomationFunctionId, int l_iPortId)
 {
     lock (m_TrendPointsData)
     {
         long l_iUniqueKey = CreateUniqueKey(l_iAutomationFunctionId, l_iPortId);
         if (m_TrendPointsData.ContainsKey(l_iUniqueKey) == false)
         {
             TrendPoint l_TrendPoint = new TrendPoint();
             l_TrendPoint.ID          = l_iUniqueKey;
             l_TrendPoint.LastestTime = 0;
             l_TrendPoint.SessionID   = -1;
             l_TrendPoint.Data.Clear();
             m_TrendPointsData.Add(l_iUniqueKey, l_TrendPoint);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Merges the trends providing a single timeline.
        /// </summary>
        public static TrendBundle MergeTrends(IList <Trend> trends)
        {
            if (trends == null)
            {
                throw new ArgumentNullException(nameof(trends));
            }

            // simple cases first
            int cnlCnt = trends.Count;

            if (cnlCnt == 0)
            {
                return(new TrendBundle(0, 0));
            }

            if (cnlCnt == 1)
            {
                return(CreateTrendBundle(trends[0]));
            }

            // full case
            int maxTrendCapacity = 0;

            int[] cnlNums        = new int[cnlCnt];
            int[] trendPositions = new int[cnlCnt]; // trend reading positions

            for (int i = 0; i < cnlCnt; i++)
            {
                Trend trend = trends[i];
                cnlNums[i]        = trend.CnlNum;
                trendPositions[i] = 0;

                if (maxTrendCapacity < trend.Points.Count)
                {
                    maxTrendCapacity = trend.Points.Count;
                }
            }

            const double CapacityRatio = 1.1;
            TrendBundle  trendBundle   = new TrendBundle(cnlNums, (int)(maxTrendCapacity * CapacityRatio));

            while (true)
            {
                // determine the minimum timestamp at trend reading positions
                DateTime minTimestamp = DateTime.MaxValue;
                bool     endReached   = true;

                for (int i = 0; i < cnlCnt; i++)
                {
                    List <TrendPoint> trendPoints = trends[i].Points;
                    int trendPos = trendPositions[i];

                    if (trendPos < trendPoints.Count)
                    {
                        endReached = false;
                        DateTime pointTimestamp = trendPoints[trendPos].Timestamp;

                        if (minTimestamp > pointTimestamp)
                        {
                            minTimestamp = pointTimestamp;
                        }
                    }
                }

                if (endReached)
                {
                    break;
                }

                // copy data with found timestamp
                trendBundle.Timestamps.Add(minTimestamp);

                for (int i = 0; i < cnlCnt; i++)
                {
                    Trend   trend    = trends[i];
                    int     trendPos = trendPositions[i];
                    CnlData cnlData  = CnlData.Empty;

                    if (trendPos < trend.Points.Count)
                    {
                        TrendPoint trendPoint = trend.Points[trendPos];

                        if ((trendPoint.Timestamp - minTimestamp).TotalMilliseconds < TimeDiscreteness)
                        {
                            cnlData = new CnlData(trendPoint.Val, trendPoint.Stat);
                            trendPositions[i]++;
                        }
                    }

                    trendBundle.Trends[i].Add(cnlData);
                }
            }

            return(trendBundle);
        }