예제 #1
0
        public Test()
        {
            //my(typeof(Test).GetProperty("Value"));
            RecordValues vals = new RecordValues();

            vals.SetValue(2, 320);
            Func <RecordValues, double> func = PropertyNameToDelegate("Altitude");
            double result = func(vals);
        }
예제 #2
0
        private void WithXmlWriter(string fileName, string trackName, int recordIncrement)
        {
            Stream stream = File.Create(fileName);
            //StringBuilder builder = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent                  = true;
            settings.IndentChars             = string.Empty;
            settings.Encoding                = Encoding.UTF8;
            settings.NewLineOnAttributes     = false;
            settings.CloseOutput             = true;
            settings.WriteEndDocumentOnClose = true;

            XmlWriter writer = XmlWriter.Create(stream, settings);

            writer.WriteStartDocument();
            writer.WriteStartElement("gpx", "http://www.topografix.com/GPX/1/1");
            writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
            writer.WriteAttributeString("xsi", "schemaLocation", null, "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");
            writer.WriteAttributeString("creator", "ELEMNTViewer");
            writer.WriteAttributeString("version", "1.1");

            writer.WriteStartElement("metadata");
            writer.WriteStartElement("name");
            writer.WriteCData(trackName);
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteStartElement("trk");
            writer.WriteElementString("name", trackName);
            writer.WriteStartElement("trkseg");

            double lon;
            double lat;
            double ele;

            for (int i = 0; i < _recordValuesList.Count; i += recordIncrement)
            {
                RecordValues values = _recordValuesList[i];
                lon = values.PositionLong;
                lat = values.PositionLat;
                ele = values.Altitude;
                writer.WriteStartElement("trkpt");
                writer.WriteAttributeString("lon", lon.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("lat", lat.ToString(CultureInfo.InvariantCulture));
                writer.WriteElementString("ele", ele.ToString(CultureInfo.InvariantCulture));
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteEndElement();
            //writer.WriteEndDocument();
            writer.Close();
        }
예제 #3
0
        public void FillSeriesWithNewData(int fromIndex, int toIndex)
        {
            Chart chartMain = Chart;

            if (_smoothing != null)
            {
                _smoothing.StartIndex = fromIndex;
            }
            chartMain.BeginInit();
            DataPointCollection points = _series.Points;

            points.ClearFast(); //MsChartExtension
            if (fromIndex < 0 || fromIndex >= toIndex)
            {
                return;
            }
            points.SuspendUpdates();
            for (int i = fromIndex; i <= toIndex; i++)
            {
                RecordValues values = DataManager.Instance.RecordList[i];
                if (_smoothing == null)
                {
                    //points.AddXY(values.Distance, propertyFunc(values));
                    points.AddXY(values.Timestamp, _propertyFunc(values));
                }
                else
                {
                    _smoothing.SetSmoothValue(values, _propertyFunc, i);
                    //points.AddXY(values.Distance, smoothing.SmoothValue);
                    points.AddXY(values.Timestamp, _smoothing.SmoothValue);
                }
            }
            if (_smoothing == null || _smoothing.AvgTime == 0)
            {
                _series.Name = _propertyName;
            }
            else
            {
                _series.Name = _propertyName + " (" + _smoothing.AvgTime.ToString() + ")";
            }

            points.ResumeUpdates();
            if (!chartMain.Series.Contains(_series))
            {
                chartMain.Series.Add(_series);
            }
            chartMain.EndInit();
        }
예제 #4
0
        void CalculateSessionMaxValues()
        {
            double maxPosGrade = 0;
            double maxNegGrade = 0;
            double avgGrade    = 0;
            //DateTime firstDateTime;
            //DateTime lastDateTime = DateTime.Now;
            //TimeSpan span = new TimeSpan();
            //bool greater = false;
            List <RecordValues> list = DataManager.Instance.RecordList;

            for (int i = 0; i < list.Count; i++)
            {
                RecordValues values = list[i];
                //if (i == 0)
                //{
                //    lastDateTime = values.Timestamp;
                //    firstDateTime = lastDateTime;
                //}
                //else
                //{
                //    span = values.Timestamp - lastDateTime;
                //    lastDateTime = values.Timestamp;
                //}
                //if (span.Milliseconds > 1000)
                //    greater = true;
                avgGrade += values.Grade;
                if (values.Grade > maxPosGrade)
                {
                    maxPosGrade = values.Grade;
                }
                if (values.Grade < maxNegGrade)
                {
                    maxNegGrade = values.Grade;
                }
            }
            if (list.Count > 0)
            {
                this._avgGrade = avgGrade / list.Count;
            }
            else
            {
                this._avgGrade = 0;
            }
            this._maxNegGrade = maxNegGrade;
            this._maxPosGrade = maxPosGrade;
        }
예제 #5
0
        //public void SetSmoothValue1(RecordValues values, Delegate propertyFunc, int recordIndex) {
        //    double result = (double)propertyFunc.DynamicInvoke(values);
        //    SmoothValue = result;
        //}

        public void SetSmoothValue(RecordValues values, Func <RecordValues, double> propertyFunc, int recordIndex)
        {
            if (_avgTime == 0)
            {
                SmoothValue = propertyFunc(values);
            }
            else
            {
                _sum += propertyFunc(values);
                if ((recordIndex - _startIndex) >= _avgTime)
                {
                    _sum -= propertyFunc(DataManager.Instance.RecordList[_firstIndex]);
                    _firstIndex++;
                }
                SmoothValue = _sum / (double)(recordIndex + 1 - _firstIndex);
            }
        }
예제 #6
0
        static async void HandleRecord(MesgEventArgs e)
        {
            RecordValues values = new RecordValues();
            object       value;

            int i = 0;

            foreach (Field field in e.mesg.Fields)
            {
                for (int j = 0; j < field.GetNumValues(); j++)
                {
                    value = field.GetValue(j);
                    values.SetValue(field.Num, value);
                }

                i++;
            }
            DataManager.Instance.RecordList.Add(values);
            await Task.CompletedTask;
        }
예제 #7
0
        void AvgLeftRight()
        {
            double balance            = 0;
            double leftPowerSmooth    = 0;
            double leftThreshholdEff  = 0;
            double rightPowerSmooth   = 0;
            double rightThreshholdEff = 0;
            List <RecordValues> list  = DataManager.Instance.RecordList;
            DateTime            lastTime;

            if (list.Count > 0)
            {
                lastTime = list[0].Timestamp;
            }
            else
            {
                _leftRightBalance = 0;
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                RecordValues values = list[i];
                balance            += values.LeftRightBalance;
                leftPowerSmooth    += values.LeftPedalSmoothness;
                leftThreshholdEff  += values.LeftTorqueEffectiveness;
                rightPowerSmooth   += values.RightPedalSmoothness;
                rightThreshholdEff += values.RightTorqueEffectiveness;
                DateTime actTime      = values.Timestamp;
                TimeSpan delta        = actTime - lastTime;
                long     deltaSeconds = delta.Ticks / TimeSpan.TicksPerSecond;
                lastTime = actTime;
                if (deltaSeconds > 1)
                {
                }
            }
            _leftRightBalance = balance / list.Count;
            _leftPS           = leftPowerSmooth / list.Count;
            _leftTE           = leftThreshholdEff / list.Count;
            _rightPS          = rightPowerSmooth / list.Count;
            _rightTE          = rightThreshholdEff / list.Count;
        }
예제 #8
0
        private void WithXmlDocument(string fileName, string trackName, int recordIncrement)
        {
            XmlDocument document = new XmlDocument();

            document.PreserveWhitespace = false;
            //Create an XML declaration.
            XmlDeclaration xmldecl;

            xmldecl          = document.CreateXmlDeclaration("1.0", "utf-8", null);
            xmldecl.Encoding = "utf-8";
            document.AppendChild(xmldecl);
            XmlElement gpxNode = document.CreateElement("gpx");

            gpxNode.SetAttribute("xmlns", "http://www.topografix.com/GPX/1/1");
            gpxNode.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            gpxNode.SetAttribute("schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");

            XmlAttribute creatorAttr = document.CreateAttribute("creator");
            XmlAttribute versionAttr = document.CreateAttribute("version");

            creatorAttr.Value = "ELEMNTViewer";
            versionAttr.Value = "1.1";
            gpxNode.Attributes.SetNamedItem(creatorAttr);
            gpxNode.Attributes.SetNamedItem(versionAttr);

            XmlNode         metadataNode = document.CreateElement("metadata");
            XmlNode         nameNode     = document.CreateElement("name");
            XmlCDataSection cData        = document.CreateCDataSection(trackName);

            metadataNode.AppendChild(nameNode);
            nameNode.AppendChild(cData);
            gpxNode.AppendChild(metadataNode);

            XmlNode trkNode     = document.CreateElement("trk");
            XmlNode nameNodeTrk = document.CreateElement("name");

            nameNodeTrk.InnerText = trackName;
            trkNode.AppendChild(nameNodeTrk);
            XmlNode trksegNode = document.CreateElement("trkseg");

            gpxNode.AppendChild(trkNode);
            trkNode.AppendChild(trksegNode);

            double lon;
            double lat;
            double ele;

            for (int i = 0; i < _recordValuesList.Count; i += recordIncrement)
            {
                RecordValues values = _recordValuesList[i];
                lon = values.PositionLong;
                lat = values.PositionLat;
                ele = values.Altitude;
                XmlNode      trkptNode = document.CreateElement("trkpt");
                XmlAttribute lonAttr   = document.CreateAttribute("lon");
                lonAttr.Value = lon.ToString(CultureInfo.InvariantCulture);
                XmlAttribute latAttr = document.CreateAttribute("lat");
                latAttr.Value = lat.ToString(CultureInfo.InvariantCulture);
                trkptNode.Attributes.SetNamedItem(lonAttr);
                trkptNode.Attributes.SetNamedItem(latAttr);
                XmlNode eleNode = document.CreateElement("ele");
                eleNode.InnerText = ele.ToString(CultureInfo.InvariantCulture);
                trkptNode.AppendChild(eleNode);
                trksegNode.AppendChild(trkptNode);
            }

            document.AppendChild(gpxNode);
            document.Save(fileName);
        }