public async Task EditWorkout(object sender, System.EventArgs e)
        {
            if (DatePicker.Date > DateTime.Now.AddDays(1000) || DatePicker.Date < DateTime.Now.AddDays(-1000))
            {
                DatePicker.BackgroundColor = Color.LightGray;
                DisplayAlert("Invalid Date", "Please insert a realistic date", "Ok");
            }
            else if (String.IsNullOrEmpty(LocationField.Text))
            {
                LocationField.BackgroundColor = Color.LightGray;
                DisplayAlert("Invalid Location", "Please insert a valid location for your workout", "Ok");
            }
            else
            {
                var users = await Models.Persistence.UsersCredentials.GetAllUsers(_connection);

                var user = users[0]; //SHOULD NEVER BE A CASE WHERE THIS FAILS. MAYBE NEED TO ADD VALIDATION IN THE FUTURE

                Models.Persistence.Workout workout = new Models.Persistence.Workout()
                {
                    Id          = WorkoutId,
                    WorkoutDate = DatePicker.Date,
                    Location    = LocationField.Text,
                    Completed   = false,
                    UserGuid    = user.UserGuid
                };

                _connection.UpdateAsync(workout);

                await Navigation.PushAsync(new Views.Workout.ViewWorkoutsPage());

                Navigation.RemovePage(this);
            }
        }
        public async Task ExerciseAlgorithm(string exercise1, string exercise2, Models.Persistence.Workout workout)
        {
            if (exercise1 != "I don't need help!" && exercise1 != "")
            {
                bool result = await WorkoutFactory.CheckExerciseHistory(_connection, exercise1);

                var doExerciseRecordsExist = await WorkoutFactory.CreateExerciseSets(_connection, exercise1, workout);

                DateTime date = doExerciseRecordsExist.ExerciseSetAssistantDate;

                if (result)
                {
                    if (doExerciseRecordsExist.Exist == false)
                    {
                        await DisplayAlert("No " + exercise1 + " History Found!", "Please complete sets of 12,10,8,6,4 repetitions for this exercise for the application to generate future workouts.", "Ok");

                        await WorkoutFactory.CreateEmptyExerciseSets(_connection, exercise1, workout, date);
                    }
                }
                else
                {
                    await DisplayAlert("No " + exercise1 + " History Found!", "Please complete sets of 12,10,8,6,4 repetitions for this exercise for the application to generate future workouts.", "Ok");

                    await WorkoutFactory.CreateEmptyExerciseSets(_connection, exercise1, workout, date);
                }
            }

            if (exercise2 != "I don't need help!" && exercise2 != "" && exercise2 != "None")
            {
                bool result = await WorkoutFactory.CheckExerciseHistory(_connection, exercise2);

                var doExerciseRecordsExist = await WorkoutFactory.CreateExerciseSets(_connection, exercise2, workout);

                DateTime date = doExerciseRecordsExist.ExerciseSetAssistantDate;

                if (result)
                {
                    if (doExerciseRecordsExist.Exist == false)
                    {
                        await DisplayAlert("No " + exercise1 + " history found!", "Please complete sets of 12,10,8,6,4 repetitions for this exercise for the application to generate future workouts.", "Ok");

                        await WorkoutFactory.CreateEmptyExerciseSets(_connection, exercise2, workout, date);
                    }
                }
                else
                {
                    await DisplayAlert("No " + exercise2 + " history found!", "Please complete sets of 12,10,8,6,4 repetitions for this exercise for the application to generate future workouts.", "Ok");

                    await WorkoutFactory.CreateEmptyExerciseSets(_connection, exercise2, workout, date);
                }
            }



            ///////
        }
        public async Task AddWorkoutToInternalDb(DateTime date, string location, string exerciseOne, string exerciseTwo)
        {           //guid later
            //Add workout record

            await DisplayAlert("Disclaimer", "This application may create sets for you. Please only lift weights in a safe way, with a spotter if necessary.", "I Understand");

            var users = await Models.Persistence.UsersCredentials.GetAllUsers(_connection);

            var user = users[0];             //SHOULD NEVER BE A CASE WHERE THIS FAILS. MAYBE NEED TO ADD VALIDATION IN THE FUTURE

            var workout1 = new Models.Persistence.Workout
            {
                WorkoutDate = date,
                Location    = location,
                Completed   = false,
                UserGuid    = user.UserGuid
            };

            await _connection.InsertAsync(workout1);

            var workouts = await Models.Persistence.Workout.GetAllWorkoutRecordsByDate(_connection, date);

            await ExerciseAlgorithm(exerciseOne, exerciseTwo, workouts[0]);

            if (workouts.Count != 1)
            {
                await Navigation.PushAsync(new Views.Workout.ViewWorkoutsPage());

                Navigation.RemovePage(this);
            }
            else
            {
                //WorkoutList item = new WorkoutList()
                //{
                //    Id = workouts[0].Id
                //};

                await Navigation.PushAsync(new Views.Workout.ViewWorkoutsPage());

                Navigation.RemovePage(this);
            }
        }
Beispiel #4
0
        public static async Task SubmitSetsOnline(SQLiteAsyncConnection _connection, Models.Persistence.Workout workout, Models.Persistence.UsersCredentials user)
        {
            var exercises = await Models.Persistence.Exercise.GetAllExerciseRecordsByWorkoutId(_connection, workout.Id);

            foreach (var item in exercises)             //FOR EACH EXERCISE IN THE WORKOUT, DO THE FOLLOWING
            {
                var exerciseNameForExercise = await Models.Persistence.ExerciseName.GetAllExerciseNameRecordsById(_connection, item.Id);

                var exerciseName = exerciseNameForExercise[0];

                if (exerciseName.ExerciseNameString == "Bench Press" || exerciseName.ExerciseNameString == "Military Press" ||
                    exerciseName.ExerciseNameString == "Squat" || exerciseName.ExerciseNameString == "Deadlift")
                {
                    var setsForExercise = await Models.Persistence.Set.GetAllSetsByExerciseId(_connection, item.Id);

                    foreach (var set in setsForExercise)
                    {
                        if (set.Weight > 0m)
                        {
                            SetOnline s = new SetOnline()
                            {
                                Handle       = user.Handle,
                                Weight       = set.Weight,
                                Reps         = set.Reps,
                                Date         = DateTime.Now,
                                ExerciseName = exerciseName.ExerciseNameString
                            };

                            string     url      = "https://myapi20180503015443.azurewebsites.net/api/OnlineSet/AddSetForUser";
                            HttpClient client   = new HttpClient();
                            var        data     = JsonConvert.SerializeObject(s);
                            var        content  = new StringContent(data, Encoding.UTF8, "application/json");
                            var        response = await client.PostAsync(url, content);

                            var result = JsonConvert.DeserializeObject <OnlineWorkoutFromPhone>(response.Content.ReadAsStringAsync().Result);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        private void CompletedWorkout(WorkoutList item)
        {
            if (item.Completed == false)
            {
                item.Completed = true;
            }
            else
            {
                item.Completed = false;
            }

            Models.Persistence.Workout workout = new Models.Persistence.Workout()
            {
                Id          = item.Id,
                WorkoutDate = item.WorkoutDate,
                Completed   = item.Completed,
                Location    = item.Location,
                UserGuid    = item.UserGuid
            };

            _connection.UpdateAsync(workout);
        }
        public static async Task CreateEmptyExerciseSets(SQLiteAsyncConnection _connection, string exercise, Models.Persistence.Workout workout, DateTime date)
        {
            //DateTime date = await CreateExerciseRecordForWorkout(_connection, exercise, workout);
            var exerciseRecords = await Models.Persistence.Exercise.GetAllExerciseRecordsByDate(_connection, date);

            //var testing = await Models.Persistence.Exercise.GetAllExercise(_connection);
            int exerciseId = exerciseRecords[0].Id;

            List <int> setReps = new List <int>(new int[] { 12, 10, 8, 6, 4 });

            foreach (var s in setReps)
            {
                //add set record
                DateTime d = DateTime.Now;

                var set = new Models.Persistence.Set
                {
                    ExerciseId = exerciseId,
                    TimeOfSet  = d,
                    Weight     = 0m,
                    Reps       = s
                };

                await _connection.InsertAsync(set);

                Task.Delay(100).Wait();
            }
        }
        public static async Task <Models.Persistence.ExerciseSetAssistant> CreateExerciseSets(SQLiteAsyncConnection _connection, string exercise, Models.Persistence.Workout workout)
        {
            Models.Persistence.ExerciseSetAssistant setAssistant = new Models.Persistence.ExerciseSetAssistant();
            string exerciseString     = GetExerciseNameString(exercise);
            var    listOfExerciseName = await Models.Persistence.ExerciseName.GetAllExerciseNameRecordsByExerciseNameString(_connection, exerciseString);


            int exerciseListInt = listOfExerciseName[0].Id;
            var exercises       = await Models.Persistence.Exercise.GetAllExerciseRecordsByExerciseNameId(_connection, exerciseListInt);       //Gets all exercises records for 'Bench Press' or whatever lift.

            DateTime date = await CreateExerciseRecordForWorkout(_connection, exercise, workout);

            setAssistant.ExerciseSetAssistantDate = date;

            if (exercises.Count < 1)
            {
                setAssistant.Exist = false;
                return(setAssistant);
            }

            var exerciseRecords = await Models.Persistence.Exercise.GetAllExerciseRecordsByDate(_connection, date); //Gets the current exercise record that's just been created.

            int exerciseIdForSets = exerciseRecords[0].Id;                                                          //Gets the Id for the new exercise record


            int exForPrvSet = exercises.Count() - 1;
            int exerciseIdForPreviousSets = exercises[exForPrvSet].Id;                                                                   //Gets the ID of the latest historic exercise.
            var previousExercise          = exercises[exForPrvSet];
            var setsForLastExercise       = await Models.Persistence.Set.GetAllSetsByExerciseId(_connection, exerciseIdForPreviousSets); //Get the sets for the previous historic exercise


            //Calculate lowest reps
            int     repValue    = 10000;
            decimal weightValue = 10000m;

            //Get the values for rep and weight of the set with the lowest reps (if any).
            foreach (var item in setsForLastExercise)
            {
                if (item.Reps < repValue && item.Reps > 0)
                {
                    repValue    = item.Reps;
                    weightValue = item.Weight;
                }
            }

            //IF the highest set had zero reps, create empty sets
            if (repValue == 10000 || weightValue == 0)
            {
                //await CreateEmptyExerciseSets(_connection, exercise, workout);
                setAssistant.Exist = false;
                return(setAssistant);
            }

            //CONSIDER DATES IN HERE
            var      dateNow = DateTime.Now;
            var      date10  = dateNow.AddDays(-10);
            var      date15  = dateNow.AddDays(-15);
            var      date20  = dateNow.AddDays(-20);
            DateTime prv     = previousExercise.DateOfExercise;

            //TESTING
            int testing = 0;

            if (testing == 1)
            {
                prv = dateNow.AddDays(-8);
            }
            //

            decimal increment;

            if (prv < date20)             //IF OVER 20 DAYS SINCE LAST EXERCISE
            {
                await CreateEmptyExerciseSets(_connection, exercise, workout, date);

                setAssistant.Exist = false;
                return(setAssistant);
            }
            else if (prv < date15)             //IF BETWEEN 15-20 DAYS SINCE LAST EXERCISE
            {
                increment = -2.5m;
                await CreateSetsWithValues(_connection, exerciseIdForSets, repValue, weightValue, increment);
            }
            else if (prv < date10)             //IF BETWEEN 10-15 DAYS SINCE LAST EXERCISE
            {
                increment = 0m;
                await CreateSetsWithValues(_connection, exerciseIdForSets, repValue, weightValue, increment);
            }
            else             //IF LESS THAN 10 DAYS SINCE LAST EXERCISE
            {
                increment = 2.5m;
                await CreateSetsWithValues(_connection, exerciseIdForSets, repValue, weightValue, increment);
            }
            setAssistant.Exist = true;
            //setAssistant.ExerciseSetAssistantDate = date;
            return(setAssistant);
        }
        public static async Task <List <string> > GetListOfExerciseStrings(SQLiteAsyncConnection _connection, Models.Persistence.Workout w)
        {
            var exercise = await Exercise.GetAllExerciseRecordsByWorkoutId(_connection, w.Id);

            List <string> muscleGroupList = new List <string>();

            int exerciseCount = exercise.Count;
            //int exerciseListDivider = 1;
            List <string> fullListOfStrings = new List <string>();

            foreach (var item in exercise)
            {
                var exerciseName = await ExerciseName.GetAllExerciseNameRecordsById(_connection, item.ExerciseNameId);

                string mg   = exerciseName[0].ExerciseMuscleGroup;
                bool   word = fullListOfStrings.Any(mg.Contains);

                if (word == false)
                {
                    fullListOfStrings.Add(mg);
                }
            }
            return(fullListOfStrings);
        }
        public static async Task <string> CreateWorkoutString(SQLiteAsyncConnection _connection, Models.Persistence.Workout workout)
        {
            string newLine     = "NEWLINE";
            string date        = workout.WorkoutDate.ToString("dddd, dd MMMM yyyy");     //{0:dd-MMM-yy}
            string finalString = "Date: " + date + newLine;

            finalString += "Location: " + workout.Location + newLine + newLine;

            var exercises = await Models.Persistence.Exercise.GetAllExerciseRecordsByWorkoutId(_connection, workout.Id);

            foreach (var item in exercises)             //FOR EACH EXERCISE IN THE WORKOUT, DO THE FOLLOWING
            {
                var exerciseNameForExercise = await Models.Persistence.ExerciseName.GetAllExerciseNameRecordsById(_connection, item.Id);

                var exerciseName = exerciseNameForExercise[0];

                finalString += exerciseName.ExerciseNameString + newLine + newLine;                 //ADD NAME OF THE EXERCISE

                var setsForExercise = await Models.Persistence.Set.GetAllSetsByExerciseId(_connection, item.Id);

                foreach (var set in setsForExercise)
                {
                    finalString += set.Weight.ToString() + "kg x " + set.Reps.ToString() + newLine;
                }

                finalString += newLine + newLine;
            }
            return(finalString);
        }
Beispiel #10
0
        protected override async void OnAppearing()
        {
            //Check for valid internet connection
            await NetConnection();

            //await CreateBlankUserRecord();
            //Create the table if it doesnt exist
            await _connection.CreateTableAsync <UsersCredentials>();

            await _connection.CreateTableAsync <Models.Persistence.Workout>();

            await _connection.CreateTableAsync <Exercise>();

            await _connection.CreateTableAsync <ExerciseGroup>();

            await _connection.CreateTableAsync <ExerciseName>();

            //add 'static' data
            await PopulateTablesWithData();



            //await CreateBlankUserRecord();

            //Get the records
            var user = await _connection.Table <UsersCredentials>().ToListAsync();

            var userCount = user.Count();

            //tests
            int testOne = 1;

            if (testOne > 0)
            {
                var exerciseGroup = await _connection.Table <ExerciseGroup>().ToListAsync();

                var exerciseGroupCount = exerciseGroup.Count();

                var exerciseName = await _connection.Table <ExerciseName>().ToListAsync();

                var exerciseNameCount = exerciseName.Count();

                var workout1 = new Models.Persistence.Workout {
                    WorkoutDate = DateTime.Now,
                    Location    = "Leicester",
                    Completed   = true
                };

                var workout2 = new Models.Persistence.Workout
                {
                    WorkoutDate = DateTime.Now,
                    Location    = "London",
                    Completed   = true
                };

                await _connection.InsertAsync(workout1);

                await _connection.InsertAsync(workout2);
            }

            //public class Workout
            //{
            //[PrimaryKey, AutoIncrement]
            //public int Id { get; set; }
            //public Guid UserGuid { get; set; }
            //public DateTime WorkoutDate { get; set; }
            //[MaxLength(255)]
            //public string Location { get; set; }
            //public bool Completed { get; set; }



            //await CreateBlankUserRecord();
            await DatabaseChecks(userCount, user);

            base.OnAppearing();
        }