Esempio n. 1
0
        /// <summary>
        /// Description:
        ///     Suggest some workouts to a user to find his 1RMs.
        /// History:
        ///     Amir Naji   22/02/2017
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>0: There is a unfinished plan. 1: There is no plan. 2: There is a finished plan.</returns>
        public int SuggestWorkoutFor1RM(string userId)
        {
            // 1. Check if user has an on going workout in table.
            // 2. Check if user has 1RM.
            // 3. If he doesn't have any of above then it can suggest.
            var vPlan = db.Plans.Where(x => x.UserID == userId);

            //The user does not have any plan. First time.
            if (vPlan.Count() == 0)
            {
                var         vWorkout = db.Workouts.Where(x => x.Difficulty == 1).ToList();
                var         v1Rm     = db.C1RM.FirstOrDefault(x => x.UserID == userId);
                C1RMWorkout cWorkout = new C1RMWorkout();
                foreach (var v in vWorkout)
                {
                    cWorkout.RMID      = v1Rm.RMID;
                    cWorkout.WorkoutID = v.WorkoutID;
                    db.C1RMWorkout.Add(cWorkout);
                    db.SaveChanges();
                }
                return(1);
            }
            else
            {
                /// 1. If there is any finished plan.
                /// 2. If the date is not more than 2 weeks old(optional).
                /// 3. Check the last months 1RMs.
                /// 4. Compare it with statistics, and last month.
                /// 5. Suggest new workouts.
                var vLastPlan = db.Plans.Where(x => x.UserID == userId).OrderByDescending(x => x.PlanDate).ToList()[0];
                // The condition has to change if the number 2 wanted to happen.
                if (vLastPlan.FinishDate != null)
                {
                    var vWorkoutPlan = db.WorkoutPlans.Where(x => x.PlanID == vLastPlan.PlanID);
                    var v1RMWorkout  = db.C1RMWorkout.Where(x => x.RMPlanId == vLastPlan.PlanID);
                    return(2);
                }
            }
            return(0);
        }
Esempio n. 2
0
        public void WorkoutsForPlan(string userId)
        {
            C1RMWorkout rm    = new C1RMWorkout();
            var         vPlan = db.Plans.Where(x => x.UserID == userId).ToList();

            if (vPlan.Count() > 0)
            {
                var vUnfinishedPlan = db.Plans.FirstOrDefault(x => x.UserID == userId && x.FinishDate == null);
                // If there is anything to compare.
                // There can't be any unfinished plan.
                var vLastPlans = GetLastTwoPlans(userId);
                if (vLastPlans.Count() > 1)
                {
                    var vCompareWorkout = CompareWorkouts(vLastPlans);
                }
                else
                {
                    //JsonConvert.DeserializeObject()
                    using (StreamReader r = new StreamReader(HttpContext.Current.Server.MapPath("/CycleFlow.json")))
                    {
                        string json  = r.ReadToEnd();
                        var    items = JsonConvert.DeserializeObject <JsonCycle>(json);

                        //DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(JsonCycle));
                        //MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(File.ReadAllText(HttpContext.Current.Server.MapPath("/CycleFlow.json"))));
                        //List<JsonCycle> contacts = (List<JsonCycle>)js.ReadObject(stream);

                        var         vCompareWorkout = CompareWorkouts(userId);
                        WorkoutPlan newWorkout      = new WorkoutPlan();
                        WeeksCount = items.CycleSteps.Count();
                        foreach (var item in items.CycleSteps)
                        {
                            foreach (var workout in vCompareWorkout)
                            {
                                newWorkout.PlanID            = vUnfinishedPlan.PlanID;
                                newWorkout.Repetition        = items.CyclesFlow[item.CycleName].Repetition;
                                newWorkout.WorkoutPlanSet    = items.CyclesFlow[item.CycleName].Sets;
                                newWorkout.WorkoutPlanWeight = (items.CyclesFlow[item.CycleName].Weight * workout.Weight) / 100;
                                newWorkout.Rest        = items.CyclesFlow[item.CycleName].Rest;
                                newWorkout.WorkoutWeek = items.CyclesFlow[item.CycleName].Week;
                                newWorkout.WorkoutID   = workout.WorkoutId;
                                db.WorkoutPlans.Add(newWorkout);
                                db.SaveChanges();
                            }
                            //db.WorkoutPlans.Add(newWorkout);
                            //db.SaveChanges();
                        }
                        //foreach (var item in vCompareWorkout)
                        //{
                        //    for (var i = 0; i < 6; i++)
                        //    {
                        //        newWorkout.PlanID = vUnfinishedPlan.PlanID;
                        //        newWorkout.Repetition = 0;
                        //        newWorkout.WorkoutPlanSet = 0;
                        //        newWorkout.WorkoutPlanWeight = 0;
                        //        newWorkout.Rest = 0;
                        //        newWorkout.WorkoutID = item.WorkoutId;
                        //    }
                        //}
                    }
                }
            }
        }