/// <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); }
/// <summary> /// Return true if other measMsg has same timestamp, station and measurement names match /// </summary> /// <param name="measMsg"></param> /// <returns></returns> public bool CheckForDuplicateFilter(MeasMsg measMsg) { if (measMsg == null) { return(false); } if (measMsg.obsTime != this.obsTime) { return(false); } if (measMsg.Station != this.station) { return(false); } if (measMsg.Count != this.Count) { return(false); } for (var i = 0; i < Count; i++) { string measName = measList[i].Name; string dataValueInThisMeasMsg; bool ok = this.GetMeasObsValueByName(measName, out dataValueInThisMeasMsg); if (!ok) { return(false); } string dataValueInTheOtherMeasMsg; ok = measMsg.GetMeasObsValueByName(measName, out dataValueInTheOtherMeasMsg); if (!ok) { return(false); } //if (measName == "Vx3s" && measMsg.Time.Second < 4) // SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, "Vx3s comparison this:" + dataValueInThisMeasMsg + "\t:other:" + dataValueInTheOtherMeasMsg); bool thisContainsSlashesButTheOtherOneDoesnt = dataValueInThisMeasMsg.Contains("/") && !dataValueInTheOtherMeasMsg.Contains("/"); if (thisContainsSlashesButTheOtherOneDoesnt) { // if (measName == "Vx3s" && measMsg.Time.Second < 4) // SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, "Vx3s thisContainsSlashesButTheOtherOneDoesnt this:" + dataValueInThisMeasMsg + "\t:other:" + dataValueInTheOtherMeasMsg); return(false); } //bool theOtherOneContainsSlashesButThisDoesnt = !dataValueInThisMeasMsg.Contains("/") && dataValueInTheOtherMeasMsg.Contains("/"); //if (theOtherOneContainsSlashesButThisDoesnt) //{ // if (measName == "Vx3s" && measMsg.Time.Second < 4) // SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, "Vx3s theOtherOneContainsSlashesButThisDoesnt this:" + dataValueInThisMeasMsg + "\t:other:" + dataValueInTheOtherMeasMsg); //// return true; //} } return(true); }