/** * Gets the hole where the player plays the worst in a specific golf course * allScoreHoles : a list of ScoreHole * golfCourse : the concerned golf course * return the numero of the worst hole */ public static int getWorstHole(List <ScoreHole> allScoreHoles, GolfCourse golfCourse) { int holeNumber = 0; List <ScoreHole> scoreHoles = getScoreHoles(allScoreHoles, golfCourse); if (scoreHoles.Count > 0) { //Dictionnary<Hole, Tuple<sum, count>> to compute mean Dictionary <Hole, double> sumScorePerHole = new Dictionary <Hole, double>(); Dictionary <Hole, double> countScorePerHole = new Dictionary <Hole, double>(); foreach (ScoreHole sh in scoreHoles) { if (!sumScorePerHole.ContainsKey(sh.Hole)) { sumScorePerHole.Add(sh.Hole, 0.0); countScorePerHole.Add(sh.Hole, 0.0); } sumScorePerHole[sh.Hole] += sh.Score; countScorePerHole[sh.Hole] += 1.0; } double maxScore = 0.0; foreach (Hole hole in sumScorePerHole.Keys) { double currentMean = sumScorePerHole[hole] / countScorePerHole[hole]; if (currentMean > maxScore) { maxScore = currentMean; holeNumber = golfCourse.Holes.IndexOf(hole) + 1; } } } return(holeNumber); }
public Hole(MyPosition p, int par, GolfCourse golfCourse) { this.Position = p; this.Par = par; GolfCourse = golfCourse; }
/** * Gets the proportion of each score done in a golf course * allScoreHoles : a list a ScoreHole * golfCourse : the concerned golf course * return a dictionnary where each possible score entry gives its proportion (it's not a percentage but it's over the number of holes ofgolf course) */ public static Dictionary <ScorePossible, float> getProportionScore(List <ScoreHole> allScoreHoles, GolfCourse golfCourse) { Dictionary <ScorePossible, float> res = new Dictionary <ScorePossible, float>(); List <ScoreHole> allNeededScoreHoles = getScoreHoles(allScoreHoles, golfCourse); int nbTotal = allNeededScoreHoles.Count; res.Add(ScorePossible.ALBATROS, allNeededScoreHoles.Where <ScoreHole>(sh => (sh.Score <= (int)ScorePossible.ALBATROS)).Count() / (float)nbTotal * golfCourse.Holes.Count); res.Add(ScorePossible.EAGLE, allNeededScoreHoles.Where <ScoreHole>(sh => (sh.Score == (int)ScorePossible.EAGLE)).Count() / (float)nbTotal * golfCourse.Holes.Count); res.Add(ScorePossible.BIRDIE, allNeededScoreHoles.Where <ScoreHole>(sh => (sh.Score == (int)ScorePossible.BIRDIE)).Count() / (float)nbTotal * golfCourse.Holes.Count); res.Add(ScorePossible.PAR, allNeededScoreHoles.Where <ScoreHole>(sh => (sh.Score == (int)ScorePossible.PAR)).Count() / (float)nbTotal * golfCourse.Holes.Count); res.Add(ScorePossible.BOGEY, allNeededScoreHoles.Where <ScoreHole>(sh => (sh.Score == (int)ScorePossible.BOGEY)).Count() / (float)nbTotal * golfCourse.Holes.Count); res.Add(ScorePossible.DOUBLE_BOUGEY, allNeededScoreHoles.Where <ScoreHole>(sh => (sh.Score == (int)ScorePossible.DOUBLE_BOUGEY)).Count() / (float)nbTotal * golfCourse.Holes.Count); res.Add(ScorePossible.MORE, allNeededScoreHoles.Where <ScoreHole>(sh => (sh.Score >= (int)ScorePossible.MORE)).Count() / (float)nbTotal * golfCourse.Holes.Count); return(res); }
/** * Filters the ScoreHole in the given list that took place in the given golf course * allScoreHoles : the initial list of ScoreHole * golfCourse : the golf course filter */ public static List <ScoreHole> getScoreHoles(List <ScoreHole> allScoreHoles, GolfCourse golfCourse) { List <ScoreHole> allNeededScoreHoles = allScoreHoles.Where(sh => sh.Hole.IdGolfC.Equals(golfCourse.Name)).ToList(); return(allNeededScoreHoles); }
/** * Gets the games that wasn't finished yet on a specific golf course * golfCourse : the specific golf course */ public static async Task <List <ScorePartie> > getNotFinishedGames(GolfCourse golfCourse) { List <ScorePartie> allNeededScoreParties = (await StatistiquesGolf.getScoreParties()).Where(sp => sp.scoreHoles[0].Hole.IdGolfC.Equals(golfCourse.Name) && sp.scoreHoles.Count != 9 && sp.scoreHoles.Count != 18).ToList(); return(allNeededScoreParties); }