Exemple #1
0
        /// <summary>
        /// Will only merge the two if they have same RelayID and same Timestamp.
        /// Mergning is done based on the list, not raw data.
        /// </summary>
        /// <param name="mergeWith"></param>
        /// <returns></returns>
        public static RelayHistory Merge(RelayHistory slice1, RelayHistory slice2)
        {
            if (slice1.RelayID != slice2.RelayID)
            {
                throw new Exception("Attempted to merge RelayHistory slices with different ID's! "
                                    + slice1.RelayID + " and " + slice2.RelayID);
            }
            if (slice1.LocationID != slice2.LocationID)
            {
                throw new Exception("Attempted to merge RelayHistory from different Locations!! "
                                    + slice1.LocationID + " and " + slice2.LocationID);
            }
            if ((slice1.TimeStamp - slice2.TimeStamp).TotalHours > 24 ||
                (slice2.TimeStamp - slice1.TimeStamp).TotalHours > 24)
            {
                throw new Exception("Attempted to merge RelayHistory from different days! "
                                    + slice1.TimeStamp + " and " + slice2.TimeStamp);
            }

            RelayHistory result = new RelayHistory
            {
                RelayID    = slice1.RelayID,
                Relay      = slice1.Relay,
                TimeStamp  = slice1.TimeStamp,
                LocationID = slice1.LocationID,
                Location   = slice1.Location,
                Data       = new List <RelayDatapoint>()
            };

            List <RelayDatapoint> tempList = new List <RelayDatapoint>(slice1.Data);

            tempList.AddRange(slice2.Data);

            tempList.Sort((a, b) => a.TimeStamp.CompareTo(b.TimeStamp));

            for (int i = 0; i < tempList.Count; i++)
            {
                if (i >= (tempList.Count - 1))
                {
                    result.Data.Add(tempList[i]);
                }
                else if (tempList[i].TimeStamp != tempList[i + 1].TimeStamp)
                {
                    result.Data.Add(tempList[i]);
                }
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Creates a new controlHistory object that contains only data past a certain point.
        /// This is done based on the list, not Raw data. If the list is empty, you will get nothing!
        /// </summary>
        /// <param name="slicePoint">Time, before which data is not included</param>
        /// <returns></returns>
        public RelayHistory Slice(DateTimeOffset slicePoint)
        {
            RelayHistory result = new RelayHistory
            {
                Relay      = this.Relay,
                RelayID    = this.RelayID,
                TimeStamp  = this.TimeStamp,
                LocationID = this.LocationID,
                Location   = this.Location,
                Data       = new List <RelayDatapoint>()
            };

            foreach (RelayDatapoint item in Data)
            {
                if (item.TimeStamp > slicePoint)
                {
                    result.Data.Add(item);
                }
            }
            return(result);
        }