/** * Updates the green in regulation stat labels */ private void updateGIR(List <ScorePartie> allScoreParties) { List <ScorePartie> scoreParties = StatistiquesGolf.getScoreParties(allScoreParties, this.golfCourse); double sum = 0.0; foreach (ScorePartie sp in scoreParties) { foreach (ScoreHole sh in sp.scoreHoles) { sum += (sh.Hit) ? 1.0 : 0.0; } } if (scoreParties.Count == 0) { this.averageGIR.Text = GeneralStatPage.NO_DATA; this.averageGIR.TextColor = Color.Gray; this.averageGIR.FontSize = 15; } else { this.averageGIR.Text = "" + (sum / scoreParties.Count).ToString("0.00"); this.averageGIR.TextColor = Color.FromHex("#39B54A"); this.averageGIR.FontSize = 30; } }
/** * This method is called when the button to consult the game card is clicked */ private async void OnCardClicked(object sender, EventArgs e) { Profil profil = StatistiquesGolf.getProfil(); await partie.gameFinished(profil.SaveStats); await Navigation.PushModalAsync(new DetailsPartiePage(partie.ScoreOfThisPartie)); }
public ChooseAvatar() { InitializeComponent(); col = Color.Gray; title.FontSize = 30; ok.FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)); ok.Margin = MainPage.responsiveDesign(-15); ok.HeightRequest = MainPage.responsiveDesign(80); ok.WidthRequest = MainPage.responsiveDesign(80); this.photos = new ImageButton[6]; this.photos[0] = photo1; this.photos[1] = photo2; this.photos[2] = photo3; this.photos[3] = photo4; this.photos[4] = photo5; this.photos[5] = photo6; this.InitBDD(); LocalUser = StatistiquesGolf.getProfil(); title.Margin = new Thickness(80, 5, 80, 10); lastPhotoIndex = LocalUser.Photo - 1; this.photos[lastPhotoIndex].BorderWidth = 3; this.photos[lastPhotoIndex].BorderColor = col; }
/** * This method is called when the button to go back to main menu is clicked */ private async void OnGoBackClicked(object sender, EventArgs e) { Profil profil = StatistiquesGolf.getProfil(); await partie.gameFinished(profil.SaveStats); await Navigation.PopToRootAsync(); }
/** * Updates the labels describing the information of the user */ public void updateLabels() { LocalUser = StatistiquesGolf.getProfil(); user.Text = LocalUser.Username; index.Text = LocalUser.Index.ToString(); golfref.Text = LocalUser.GolfRef; photo.Source = "user" + LocalUser.Photo.ToString() + ".png"; if (LocalUser.Index > 30) { niv.Text = "Debutant"; } else if (LocalUser.Index > 18) { niv.Text = "Moyen"; } else if (LocalUser.Index > 11) { niv.Text = "Confirmé"; } else if (LocalUser.Index > 5) { niv.Text = "Très bon joueur"; } else { niv.Text = "Compétitif"; } }
/** * Updates different labels of the view */ private void updateLabels() { LocalUser = StatistiquesGolf.getProfil(); username.Text = LocalUser.Username; index.Text = LocalUser.Index.ToString(); golfref.Text = LocalUser.GolfRef; photo.Source = "user" + LocalUser.Photo + ".png"; }
async protected override void OnAppearing() { if (this.allShots == null) { this.allShots = await StatistiquesGolf.getShots(); } this.updateChart(); this.updateAveragePutts(); this.updateNotableScores(); }
/* * Called when a golf course is picked by the user * This method ask the user whether he wants to load a not ended game or start a new one. Then the game is start */ private async void onGolfSelection(object sender, EventArgs e) { var g = ListGolfCourse.SelectedItem as GolfCourse; if (p == null)//if not in game part (if in stat part) { if (this.golfCourseStatPage == null) { this.golfCourseStatPage = new GolfCourseStatPage(g); } else { this.golfCourseStatPage.changeGolfCourse(g); } await Navigation.PushModalAsync(this.golfCourseStatPage, true); } else { p.GolfCourse = g; Func <Club, bool> f = (c => true); List <Club> clubselected = await GestionGolfs.getListClubsAsync(f); clubselected.RemoveAll(c => c.selected == false); //Checks if the user has at least one club on his bag if (clubselected.Count == 0) { await this.DisplayAlert("Erreur", "Vous n'avez aucun club dans votre sac. Veuillez en choisir au moins un dans le page 'Profil'", "ok"); } else { p.Clubs = clubselected; List <ScorePartie> scoreParties = await StatistiquesGolf.getNotFinishedGames(g); if (scoreParties.Count > 0) { var newGame = await this.DisplayAlert("Lancement d'une partie", "Voulez vous lancer une nouvelle partie ou charger une existante ?", "Nouvelle partie", "Charger une existante"); if (newGame) { await Navigation.PushAsync(new Game.MainGamePage(p), false); } else//if load a not ended game then show the list of not ended games { await Navigation.PushAsync(new ViewPartieListPage(2, scoreParties, p), false); } } else //if no not ended game then start a new one directly { await Navigation.PushAsync(new Game.MainGamePage(p), false); } } } }
/** * This method is executed when the page is loaded * */ async protected override void OnAppearing() { try { if (scoreParties == null) { //Sort in descending order of games date scoreParties = (await StatistiquesGolf.getScoreParties()).OrderByDescending(d => d.DateDebut).ToList(); } listPartie.ItemsSource = scoreParties; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error : " + e.StackTrace); } }
public OptionPage() { InitializeComponent(); DBConnection = DependencyService.Get <ISQLiteDb>().GetConnection(); profil = StatistiquesGolf.getProfil(); if (profil != null) { this.OnOff.IsToggled = profil.SaveStats; } else { this.OnOff.IsToggled = false; } UpdateSwitchLabel(); }
async protected override void OnAppearing() { if (this.allScoreHoles == null) { this.allScoreHoles = await StatistiquesGolf.getScoreHoles(); } this.updateChart(allScoreHoles); if (this.allScoreParties == null) { this.allScoreParties = await StatistiquesGolf.getScoreParties(); } this.updateGIR(allScoreParties); this.updateAveragePutts(allScoreHoles); this.updateWorstHole(allScoreHoles); }
private void updateAveragePar(List <ScorePartie> allScoreParties) { double avPars = StatistiquesGolf.getAveragePars(allScoreParties); if (avPars == -1.0) { this.averagePars.Text = NO_DATA; this.averagePars.TextColor = Color.Gray; this.averagePars.FontSize = 15; } else { this.averagePars.Text = "" + avPars.ToString("0.00"); this.averagePars.TextColor = Color.FromHex("#39B54A"); this.averagePars.FontSize = 30; } }
/** * Updates the average putts count labels */ private void updateAveragePutts(List <ScoreHole> allScoreHoles) { double avPutts = StatistiquesGolf.getAveragePutts(StatistiquesGolf.getScoreHoles(allScoreHoles, this.golfCourse)); if (avPutts == -1.0) { this.averagePutts.Text = GeneralStatPage.NO_DATA; this.averagePutts.TextColor = Color.Gray; this.averagePutts.FontSize = 15; } else { this.averagePutts.Text = "" + avPutts.ToString("0.00"); this.averagePutts.TextColor = Color.FromHex("#39B54A"); this.averagePutts.FontSize = 30; } }
/** * Updates the labels to display average putts count statistic */ private void updateAveragePutts() { double averagePutts = StatistiquesGolf.getAveragePutts(this.scorePartie.scoreHoles); if (averagePutts == -1.0) { this.averagePutt.Text = GeneralStatPage.NO_DATA; this.averagePutt.TextColor = Color.Gray; this.averagePutt.FontSize = 15; } else { this.averagePutt.Text = "" + averagePutts.ToString("0.00"); this.averagePutt.TextColor = Color.FromHex("#39B54A"); this.averagePutt.FontSize = 30; } }
/** * Updates the worst hole label */ private void updateWorstHole(List <ScoreHole> allScoreHoles) { int worstHoleNumber = StatistiquesGolf.getWorstHole(allScoreHoles, this.golfCourse); if (worstHoleNumber == 0) { this.worstHole.Text = GeneralStatPage.NO_DATA; this.worstHole.TextColor = Color.Gray; this.worstHole.FontSize = 15; } else { this.worstHole.Text = "" + worstHoleNumber; this.worstHole.TextColor = Color.FromHex("#39B54A"); this.worstHole.FontSize = 30; } }
private void updateMaxDistClubStat(List <Shot> allShots) { Tuple <string, int> maxDist = StatistiquesGolf.getMaxDistClub(allShots); if (maxDist.Item2 == 0.0) { this.maxDistClubLabel.Text = "Coup le plus long"; this.maxDistClub.Text = NO_DATA; this.maxDistClub.TextColor = Color.Gray; this.maxDistClub.FontSize = 15; } else { this.maxDistClubLabel.Text = maxDist.Item1 + " le plus long"; this.maxDistClub.Text = maxDist.Item2 + " m"; this.maxDistClub.TextColor = Color.FromHex("#39B54A"); this.maxDistClub.FontSize = 30; } }
/** * This method is called when clicking the button to end the game * The current holes is saved before ending the game */ private async void stopPartieClicked(object sender, EventArgs e) { if (partie.Shots.Count == 0)//checks if the current hole was played { await this.DisplayAlert("Erreur", "Vous devez avoir joué ce trou pour arrêter la partie ici", "Ok"); } else { //the user has to confirm his click var confirm = await this.DisplayAlert("Arrêter la partie", "Voulez vous vraiment arrêter la partie après ce trou ?", "Oui", "Non"); if (confirm) { MessagingCenter.Send <HoleFinishedPage, int>(this, "ReallyFinit", 2);//sends a message : the game is finished Profil profil = StatistiquesGolf.getProfil(); partie.holeFinished(profil.SaveStats); await Navigation.PopModalAsync(); } } }
/** * Updates the chart of the average distance of each club */ private async void updateChart(Func <Club, bool> f) { IEnumerable <Tuple <Club, double> > res = await StatistiquesGolf.getAverageDistanceForClubsAsync(f, null); List <Entry> entries = new List <Entry>(); foreach (Tuple <Club, double> couple in res) { Entry e = new Entry((float)couple.Item2) { Label = couple.Item1.Name, ValueLabel = couple.Item2.ToString("n2") + "m", Color = SKColor.Parse("#39B54A") }; entries.Add(e); } this.chartView.Chart = new PointChart() { Entries = entries, LabelTextSize = 33 }; }
/** * This method is called when clicking on the button to valid the current hole and go through the the next one */ private async void validButtonClicked(object sender, EventArgs e) { if (partie.Shots.Count == 0)//checks if at least one shot was performed { await DisplayAlert("0 coups rentrés", "Impossible de valider avec aucun shot", "OK"); return; } //the user has to confirm his click var confirm = await this.DisplayAlert("Trou sivant", "Passer au trou suivant ?", "Oui", "Non"); if (confirm) { MessagingCenter.Send <HoleFinishedPage, int>(this, "ReallyFinit", 1);//sends a message : the hole is finished next.IsEnabled = false; Profil profil = StatistiquesGolf.getProfil(); partie.holeFinished(profil.SaveStats); await Navigation.PopModalAsync(); next.IsEnabled = true; } }
/** * This method is called when clicking on the back button of his phone */ protected override bool OnBackButtonPressed() { Profil profil = StatistiquesGolf.getProfil(); System.Diagnostics.Debug.WriteLine(this.partie.holeFinishedCount); Device.BeginInvokeOnMainThread(async() => { //the user has to confirm his click if (await DisplayAlert("Quitter", "Voulez vous arreter cette partie maintenant ?", "Oui", "Non")) { if (profil.SaveStats)//check wether the user wants to save his stats or not (a switch in option page manages this choice) { if (this.partie.holeFinishedCount <= 0) { base.OnBackButtonPressed(); await Navigation.PopToRootAsync(); } else { if (await DisplayAlert("Sauvegarder", "Voulez vous sauvegarder cette partie ?", "Oui", "Non")) { await Navigation.PushAsync(new GameFinishedPage(partie)); } else { base.OnBackButtonPressed(); await Navigation.PopToRootAsync(); } } } else { base.OnBackButtonPressed(); await Navigation.PopToRootAsync(); } } }); return(true); }
async protected override void OnAppearing() { if (this.allGolfCourses == null) { this.allGolfCourses = await StatistiquesGolf.getGolfCourses(); } if (this.allScoreParties == null) { this.allScoreParties = await StatistiquesGolf.getScoreParties(); } this.updateLast4Scores(allGolfCourses, allScoreParties); if (this.allShots == null) { this.allShots = await StatistiquesGolf.getShots(); } this.updateMaxDistClubStat(allShots); if (this.allScoreHoles == null) { this.allScoreHoles = await StatistiquesGolf.getScoreHoles(); } this.updateAveragePutts(allScoreHoles); this.updateAveragePar(allScoreParties); }
/** * Updates the chart */ private void updateChart(List <ScoreHole> allScoreHoles) { /*float albatros = 0f;*/ float eagle = 0f; float birdie = 0f; float par = 0f; float bogey = 0f; float dbogey = 0f; float more = 0f; Dictionary <Hole.ScorePossible, float> d = StatistiquesGolf.getProportionScore(allScoreHoles, this.golfCourse); foreach (KeyValuePair <Hole.ScorePossible, float> k in d) { /*if (k.Key.Equals(Hole.ScorePossible.ALBATROS)) * { * albatros = k.Value; * }*/ if (k.Key.Equals(Hole.ScorePossible.BIRDIE)) { birdie = k.Value; } if (k.Key.Equals(Hole.ScorePossible.BOGEY)) { bogey = k.Value; } if (k.Key.Equals(Hole.ScorePossible.DOUBLE_BOUGEY)) { dbogey = k.Value; } if (k.Key.Equals(Hole.ScorePossible.EAGLE)) { eagle = k.Value; } if (k.Key.Equals(Hole.ScorePossible.MORE)) { more = k.Value; } if (k.Key.Equals(Hole.ScorePossible.PAR)) { par = k.Value; } } var entries = new[] { /*new Entry(albatros) * { * Label = "Albatros", * ValueLabel =float.IsNaN(albatros)?"N/A":(albatros.ToString("n2") +"%"), * Color = SKColor.Parse("#0BF5A3") * },*/ new Entry(eagle) { Label = "Eagle", ValueLabel = float.IsNaN(eagle)?"N/A": (eagle.ToString("n2")), Color = SKColor.Parse("#0BF5A3") }, new Entry(birdie) { Label = "Birdie", ValueLabel = float.IsNaN(birdie)?"N/A":(birdie.ToString("n2")), Color = SKColor.Parse("#0BF54E") }, new Entry(par) { Label = "Par", ValueLabel = float.IsNaN(par)?"N/A":(par.ToString("n2")), Color = SKColor.Parse("#44F50B") }, new Entry(bogey) { Label = "Bogey", ValueLabel = float.IsNaN(bogey)?"N/A":(bogey.ToString("n2")), Color = SKColor.Parse("#C0F50B") }, new Entry(dbogey) { Label = "Dbl-Bogey", ValueLabel = float.IsNaN(dbogey)?"N/A":(dbogey.ToString("n2")), Color = SKColor.Parse("#F5A00B") }, new Entry(more) { Label = "More", ValueLabel = float.IsNaN(more)?"N/A":(more.ToString("n2")), Color = SKColor.Parse("#F5340B") }, }; this.chartView.Chart = new BarChart() { Entries = entries, LabelTextSize = 26, MaxValue = this.golfCourse.Holes.Count, ValueLabelOrientation = Orientation.Horizontal, LabelOrientation = Orientation.Horizontal }; }
/** * Updates notable scores */ private void updateNotableScores() { Dictionary <string, int> notableScores = new Dictionary <string, int>(); List <Shot> ulgss = StatistiquesGolf.getShotsFromPartie(this.scorePartie, this.allShots).Where(sh => sh.ShotType.Equals(Shot.ShotCategory.UnexpectedLongShot)).ToList(); string key = "UnbelievableUnexpectedShot"; double max = 0.0; double currentDist = 0.0; int i = 0; int girCount = 0; double index = StatistiquesGolf.getPlayerIndex(); int averageScorePerHole = (int)Math.Round(index / 18.0); //fills the dictionnary of relevent scores foreach (Shot shot in ulgss)//manages unbelievable unexpected shot index { currentDist = shot.RealShotDist(); if (currentDist > max) { max = currentDist; notableScores[key] = i; } i++; } foreach (ScoreHole sh in this.scorePartie.scoreHoles) { if (sh.Score >= averageScorePerHole + 2)//manages bad scores count { key = "More"; incrementDicoKey(notableScores, key); } else if (sh.Score <= 0) //manages great scores count { key = "" + sh.Score; incrementDicoKey(notableScores, key); } if (sh.NombrePutt == 0)//manages approaches in count { key = "approachIn"; incrementDicoKey(notableScores, key); } if (sh.NombrePutt == 1)//manages one putt count { key = "onePutt"; incrementDicoKey(notableScores, key); } if (sh.Hit)//manages green in regulation count { girCount++; } } int minScoreCount = 2;//for 9 holes or less if (this.scorePartie.scoreHoles.Count > 9) { minScoreCount = 4; } //checks if there are enought bad scores so that is relevent if (notableScores.ContainsKey("More")) { if (notableScores["More"] < minScoreCount) { notableScores.Remove("More"); } } //checks if there are enought pars so that is relevent if (notableScores.ContainsKey("0")) { int courseSizeMult = this.scorePartie.scoreHoles.Count / 9;//constants variate if it's a 9 or 18 holes int parMinCount = this.scorePartie.scoreHoles.Count - averageScorePerHole * 3 * courseSizeMult; if (averageScorePerHole == 0) { parMinCount = this.scorePartie.scoreHoles.Count - 2 * courseSizeMult; } if (parMinCount >= 1) { if (notableScores["0"] < parMinCount) { notableScores.Remove("0"); } } } //checks if there are enought one putt so that is relevent if (notableScores.ContainsKey("onePutt")) { if (notableScores["onePutt"] < minScoreCount) { notableScores.Remove("onePutt"); } } //choses the more relevent scores int chosenCount = 0; i = 0; if (notableScores.Keys.Count > 1) { this.notableScore2Frame.IsVisible = true; this.notableScore2Label.IsVisible = true; for (int j = -3; j < 0; ++j) //choses between albatros eagle and birdie { if (notableScores.ContainsKey("" + j)) //albatros { updateNotableLabel(averageScorePerHole, this.notableScore1, this.notableScore1Label, "" + j, ulgss, notableScores); chosenCount++; break; } } Label notForScore = this.notableScore1; Label notForScoreLabel = this.notableScore1Label; if (chosenCount == 1) { notForScore = this.notableScore2; notForScoreLabel = this.notableScore2Label; } //choses one between the ones left if (notableScores.ContainsKey("approachIn")) { updateNotableLabel(averageScorePerHole, notForScore, notForScoreLabel, "approachIn", ulgss, notableScores); chosenCount++; } else if (notableScores.ContainsKey("onePutt")) { updateNotableLabel(averageScorePerHole, notForScore, notForScoreLabel, "onePutt", ulgss, notableScores); chosenCount++; } else if (notableScores.ContainsKey("UnbelievableUnexpectedShot")) { updateNotableLabel(averageScorePerHole, notForScore, notForScoreLabel, "UnbelievableUnexpectedShot", ulgss, notableScores); chosenCount++; } if (chosenCount < 2) { if (chosenCount == 0)//if par and more are left -> display GIR on the first labels { this.updateGIR(girCount); if (notableScores.ContainsKey("More")) { updateNotableLabel(averageScorePerHole, this.notableScore2, this.notableScore2Label, "More", ulgss, notableScores); } } else { if (notableScores.ContainsKey("More")) { updateNotableLabel(averageScorePerHole, this.notableScore2, this.notableScore2Label, "More", ulgss, notableScores); } else if (notableScores.ContainsKey("0")) { updateNotableLabel(averageScorePerHole, this.notableScore2, this.notableScore2Label, "0", ulgss, notableScores); } else { updateGIR(this.notableScore2, this.notableScore2Label, girCount); } } } } else { this.updateGIR(girCount); if (notableScores.Keys.Count == 1) { updateNotableLabel(averageScorePerHole, this.notableScore2, this.notableScore2Label, notableScores.Keys.First(), ulgss, notableScores); this.notableScore2Frame.IsVisible = true; this.notableScore2Label.IsVisible = true; } else //nothing notable { this.notableScore2Frame.IsVisible = false; this.notableScore2Label.IsVisible = false; } } }
private void updateLast4Scores(List <GolfCourse> allGolfCourses, List <ScorePartie> allScoreParties) { int index = (int)StatistiquesGolf.getPlayerIndex(); int rowCount = last4ScoresGrid.Children.Count / 3; var scores = allScoreParties.OrderByDescending(d => d.DateDebut).ToList(); int col = 0; int row = 0; foreach (View label in last4ScoresGrid.Children) { if (row > 0) { switch (col) { case 0: //column golf name if (row <= scores.Count) { string courseName = ""; string id = scores[row - 1].scoreHoles[0].IdHole; foreach (GolfCourse gc in allGolfCourses) { foreach (Hole h in gc.Holes) { if (h.Id.Equals(id)) { courseName = gc.Name; break; } } } ((Label)label).Text = courseName; } else { ((Label)label).Text = NO_DATA_LIST; } break; case 1: //column date if (row <= scores.Count) { ((Label)label).Text = "" + scores[row - 1].DateString; } else { ((Label)label).Text = NO_DATA_LIST; } break; case 2: //column score if (row <= scores.Count) { Tuple <int, int> score = scores[row - 1].GetScore(); int perf = (int)((double)score.Item1 / (double)score.Item2 * 18.0) - index; ((Label)label).Text = ((score.Item1 >= 0) ? "+" : "") + score.Item1 + " / " + score.Item2 + " trous"; if (perf == 0) //you played your index { ((Label)label).TextColor = Color.Gray; } else if (perf < 0) //you played better than your index { ((Label)label).TextColor = Color.Green; } else if (perf < 10) //you played worse than your index { ((Label)label).TextColor = Color.Orange; } else //you played than your index { ((Label)label).TextColor = Color.Red; } } else { ((Label)label).Text = NO_DATA_LIST; } break; default: break; } row++; if (row == rowCount) { row = 0; col++; } } else { row++; } } }
/** * Updates the chart */ private void updateChart() { List <Shot> allNeededShots = this.allShots.Where(sh => sh.Date >= scorePartie.DateDebut && sh.Date <= scorePartie.DateFin).ToList(); Dictionary <Shot.ShotCategory, int> dico = StatistiquesGolf.getProportionShot(allNeededShots); int shotCount = 0; foreach (Shot.ShotCategory sc in dico.Keys) { if (!sc.Equals(Shot.ShotCategory.ChipShot)) { shotCount += dico[sc]; } } var entries = new[] { new Entry(dico[Shot.ShotCategory.PerfectShot]) { Label = "CP", ValueLabel = dico[Shot.ShotCategory.PerfectShot].ToString(), Color = SKColor.Parse("#0BF5A3") }, new Entry(dico[Shot.ShotCategory.GoodShot]) { Label = "BC", ValueLabel = dico[Shot.ShotCategory.GoodShot].ToString(), Color = SKColor.Parse("#44F50B") }, new Entry(dico[Shot.ShotCategory.TolerableShot]) { Label = "CA", ValueLabel = dico[Shot.ShotCategory.TolerableShot].ToString(), Color = SKColor.Parse("#F5A00B") }, new Entry(dico[Shot.ShotCategory.UnexpectedLongShot]) { Label = "LCI", ValueLabel = dico[Shot.ShotCategory.UnexpectedLongShot].ToString(), Color = SKColor.Parse("#F9E65E") }, new Entry(dico[Shot.ShotCategory.NotStraightShot]) { Label = "CD", ValueLabel = dico[Shot.ShotCategory.NotStraightShot].ToString(), Color = SKColor.Parse("#F5340B") }, new Entry(dico[Shot.ShotCategory.FailedShot]) { Label = "CR", ValueLabel = dico[Shot.ShotCategory.FailedShot].ToString(), Color = SKColor.Parse("#818181") }, new Entry(dico[Shot.ShotCategory.PenalityShot]) { Label = "CdP", ValueLabel = dico[Shot.ShotCategory.PenalityShot].ToString(), Color = SKColor.Parse("#313030") }, }; this.chartView.Chart = new BarChart() { Entries = entries, LabelTextSize = 36, MaxValue = shotCount, ValueLabelOrientation = Orientation.Horizontal, LabelOrientation = Orientation.Horizontal }; }