// returns string containting MeasValues from measMsgToBeFormatted as defined by the sample measTemplate public static string FormatMeasMsg(MeasMsg measMsgToBeFormatted, MeasMsg measTemplate, bool header, char dataDelimiter) { if ((measMsgToBeFormatted == null) || (measTemplate == null)) { return(string.Empty); } var sb = new StringBuilder(); // header if (header) { sb.Append(GetHeaderByMeasNames(measMsgToBeFormatted, dataDelimiter)); } // body foreach (var meas in measTemplate.MeasList) { // measTemplate.MeasList.ForEach(delegate(Meas meas) { Meas measToBeFormatted = new Meas(); if (measMsgToBeFormatted.GetMeasByName(meas.Name, ref measToBeFormatted)) { sb.Append(meas.ObsValue); } sb.Append(dataDelimiter); //}); } return(sb.ToString()); }
public bool GetMeasByName(string name, ref Meas meas) { try { Debug.Assert(!string.IsNullOrEmpty(name), "GetMeasByName, invalid argument"); if (string.IsNullOrEmpty(name)) { return(false); } var m1 = measList.Find(item => item.Name == name); if (m1.Name != null && m1.Name == name) { meas = m1; return(true); } //foreach (var m1 in measList) // if (m1.Name == name) // { // meas = m1; // return true; // } return(false); } catch (Exception ex) { ExceptionRecorder.RecordException("GetMeasByName " + ex.Message); return(false); } }
private static bool InitialiseFields(string sInput, out Meas meas) { meas = new Meas(); const int numberOfTabs = 10; const string delimStr = "\t"; char[] delimiter = delimStr.ToCharArray(); string[] fields = sInput.Split(delimiter); if (fields.GetUpperBound(0) != numberOfTabs) { return(false); } // station = fields[1]; // name = fields[4]; DateTime obsTime; if (!ParseDateTime(fields[7], out obsTime)) { return(false); } // obsValue = fields[8]; MeasStatus status = MeasStatus.cNOT_OK; if (string.Compare(fields[9], "0", false) == 0) { status = MeasStatus.c*K; } meas = new Meas(fields[4], obsTime, fields[8], status, fields[1]); return(true); }
public bool GetNumericObsValueByName(string name, out float obsValue) { obsValue = 0; Meas meas = new Meas(); if (!GetMeasByName(name, ref meas)) { return(false); } if (!meas.HasDoubleObsValue) { return(false); } obsValue = (float)meas.DoubleObsValue; return(true); //obsValue = 0; //string stringValue = string.Empty; //if (!GetMeasObsValueByName(name, out stringValue)) // return false; //float dValue = 0; //if (!StringUtil.TryParseFloat(stringValue, out dValue)) // return false; //obsValue = dValue; //return true; }
public bool GetNumericObsValueByName(string name, ref double obsValue) { Meas meas = new Meas(); if (!GetMeasByName(name, ref meas)) { return(false); } if (!meas.HasDoubleObsValue) { return(false); } obsValue = meas.DoubleObsValue; return(true); //string stringValue; //if (!GetMeasObsValueByName(name, out stringValue)) // return false; //double dValue; //if (!StringUtil.TryParseDouble(stringValue, out dValue)) // return false; //obsValue = dValue; //return true; }
public static string FormatMeasMsgWithDynCol(MeasMsg measMsg, bool header, char dataDelimiter) { if (measMsg.Count == 0) { return(string.Empty); } var sb = new StringBuilder(); if (header) { sb.Append(GetVaisalaHeader(measMsg, dataDelimiter, true)); } sb.Append((measMsg.MeasList[0]).ObsTime.ToString(DateTimeFormat, CultureInfo.InvariantCulture)); sb.Append(' '); var count = measMsg.MeasList.Count; for (var i = 0; i < count; i++) { Meas meas = measMsg.MeasList[i]; sb.Append(meas.ObsValue); if (i < measMsg.MeasList.Count - 1) { int numSpaces = GetNumberOfSpacesToAdd(meas); sb.Append(' ', numSpaces); } } sb.Append(Environment.NewLine); return(sb.ToString()); }
public bool Initialise(string sInput) { if (null == sInput) { return(false); } string sMeas = string.Empty; while (GetNextMeasString(ref sInput, ref sMeas)) { Meas meas = new Meas(); if (Meas.Initialise(sMeas, out meas)) { AddMeas(meas); } else { Debug.Assert(true, "Received string was incomplete: " + sMeas); } } if (channel == int.MinValue) { this.Channel = -1; } if (Count == 0) { return(false); } measList.Reverse(); return(true); //return (Count>0); }
public static MeasMsg RenameMeasurements(MeasMsg measMsg, Dictionary <string, string> replacementNames) { MeasMsg result = new MeasMsg(); result.Station = measMsg.Station; result.Time = measMsg.Time; foreach (var meas in measMsg.MeasList) { if (replacementNames.ContainsKey(meas.Name)) { string newName = replacementNames[meas.Name]; if (newName == "?") { newName = meas.Name + "?"; } Meas meas2 = new Meas(newName, meas.ObsTime, meas.ObsValue, meas.Status); result.AddMeas(meas2); } else { Meas meas2 = new Meas("****" + meas.Name, meas.ObsTime, meas.ObsValue, meas.Status); result.AddMeas(meas2); } } return(result); }
internal static bool InitialiseFromSmallString(DateTime dateTime, string station, string input, out Meas meas) { meas = new Meas(); const char separator1 = '|'; if (string.IsNullOrWhiteSpace(input)) { return(false); } if (input.IndexOf(separator1) == -1) { return(false); } const int numberOfFields = 2; char[] delimiter = { separator1 }; string[] fields = input.Split(delimiter); if (fields.GetLength(0) != numberOfFields) { return(false); } string name = fields[0]; string dataValue = fields[1]; meas = new Meas(name, dateTime, dataValue, MeasStatus.c*K, station); return(true); }
public override bool Equals(object obj) { if (obj == null) { return(false); } //if (object.ReferenceEquals(this, obj)) return true; if (GetType() != obj.GetType()) { return(false); } Meas otherMeas = (Meas)obj; if (string.Compare(this.Name, otherMeas.Name, false) != 0) { return(false); } if (otherMeas.ObsTime != this.ObsTime) { return(false); } if (otherMeas.ObsValue != this.ObsValue) { return(false); } return(string.Compare(ToStdString(string.Empty), otherMeas.ToStdString(string.Empty), false) == 0); }
//private string StatusDesc {get {if (Status == MeasStatus.c*K) return "OK"; return "FAIL"; }} //public bool HasNumericObsValue(ref double dValue) { // return (SimpleConversions.IsNumericDataValue(obsValue, ref dValue)); } public int Compare(Meas otherMeas) { int tmp = string.Compare(this.Name, otherMeas.Name, false); if (tmp != 0) { return(tmp); } if (otherMeas.ObsTime < this.ObsTime) { return(1); } if (otherMeas.ObsTime > this.ObsTime) { return(-1); } tmp = string.Compare(this.ObsValue, otherMeas.ObsValue, false); if (tmp != 0) { return(tmp); } return(string.Compare( ToStdString(string.Empty), otherMeas.ToStdString(string.Empty), false )); }
public void UpdateMeas(int index, Meas meas) { if (Count > index) { UpdateMeasByIndex(index, meas); return; } UpdateMeas(meas); }
public void UpsertMeas(Meas meas) { if (!ContainsMeas(meas)) { AddMeas(meas); } else { UpdateMeas(meas); } }
public static string FormatMeasMsgInReverse(MeasMsg measMsg) { var sb = new StringBuilder(); for (var i = measMsg.Count - 1; i > -1; i--) { Meas m = measMsg.MeasList[i]; sb.Append(m.ToStdString(measMsg.Station)); } return(sb.ToString()); }
private static int GetNumberOfSpacesToAdd(Meas meas) { int lenObsValue = meas.ObsValue.Length; int lenName = Math.Max(meas.Name.Length, DynColumnMinLen); if (lenName > lenObsValue) { return(lenName - lenObsValue + 1); } return(0); }
public void UpdateMeas(Meas meas) { for (var i = 0; i < Count; i++) { if (UpdateMeasByIndex(i, meas)) { return; } } Debug.Assert(false, "UpdateMeas did not find the meas name in the meas list, name = " + meas.Name); }
public bool GetMeasObsValueByName(string name, out string obsValue) { obsValue = string.Empty; Meas m = new Meas(); if (GetMeasByName(name, ref m)) { obsValue = m.ObsValue; return(true); } return(false); }
public void SetStationInEachMeas(string stationName) { Station = stationName; var count = Count; for (var i = 0; i < count; i++) { Meas meas = measList[i]; MeasList[i] = new Meas(meas.Name, meas.ObsTime, meas.ObsValue, meas.Status, stationName); } }
public void UpdateMeas(string measName, string dataValue) { if (!ContainsMeas(measName)) { return; } Meas meas = measList.Find(m => m.Name == measName); meas = new Meas(meas, dataValue); UpdateMeas(meas); }
public void AddMeas(string measName, string measValue) { Debug.Assert(measName != null, "measName was null "); Debug.Assert(measValue != null, "measValue was null , name = " + measName); if (measValue == null) { measValue = string.Empty; } var meas = new Meas(measName, Time, measValue, MeasStatus.c*K, station); AddMeas(meas); }
public bool ContainsMeas(Meas meas) { Debug.Assert(meas.Name != null, "meas.Name was null "); for (var i = 0; i < Count; i++) { Meas curMeas = measList[i]; if (StringUtil.CompareIC(curMeas.Name, meas.Name, false)) { return(true); } } return(false); }
public bool InitialiseFromSmallString(string input) { if (string.IsNullOrWhiteSpace(input)) { return(false); } if (input.IndexOf(tab) == -1) { return(false); } char[] key = { tab }; var items = input.Split(key); var len = items.GetLength(0); if (len < 2) { return(false); } DateTime dateTime; if (!DateTimeEx.TryParseStandardFormat(items[1], out dateTime)) { return(false); } this.Station = items[0]; this.obsTime = dateTime; if (channel == int.MinValue) { this.Channel = -1; } for (int i = 2; i < len; i++) { if (string.IsNullOrWhiteSpace(items[i])) { continue; } Meas meas; if (Meas.InitialiseFromSmallString(dateTime, Station, items[i], out meas)) { this.AddMeas(meas); } } return(true); }
private bool UpdateMeasByIndex(int index, Meas meas) { Meas currentMeas = measList[index]; if (StringUtil.CompareIC(currentMeas.Name, meas.Name, false)) { currentMeas = new Meas(meas); //currentMeas.ObsValue = meas.ObsValue; //currentMeas.ObsTime = meas.ObsTime; //currentMeas.Station = meas.Station; //currentMeas.Status = meas.Status; measList[index] = currentMeas; return(true); } return(false); }
public void AddMeas(Meas meas) { if (obsTime == DateTime.MinValue) { obsTime = meas.ObsTime; } if (string.IsNullOrEmpty(Station) && !string.IsNullOrEmpty(meas.Station)) { Station = meas.Station; } else if (string.IsNullOrEmpty(meas.Station) && !string.IsNullOrEmpty(Station)) { meas = new Meas(meas.Name, meas.ObsTime, meas.ObsValue, meas.Status, Station); } measList.Add(meas); }
public bool ContainsMeas(string name) { if (string.IsNullOrEmpty(name)) { return(false); } for (var i = 0; i < Count; i++) { Meas curMeas = measList[i]; if (StringUtil.CompareIC(curMeas.Name, name, false)) { return(true); } } return(false); }
internal static bool Initialise(string sInput, out Meas meas) { meas = new Meas(); try { if (null == sInput) { return(false); } const string cMeas = "MEAS"; if (sInput.IndexOf(cMeas) != 0) { return(false); } return(InitialiseFields(sInput, out meas)); } catch (System.ArgumentNullException) { ExceptionRecorder.RecordException("Null argument in meas initialisation, string =" + sInput); return(false); } catch (System.ArgumentException) { Debug.Assert(false, "Check date format in meas " + sInput); ExceptionRecorder.RecordException("Argument exception in meas initialisation, string =" + sInput); return(false); } catch (System.FormatException) { ExceptionRecorder.RecordException("Format exception in meas initialisation, string =" + sInput); return(false); } catch (System.OverflowException) { ExceptionRecorder.RecordException("Overflow exception in meas initialisation, string =" + sInput); return(false); } }
public Meas(Meas meas, double newValue) : this(meas.Name, meas.obsTime, newValue.ToString(CultureInfo.InvariantCulture), meas.status, meas.station) { }
public Meas(Meas meas, string newValue) : this(meas.Name, meas.obsTime, newValue, meas.status, meas.station) { }
public void AddMeas(string measName, string measValue, DateTime obsTime) { var meas = new Meas(measName, obsTime, measValue, MeasStatus.c*K, this.Station); measList.Add(meas); }
/// <summary> /// If this has slashes on some meas, copy value from the other one /// If this is missing some meas, copy valuee from the other one /// Return negative value if station, obstime, count are different /// Return 0 if measMsg contains same data values as this /// Return number of modified measValues /// </summary> /// <param name="measMsg"></param> /// <returns></returns> public int Merge(MeasMsg measMsg) { List <Meas> itemsToAdd = new List <Meas>(); List <Meas> itemsToChange = new List <Meas>(); int returnValue = 0; if (measMsg == null) { return(-1); } if (measMsg.obsTime != this.obsTime) { return(-2); } if (measMsg.Station != this.station) { return(-3); } for (var i = 0; i < Count; i++) { string measName = measList[i].Name; string dataValueInThisMeasMsg; bool ok = this.GetMeasObsValueByName(measName, out dataValueInThisMeasMsg); if (!ok) { return(-10 - i); } string dataValueInTheOtherMeasMsg; ok = measMsg.GetMeasObsValueByName(measName, out dataValueInTheOtherMeasMsg); if (!ok) { continue; } bool thisContainsSlashesButTheOtherOneDoesnt = dataValueInThisMeasMsg.Contains("/") && !dataValueInTheOtherMeasMsg.Contains("/"); if (thisContainsSlashesButTheOtherOneDoesnt) { Meas tmp = new Meas(); bool ok2 = measMsg.GetMeasByName(measName, ref tmp); Debug.Assert(ok2, "Merge 1"); //if (tmp.Name == "PA1") // SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, "öåöå Merging PA1. Old value:" + dataValueInThisMeasMsg + " . New value: " + dataValueInTheOtherMeasMsg); itemsToChange.Add(tmp); returnValue++; } } foreach (var meas in itemsToChange) { this.UpdateMeas(meas); } for (var i = 0; i < measMsg.Count; i++) { Meas meas = measMsg.MeasList[i]; if (!this.ContainsMeas(meas.Name)) { this.AddMeas(meas); returnValue++; } } return(returnValue); }