Esempio n. 1
0
            public SplitItem(SplitV2 item, bool splitsInKm)
            {
                this.Distance      = item.SplitDistance;
                this.Time          = item.SplitTime;
                this.TotalDistance = item.TotalDistance;
                this.TotalTime     = item.TotalTime;

                this.SplitsInKm = splitsInKm;
            }
Esempio n. 2
0
        /// <summary>
        /// Recalculate splits based upon user selections.  This wipes out any customizations.
        /// </summary>
        //private void RecalculateSplits()
        //{
        //    ZAMsettings.Settings.SplitsV2.Splits.Clear();
        //    ZAMsettings.Settings.SplitsV2.GoalSpeed = 0;

        //    SplitsManagerV2.SplitGoals splitGoals = SplitsManagerV2.GetSplitGoals();

        //    if (splitGoals == null)
        //        return;

        //    foreach (SplitsManagerV2.SplitGoal goal in splitGoals.Goals)
        //    {
        //        ZAMsettings.Settings.SplitsV2.Splits.Add(new SplitV2(goal.SplitDistance, goal.SplitTime, 0.0, goal.TotalDistance, goal.TotalTime, 0.0));
        //    }

        //    ZAMsettings.Settings.SplitsV2.GoalSpeed = splitGoals.GoalSpeed;
        //}

        private void SaveSplits()
        {
            DataTable table = (DataTable)dgvSplits.DataSource;

            SplitsV2 splits = ZAMsettings.Settings.SplitsV2;

            splits.Splits.Clear();

            foreach (DataRow row in ((DataTable)dgvSplits.DataSource).Rows)
            {
                if (this.IsNullorDBNull(row.Field <object>(SplitDistanceCol)) > 0 || this.IsNullorDBNull(row.Field <object>(SplitTimeCol)) > 0)
                {
                    continue;
                }

                ZAMsettings.Settings.SplitsV2.Splits.Add(new SplitV2(
                                                             row.Field <double>(SplitDistanceCol),
                                                             row.Field <TimeSpan>(SplitTimeCol),
                                                             row.Field <double>(SplitSpeedCol),
                                                             row.Field <double>(TotalDistanceCol),
                                                             row.Field <TimeSpan>(TotalTimeCol),
                                                             row.Field <double>(AverageSpeedCol),
                                                             splits
                                                             ));
            }

            splits.Customized = true;

            // the last split row has the totals
            int lastSplitRow = splits.Splits.Count - 1;

            if (lastSplitRow >= 0)
            {
                SplitV2 lastSplit = splits.Splits[lastSplitRow];

                // Setting of these values to invalid numbers can throw an exception

                splits.GoalDistance = lastSplit.TotalDistance;
                splits.GoalTime     = lastSplit.TotalTime;
                splits.GoalSpeed    = lastSplit.AverageSpeed;
            }
            else
            {
                throw new FormatException("No goals entered.");
            }
        }
        /// <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 || !m_splits.ShowSplits)
            {
                return;
            }

            SplitV2 split = null;

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

                // get the in-progress split
                split = m_splits.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 kmsTravelled   = totalMeters / 1000.0;
            double milesTravelled = kmsTravelled / 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 ? m_splits.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);

            // Now round the distance
            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, splitSpeed, totalDistance, runningTime, m_splits.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, splitSpeed, splitDistance, runningTime, m_splits.SplitsInKm, deltaTime);
                    OnSplitUpdatedEvent(args);

                    Logger.LogInformation($"%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, splitSpeed, totalDistance, runningTime, m_splits.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, splitSpeed, splitDistance, runningTime, m_splits.SplitsInKm);
                    OnSplitUpdatedEvent(args);
                }
            }
        }