/// <summary> /// Two qualifieres are equal if they have the same qualifier code. /// </summary> public override bool Equals(object obj) { Qualifier other = obj as Qualifier; if (other == null) { return(base.Equals(obj)); } return(Code.Equals(other.Code)); }
/// <summary> /// Creates a new composite qualifier. This is a qualifier with multiple codes /// for example 'p, ice'. This is used to simplify access to the database in /// cases when one data value can have only one qualifier. /// </summary> /// <param name="qualifiers">The list of multiple qualifiers</param> /// <returns>The new composite qualifier</returns> public static Qualifier CreateCompositeQualifier(IList<Qualifier> qualifiers) { string newDescription = ""; string newCode = ""; foreach (Qualifier qual in qualifiers) { newDescription += qual.Description + ", "; newCode += qual.Code + ", "; } newDescription = newDescription.Remove(newDescription.LastIndexOf(",")); newCode = newCode.Remove(newCode.LastIndexOf(",")); Qualifier newQualifier = new Qualifier(); newQualifier.Code = newCode; newQualifier.Description = newDescription; return newQualifier; }
/// <summary> /// Creates a new composite qualifier. This is a qualifier with multiple codes /// for example 'p, ice'. This is used to simplify access to the database in /// cases when one data value can have only one qualifier. /// </summary> /// <param name="qualifiers">The list of multiple qualifiers</param> /// <returns>The new composite qualifier</returns> public static Qualifier CreateCompositeQualifier(IList <Qualifier> qualifiers) { string newDescription = ""; string newCode = ""; foreach (Qualifier qual in qualifiers) { newDescription += qual.Description + ", "; newCode += qual.Code + ", "; } newDescription = newDescription.Remove(newDescription.LastIndexOf(",")); newCode = newCode.Remove(newCode.LastIndexOf(",")); Qualifier newQualifier = new Qualifier(); newQualifier.Code = newCode; newQualifier.Description = newDescription; return(newQualifier); }
/// <summary> /// If the qualifier is a composite qualifier, split it into a list of /// simple qualifiers /// </summary> /// <returns>The collection of simple qualifiers</returns> public virtual IList <Qualifier> GetSimpleQualifiers() { var resultList = new List <Qualifier>(); if (IsCompositeQualifier == false) { resultList.Add(this); } else { var separators = new string[] { "," }; var codes = Code.Split(separators, StringSplitOptions.RemoveEmptyEntries); var descriptions = Description.Split(separators, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < codes.Length; i++) { var newQual = new Qualifier(); newQual.Code = codes[i].Trim(); newQual.Description = descriptions[i].Trim(); resultList.Add(newQual); } } return(resultList); }
/// <summary> /// If the qualifier is a composite qualifier, split it into a list of /// simple qualifiers /// </summary> /// <returns>The collection of simple qualifiers</returns> public virtual IList<Qualifier> GetSimpleQualifiers() { var resultList = new List<Qualifier>(); if (IsCompositeQualifier == false) { resultList.Add(this); } else { var separators = new string[] {","}; var codes = Code.Split(separators,StringSplitOptions.RemoveEmptyEntries); var descriptions = Description.Split(separators, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < codes.Length; i++) { var newQual = new Qualifier(); newQual.Code = codes[i].Trim(); newQual.Description = descriptions[i].Trim(); resultList.Add(newQual); } } return resultList; }
/// <summary> /// Adds a data value to the end of this series /// </summary> /// <param name="time">the local observation time of the data value</param> /// <param name="value">the observed value</param> /// <param name="utcOffset">the difference between UTC and local time</param> /// <param name="qualifier">the qualifier (contains information about specific /// observation conditions</param> /// <returns>the DataValue object</returns> public virtual DataValue AddDataValue(DateTime time, double value, double utcOffset, Qualifier qualifier) { DataValue val = new DataValue(value, time, utcOffset); val.Qualifier = qualifier; DataValueList.Add(val); val.Series = this; UpdateSeriesInfoFromDataValues(); return(val); }
/// <summary> /// Adds a data value to the end of this series /// </summary> /// <param name="time">the local observation time of the data value</param> /// <param name="value">the observed value</param> /// <param name="utcOffset">the difference between UTC and local time</param> /// <param name="qualifier">the qualifier (contains information about specific /// observation conditions</param> /// <returns>the DataValue object</returns> public virtual void AddDataValue(DateTime time, double value, double utcOffset, Qualifier qualifier) { var val = new DataValue(value, time, utcOffset) { Qualifier = qualifier }; AddDataValue(val); }
/// <summary> /// Reads information about a qualifier /// </summary> private static void ReadQualifier(XmlReader r, IDictionary<string, Qualifier> qualifiers) { string qualifierCode = r.GetAttribute("qualifierCode"); if (String.IsNullOrEmpty(qualifierCode)) return; if (!qualifiers.ContainsKey(qualifierCode)) { var newQualifier = new Qualifier {Code = qualifierCode}; qualifiers.Add(qualifierCode, newQualifier); } var qualifier = qualifiers[qualifierCode]; r.Read(); qualifier.Description = r.Value; }
/// <summary> /// Reads the DataValues section /// </summary> protected override IList<Series> ReadDataValues(XmlReader r) { int valueCount; var lst = new List<DataValueWrapper>(Int32.TryParse(r.GetAttribute("count"), out valueCount) ? valueCount : 4); var qualifiers = new Dictionary<string, Qualifier>(); var methods = new Dictionary<string, Method>(); var sources = new Dictionary<string, Source>(); var qualityControlLevels = new Dictionary<string, QualityControlLevel>(); var samples = new Dictionary<string,Sample>(); var offsets = new Dictionary<string, OffsetType>(); var seriesDictionary = new Dictionary<string, Series>(); while (r.Read()) { if (r.NodeType == XmlNodeType.Element) { if (r.Name == "value") { //create a new empty data value and add it to the list var wrapper = new DataValueWrapper(); var val = new DataValue(); wrapper.DataValue = val; lst.Add(wrapper); if (r.HasAttributes) { var censorCode = r.GetAttribute("censorCode"); if (!string.IsNullOrEmpty(censorCode)) { val.CensorCode = censorCode; } //fix by Jiri - sometimes the dateTime attribute is uppercase var localDateTime = r.GetAttribute("dateTime"); if (string.IsNullOrEmpty(localDateTime)) { localDateTime = r.GetAttribute("DateTime"); } val.LocalDateTime = Convert.ToDateTime(localDateTime, CultureInfo.InvariantCulture); val.DateTimeUTC = val.LocalDateTime; val.UTCOffset = 0.0; //method var methodID = r.GetAttribute("methodID"); if (String.IsNullOrEmpty(methodID)) { methodID = "0"; //when a method ID is unspecified } if (!methods.ContainsKey(methodID)) { var newMethod = Method.Unknown; methods.Add(methodID, newMethod); } wrapper.MethodID = methodID; //quality control level string qualityCode = r.GetAttribute("qualityControlLevel"); if (String.IsNullOrEmpty(qualityCode)) { qualityCode = "unknown"; //when the quality control level is unspecified } if (!qualityControlLevels.ContainsKey(qualityCode)) { var qualControl = QualityControlLevel.Unknown; qualControl.Code = qualityCode; qualControl.Definition = qualityCode; qualControl.Explanation = qualityCode; qualityControlLevels.Add(qualityCode, qualControl); } //source var sourceID = r.GetAttribute("sourceID"); if (String.IsNullOrEmpty(sourceID)) { sourceID = "0"; //when a source ID is unspecified } if (!sources.ContainsKey(sourceID)) { sources.Add(sourceID, Source.Unknown); } wrapper.SourceID = sourceID; wrapper.SeriesCode = SeriesCodeHelper.CreateSeriesCode(methodID, qualityCode, sourceID); //----method-source-qualityControl combination---- //sample var sampleID = r.GetAttribute("sampleID"); if (!String.IsNullOrEmpty(sampleID)) { if (!samples.ContainsKey(sampleID)) { samples.Add(sampleID, Sample.Unknown); } } wrapper.SampleID = sampleID; //qualifiers string qualifierCodes = r.GetAttribute("qualifiers"); if (!String.IsNullOrEmpty(qualifierCodes)) { if (!qualifiers.ContainsKey(qualifierCodes)) { var newQualifier = new Qualifier {Code = qualifierCodes}; qualifiers.Add(qualifierCodes, newQualifier); val.Qualifier = newQualifier; } else { val.Qualifier = qualifiers[qualifierCodes]; } } //vertical offset var offsetID = r.GetAttribute("offsetTypeID"); if (!String.IsNullOrEmpty(offsetID)) { if (!offsets.ContainsKey(offsetID)) { offsets.Add(offsetID, new OffsetType()); } var offsetValue = r.GetAttribute("offsetValue"); if (!String.IsNullOrEmpty(offsetValue)) { val.OffsetValue = Convert.ToDouble(offsetValue, CultureInfo.InvariantCulture); } } wrapper.OffsetID = offsetID; //data value val.Value = Convert.ToDouble(r.ReadString(), CultureInfo.InvariantCulture); } } else if (r.Name == "method") { var method = ReadMethod(r); var methodCodeKey = method.Code.ToString(CultureInfo.InvariantCulture); if (methods.ContainsKey(methodCodeKey)) { methods[methodCodeKey] = method; } } else if (r.Name == "source") { var source = ReadSource(r); var sourceCodeKey = source.OriginId.ToString(CultureInfo.InvariantCulture); if (sources.ContainsKey(sourceCodeKey)) { sources[sourceCodeKey] = source; } } else if (r.Name == "qualityControlLevel") { //quality control level seems to be included with each value } else if (r.Name == "qualifier") { ReadQualifier(r, qualifiers); } else if (r.Name == "offset") { ReadOffset(r, offsets); } } } //to assign special properties of each data value foreach (var wrapper in lst) { var val = wrapper.DataValue; //which series does the data value belong to? var seriesCode = wrapper.SeriesCode; if (!seriesDictionary.ContainsKey(seriesCode)) { var newSeries = new Series(); seriesDictionary.Add(seriesCode, newSeries); //assign method, source and qual.control level //assign method, source and qual.control level try { newSeries.Method = methods[SeriesCodeHelper.GetMethodCode(seriesCode)]; //fix by Jiri: fixes the case when sourceID is unspecified sources //has more than one source entry string sourceCode = SeriesCodeHelper.GetSourceCode(seriesCode); if (sourceCode == "0" && sources.Count > 0) { foreach (string sc in sources.Keys) { if (sc != "0") { sourceCode = sc; break; } } } newSeries.Source = sources[sourceCode]; newSeries.QualityControlLevel = qualityControlLevels[SeriesCodeHelper.GetQualityCode(seriesCode)]; } catch { } } //add the data value to the correct series var series = seriesDictionary[seriesCode]; series.DataValueList.Add(val); val.Series = series; Sample sample; if (!string.IsNullOrEmpty(wrapper.SampleID) && samples.TryGetValue(wrapper.SampleID, out sample)) { val.Sample = sample; } OffsetType offset; if (!string.IsNullOrEmpty(wrapper.OffsetID) && offsets.TryGetValue(wrapper.OffsetID, out offset)) { val.OffsetType = offset; } if (series.Method == null) { series.Method = methods[wrapper.MethodID]; } if (series.Source == null) { series.Source = sources[wrapper.SourceID]; } } //to check the qualifiers CheckQualifiers(qualifiers); return seriesDictionary.Values.ToList(); }
/// <summary> /// Adds a data value to the end of this series /// </summary> /// <param name="time">the local observation time of the data value</param> /// <param name="value">the observed value</param> /// <param name="utcOffset">the difference between UTC and local time</param> /// <param name="qualifier">the qualifier (contains information about specific /// observation conditions</param> /// <returns>the DataValue object</returns> public virtual void AddDataValue(DateTime time, double value, double utcOffset, Qualifier qualifier) { var val = new DataValue(value, time, utcOffset) {Qualifier = qualifier}; AddDataValue(val); }