private void SendButton_Clicked(object sender, EventArgs e) { int progress = 0; try { if (type == App.TypeExercises.Count) { progress = int.Parse((ResultStackLayout.Children[0] as Entry).Text); var exercisesCountTableRepository = new ExercisesCountTableRepository(Path.Combine(DBSaverLoader.documentsPath, App.Database.GetItem(Exercises.CurrentExercisesId).StringID + ".db")); exercisesCountTableRepository.SaveItem(new ExercisesCountTable { Count = progress, Data = DateTime.Now }); int count = exercisesCountTableRepository.Count; if (count > App.Pivot) { exercisesCountTableRepository.DeleteFirst(); } } else if (type == App.TypeExercises.Approach) { string result = ""; int Count = ResultStackLayout.Children.Count; for (int i = 0; i < Count - 2; i++) { result += string.Format($"{(ResultStackLayout.Children[i] as Entry).Text}/"); } result += (ResultStackLayout.Children[Count - 2] as Entry).Text; var exercisesApproachTableRepository = new ExercisesApproachTableRepository(Path.Combine(DBSaverLoader.documentsPath, App.Database.GetItem(Exercises.CurrentExercisesId).StringID + ".db")); exercisesApproachTableRepository.SaveItem(new ExercisesApproachTable { Count = result, Data = DateTime.Now }); int count = exercisesApproachTableRepository.Count; if (count > App.Pivot) { exercisesApproachTableRepository.DeleteFirst(); } } else if (type == App.TypeExercises.Time) { progress = int.Parse(TimeResult); var exercisesTimeTableRepository = new ExercisesTimeTableRepository(Path.Combine(DBSaverLoader.documentsPath, App.Database.GetItem(Exercises.CurrentExercisesId).StringID + ".db")); exercisesTimeTableRepository.SaveItem(new ExercisesTimeTable { Count = new TimeSpan(0, 0, progress), Data = DateTime.Now }); int count = exercisesTimeTableRepository.Count; if (count > App.Pivot) { exercisesTimeTableRepository.DeleteFirst(); } } } catch (Exception) { } Navigation.PushAsync(new StatisticPage()); }
private void PrintInfoExercises() { if (mainTable.Type == (byte)App.TypeExercises.Count) { ExercisesCountTableRepository exercisesCountTableRepository = new ExercisesCountTableRepository(Path.Combine(DBSaverLoader.documentsPath, mainTable.StringID + ".db")); if (exerciseByDataViewModel.exerciseInfoByDates.Count != exercisesCountTableRepository.Count) { exerciseByDataViewModel.exerciseInfoByDates.Clear(); } int tableCount = exercisesCountTableRepository.Count; if (tableCount != 0) { ExerciseName.Text = mainTable.Name; double percent = 0.0; int progress = 0; var arrayExercisesCountTable = exercisesCountTableRepository.GetItems(); if (tableCount >= 2) { percent = GetPercent(mainTable.Purpose, arrayExercisesCountTable[arrayExercisesCountTable.Length - 1].Count); progress = arrayExercisesCountTable[arrayExercisesCountTable.Length - 1].Count - arrayExercisesCountTable[arrayExercisesCountTable.Length - 2].Count; } if (tableCount == 1) { percent = GetPercent(mainTable.Purpose, arrayExercisesCountTable[arrayExercisesCountTable.Length - 1].Count); } PercentSFCircularGaugeLabel.Text = ((int)percent).ToString() + "%"; ProgresSFCircularGauge.Value = (int)percent; CheckForProgress(ProgresLabelWithConclusion, ProgresSFCircularGauge, ProgresLabel, progress); ProgresLabel.Text = $"{arrayExercisesCountTable[arrayExercisesCountTable.Length - 1].Count}/{mainTable.Purpose}"; int CountOfExForChart = tableCount <= 20 ? tableCount : 20; for (int i = 0, j = tableCount - 1; i < CountOfExForChart; i++, j--) { var exerciseHist = arrayExercisesCountTable[j]; var dataHist = exerciseHist.Data.ToString(); var percentHist = (int)GetPercent(mainTable.Purpose, arrayExercisesCountTable[j].Count); ExerciseByDataStackLayout.Children.Add(CreateNewItem(dataHist, percentHist, arrayExercisesCountTable[j].Count.ToString())); } CountOfExForChart = tableCount <= 10 ? tableCount : 10; int TableCount = tableCount - CountOfExForChart; for (int i = CountOfExForChart - 1; i >= 0; --i) { var exerciseHist = arrayExercisesCountTable[TableCount]; if ((exerciseByDataViewModel.exerciseInfoByDates.Count != tableCount) && exerciseHist.Data.Month == DateTime.Now.Month) { exerciseByDataViewModel.exerciseInfoByDates.Add(new ExerciseInfoByDate() { Data = exerciseHist.Data.Day.ToString() + "/" + exerciseHist.Data.Month.ToString(), Count = exerciseHist.Count, Purpose = int.Parse(mainTable.Purpose) }); } TableCount++; } } } else if (mainTable.Type == (byte)App.TypeExercises.Approach) { ExercisesApproachTableRepository exercisesApproachTableRepository = new ExercisesApproachTableRepository(Path.Combine(DBSaverLoader.documentsPath, mainTable.StringID + ".db")); if (exerciseByDataViewModel.exerciseInfoByDates.Count != exercisesApproachTableRepository.Count) { exerciseByDataViewModel.exerciseInfoByDates.Clear(); } int tableCount = exercisesApproachTableRepository.Count; if (tableCount != 0) { ExerciseName.Text = mainTable.Name; double percent = 0.0; int progress = 0; var arrayExercisesApproachTable = exercisesApproachTableRepository.GetItems(); int Purpose = GetSum(mainTable.Purpose); int LastCount = GetSum(arrayExercisesApproachTable[arrayExercisesApproachTable.Length - 1].Count); if (tableCount >= 2) { percent = GetPercent(Purpose, LastCount); progress = LastCount - GetSum(arrayExercisesApproachTable[arrayExercisesApproachTable.Length - 2].Count); } if (tableCount == 1) { percent = GetPercent(Purpose, LastCount); } PercentSFCircularGaugeLabel.Text = ((int)percent).ToString() + "%"; ProgresSFCircularGauge.Value = (int)percent; CheckForProgress(ProgresLabelWithConclusion, ProgresSFCircularGauge, ProgresLabel, progress); ProgresLabel.Text = $"{LastCount}/{Purpose}"; int CountOfExForChart = tableCount <= 20 ? tableCount : 20; for (int i = 0, j = tableCount - 1; i < CountOfExForChart; i++, j--) { LastCount = GetSum(arrayExercisesApproachTable[j].Count); var exerciseHist = arrayExercisesApproachTable[j]; var dataHist = $"{exerciseHist.Data.ToString()}\n{arrayExercisesApproachTable[j].Count}"; int count = GetSum(arrayExercisesApproachTable[j].Count); var percentHist = (int)GetPercent(Purpose, count); ExerciseByDataStackLayout.Children.Add(CreateNewItem(dataHist, percentHist, $"{LastCount}")); } CountOfExForChart = tableCount <= 10 ? tableCount : 10; int TableCount = tableCount - CountOfExForChart; for (int i = CountOfExForChart - 1; i >= 0; --i) { var exerciseHist = arrayExercisesApproachTable[TableCount]; int count = GetSum(arrayExercisesApproachTable[TableCount].Count); if ((exerciseByDataViewModel.exerciseInfoByDates.Count != tableCount) && exerciseHist.Data.Month == DateTime.Now.Month) { exerciseByDataViewModel.exerciseInfoByDates.Add(new ExerciseInfoByDate() { Data = exerciseHist.Data.Day.ToString() + "/" + exerciseHist.Data.Month.ToString(), Count = count, Purpose = Purpose }); } TableCount++; } } } else if (mainTable.Type == (byte)App.TypeExercises.Time) { ExercisesTimeTableRepository exercisesTimeTableRepository = new ExercisesTimeTableRepository(Path.Combine(DBSaverLoader.documentsPath, mainTable.StringID + ".db")); if (exerciseByDataViewModel.exerciseInfoByDates.Count != exercisesTimeTableRepository.Count) { exerciseByDataViewModel.exerciseInfoByDates.Clear(); } int tableCount = exercisesTimeTableRepository.Count; if (tableCount != 0) { ExerciseName.Text = mainTable.Name; double percent = 0.0; TimeSpan progress = new TimeSpan(0, 0, 0); var arrayExercisesCountTable = exercisesTimeTableRepository.GetItems(); if (tableCount >= 2) { percent = GetPercent(mainTable.Purpose, arrayExercisesCountTable[arrayExercisesCountTable.Length - 1].Count.TotalSeconds); progress = arrayExercisesCountTable[arrayExercisesCountTable.Length - 1].Count - arrayExercisesCountTable[arrayExercisesCountTable.Length - 2].Count; } if (tableCount == 1) { percent = GetPercent(mainTable.Purpose, arrayExercisesCountTable[arrayExercisesCountTable.Length - 1].Count.TotalSeconds); } PercentSFCircularGaugeLabel.Text = ((int)percent).ToString() + "%"; ProgresSFCircularGauge.Value = (int)percent; CheckForProgress(ProgresLabelWithConclusion, ProgresSFCircularGauge, ProgresLabel, (int)progress.TotalSeconds, true); ProgresLabel.Text = $"{arrayExercisesCountTable[arrayExercisesCountTable.Length - 1].Count}/\n{new TimeSpan(0,0, int.Parse(mainTable.Purpose)).ToString()}"; int CountOfExForChart = tableCount <= 20 ? tableCount : 20; for (int i = 0, j = tableCount - 1; i < CountOfExForChart; i++, j--) { var exerciseHist = arrayExercisesCountTable[j]; var dataHist = exerciseHist.Data.ToString(); var percentHist = (int)GetPercent(mainTable.Purpose, arrayExercisesCountTable[j].Count.TotalSeconds); ExerciseByDataStackLayout.Children.Add(CreateNewItem(dataHist, percentHist, arrayExercisesCountTable[j].Count.ToString())); } CountOfExForChart = tableCount <= 10 ? tableCount : 10; int TableCount = tableCount - CountOfExForChart; for (int i = CountOfExForChart - 1; i >= 0; --i) { var exerciseHist = arrayExercisesCountTable[TableCount]; if ((exerciseByDataViewModel.exerciseInfoByDates.Count != tableCount) && exerciseHist.Data.Month == DateTime.Now.Month) { exerciseByDataViewModel.exerciseInfoByDates.Add(new ExerciseInfoByDate() { Data = exerciseHist.Data.Day.ToString() + "/" + exerciseHist.Data.Month.ToString(), Count = (int)exerciseHist.Count.TotalSeconds, Purpose = int.Parse(mainTable.Purpose) }); } TableCount++; } } } }
private StackLayout AddStatisticByExercise(MainTable mainTable) { int progress = 0; double percent = 0.0; if (mainTable.Type == (byte)App.TypeExercises.Count) { ExercisesCountTableRepository exercisesCountTableRepository = new ExercisesCountTableRepository(Path.Combine(DBSaverLoader.documentsPath, mainTable.StringID + ".db")); int exercisesTableLength = exercisesCountTableRepository.Count; if (exercisesTableLength == 0) { return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, 0, 0.0, "count.jpg")); } ExercisesCountTable lastItem = exercisesCountTableRepository.GetItem(exercisesCountTableRepository.StartPosition + exercisesTableLength - 1); double purpose = double.Parse(mainTable.Purpose); if (exercisesTableLength >= 2) { ExercisesCountTable penultItem = exercisesCountTableRepository.GetItem(exercisesCountTableRepository.StartPosition + exercisesTableLength - 2); progress = lastItem.Count - penultItem.Count; percent = (double)lastItem.Count / purpose * 100.0; } if (exercisesTableLength == 1) { percent = (double)lastItem.Count / purpose * 100.0; } } else if (mainTable.Type == (byte)App.TypeExercises.Approach) { ExercisesApproachTableRepository exercisesApproachTableRepository = new ExercisesApproachTableRepository(Path.Combine(DBSaverLoader.documentsPath, mainTable.StringID + ".db")); int exercisesTableLength = exercisesApproachTableRepository.Count; if (exercisesTableLength == 0) { return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, 0, 0.0, "approach.jpg")); } int lastItem = (from item in exercisesApproachTableRepository.GetItem(exercisesApproachTableRepository.StartPosition + exercisesTableLength - 1).Count.Split('/') select int.Parse(item)).Sum(); double purpose = (from item in mainTable.Purpose.Split('/') select double.Parse(item)).Sum(); if (exercisesTableLength >= 2) { int penultItem = (from item in exercisesApproachTableRepository.GetItem(exercisesApproachTableRepository.StartPosition + exercisesTableLength - 2).Count.Split('/') select int.Parse(item)).Sum(); progress = lastItem - penultItem; percent = (double)lastItem / purpose * 100.0; } if (exercisesTableLength == 1) { percent = (double)lastItem / purpose * 100.0; } } else if (mainTable.Type == (byte)App.TypeExercises.Time) { ExercisesTimeTableRepository exercisesTimeTableRepository = new ExercisesTimeTableRepository(Path.Combine(DBSaverLoader.documentsPath, mainTable.StringID + ".db")); int exercisesTableLength = exercisesTimeTableRepository.Count; TimeSpan progressTime = new TimeSpan(0, 0, 0); if (exercisesTableLength == 0) { return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, 0, 0.0, "timer.jpg")); } ExercisesTimeTable lastItem = exercisesTimeTableRepository.GetItem(exercisesTimeTableRepository.StartPosition + exercisesTableLength - 1); double purpose = double.Parse(mainTable.Purpose); if (exercisesTableLength >= 2) { ExercisesTimeTable penultItem = exercisesTimeTableRepository.GetItem(exercisesTimeTableRepository.StartPosition + exercisesTableLength - 2); progressTime = lastItem.Count - penultItem.Count; percent = (double)lastItem.Count.TotalSeconds / purpose * 100.0; } if (exercisesTableLength == 1) { percent = (double)lastItem.Count.TotalSeconds / purpose * 100.0; } return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, (int)progressTime.TotalSeconds, percent, "timer.jpg", true)); } string photo = ""; if (mainTable.Type == (byte)App.TypeExercises.Time) { photo = "timer.jpg"; } if (mainTable.Type == (byte)App.TypeExercises.Approach) { photo = "approach.jpg"; } if (mainTable.Type == (byte)App.TypeExercises.Count) { photo = "count.jpg"; } return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, progress, percent, photo)); }