/// <summary> /// Update `BeginningTime` accroding to `RecurringFrequency`. /// </summary> /// <returns>Boolean value indicating whether `BeginningTime` is up to date or not.</returns> public virtual bool UpdateBeginningTime() { if (RecurringFrequency == RecurringFrequencies.None) { return(false); } if (BeginningTime > DateTime.Now) { return(true); // BeginningTime is up-to-date. } // assume that `dt` is today, check whether it has been expired or not. (if it is expired: starts from next day) DateTime beginningDateTime = BeginningTime.AddDays((DateTime.Today.Date - BeginningTime.Date).Days); // Compare time part of the day only DayOfWeek targetWeekday = (BeginningTime.TimeOfDay <= DateTime.Now.TimeOfDay) ? DateTime.Now.DayOfWeek + 1 : DateTime.Now.DayOfWeek; Weekday nextRecurringWeekday = Utils.GetNextRecurringWeekday(targetWeekday, RecurringFrequency); if (nextRecurringWeekday.ToSystemWeekday() == DateTime.Today.DayOfWeek) { BeginningTime = DateTime.Today.Date.Add(BeginningTime.TimeOfDay); } else { BeginningTime = Utils.DateTimeOfNextWeekday(beginningDateTime, nextRecurringWeekday.ToSystemWeekday()); } return(true); }
public void Trim() { if (Points.Count > PointsMaximum) { List <OratorDataPoint> resultList = new List <OratorDataPoint>(); double minTime = 0.0; if (BeginningTime != DateTime.MinValue) { minTime = BeginningTime.ToOADate(); } else { minTime = Points[0].X; } double maxTime = 0.0; if (EndTime != DateTime.MinValue) { maxTime = EndTime.ToOADate(); } else { maxTime = Points[Points.Count - 1].X; } double timeInterval = (maxTime - minTime) / PointsMaximum; double peakValue = 0; double peakValueTime = 0; double troughValue = Points[0].Y1; double troughValueTime = Points[0].X; double timePeriod = minTime + timeInterval; double runningTotal = 0.0; int pointCount = 0; DateTime startTime = DateTime.FromOADate(minTime); DateTime endTime = DateTime.FromOADate(maxTime); //switch (DataPointCombiningMode) //{ // case CombiningModeOptions.TroughAndPeak: // foreach (OratorDataPoint dataPoint in Points) // { // if (dataPoint.Y1 >= peakValue) // { // peakValue = dataPoint.Y1; // peakValueTime = dataPoint.X; // } // else if (dataPoint.Y1 <= troughValue) // { // troughValue = dataPoint.Y1; // troughValueTime = dataPoint.X; // } // if (dataPoint.X >= timePeriod) // { // if (troughValueTime < peakValueTime) // { // resultList.Add(new OratorDataPoint(troughValueTime, troughValue)); // resultList.Add(new OratorDataPoint(peakValueTime, peakValue)); // } // else // { // resultList.Add(new OratorDataPoint(peakValueTime, peakValue)); // resultList.Add(new OratorDataPoint(troughValueTime, troughValue)); // } // peakValue = 0; // troughValue = dataPoint.Y1; // troughValueTime = dataPoint.X; // timePeriod += timeInterval; // } // } // //Last point // if (troughValueTime < peakValueTime) // { // resultList.Add(new OratorDataPoint(troughValueTime, troughValue)); // resultList.Add(new OratorDataPoint(peakValueTime, peakValue)); // } // else // { // resultList.Add(new OratorDataPoint(peakValueTime, peakValue)); // resultList.Add(new OratorDataPoint(troughValueTime, troughValue)); // } // break; // case CombiningModeOptions.Average: // foreach (OratorDataPoint dataPoint in Points) // { // pointCount++; // runningTotal += dataPoint.Y1; // if (dataPoint.X >= timePeriod) // { // double timeStamp = timePeriod - (timeInterval / 2); // resultList.Add(new OratorDataPoint(timeStamp, runningTotal / (double)pointCount)); // pointCount = 0; // runningTotal = 0.0; // timePeriod += timeInterval; // } // } // break; //} //foreach (OratorDataPoint dataPoint in Points) //{ // switch (DataPointCombiningMode) // { // case CombiningModeOptions.TroughAndPeak: // if (dataPoint.Y1 >= peakValue) // { // peakValue = dataPoint.Y1; // peakValueTime = dataPoint.X; // } // else if (dataPoint.Y1 <= troughValue) // { // troughValue = dataPoint.Y1; // troughValueTime = dataPoint.X; // } // if (dataPoint.X >= timePeriod) // { // if (troughValueTime < peakValueTime) // { // resultList.Add(new OratorDataPoint(troughValueTime, troughValue)); // resultList.Add(new OratorDataPoint(peakValueTime, peakValue)); // } // else // { // resultList.Add(new OratorDataPoint(peakValueTime, peakValue)); // resultList.Add(new OratorDataPoint(troughValueTime, troughValue)); // } // peakValue = 0; // troughValue = dataPoint.Y1; // troughValueTime = dataPoint.X; // timePeriod += timeInterval; // } // break; // case CombiningModeOptions.Average: // pointCount++; // runningTotal += dataPoint.Y1; // if (dataPoint.X >= timePeriod) // { // double timeStamp = timePeriod - (timeInterval / 2); // resultList.Add(new OratorDataPoint(timeStamp, runningTotal / (double)pointCount)); // pointCount = 0; // runningTotal = 0.0; // timePeriod += timeInterval; // } // break; // } //} #region fix the Bug70964 by Zhao xingman switch (DataPointCombiningMode) { case CombiningModeOptions.TroughAndPeak: foreach (OratorDataPoint dataPoint in Points) { if (dataPoint.Y1 >= peakValue) { peakValue = dataPoint.Y1; peakValueTime = dataPoint.X; } else if (dataPoint.Y1 <= troughValue) { troughValue = dataPoint.Y1; troughValueTime = dataPoint.X; } if (dataPoint.X >= timePeriod) { if (troughValueTime < peakValueTime) { resultList.Add(new OratorDataPoint(troughValueTime, troughValue)); resultList.Add(new OratorDataPoint(peakValueTime, peakValue)); } else { resultList.Add(new OratorDataPoint(peakValueTime, peakValue)); resultList.Add(new OratorDataPoint(troughValueTime, troughValue)); } peakValue = 0; troughValue = dataPoint.Y1; troughValueTime = dataPoint.X; timePeriod += timeInterval; } } break; case CombiningModeOptions.Average: int pointIndex = 0; int pointNumber = 1; while (pointNumber <= PointsMaximum) { timePeriod = minTime + timeInterval * pointNumber; pointCount = 0; runningTotal = 0.0; for (int i = pointIndex; i < Points.Count; i++) { OratorDataPoint dataPoint = Points[i]; if (dataPoint.X <= timePeriod) { pointCount++; runningTotal += dataPoint.Y1; } else { double timeStamp = timePeriod - (timeInterval / 2); double y1 = 0; if (pointCount > 0) { y1 = runningTotal / (double)pointCount; } resultList.Add(new OratorDataPoint(timeStamp, y1)); pointIndex = i; break; } } if (pointIndex >= Points.Count) { double timeStamp = timePeriod - (timeInterval / 2); resultList.Add(new OratorDataPoint(timeStamp, 0d)); } pointNumber++; } break; } #endregion Points = resultList; } }