Example #1
0
        private void UpdateViewerMovingAverages(MovingAverageWrapper wrapper, string average, string averageMax, string Ftp, string heartRate)
        {
            lock (this.lvViewer)
            {
                ViewerListViewItem listViewItem = wrapper.ViewerListViewItem;
                ViewerItem         viewerItem   = listViewItem.ViewerItem;

                if (average != null)
                {
                    viewerItem.Average = average;
                }

                if (averageMax != null)
                {
                    viewerItem.AverageMax = averageMax;
                }

                if (Ftp != null)
                {
                    viewerItem.Ftp = Ftp;
                }

                if (heartRate != null)
                {
                    viewerItem.HeartRate = heartRate;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Occurs each time a collector's moving average changes.  Allows for UI update by marshalling the call accordingly.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MovingAverageChangedEventHandler(object sender, MovingAverage.MovingAverageChangedEventArgs e)
        {
            //if (!m_dispatcher.CheckAccess()) // are we currently on the UI thread?
            //{
            //    // We're not in the UI thread, ask the dispatcher to call this same method in the UI thread, then exit
            //    m_dispatcher.BeginInvoke(new MovingAverageChangedEventHandlerDelegate(MovingAverageChangedEventHandler), new object[] { sender, e });
            //    return;
            //}

            string average   = "";
            string Ftp       = null;
            string heartRate = "";

            MovingAverageWrapper wrapper   = m_maCollection[e.DurationType];
            Collector            collector = wrapper.Collector;

            switch (collector.FieldAvgType)
            {
            case FieldUomType.Watts:
                average = e.AveragePower.ToString();
                break;

            case FieldUomType.Wkg:
                if (CurrentUser.WeightAsKgs > 0)
                {
                    average = Math.Round(e.AveragePower / CurrentUser.WeightAsKgs, 2).ToString("#.00");
                }
                break;
            }

            if (e.AverageHR > 0)
            {
                heartRate = e.AverageHR.ToString();
            }

            // The FTP column will track the AvgPower until the time duration is satisfied.
            // This enables the rider to see what his FTP would be real-time.
            // Once the time duration is satisfied, we no longer will update using the AvgPower.
            if (!wrapper.MaxDurationTriggered)
            {
                switch (collector.FieldFtpType)
                {
                case FieldUomType.Watts:
                    Ftp = Math.Round(e.AveragePower * 0.95, 0).ToString();
                    break;

                case FieldUomType.Wkg:
                    if (CurrentUser.WeightAsKgs > 0)
                    {
                        Ftp = Math.Round((e.AveragePower / CurrentUser.WeightAsKgs) * 0.95, 2).ToString("#.00");
                    }
                    break;
                }
            }

            this.UpdateViewerMovingAverages(wrapper, average, null, Ftp, heartRate);
        }
        /// <summary>
        /// Occurs each time a collector's moving average max value changes.  Allows for UI update by marshalling the call accordingly.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MovingAverageMaxChangedEventHandler(object sender, MovingAverage.MovingAverageMaxChangedEventArgs e)
        {
            //if (!m_dispatcher.CheckAccess()) // are we currently on the UI thread?
            //{
            //    // We're not in the UI thread, ask the dispatcher to call this same method in the UI thread, then exit
            //    m_dispatcher.BeginInvoke(new MovingAverageMaxChangedEventHandlerDelegate(MovingAverageMaxChangedEventHandler), new object[] { sender, e });
            //    return;
            //}

            lock (lvViewer)
            {
                MovingAverageWrapper wrapper      = m_maCollection[e.DurationType];
                Collector            collector    = wrapper.Collector;
                ViewerListViewItem   listViewItem = wrapper.ViewerListViewItem;
                ViewerItem           viewerItem   = listViewItem.ViewerItem;

                switch (collector.FieldAvgMaxType)
                {
                case FieldUomType.Watts:
                    viewerItem.AverageMax = e.MaxAvgPower.ToString();
                    break;

                case FieldUomType.Wkg:
                    if (m_currentUser.WeightAsKgs > 0)
                    {
                        viewerItem.AverageMax = Math.Round(e.MaxAvgPower / m_currentUser.WeightAsKgs, 2).ToString("#.00");
                    }
                    break;
                }

                // Save the fact that this moving average has fulfilled it's time duration
                wrapper.MaxDurationTriggered = true;

                // The FTP column will now track the MaxAvgPower now that the time duration is satisfied.
                switch (collector.FieldFtpType)
                {
                case FieldUomType.Watts:
                    viewerItem.Ftp = Math.Round(e.MaxAvgPower * 0.95, 0).ToString();
                    break;

                case FieldUomType.Wkg:
                    if (m_currentUser.WeightAsKgs > 0)
                    {
                        viewerItem.Ftp = Math.Round((e.MaxAvgPower / m_currentUser.WeightAsKgs) * 0.95, 2).ToString("#.00");
                    }
                    break;
                }
            }
        }