예제 #1
0
        public string ToCSV(Mask mask)
        {
            if (mask == null)
            {
                throw new Exception("Не задана маска измерения");
            }

            DateTime starttime = StartTime;
            string   separator = ";";
            string   nl        = "\r\n";

            string result = "\"Название\"" + separator + "\"" + Name + "\"" + nl;

            result += "\"Продолжительность\"" + separator + FullMeasureLength + nl;
            result += "\"Тип\"" + separator + (IsMeasured ? "измерение" : "среднее измерение") + nl;
            result += "\"Статистические данные\"" + separator + (DispData != null ? "есть" : "нет") + nl;
            result += "\"Начало\"" + separator + starttime.ToString() + nl;
            result += nl;



            Dictionary <Sensor, double> start = StartValues;

            result += "\"Значения\"" + nl + "\"время\\сенсоры\"";

            foreach (Sensor s in start.Keys)
            {
                result += separator + "\"" + s.ToString() + "\"";
            }

            result += nl + "\"Базовая частота\"";
            foreach (Sensor s in start.Keys)
            {
                result += separator + start[s].ToString();
            }

            for (int i = 0; i < mask.TimePoints.Length && mask.TimePoints[i] <= FullMeasureLength; i++)
            {
                result += nl;
                double tick = mask.TimePoints[i];
                Dictionary <Sensor, double> data = this.GetDataAtTheMoment(starttime.AddSeconds(tick));
                foreach (Sensor sen in start.Keys)
                {
                    result += separator + data[sen].ToString();
                }
            }

            if (DispData != null)
            {
                result += nl + "\"доверительные интервалы\"" + nl;
                foreach (Sensor s in DispData.Keys)
                {
                    result += "\"" + s + " (cек)" + "\"" + separator;
                    foreach (double t in DispData[s].Keys)
                    {
                        result += t.ToString() + separator;
                    }
                    result += nl + "\"дов. интервал +/-\"" + separator;
                    foreach (double t in DispData[s].Keys)
                    {
                        result += DispData[s][t].ToString() + separator;
                    }
                    result += nl;
                }
            }



            return(result);
        }
예제 #2
0
        public static MeasureData calculateMedianMeasure(Dictionary <MeasureData, double> measuresCorrecture, Mask mask, double length)
        {
            Dictionary <Sensor, Dictionary <double, double> > data = new Dictionary <Sensor, Dictionary <double, double> >();
            Dictionary <Sensor, int> dividers = new Dictionary <Sensor, int>();
            Dictionary <MeasureData, Dictionary <Sensor, double> > inits = new Dictionary <MeasureData, Dictionary <Sensor, double> >();
            Dictionary <Sensor, double> starts = new Dictionary <Sensor, double>();

            foreach (MeasureData md in measuresCorrecture.Keys)
            {
                inits.Add(md, md.StartValues);
            }

            foreach (MeasureData md in measuresCorrecture.Keys)
            {
                Dictionary <Sensor, double> sv = md.StartValues;
                foreach (Sensor s in md.AllData.Keys)
                {
                    if (!data.ContainsKey(s))
                    {
                        data.Add(s, new Dictionary <double, double>());
                    }

                    if (!dividers.ContainsKey(s))
                    {
                        dividers.Add(s, 1);
                    }
                    else
                    {
                        dividers[s] = dividers[s] + 1;
                    }

                    if (!starts.ContainsKey(s))
                    {
                        starts.Add(s, sv[s]);
                    }
                    else
                    {
                        starts[s] = starts[s] + sv[s];
                    }
                }
            }


            Dictionary <Sensor, double> _starts = new Dictionary <Sensor, double>();

            foreach (Sensor s in starts.Keys)
            {
                _starts.Add(s, starts[s] / dividers[s]);
            }



            List <double> ticks = new List <double>();


            foreach (double tick in mask.TimePoints)
            {
                if (tick <= length)
                {
                    ticks.Add(tick);
                }
            }

            foreach (double tick in ticks)
            {
                foreach (Sensor ssen in data.Keys)
                {
                    data[ssen].Add(tick, 0d);
                }

                foreach (MeasureData md in measuresCorrecture.Keys)
                {
                    Dictionary <Sensor, double> momdat = md.GetDataAtTheMoment(md.StartTime.AddSeconds(tick - measuresCorrecture[md]));
                    foreach (Sensor ssen in momdat.Keys)
                    {
                        data[ssen][tick] = data[ssen][tick] - (momdat[ssen] - inits[md][ssen]);
                    }
                }

                foreach (Sensor ssen in data.Keys)
                {
                    data[ssen][tick] = data[ssen][tick] / dividers[ssen];
                }
            }



            Dictionary <Sensor, List <PointD> > fdata = new Dictionary <Sensor, List <PointD> >();

            foreach (Sensor sen in data.Keys)
            {
                fdata.Add(sen, new List <PointD>());
                fdata[sen].Add(new PointD(-1d, _starts[sen]));
                foreach (double time in data[sen].Keys)
                {
                    fdata[sen].Add(new PointD(time, _starts[sen] - data[sen][time]));
                }
            }


            MeasureData result = new MeasureData(fdata, -1, "", DateTime.Now, "", -1, length, 1, false, mask);

            return(result);
        }
예제 #3
0
        public static MeasureData fromXML(string XML, List <Mask> masks, List <Sensor> sensors)
        {
            XmlDocument xdoc = new XmlDocument();

            try
            {
                xdoc.LoadXml(XML);
                string name = xdoc.GetElementsByTagName("name")[0].InnerText;
                string desc = xdoc.GetElementsByTagName("description")[0].InnerText;
                int    gid  = Convert.ToInt32(xdoc.GetElementsByTagName("group")[0].InnerText);
                int    mask = Convert.ToInt32(xdoc.GetElementsByTagName("mask")[0].InnerText);

                DateTime start      = DateTime.Parse(xdoc.GetElementsByTagName("start")[0].InnerText);
                double   length     = double.Parse(xdoc.GetElementsByTagName("length")[0].InnerText);
                bool     isMeasured = bool.Parse(xdoc.GetElementsByTagName("ismeasured")[0].InnerText);

                Dictionary <Sensor, Dictionary <double, double> > dispdata = null;

                if (!isMeasured)
                {
                    dispdata = new Dictionary <Sensor, Dictionary <double, double> >();
                }


                XmlNodeList list = xdoc.GetElementsByTagName("sensor");
                Dictionary <Sensor, List <PointD> > data = new Dictionary <Sensor, List <PointD> >();

                Mask m = null;
                foreach (Mask mm in masks)
                {
                    if (mm.ID == mask)
                    {
                        m = mm;
                    }
                }


                foreach (XmlNode node in list)
                {
                    string sid = node.Attributes["sid"].Value;

                    Sensor s = null;
                    foreach (Sensor se in sensors)
                    {
                        if (se.SID == sid)
                        {
                            s = se;
                        }
                    }

                    if (s != null)
                    {
                        data.Add(s, new List <PointD>());
                        if (!isMeasured)
                        {
                            dispdata.Add(s, new Dictionary <double, double>());
                        }
                        foreach (XmlNode dnode in node.ChildNodes)
                        {
                            PointD point = new PointD();
                            XmlAttributeCollection collect = dnode.Attributes;
                            point.X = double.Parse(collect["time"].Value);
                            point.Y = double.Parse(collect["value"].Value);
                            if (point.X >= 0d)
                            {
                                if (!isMeasured)
                                {
                                    try
                                    {
                                        dispdata[s].Add(point.X, Double.Parse(collect["disp"].Value));
                                    }
                                    catch {}
                                }
                            }
                            data[s].Add(point);
                        }
                    }
                }

                MeasureData dat = new MeasureData(data, -1, name, start, desc, gid, length, 1, isMeasured, m);
                dat.DispData = dispdata;
                return(dat);
            }
            catch (Exception ex) { message = ex.Message; return(null); }
        }
예제 #4
0
 public Measure(MeasureData meas, Mask mask, double timeCorrecture)
 {
     this.measure = meas;
     this.mask    = mask;
     timeCorr     = timeCorrecture;
 }