/// <summary> /// Process the FIFO time buffer /// </summary> public void FIFO_TimeBuffer() { //TODO: Update serie Min/Max/Avg stats on value removal //TODO: Raise an event on Min/Max values change for series conversion coords re-computing and Y axis values updates if (TimeBufferSize != -1) { if (DataSamplingMode == SamplingMode.MultipleRates) { foreach (GW_DataChannel oChan in Channels) { if (oChan.Samples.Count > 1) { SerieSample sLastSample = oChan.Samples[oChan.Samples.Count - 1]; while (sLastSample.SampleTime - oChan.Samples[0].SampleTime > TimeBufferSize) { oChan.Samples.RemoveAt(0); } } } } else { if (Time.Values.Count > 1) { double LastSampleTime = Time.Values[Time.Values.Count - 1]; while (LastSampleTime - Time.Values[0] > TimeBufferSize) { Time.Values.RemoveAt(0); foreach (GW_DataChannel oChan in Channels) { oChan.Values.RemoveAt(0); } } } } } }
/// <summary> /// Add a value into the channel values collection and update min, max and average values /// </summary> /// <param name="Value">Value to add into the values collection</param> public void Add_ChannelValue(object Value) { double DataValue = 0;; int ValCnt = 0; if (Value.GetType().Equals(typeof(double))) //Single sampling rate data file { DataValue = (double)Value; Values.Add(DataValue); ValCnt = Values.Count; } else if (Value.GetType().Equals(typeof(SerieSample))) //Multiple sampling rate data file { SerieSample sSample = (SerieSample)Value; if (Samples.Count == 0) //Data channel values list is empty yet { Samples.Add(sSample); } else //Data channel values list contains some samples already { if (Samples[Samples.Count - 1].SampleTime < sSample.SampleTime) //Is new sample time posterior to previous sample ? { Samples.Add(sSample); double SampleTime = sSample.SampleTime - Samples[Samples.Count - 2].SampleTime; if (Samples.Count == 2) { ChannelStepTimeMin = SampleTime; ChannelStepTimeMax = SampleTime; } else { if (SampleTime < ChannelStepTimeMin) { ChannelStepTimeMin = SampleTime; } if (SampleTime > ChannelStepTimeMax) { ChannelStepTimeMax = SampleTime; } } } else //No sample adding abort { return; } } DataValue = sSample.SampleValue; ValCnt = Samples.Count; } else { return; } //Serie statistics updating if (ValCnt > 1) { if (DataValue < Min) { Min = DataValue; ParentDataFile.CoordConversionUpdateRequested = true; } if (DataValue > Max) { Max = DataValue; ParentDataFile.CoordConversionUpdateRequested = true; } Avg = ((Avg * (ValCnt - 1)) + DataValue) / ValCnt; } else { Min = DataValue; Max = DataValue; Avg = DataValue; ParentDataFile.CoordConversionUpdateRequested = true; } }
/// <summary> /// Read a XML data file /// </summary> /// <param name="fPath">Path of the XML file to read</param> /// <param name="HeaderOnly">Read only data file header flag</param> /// <returns>Reading error flag: True = No Error / False = Error</returns> public bool Load_XmlDataFile(string fPath, bool HeaderOnly) { XmlNode xDataFile, xHeader, xChannels, xSamples; XmlNode xElemParent, xElemChild; this.DataSamplingMode = SamplingMode.MultipleRates; try { XmlDocument oXDoc = new XmlDocument(); oXDoc.Load(fPath); xDataFile = oXDoc.SelectSingleNode("XmlGraphDataFile"); #region XML Data file header //Header reading xHeader = xDataFile.SelectSingleNode("DataFileHeader"); //Data file start time xElemChild = xHeader.SelectSingleNode("DataStartTime"); this.DataStartTime = DateTime.FromBinary(long.Parse(xElemChild.InnerText)); //User comment xElemChild = xHeader.SelectSingleNode("DataUserComment"); this.UserComment = xElemChild.InnerText; //Data file user properties xElemParent = xHeader.SelectSingleNode("DataCustomProperties"); foreach (XmlNode xProp in xElemParent.ChildNodes) { GW_XmlDataFileCustomProperty oProp = new GW_XmlDataFileCustomProperty(); oProp.Name = xProp.Attributes["CustomPropertyName"].Value; string PropType = xProp.Attributes["CustomPropertyType"].Value; oProp.ParsePropertyStringValue(xProp.InnerText, PropType); this.XmlDataFileCustomProperties.Add(oProp); } #endregion #region XML Data files channels //Data reading if (!HeaderOnly) { xChannels = xDataFile.SelectSingleNode("DataFileChannels"); foreach (XmlNode xChan in xChannels.ChildNodes) { GW_DataChannel oChan = new GW_DataChannel(SamplingMode.MultipleRates); //Read channel properties oChan.KeyId = int.Parse(xChan.Attributes["ChanId"].Value); xElemChild = xChan.SelectSingleNode("ChannelName"); oChan.Name = xElemChild.InnerText; xElemChild = xChan.SelectSingleNode("ChannelDescription"); oChan.Description = xElemChild.InnerText; xElemChild = xChan.SelectSingleNode("ChannelUnit"); oChan.Unit = xElemChild.InnerText; xElemChild = xChan.SelectSingleNode("ValueFormat"); oChan.GraphicFormat.SetSerieValueFormatFromXmlNode(xElemChild); xElemParent = xChan.SelectSingleNode("ChannelReferenceLines"); if (!(xElemParent == null)) { foreach (XmlNode xRefLine in xElemParent.ChildNodes) { GraphReferenceLine oLine = new GraphReferenceLine(); if (oLine.Read_GraphLineXmlNode(xRefLine)) { oChan.ChannelReferenceLines.Add(oLine); } } } //Read channel samples xSamples = xChan.SelectSingleNode("ChannelSamples"); foreach (XmlNode xSerieSample in xSamples.ChildNodes) { SerieSample sSample = new SerieSample(); sSample.SampleTime = double.Parse(xSerieSample.Attributes["ST"].Value); sSample.SampleValue = double.Parse(xSerieSample.InnerText); oChan.Samples.Add(sSample); if (oChan.Samples.Count == 1) { oChan.Min = sSample.SampleValue; oChan.Max = sSample.SampleValue; } else { if (sSample.SampleValue < oChan.Min) { oChan.Min = sSample.SampleValue; } if (sSample.SampleValue > oChan.Max) { oChan.Max = sSample.SampleValue; } } } this.Channels.Add(oChan); } } #endregion } catch { return(false); } return(true); }