Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        // 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());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts MeasMsg into XML format
        /// </summary>
        /// <param name="measMsg"></param>
        /// <returns></returns>
        public static string ToXml(MeasMsg measMsg)
        {
            var sb = new StringBuilder();
            var xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Encoding = Encoding.UTF8;

            var utf8noBOM = new UTF8Encoding(false);
            var settings  = new XmlWriterSettings();

            settings.Indent   = true;
            settings.Encoding = utf8noBOM;

            using (XmlWriter writer = XmlWriter.Create(sb, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("Measurements");
                writer.WriteElementString("Station", measMsg.Station);
                writer.WriteElementString("Time", DateTimeEx.ToFileStringFormat(measMsg.Time));

                var query = measMsg.MeasList.OrderBy(m => m.Name, StringComparer.Ordinal);
                var list  = query.ToList();
                foreach (Meas meas in list)
                {
                    writer.WriteStartElement("Meas");
                    writer.WriteElementString("ID", meas.Name);
                    writer.WriteElementString("Data", meas.ObsValue);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            return(sb.ToString());
        }
Ejemplo n.º 5
0
        public static string ToFortumXml(MeasMsg measMsg, Dictionary <string, string> replacementNames)
        {
            StringBuilder     sb = new StringBuilder();
            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Encoding = Encoding.UTF8;

            Encoding          utf8noBOM = new UTF8Encoding(false);
            XmlWriterSettings settings  = new XmlWriterSettings();

            settings.Indent   = true;
            settings.Encoding = utf8noBOM;

            using (XmlWriter writer = XmlWriter.Create(sb, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("Measurements");
                writer.WriteElementString("Station", measMsg.Station);
                writer.WriteElementString("Time", DateTimeEx.ToFileStringFormat(measMsg.Time));

                var query = measMsg.MeasList.OrderBy(m => m.Name, StringComparer.Ordinal);
                var list  = query.ToList();

                foreach (Meas meas in list)
                {
                    string newName = string.Empty;
                    if (replacementNames.ContainsKey(meas.Name))
                    {
                        newName = replacementNames[meas.Name];
                    }
                    else
                    {
                        continue;
                    }

                    string dataValue = meas.ObsValue;
                    if (timeSeriesWhichUseReplacementTable.Contains(meas.Name))
                    {
                        if (replacementTable.ContainsKey(dataValue))
                        {
                            dataValue = replacementTable[dataValue];
                        }
                    }


                    writer.WriteStartElement("Meas");
                    writer.WriteElementString("ID", newName);
                    writer.WriteElementString("VaisalaID", meas.Name);
                    writer.WriteElementString("ObsTime", DateTimeEx.ToFileStringFormat(meas.ObsTime));
                    writer.WriteElementString("Data", dataValue);

                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            return(sb.ToString());
        }
Ejemplo n.º 6
0
 public MeasMsg(MeasMsg measMsg) : this()
 {
     Station = measMsg.Station;
     Time    = measMsg.Time;
     foreach (var m in measMsg.MeasList)
     {
         AddMeas(m);
     }
 }
Ejemplo n.º 7
0
 public void AddMeasMsg(MeasMsg otherMeasMsg)
 {
     foreach (var meas in otherMeasMsg.MeasValues)
     {
         if (!measList.Contains(meas))
         {
             measList.Add(meas);
         }
     }
 }
Ejemplo n.º 8
0
        internal static string WriteIntoString(MeasMsg measMsg)
        {
            var sb = new StringBuilder();

            foreach (var m in measMsg.MeasList)
            {
                sb.Append(m.ToStdString(measMsg.Station));
            }
            return(sb.ToString());
        }
Ejemplo n.º 9
0
        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());
        }
Ejemplo n.º 10
0
        private static string GetHeaderByMeasNames(MeasMsg measMsg, char dataDelimiter)
        {
            var sb = new StringBuilder();

            foreach (var m in measMsg.MeasList)
            {
                sb.Append(dataDelimiter);
                sb.Append(m.Name);
            }
            sb.Append(Environment.NewLine);
            return(sb.ToString());
        }
Ejemplo n.º 11
0
        private static string GetHeaderByMeasNamesWithDynCol(MeasMsg measMsg)
        {
            var sb = new StringBuilder();

            foreach (var m in measMsg.MeasList)
            {
                sb.Append(m.Name);
                int spacesToAdd = Math.Max(0, DynColumnMinLen - m.Name.Length) + 1;
                sb.Append(' ', spacesToAdd);
            }
            sb.Append(Environment.NewLine);
            return(sb.ToString());
        }
Ejemplo n.º 12
0
 public void UpsertMeasMsg(MeasMsg mm)
 {
     Debug.Assert(mm != null, "mm was null");
     if (mm == null)
     {
         return;
     }
     obsTime = mm.Time;
     station = mm.Station;
     foreach (var m in mm.MeasList)
     {
         UpsertMeas(m);
     }
 }
Ejemplo n.º 13
0
        public static string GetVaisalaHeader(MeasMsg measMsg, char dataDelimiter, bool useDynamicColumns)
        {
            var sb = new StringBuilder();

            sb.Append("TIME");

            // 16 = LEN ("yyyy-MM-dd HH:mm:ss") - LEN("TIME") + 2
            if (useDynamicColumns)
            {
                sb.Append(' ', 16);
                sb.Append(GetHeaderByMeasNamesWithDynCol(measMsg));
            }
            else
            {
                sb.Append(GetHeaderByMeasNames(measMsg, dataDelimiter));
            }
            return(sb.ToString());
        }
Ejemplo n.º 14
0
        public static string FormatMeasMsg(MeasMsg measMsg, bool header, char dataDelimiter)
        {
            if (measMsg.Count == 0)
            {
                return(string.Empty);
            }
            var sb = new StringBuilder();

            if (header)
            {
                sb.Append(GetVaisalaHeader(measMsg, dataDelimiter, false));
            }
            sb.Append((measMsg.MeasList[0]).ObsTime.ToString(DateTimeFormat, CultureInfo.InvariantCulture));
            foreach (var m in measMsg.MeasList)
            {
                sb.Append(dataDelimiter);
                sb.Append(m.ObsValue);
            }
            sb.Append(Environment.NewLine);
            return(sb.ToString());
        }
Ejemplo n.º 15
0
        /// <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);
        }
Ejemplo n.º 16
0
 public static string FormatMeasMsg(MeasMsg measMsg)
 {
     return(MeasMsg.WriteIntoString(measMsg));
 }
Ejemplo n.º 17
0
        /// <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);
        }