PurplePen.CourseView.ComputeStatistics C# (CSharp) Method

ComputeStatistics() private method

private ComputeStatistics ( ) : void
return void
        private void ComputeStatistics()
        {
            totalPoints = 0;
            normalControlCount = 0;
            partLength = 0;
            Course course = courseDesignator.IsAllControls ? null : eventDB.GetCourse(courseDesignator.CourseId);

            if (courseDesignator.IsAllControls)
                totalClimb = -1;
            else
                totalClimb = course.climb;

            for (int i = 0; i < controlViews.Count; ++i) {
                ControlView controlView = controlViews[i];

                if (controlView.controlId.IsNotNone) {
                    ControlPoint control = eventDB.GetControl(controlView.controlId);
                    if (control.kind == ControlPointKind.Normal)
                        ++normalControlCount;
                }

                if (controlView.courseControlIds[0].IsNotNone) {
                    ControlPoint control = eventDB.GetControl(controlView.controlId);
                    CourseControl courseControl = eventDB.GetCourseControl(controlView.courseControlIds[0]);
                    if (control.kind == ControlPointKind.Normal && courseControl.points > 0)
                        totalPoints += courseControl.points;
                }

                // Always use the first leg for split controls.
                if (controlView.legTo != null && controlView.legTo.Length > 0)
                    partLength += controlView.legLength[0];
            }

            // Get the total length from another course view, if this is just a partial course.
            if (courseDesignator.IsAllControls) {
                minMeasuredLength = maxMeasuredLength = partLength;
            }
            else if (!courseDesignator.IsVariation && QueryEvent.HasVariations(eventDB, courseDesignator.CourseId)) {
                // All variations. Get range from every variation.
                Debug.Assert(courseDesignator.AllParts);
                List<CourseView> allVariations = AllCourseVariations(courseDesignator.CourseId);
                minMeasuredLength = (from view in allVariations select view.MinMeasuredLength).Min();
                partLength = maxMeasuredLength = (from view in allVariations select view.MaxMeasuredLength).Max();
            }
            else if (courseDesignator.AllParts) {
                minMeasuredLength = maxMeasuredLength = partLength;
            }
            else {
                CourseView viewEntireCourse = CourseView.CreateCourseView(eventDB, new CourseDesignator(courseDesignator.CourseId), false, false);
                minMeasuredLength = viewEntireCourse.MinMeasuredLength;
                maxMeasuredLength = viewEntireCourse.MaxMeasuredLength;
            }

            if (course != null && course.overrideCourseLength.HasValue) {
                minTotalLength = maxTotalLength = course.overrideCourseLength.Value;
            }
            else {
                minTotalLength = minMeasuredLength;
                maxTotalLength = maxMeasuredLength;
            }

            if (!courseDesignator.IsVariation && QueryEvent.HasVariations(eventDB, courseDesignator.CourseId)) {
                List<CourseView> allVariations = AllCourseVariations(courseDesignator.CourseId);
                minNormalControls = (from view in allVariations select view.TotalNormalControls).Min();
                maxNormalControls = (from view in allVariations select view.TotalNormalControls).Max();
            }
            else {
                minNormalControls = maxNormalControls = normalControlCount;
            }
        }