Ejemplo n.º 1
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            var workouts = await _workoutsRepository.AllAsync();

            var exercises = await _exercisesRepository.AllAsync();

            var chartsPage = new ChartsPage(_componentContext, _messagingService, exercises, workouts);

            Children.Add(chartsPage);

            var exerciseStatsPage = new ExerciseStatsPage(_componentContext, _screenSizeHandler, exercises, workouts);

            Children.Add(exerciseStatsPage);
        }
        private async Task <ObservableCollection <ExerciseItem> > GetExercises()
        {
            var collection = new ObservableCollection <ExerciseItem>();
            var list       = await _exercisesRepository.AllAsync();

            foreach (var item in list)
            {
                var vm = new ExerciseItem
                {
                    Exercise     = item,
                    TrainingDays = await _exercisesRepository.GetTrainingDays(item)
                };
                collection.Add(vm);
            }

            return(collection);
        }
Ejemplo n.º 3
0
        private async Task <ObservableCollection <RoutineItem> > GetRoutine(DateTime date)
        {
            var collection = new ObservableCollection <RoutineItem>();
            var list       = await _routineDaysRepository.GetRoutine(date);

            var exercises = await _exercisesRepository.AllAsync();

            var workouts = await _workoutsRepository.GetWorkouts(date);

            foreach (var day in list)
            {
                // we shouldn't have days without an Exercise but we might have them because of an older fixed bug
                if (day.ExerciseId == 0)
                {
                    continue;
                }

                var vm = new RoutineItem
                {
                    RoutineDay = day,
                    Exercise   = exercises.FirstOrDefault(x => x.ExerciseId == day.ExerciseId),
                    Workout    = workouts.FirstOrDefault(x => x.ExerciseId == day.ExerciseId),
                };

                var previousWorkout = await _workoutsRepository.GetPreviousWorkout(vm.Exercise.ExerciseId, date);

                if (previousWorkout != null)
                {
                    vm.PreviousReps   = previousWorkout.Reps;
                    vm.PreviousWeight = previousWorkout.Weight;
                }

                var targetWorkout = await _workoutRules.GetTargetWorkout(vm.Exercise, previousWorkout);

                if (!targetWorkout.Equals(default(KeyValuePair <int, double>)))
                {
                    vm.TargetReps   = targetWorkout.Key;
                    vm.TargetWeight = targetWorkout.Value;
                }

                collection.Add(vm);
            }

            return(collection);
        }
Ejemplo n.º 4
0
        public async Task <string> ExportToCsv()
        {
            try
            {
                var sb       = new StringBuilder();
                var workouts = await _workoutsRepository.AllAsync();

                workouts = workouts.OrderBy(x => x.Created).ToList();
                var exercises = await _exercisesRepository.AllAsync();

                sb.AppendLine(
                    $"\"{"Date"}\",\"{"Exercise"}\",\"{"Reps"}\",\"{"Weight"}\",\"{"Target Reps"}\",\"{"Target Weight"}\",\"{"Trophies"}\",\"{"Workout Notes"}\"");

                foreach (var workout in workouts)
                {
                    var exercise = exercises.FirstOrDefault(x => x.ExerciseId == workout.ExerciseId);
                    if (exercise == null)
                    {
                        continue;
                    }

                    var line =
                        $"{workout.Created.Date.ToString("d")},\"{exercise.Name}\",{workout.Reps},{WeightMetricToImperialConverter.GetWeightAsDouble(workout.Weight)},{workout.TargetReps},{WeightMetricToImperialConverter.GetWeightAsDouble(workout.TargetWeight)},{workout.Trophies},\"{workout.Notes}\"";

                    sb.AppendLine(line);
                }

                return(_textStorage.Save(sb, "oneset.csv"));
            }
            catch (Exception ex)
            {
                App.ShowErrorPage(this, ex);
            }

            return(string.Empty);
        }