protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         Dictionary <int, string> leagues = DatabaseFunctions.GetLeagues();
         GolfLeagueWebsiteGlobals.PopulateDropdownList(leagues, DropdownLeagues, leagues.FirstOrDefault().Key);
     }
 }
Example #2
0
    private static void AggregateHandicapDifferentials(Dictionary <int, int> playerHandicapsByEvent, List <HandicapCalculationData> handicapCalculationData, bool useCurrentRound)
    {
        List <double> handicapDifferentials = new List <double>();

        for (int i = 0; i < handicapCalculationData.Count; i++)
        {
            if (handicapDifferentials.Count == 0 || useCurrentRound)
            {
                handicapDifferentials.Add(handicapCalculationData[i].HandicapDifferential);
            }
            else if (i > 1)
            {
                handicapDifferentials.Add(handicapCalculationData[i - 1].HandicapDifferential);
            }

            if (handicapDifferentials.Count > 20)//Make sure we use no more than 20 rounds in the past to calculate handicap
            {
                handicapDifferentials.RemoveAt(0);
            }

            if (handicapCalculationData[i].HandicapOvveride == null)
            {
                int numberOfRoundsToUse = GolfLeagueWebsiteGlobals.GetPortableHandicapNumberOfRoundsToUse(handicapDifferentials.Count);

                //copy the list so we don't disturb its chronological ordering when sorting
                List <double> handicapDifferentialsSorted = new List <double>(handicapDifferentials);  //.Sort();
                handicapDifferentialsSorted.Sort();

                double differentialTotal = 0;
                for (int j = 0; j < numberOfRoundsToUse; j++)
                {
                    differentialTotal += handicapDifferentialsSorted[j];
                }

                if (numberOfRoundsToUse == 1)
                {
                    differentialTotal = differentialTotal * .8;
                }
                else if (numberOfRoundsToUse == 2)
                {
                    differentialTotal = differentialTotal * .9;
                }

                playerHandicapsByEvent.Add(handicapCalculationData[i].LeagueEventID, Convert.ToInt32(differentialTotal / numberOfRoundsToUse));
            }
            else
            {
                playerHandicapsByEvent.Add(handicapCalculationData[i].LeagueEventID, (int)handicapCalculationData[i].HandicapOvveride);
            }
        }
    }