示例#1
0
        public List<Models.LeaderBoard> GetLeaderBoard(Models.Result dbResult)
        {
            int ridersRiddenAll = 0;
            var lBoardModels = new List<LeaderBoard>(AthletesRidesLBoards.Count);
            var yellowPtsWhenNotRidden = new Dictionary<int, int>();                        // Dictionary, to reduce performance bottel necks

            var debugAdded = new Dictionary<int, bool>();

            foreach (var athleteLBoards in AthletesRidesLBoards)
            {
                int athleteID = athleteLBoards.Key;

                int rideCount = 0;
                int rideMinCount = 0;
                int yellowPts = 0, greenPts = 0, polkaDotPts = 0;
                var elapsedTime = new ElapsedTimes();

                var rideList = RidesWorstTime.Keys;
                foreach (var rideID in rideList)
                {
                    var segmentBoards = athleteLBoards.Value;

                    var athleteRiddenSegment = segmentBoards.ContainsKey(rideID);
                    if (athleteRiddenSegment)
                    {
                        LeaderBoard leaderBoard = segmentBoards[rideID];
                        rideCount++;
                        if (rideMinCount == 0 || leaderBoard.NoRidden < rideMinCount)
                            rideMinCount = leaderBoard.NoRidden;

                        //yellowPts += leaderBoard.YellowPoints;    Not Correct because leader will not be 00:00 (if not KOM on all)
                        greenPts += leaderBoard.GreenPoints;
                        polkaDotPts += leaderBoard.PolkaDotPoints;
                        elapsedTime.AddElapsedTimes(leaderBoard);
                    }
                    else
                    {
                        if (!yellowPtsWhenNotRidden.ContainsKey(rideID))
                        {
                            yellowPtsWhenNotRidden.Add(rideID, RidesWorstTime[rideID]);
                        }
                        elapsedTime.AddElapsedTimes(yellowPtsWhenNotRidden[rideID]);
                    }
                }

                #region debug
                if (debugAdded.ContainsKey(athleteID))
                    Debug.Fail("Shouldn't happen");
                else
                    debugAdded.Add(athleteID, true);

                #endregion

                int noRidden = 0;
                if (rideCount == RidesWorstTime.Count)
                {
                    noRidden = rideMinCount;
                    ridersRiddenAll++;
                }

                // Added to Leaderboard, but skip if only 1 ride at Region level. (but on on area - because then then to calc problem)
                bool enoughRidesToBeAdded = (rideCount > 1);
                if (rideType == RideType.Area || (rideType == RideType.Region && enoughRidesToBeAdded))
                {
                    lBoardModels.Add(new LeaderBoard()
                    {
                        ResultID = dbResult.ResultID,

                        AthleteID = athleteID,
                        ElapsedTimes = elapsedTime,
                        GreenPoints = greenPts,
                        PolkaDotPoints = polkaDotPts,
                        YellowPoints = yellowPts,
                        NoRidden = noRidden,
                    });
                }
            }
            return lBoardModels;
        }
示例#2
0
 public AthleteRideInfo()
 {
     ElapsedTimes = new ElapsedTimes();
 }