/// <summary> /// Constructor. /// </summary> /// <param name="dt">Timestamp. This must be in UTC.</param> /// <param name="v">Value.</param> /// <param name="dq">Data quality.</param> /// <exception cref="XNeut.DateTimeException">Thrown if <paramref name="dt"/> kind is not UTC.</exception> internal TimeSeriesFlexItem(DateTime dt, double v, DataQuality dq) { XNeut.Helper.ExpectDateTimeIsUtc(dt); // throws DateTimeException Timestamp = dt; Value = v; DataQualityObj = dq; }
private void SetDefaults() { // For the sake of consistency, all defaults are now set here. Description = null; Name = null; PhenomenonTime = DateTime.Now.ToUniversalTime(); ResultTime = PhenomenonTime; Procedure = ""; ObservedProperty = ""; FeatureOfInterest = ""; ResultQuality = DataQuality.CreateGood(); Result = null; }
/// <summary> /// Sets a field. /// </summary> /// <param name="n">Name.</param> /// <param name="i">Item.</param> /// <param name="dq">Data quality.</param> /// <exception cref="ArgumentException">Thrown if the item already exists.</exception> /// <exception cref="XNeut.InvalidMessageException">Thrown if the item does not support data quality information in a data record.</exception> public void Add(string n, Item i, DataQuality dq) { if (m_recItems.ContainsKey(n)) { throw new ArgumentException("Duplicate item name \"" + n + "\"", "n"); } // Data quality supported? if (!i.SupportsDataQualityInDataRecord) { throw new XNeut.InvalidMessageException("\"" + n + "\": the item type does not support data quality in data records"); } // Add item and set its quality m_recItems.Add(n, new DataRecordItem(n, i, dq)); }
/// <summary> /// Adds a value to the time series. The timestamp of the item must be after the timestamp of earlier added values. /// </summary> /// <param name="time">Timestamp. This must be in UTC.</param> /// <param name="value">Measurement value.</param> /// <param name="dq">Data quality information.</param> /// <exception cref="ArgumentException">Thrown if the timestamp is before the timestamp of an already existing value.</exception> /// <exception cref="XNeut.DateTimeException">Thrown if <paramref name="time"/> is not in UTC.</exception> public void Add(DateTime time, double value, DataQuality dq) { var newItem = new TimeSeriesFlexItem(time, value, dq); // throws DateTimeException // Checking in case of incorrect item ordering if (m_items.Count > 0) { DateTime previous = m_items[m_items.Count - 1].Timestamp; if (DateTime.Compare(previous, newItem.Timestamp) > 0) { throw new ArgumentException("Time series items must be added in the time order"); } } m_items.Add(newItem); }
/// <summary> /// Constructor. /// </summary> /// <param name="v">Value.</param> /// <param name="dq">Data quality.</param> internal TimeSeriesConstItem(double v, DataQuality dq) { Value = v; DataQualityObj = dq; }
/// <summary> /// Adds an item to the time series. /// </summary> /// <param name="value">Measurement value.</param> public void Add(double value) { Add(value, DataQuality.CreateGood()); }
/// <summary> /// Adds an item to the time series. /// </summary> /// <param name="value">Measurement value.</param> /// <param name="dq">Data quality information.</param> public void Add(double value, DataQuality dq) { m_items.Add(new TimeSeriesConstItem(value, dq)); }
private void ReadFieldValuesFromXmlDoc(XsdNs.OM_ObservationType observationRaw) { try { // Getting observation type Uri var typeUri = GetTypeUri(observationRaw); // Name specified? var nameList = observationRaw.name; Name = (nameList != null && nameList.Length > 0) ? nameList[0].Value : null; // Description Description = (observationRaw.description != null && observationRaw.description.Value != null) ? observationRaw.description.Value : null; // Phenomenon time; this is a required field PhenomenonTime = new Item_TimeInstant(observationRaw.PhenomenonTime).Value; // Result time; this is a required field ResultTime = new Item_TimeInstant(observationRaw.resultTime).Value; // These fields are required per the schema, but this processing enables non-specified values Procedure = (observationRaw.procedure != null && observationRaw.procedure.Title != null) ? observationRaw.procedure.Title : null; ObservedProperty = (observationRaw.observedProperty != null && observationRaw.observedProperty.Title != null) ? observationRaw.observedProperty.Title : null; ReadFeatureOfInterest(observationRaw); // Explicit result quality defined? if (observationRaw.resultQuality != null && observationRaw.resultQuality.Length > 0) { var qualityStringRaw = observationRaw.resultQuality[0].Title; ResultQuality = new DataQuality(qualityStringRaw); } else { ResultQuality = DataQuality.CreateGood(); } // Processing result information Result = ResultTypeManager.BuildResultFromXml(typeUri, observationRaw.result); } // If the document lacks required data: catch (ArgumentNullException e) { throw new XNeut.InvalidMessageException(ErrorMsgPopulation + " (required data missing?)", e); } catch (NullReferenceException e) { throw new XNeut.InvalidMessageException(ErrorMsgPopulation + " (required data missing?)", e); } // new DataQuality: catch (ArgumentException e) { throw new XNeut.InvalidMessageException(ErrorMsgPopulation, e); } // ResultTypeManager.buildResultFromXml: catch (NotSupportedException e) { throw new XNeut.InvalidMessageException(ErrorMsgPopulation + " (XML typing error?)", e); } catch (InvalidCastException e) { throw new XNeut.InvalidMessageException(ErrorMsgPopulation + " (XML typing error?)", e); } }
/// <summary> /// Adds a value to the time series. The timestamp of the item must be after the timestamp of earlier added values. /// The related data quality is assumed to be "good". /// </summary> /// <param name="time">Timestamp. This must be in UTC.</param> /// <param name="value">Measurement value.</param> /// <exception cref="ArgumentException">Thrown if the timestamp is before the timestamp of an already existing value.</exception> /// <exception cref="XNeut.DateTimeException">Thrown if <paramref name="time"/> is not in UTC.</exception> public void Add(DateTime time, double value) { // throws ArgumentException // throws DateTimeException Add(time, value, DataQuality.CreateGood()); }
/// <summary> /// Constructor. /// </summary> /// <param name="n">Name.</param> /// <param name="i">Item.</param> /// <param name="dq">Data quality value.</param> internal DataRecordItem(string n, Item i, DataQuality dq) { Name = n; ItemObj = i; DataQualityObj = dq; }
/// <summary> /// Constructor. /// </summary> /// <param name="n">Name.</param> /// <param name="i">Item.</param> internal DataRecordItem(string n, Item i) { Name = n; ItemObj = i; DataQualityObj = DataQuality.CreateGood(); }
private void ProcessOneField(XsdNs.DataRecordTypeField field) { string fieldName = field.name; var fieldObj = field.dataComponent; Item itemRead = null; DataQuality dataQuality = null; var simpleComponent = true; try { if (fieldObj is XsdNs.AbstractSimpleComponentType) { // Simple component (as of SWE schemata) simpleComponent = true; itemRead = ReadSimpleData(field); } else { // Complex component simpleComponent = false; switch (field.dataComponentTypeInfo) { case XsdNs.DataRecordFieldTypeType.DataRecord: var dataRec = (XsdNs.DataRecordType)fieldObj; itemRead = new Item_DataRecord(dataRec); break; case XsdNs.DataRecordFieldTypeType.AbstractGmlAsSweDataComponent: itemRead = ProcessTimeSeriesField((XsdNs.AbstractGmlAsSweDataComponentType)fieldObj); break; case XsdNs.DataRecordFieldTypeType.DataArray: itemRead = new Item_Array((XsdNs.DataArrayType)fieldObj); break; default: // For robustness, just skip unknown field types itemRead = null; break; } } } // Datetime values catch (FormatException e) { throw new XNeut.InvalidMessageException("Data record field is invalid: " + fieldName, e); } // Other errors catch (XNeut.InvalidMessageException e) { throw new XNeut.InvalidMessageException("Data record field is invalid: " + fieldName, e); } if (itemRead == null) { // Unknown field type -> skip for robustness return; } if (simpleComponent) { // Getting data quality var simpleComp = (XsdNs.AbstractSimpleComponentType)fieldObj; if (simpleComp.quality != null && simpleComp.quality.Length > 0) { var qualityProp = simpleComp.quality[0]; dataQuality = new DataQuality(qualityProp.Title); } } if (dataQuality == null) { Add(fieldName, itemRead); } else { Add(fieldName, itemRead, dataQuality); } }