public Read GetReadFromGraphTime(double pGraphTime) { double min = 9999, difference; double otherGraphTime; Read minRead = null; foreach (Read read in _DataReads) { otherGraphTime = InterruptionCycle.GetGraphTime(GraphStart, read.UTCTime, mNumCycles); difference = Math.Abs(otherGraphTime - pGraphTime); if (difference < min) { minRead = read; min = difference; } } return(minRead); }
public void CreateGraphReads() { if (!mIsMidCycleStartAllowed) { GraphStart = InterruptionCycle.GetNextCycleStart(_DataReads[0].UTCTime); } else { GraphStart = _DataReads[0].UTCTime; } GraphEnd = GraphStart.AddSeconds(InterruptionCycle.Length.TotalSeconds * mNumCycles); int setPosition; DateTime time, lastAdded = new DateTime(); double readValue; bool hasReachedEnd = false; bool repeatToFill = false; TimeSpan offset = new TimeSpan(); do { for (int i = 0; i < _DataReads.Count; ++i) { time = _DataReads[i].UTCTime.Add(offset); readValue = _DataReads[i].Value; if (time >= GraphStart && time <= GraphEnd && time > lastAdded) { setPosition = InterruptionCycle.GetSetPosition(time); mGraphReads[setPosition].Add(new GraphRead(readValue, InterruptionCycle.GetGraphTime(GraphStart, time, mNumCycles))); lastAdded = time; } if (time > GraphEnd) { hasReachedEnd = true; } } offset = offset.Add(InterruptionCycle.Length); } while (!hasReachedEnd && repeatToFill); }