bool IsItemValid(string start, string end)
        {
            bool       result = true;
            ResultItem item   = new ResultItem(start, end);
            string     strStart;
            string     strEnd;
            int        s;
            int        e;

            item.GetStartEnd(out strStart, out strEnd);
            s = int.Parse(strStart);
            e = int.Parse(strEnd);

            // accel: check if start speed > end speed
            if ((mode == ResultMode.Speed) || (mode == ResultMode.Distance))
            {
                if (s >= e)
                {
                    result = false;
                }
            }

            // brake: check if end dist > start dist
            if (mode == ResultMode.Brake)
            {
                if (e >= s)
                {
                    result = false;
                }
            }

            // ensure unique items
            foreach (ResultItem ri in runResult.Items)
            {
                if (item.CompareTo(ri) == 0)
                {
                    result = false;
                }
            }

            return(result);
        }
Beispiel #2
0
        public ResultItem GetResult(ResultItem item, SubMode subMode, string unit)
        {
            ResultItem result;
            string     start;
            string     end;
            float      speedStart;
            float      speedEnd;
            float      distanceStart;
            float      distanceEnd;
            float      resultValue;

            //Debug.LogToFileMethod("item: " + item + " // " + "subMode: " + subMode + " // " + "unit: " + unit);

            item.GetStartEnd(out start, out end);

            //Debug.LogToFileMethod("start: " + start + " // " + "end: " + end);

            // convert speed strings
            if (Settings.IsSpeedUnitKph())
            {
                // from kph-string to m/s-float
                speedStart = Tools.ToMeterPerSecond(start);
                speedEnd   = Tools.ToMeterPerSecond(end);
            }
            else
            {
                // from mph-string to m/s-float
                speedStart = Tools.ToMeterPerSecondM(start);
                speedEnd   = Tools.ToMeterPerSecondM(end);
            }

            //Debug.LogToFileMethod("speedStart: " + speedStart + " // " + "speedEnd: " + speedEnd);

            if (mode.Equals(RunModeZeroToZero.Mode)) // zerotozero results in [time] unit
            {
                // mode zerotozero -> stop is same as start, but with stop detection limit on top (avoid unfound speedStop)
                RunStartStop runStartStop = new RunStartStop(Database.GetInstance().GetActiveProfile());
                float        speedStop    = speedStart + runStartStop.GetStopLimit();

                resultValue = GetDifferenceZeroToZero(speedStart, speedEnd, speedStop, subMode);
                resultValue = runAdjust.GetAdjusted(resultValue, mode, subMode);
                result      = new ResultItem(start + " - " + end + " - " + start, Tools.ToResultFormat(resultValue, subMode, unit));
            }
            else if (mode.Equals(RunModeBrake.Mode)) // brake results in [time] unit
            {
                // adjust speedEnd with calibrated stopDetection to avoid unfound speedEnd
                RunStartStop runStartStop = new RunStartStop(Database.GetInstance().GetActiveProfile());
                speedEnd += runStartStop.GetStopLimit();

                resultValue = GetDifferenceBrake(speedStart, speedEnd, subMode);
                resultValue = runAdjust.GetAdjusted(resultValue, mode, subMode);
                result      = new ResultItem(start + " - " + end, Tools.ToResultFormat(resultValue, subMode, unit));
            }
            else // acceleretion results in [time] or [distance] unit
            {
                if (subMode == SubMode.TimeDistance)
                {
                    // convert distance strings
                    if (Settings.IsDistanceUnitMeter())
                    {
                        // from meter-string to meter-float
                        distanceStart = float.Parse(start);
                        distanceEnd   = float.Parse(end);
                    }
                    else
                    {
                        // from foot-string to meter-float
                        distanceStart = Tools.ToMeter(start);
                        distanceEnd   = Tools.ToMeter(end);
                    }

                    //Debug.LogToFileMethod("distanceStart: " + distanceStart + " // " + "distanceEnd: " + distanceEnd);

                    resultValue = GetDifferenceAcceleration(distanceStart, distanceEnd, subMode);
                    resultValue = runAdjust.GetAdjusted(resultValue, mode, subMode);

                    float  speedAtEndDistance       = GetSpeed(distanceEnd);
                    string speedAtEndDistanceString = (Settings.IsSpeedUnitKph()) ? Tools.ToKilometerPerHour(speedAtEndDistance) : Tools.ToMilesPerHour(speedAtEndDistance);
                    string unitDistance             = (Settings.IsSpeedUnitKph()) ? Localization.unitKph : Localization.unitMph;

                    result = new ResultItem(start + " - " + end, Tools.ToResultFormat(resultValue, subMode, unit) + " @" + speedAtEndDistanceString + unitDistance);
                }
                else
                {
                    resultValue = GetDifferenceAcceleration(speedStart, speedEnd, subMode);
                    resultValue = runAdjust.GetAdjusted(resultValue, mode, subMode);
                    result      = new ResultItem(start + " - " + end, Tools.ToResultFormat(resultValue, subMode, unit));
                }
            }

            return(result);
        }