Exemple #1
0
 public void calculateStblNewHcps(Hcps oldHcps)
 {
     //ToCheck9
     stblPointsForNewHcp.points.Clear();
     foreach (flight ctF in flights.Values)
     {
         foreach (team ctT in ctF.teams.Values)
         {
             foreach (playingBall b in ctT.playingBalls.Values)
             {
                 string playerString = b.GetPlayersString();
                 foreach (Player ctP in b.players.Values)
                 {
                     Double oldHcp = ctP.initialHcp;
                     if (oldHcps != null && oldHcps.hpcs.ContainsKey(ctP.name))
                     {
                         oldHcp = oldHcps.hpcs[ctP.name];
                     }
                     int ctPlayingHcp = (int)Math.Round(courseDefinition.getPlayingHcp(oldHcp), 0);
                     stblPointsForNewHcp.points.Add(ctP.name, new List <int>()
                     {
                         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                     });
                     if (scores.holeResults.ContainsKey(playerString))
                     {
                         for (int holeNr = 1; holeNr <= 18; holeNr++)
                         {
                             hole ctHoleDefinition = courseDefinition.getHolebyNr(holeNr);
                             int  Stbl             = calcStblPointforHole(scores.getScore(playerString, holeNr), ctHoleDefinition.par, ctHoleDefinition.hcp, ctPlayingHcp);
                             if (b.nbOfPlayerForBall == 1)
                             {
                                 stblPointsForNewHcp.points[ctP.name][holeNr - 1] = Stbl;
                             }
                         }
                         if (stblPointsForNewHcp.isValidForStblDay() && b.nbOfPlayerForBall == 1)
                         {
                             NewHcps.hpcs.Add(ctP.name, NewHcps.calcNewHcpASG(oldHcp, stblPointsForNewHcp.getStblPointsForLastHoles(ctP.name)));
                         }
                         else
                         {
                             NewHcps.hpcs.Add(ctP.name, oldHcp);
                         }
                     }
                     else
                     {
                         throw new Exception(String.Format("Could not find holeResults for Player {0}", playerString));
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
        public void calculate(int toDayNr)
        {
            #region 1st Loop with calc daily stbl
            ctDayOfCompetition = toDayNr;
            Hcps prHcps = null;
            for (int i = 1; i <= toDayNr; ++i)
            {
                day ctDay = getDaybyNr(i);
                ctDay.calculateStbl(); //calculate stbl for the day and every Players
                ctDay.calculateStblNewHcps(prHcps);
                prHcps = ctDay.NewHcps;
                Dictionary <string, PlayerResult> ctDailyResults = new Dictionary <string, PlayerResult>();
                List <String> sortedList = ctDay.stblPoints.getSortedPlayerList();
                foreach (Player P in Players)
                {
                    PlayerResult ctPR = new PlayerResult();
                    ctPR.PlayerName = P.name;
                    ctPR.StblDay    = ctDay.stblPoints.getStblPointsForLastHoles(P.name);
                    ctPR.shExtraDay = ctDay.getShPointsForExtra(P.name);
                    ctPR.shMatch    = ctDay.getShPointsForMatch(P.name, configForYear);
                    ctPR.shStblDay  = ctDay.getShPointsForStblDaily(P.name, configForYear);
                    int Position = sortedList.FindIndex(x => x == P.name);
                    ctPR.posStblDay = Position + 1;
                    ctDailyResults.Add(ctPR.PlayerName, ctPR);
                }
                results.Add(ctDailyResults); // stores daily scores for the day
            }
            #endregion
            #region 2nd Loop Sum up and sort for weekly stable
            for (int i = 1; i <= toDayNr; ++i)
            {
                Dictionary <String, Double> sortableScores = new Dictionary <string, Double>();
                foreach (Player P in Players)
                {
                    //loop to identify the worst day for the player (scratch it) (from begin to i)
                    int worstDay            = 1;
                    int worstDayStbl        = 1000;
                    int cntDaysValidForStbl = 0;
                    for (int j = 1; j <= i; ++j) //loop from begin to i (ctDay in the mainloop)
                    {
                        day ctDay = getDaybyNr(j);
                        if (ctDay.isFoursome)
                        {
                            continue;
                        }
                        cntDaysValidForStbl++;
                        int ctStbl = getResultsbyDayNr(j)[P.name].StblDay; // get the daily stbl
                        if (worstDayStbl > ctStbl)
                        {
                            worstDay     = j;
                            worstDayStbl = ctStbl;
                        }
                    }
                    if (cntDaysValidForStbl <= 1)
                    {
                        worstDay = -1;                                //do not scratch if there is only one day of competition valid for stbl
                    }
                    getResultsbyDayNr(i)[P.name].worstDay = worstDay; //worst day

                    //sortable score looks like 144 (sum) 0036 (stbl day4) 0033 (stbl day3) 0041 (stbl day2) 0034 (stbl day1). 0008 (position from 1st stbl)  and is used to sort out players with same sum for the week
                    Double factor          = 1;
                    Double factor_X        = 1;
                    Double sortableScore   = (100 - (double)getResultsbyDayNr(1)[P.name].posStblDay) / 1000; //initialise with position from the 1st stbl (position (not stbl) forces a position even at beginning)
                    Double sortableScore_X = (100 - (double)getResultsbyDayNr(1)[P.name].posStblDay) / 1000;
                    int    sumStbl         = 0;
                    int    sumStbl_X       = 0;
                    Double sumEff          = 0;
                    for (int j = 1; j <= i; ++j) //loop from begin to i (ctDay in the mainloop)
                    {
                        sumEff += getResultsbyDayNr(j)[P.name].shMatch + getResultsbyDayNr(j)[P.name].shStblDay + getResultsbyDayNr(j)[P.name].shExtraDay;

                        day ctDay = getDaybyNr(j);
                        if (ctDay.isFoursome)
                        {
                            continue;
                        }

                        int ctStbl = getResultsbyDayNr(j)[P.name].StblDay; // get the daily stbl

                        sumStbl       += ctStbl;                           // sum up
                        sortableScore += factor * (double)ctStbl;          //store for sort
                        factor        *= 1000;

                        //don't use the score from the worstday
                        if (j != worstDay)
                        {
                            sumStbl_X       += ctStbl;                                       // sum up
                            sortableScore_X += factor_X * (double)(ctStbl == 0 ? 1: ctStbl); //store for sort (0 is not good)
                            factor_X        *= 1000;
                        }
                    }
                    sortableScore   += factor * (double)sumStbl;          //store for sort
                    sortableScore_X += factor_X * (double)sumStbl_X;      //store for sort
                    getResultsbyDayNr(i)[P.name].shEffective = sumEff;    //sum of matchs + daily sh + extra if defined
                    getResultsbyDayNr(i)[P.name].StblWeek    = sumStbl;   //save sum for week
                    getResultsbyDayNr(i)[P.name].StblWeek_X  = sumStbl_X; //save sum for week (scratch)
                    if (configForYear.useScratch)
                    {
                        sortableScores.Add(P.name, sortableScore_X); //add sortableScore to dictionary
                    }
                    else
                    {
                        sortableScores.Add(P.name, sortableScore); //add sortableScore to dictionary
                    }
                }
                List <String> sortedList = sortableScores.OrderByDescending(kp => kp.Value).Select(kp => kp.Key).ToList();
                sortableScores.Clear();
                foreach (Player P in Players) //loop again to get Position and sh
                {
                    int Position = sortedList.FindIndex(x => x == P.name);
                    //if (!getDaybyNr(i).stblPoints.isValidForStblDay())
                    //    Position = 8; // make sure
                    getResultsbyDayNr(i)[P.name].posStblWeek = Position + 1;
                    String[] splits = configForYear.stlWeek.Replace(" ", "").Split(',');
                    double   ctSh   = 0;
                    if (splits.Length > Position)
                    {
                        Double.TryParse(splits[Position], out ctSh);
                    }
                    getResultsbyDayNr(i)[P.name].shStblWeek = ctSh;
                    getResultsbyDayNr(i)[P.name].shVirtual  = getResultsbyDayNr(i)[P.name].shEffective + ctSh;

                    #region sortable score for overall Position
                    Double sortableScore = 0;
                    Double factor        = 1;
                    sortableScore += 20 - getResultsbyDayNr(i)[P.name].posStblWeek * factor;
                    factor        *= 1000;
                    sortableScore += getResultsbyDayNr(i)[P.name].shVirtual * factor;
                    sortableScores.Add(P.name, sortableScore);
                    #endregion
                }
                sortedList.Clear();
                sortedList = sortableScores.OrderByDescending(kp => kp.Value).Select(kp => kp.Key).ToList();
                foreach (Player P in Players) //loop again to get Position and sh
                {
                    int Position = sortedList.FindIndex(x => x == P.name);
                    getResultsbyDayNr(i)[P.name].posVirtual = Position + 1;
                }
            }
            #endregion
        }