Exemple #1
0
        public SplitStatusViewerControl(SplitEventArgs splitEventArgs)
        {
            InitializeComponent();

            if (DesignMode)
            {
                return;
            }

            if (ZAMsettings.LoggerFactory == null)
            {
                return;
            }

            Logger = ZAMsettings.LoggerFactory.CreateLogger <SplitStatusViewerControl>();

            this.mSplitEventArgs = splitEventArgs;

            //DeltaTime;
            //SplitNumber;
            //SplitSpeedKph;
            //SplitSpeedMph;
            //SplitTime;
            //TotalKmTravelled;
            //TotalMiTravelled;
            //TotalTime;
        }
Exemple #2
0
        private void OnSplitGoalCompletedEvent(SplitEventArgs e)
        {
            EventHandler <SplitEventArgs> handler = SplitGoalCompletedEvent;

            if (handler != null)
            {
                try
                {
                    handler(this, e);
                }
                catch (Exception ex)
                {
                    // Don't let downstream exceptions bubble up
                    Logger.LogError(ex, $"Caught in {this.GetType()} (OnSplitGoalCompletedEvent)");
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Handle player state changes.
        /// Event distance is given in meters.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RiderStateEventHandler(object sender, RiderStateEventArgs e)
        {
            if (!m_started || !ConfiguredSplits.ShowSplits || e.CollectionTime == null)
            {
                return;
            }

            SplitV2 split = null;

            if (ConfiguredSplits.CalculateGoal)
            {
                if (m_splitCount >= ConfiguredSplits.Splits.Count)
                {
                    return;
                }

                // get the in-progress split
                split = ConfiguredSplits.Splits[m_splitCount];
            }

            DateTime now = DateTime.Now;

            TimeSpan runningTime = (now - m_startTime);
            TimeSpan splitTime   = (now - m_splitStartTime);

            if (m_eventCount++ == 0)
            {
                // Capture the current distance traveled value to use as an offset to each successive distance value.
                m_distanceSeedValue = e.Distance;
            }

            // Calculate total distance travelled
            int totalMeters = e.Distance - m_distanceSeedValue;

            double totalKmTravelled = totalMeters / 1000.0;
            double totalMiTravelled = totalKmTravelled / 1.609;

            //double totalDistance = Math.Round(m_splits.SplitsInKm ? kmsTravelled : milesTravelled, 1);

            // Calculate how deep into the current split the rider is.
            int splitMetersTravelled = totalMeters - m_lastSplitMeters;

            // How long is current split?
            int splitLengthMeters = split == null ? ConfiguredSplits.SplitDistanceAsMeters : split.SplitDistanceAsMeters;

            // How much of the split is completed (expressed as percentage)
            double splitCompletedPct = splitMetersTravelled / (double)splitLengthMeters;

            // Compute distance, leave unrounded
            double splitKmTravelled = splitMetersTravelled / 1000.0;
            double splitMiTravelled = splitKmTravelled / 1.609;

            //double splitDistance = m_splits.SplitsInKm ? splitKmTravelled : splitMiTravelled;
            //double splitSpeed = Math.Round((splitDistance / splitTime.TotalSeconds) * 3600, 1);

            double splitSpeedMph = Math.Round((splitMiTravelled / splitTime.TotalSeconds) * 3600, 1);
            double splitSpeedKph = Math.Round((splitKmTravelled / splitTime.TotalSeconds) * 3600, 1);

            // Now round the distance
            splitMiTravelled = Math.Round(splitMiTravelled, 1);
            splitKmTravelled = Math.Round(splitKmTravelled, 1);

            //splitDistance = Math.Round(splitDistance, 1);

            if (split != null)
            {
                if (splitMetersTravelled >= splitLengthMeters)
                {
                    // Calculate the deltaTime, positive number is bad, negative good.
                    TimeSpan deltaTime = new TimeSpan(0, 0, (int)Math.Round(runningTime.Subtract(split.TotalTime).TotalSeconds, 0));

                    // This completes the split.  TotalDistance travelled and Delta is included.
                    SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeedMph, splitSpeedKph, totalMiTravelled, totalKmTravelled, runningTime, ConfiguredSplits.SplitsInKm, deltaTime);
                    OnSplitGoalCompletedEvent(args);

                    // Reset time and begin next split
                    m_splitStartTime = now;
                    m_splitCount++;

                    m_lastSplitMeters = split.TotalDistanceAsMeters;
                }
                else
                {
                    // Goal time of split start
                    TimeSpan splitStartTime = split.TotalTime.Subtract(split.SplitTime);

                    // Goal time to get to this point in the split
                    TimeSpan splitWaypointTime = splitStartTime.Add(split.SplitTime.Multiply(splitCompletedPct));

                    // Calculate the deltaTime, positive number is bad, negative good.
                    TimeSpan deltaTime = new TimeSpan(0, 0, (int)Math.Round(runningTime.Subtract(splitWaypointTime).TotalSeconds, 0));

                    // This is an update to the split in-progress.  SplitDistance travelled is included.
                    SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeedMph, splitSpeedKph, splitMiTravelled, splitKmTravelled, runningTime, ConfiguredSplits.SplitsInKm, deltaTime);
                    OnSplitUpdatedEvent(args);

                    Logger.LogDebug($"%Complete: {splitCompletedPct} Start: {splitStartTime.ToString("m'm 's's'")} Waypoint: {splitWaypointTime.ToString("m'm 's's'")} Delta: {deltaTime.ToString("m'm 's's'")}");
                }
            }
            else
            {
                if (splitMetersTravelled >= splitLengthMeters)
                {
                    // This completes the split.  TotalDistance traveled is included.
                    SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeedMph, splitSpeedKph, totalMiTravelled, totalKmTravelled, runningTime, ConfiguredSplits.SplitsInKm);
                    OnSplitCompletedEvent(args);

                    // Reset time and begin next split
                    m_splitStartTime = now;
                    m_splitCount++;

                    m_lastSplitMeters = totalMeters;
                }
                else
                {
                    // This is an update to the split in-progress.  SplitDistance traveled is included.
                    SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeedMph, splitSpeedKph, splitMiTravelled, splitKmTravelled, runningTime, ConfiguredSplits.SplitsInKm);
                    OnSplitUpdatedEvent(args);
                }
            }
        }