Beispiel #1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            DateTimeOffset now        = DateTimeOffset.Now;
            TimeSpan       span       = now - App.startTime;
            String         timeString = span.ToString(@"hh\:mm");

            Time.Text            += timeString;
            NumOfEx.Text         += WorkoutSummaryParams.numberOfExercisesPerformed.ToString() + "/" + WorkoutSummaryParams.numberOfExercisesTotal.ToString();
            heartRate.Text       += HeartRateModel.getAverage();
            peak_heart_rate.Text += HeartRateModel.getPeak();
            calories.Text        += CaloriesModel.calories;

            var prevWorkoutsStatistics    = App.UserWorkoutStatistics.FindAll(stat => stat.UserId.Equals(MainDashboard.CurrentUser.Id) && stat.WorkoutId.Equals(WorkoutSummaryParams.WorkoutId));
            var otherUsersStatisticsCount = App.UserWorkoutStatistics.FindAll(stat => stat.WorkoutId.Equals(WorkoutSummaryParams.WorkoutId)).Count;


            m_prevWorkoutsStatistics = prevWorkoutsStatistics;

            if (prevWorkoutsStatistics.Count != 0)
            {
                var overallTime = span.TotalMinutes;

                var prevWorkoutsExNumPerformedAverage = Utils.CalculatePrevWorkoutsExNumAverage(prevWorkoutsStatistics);

                var prevWorkoutsPerformanceTimeAvarage = Utils.CalculatePrevWorkoutsPerformanceTimeAverage(prevWorkoutsStatistics);

                if (WorkoutSummaryParams.numberOfExercisesPerformed > prevWorkoutsExNumPerformedAverage)
                {
                    CompareToStat.Text    = "Great job! You completed more exercises than your previous workouts! Keep going!";
                    NumOfEx.Foreground    = new SolidColorBrush(Colors.Green);
                    feedback_image.Source = new BitmapImage(new Uri("ms-appx:///Images/gold.png"));
                }
                else if (WorkoutSummaryParams.numberOfExercisesPerformed < prevWorkoutsExNumPerformedAverage)
                {
                    CompareToStat.Text    = "You completed less exercises than your previous workouts. You can do better than this. Try pushing a little harder next time!";
                    NumOfEx.Foreground    = new SolidColorBrush(Colors.Red);
                    feedback_image.Source = new BitmapImage(new Uri("ms-appx:///Images/bronze.png"));
                }
                else if (prevWorkoutsPerformanceTimeAvarage > overallTime)
                {
                    CompareToStat.Text    = "Great job! Your overall workout time has decreased from previous workouts! Keep going!";
                    Time.Foreground       = new SolidColorBrush(Colors.Green);
                    feedback_image.Source = new BitmapImage(new Uri("ms-appx:///Images/gold.png"));
                }
                else
                {
                    CompareToStat.Text    = "Your overall workout time was higher from previous workouts. You can do better than this. Try pushing A little harder next time!";
                    Time.Foreground       = new SolidColorBrush(Colors.Red);
                    feedback_image.Source = new BitmapImage(new Uri("ms-appx:///Images/bronze.png"));
                }


                UserStatistics.Visibility = Visibility.Visible;
            }
            else
            {
                CompareToStat.Text    = "Great job! You finished this workout for the first time! Train next week and see your improvments.";
                feedback_image.Source = new BitmapImage(new Uri("ms-appx:///Images/gold.png"));
            }

            if (otherUsersStatisticsCount > 0)
            {
                OtherUsersStatistics.Visibility = Visibility.Visible;
            }

            var newWorkoutStatistics = new UserWorkoutStatistics()
            {
                Id        = Guid.NewGuid().ToString(),
                WorkoutId = WorkoutSummaryParams.WorkoutId,
                UserId    = MainDashboard.CurrentUser.Id,
                PerformanceTimeAvarage  = span.TotalMinutes,
                GeneralColumn1          = WorkoutSummaryParams.numberOfExercisesPerformed,
                PerformanceNumberCount  = prevWorkoutsStatistics.Count > 0 ? prevWorkoutsStatistics.Max(stat => stat.PerformanceNumberCount) + 1 : 1,
                HeartReatAvarage        = HeartRateModel.getAverage(),
                MaximalHeartRateAvarage = HeartRateModel.getPeak(),
                CaloriesBurnedAvarage   = CaloriesModel.calories,
            };

            if (App.updateStatistics)
            {
                await App.UserWorkoutStatisticsTable.InsertAsync(newWorkoutStatistics);

                App.UserWorkoutStatistics = await App.UserWorkoutStatisticsTable.ToListAsync();
            }



            App.updateStatistics = false;
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            var workoutId = UserWorkoutStaticsParams.WorkoutId;

            m_workout = await App.DefaultWorkoutsTable.LookupAsync(workoutId);

            if (UserWorkoutStaticsParams.Myself)
            {
                Title.Text          = "Previous Workouts Statistics";
                m_workoutStatistics = App.UserWorkoutStatistics.FindAll(stat => stat.UserId.Equals(MainDashboard.CurrentUser.Id) && stat.WorkoutId.Equals(workoutId));
                m_workoutStatistics.Sort(delegate(UserWorkoutStatistics x, UserWorkoutStatistics y)
                {
                    return((int)(x.PerformanceNumberCount - y.PerformanceNumberCount));
                });
            }
            else
            {
                Title.Text          = "Other Trainers Statistics";
                m_workoutStatistics = App.UserWorkoutStatistics.FindAll(stat => !stat.UserId.Equals(MainDashboard.CurrentUser.Id) && stat.WorkoutId.Equals(workoutId));
                m_workoutStatistics.Sort(delegate(UserWorkoutStatistics x, UserWorkoutStatistics y)
                {
                    return((int)(x.PerformanceNumberCount - y.PerformanceNumberCount));
                });
                int max = m_workoutStatistics.ElementAt(m_workoutStatistics.Count - 1).PerformanceNumberCount;
                List <UserWorkoutStatistics> averageStatistics = new List <UserWorkoutStatistics>();

                for (int i = 1; i <= max; i++)
                {
                    List <UserWorkoutStatistics> statisticsForIndex = m_workoutStatistics.FindAll(stat => stat.PerformanceNumberCount == i);
                    if (statisticsForIndex.Count() != 0)
                    {
                        UserWorkoutStatistics averageStatisticsForIndex = new UserWorkoutStatistics();
                        averageStatisticsForIndex.PerformanceTimeAvarage  = Utils.CalculatePrevWorkoutsPerformanceTimeAverage(statisticsForIndex);
                        averageStatisticsForIndex.GeneralColumn1          = Utils.CalculatePrevWorkoutsExNumAverage(statisticsForIndex);
                        averageStatisticsForIndex.HeartReatAvarage        = Utils.CalculatePrevWorkoutsAverageHeartRateAverage(statisticsForIndex);
                        averageStatisticsForIndex.MaximalHeartRateAvarage = Utils.CalculatePrevWorkoutsPeakHeartRateAverage(statisticsForIndex);
                        averageStatisticsForIndex.CaloriesBurnedAvarage   = Utils.CalculatePrevWorkoutsCaloriesAverage(statisticsForIndex);
                        averageStatistics.Add(averageStatisticsForIndex);
                    }
                }

                m_workoutStatistics = averageStatistics;
            }

            if (m_workoutStatistics.Count == 0)
            {
                var dialog = new MessageDialog("No statistics found");
                dialog.Commands.Add(new UICommand("Return"));
                await dialog.ShowAsync();

                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.GoBack();
            }
            else
            {
                TimeSpan span = TimeSpan.FromMinutes(Utils.CalculatePrevWorkoutsPerformanceTimeAverage(m_workoutStatistics));

                Time.Text            += span.ToString(@"hh\:mm");
                NumOfEx.Text         += Utils.CalculatePrevWorkoutsExNumAverage(m_workoutStatistics).ToString() + "/" + (m_workout.ExercisesIds.Split(';').Count());
                heartRate.Text       += Utils.CalculatePrevWorkoutsAverageHeartRateAverage(m_workoutStatistics);
                peak_heart_rate.Text += Utils.CalculatePrevWorkoutsPeakHeartRateAverage(m_workoutStatistics);
                calories.Text        += Utils.CalculatePrevWorkoutsCaloriesAverage(m_workoutStatistics);

                List <Records> timeRecords = new List <Records>();
                for (int i = 0; i < m_workoutStatistics.Count; i++)
                {
                    timeRecords.Add(new Records()
                    {
                        Name = "" + (i + 1), Amount = (int)m_workoutStatistics.ElementAt(i).PerformanceTimeAvarage
                    });
                }

                List <Records> exercisesAmountRecords = new List <Records>();
                for (int i = 0; i < m_workoutStatistics.Count; i++)
                {
                    exercisesAmountRecords.Add(new Records()
                    {
                        Name = "" + (i + 1), Amount = (int)(m_workoutStatistics.ElementAt(i).GeneralColumn1 / (m_workout.ExercisesIds.Split(';').Count()) * 100)
                    });
                }

                List <Records> heartRatesRecords = new List <Records>();
                for (int i = 0; i < m_workoutStatistics.Count; i++)
                {
                    heartRatesRecords.Add(new Records()
                    {
                        Name = "" + (i + 1), Amount = (int)m_workoutStatistics.ElementAt(i).HeartReatAvarage
                    });
                }

                List <Records> peakHeartRatesRecords = new List <Records>();
                for (int i = 0; i < m_workoutStatistics.Count; i++)
                {
                    peakHeartRatesRecords.Add(new Records()
                    {
                        Name = "" + (i + 1), Amount = (int)m_workoutStatistics.ElementAt(i).MaximalHeartRateAvarage
                    });
                }

                (LineChart.Series[0] as LineSeries).ItemsSource = timeRecords;
                (LineChart.Series[1] as LineSeries).ItemsSource = exercisesAmountRecords;
                (LineChart.Series[2] as LineSeries).ItemsSource = heartRatesRecords;
                (LineChart.Series[3] as LineSeries).ItemsSource = peakHeartRatesRecords;
            }
        }
Beispiel #3
0
 public static UserWorkoutStatistics GetUserWorkoutStatisticsCopyWithDifferentId(UserWorkoutStatistics source)
 {
     return(new UserWorkoutStatistics()
     {
         UserId = source.UserId,
         WorkoutId = source.WorkoutId,
         CaloriesBurnedAvarage = source.CaloriesBurnedAvarage,
         DistanceAvarage = source.DistanceAvarage,
         GalvanicResponseAvarage = source.GalvanicResponseAvarage,
         GeneralColumn1 = source.GeneralColumn1,
         GeneralColumns2 = source.GeneralColumns2,
         Id = Guid.NewGuid().ToString(),
         HeartReatAvarage = source.HeartReatAvarage,
         MaximalHeartRateAvarage = source.MaximalHeartRateAvarage,
         PerformanceNumberCount = source.PerformanceNumberCount,
         PerformanceTimeAvarage = source.PerformanceTimeAvarage,
         StepsAvarage = source.StepsAvarage
     });
 }