Ejemplo n.º 1
0
        public void MarkExerciseCompleted(string exerciseName, int quantity)
        {
            var exerciseHistory = ExerciseHistories.SingleOrDefault(eh =>
            {
                var todaysDate = DateTime.Today.Date;
                return(eh.RecordedDate == todaysDate && eh.ExerciseName == exerciseName);
            });

            if (exerciseHistory == null)
            {
                exerciseHistory = new ExerciseHistory
                {
                    ExerciseName      = exerciseName,
                    QuantityCompleted = quantity,
                    RecordedDate      = DateTime.Today
                };

                _db.Insert(exerciseHistory);
            }
            else
            {
                exerciseHistory.QuantityCompleted += quantity;
                _db.Update(exerciseHistory);
            }
        }
Ejemplo n.º 2
0
        public List <ExerciseTotal> GetExerciseTotals()
        {
            var totals = new Dictionary <string, int>();

            ExerciseHistories.Aggregate(totals, (t, h) =>
            {
                var name     = h.ExerciseName;
                var quantity = h.QuantityCompleted;
                if (t.ContainsKey(name))
                {
                    t[name] += quantity;
                }
                else
                {
                    t.Add(name, quantity);
                }
                return(t);
            });

            return(totals.Select(t => new ExerciseTotal {
                ExerciseName = t.Key, QuantityCompleted = t.Value
            }).Where(t => t.QuantityCompleted > 0).ToList());
        }
Ejemplo n.º 3
0
        private void Initalize(SQLiteConnection conn)
        {
            _db = conn;

            _db.CreateTable <SystemStatus>();

            if (!SystemStatus.Any())
            {
                _db.Insert(new SystemStatus {
                    IsFirstRun = true
                });
            }
            _db.CreateTable <ExerciseSchedule>();

            var hasExerciseSchedule = ExerciseSchedules.Any();

            if (!hasExerciseSchedule)
            {
                var defaultSchedule = ExerciseSchedule.CreateDefaultSchedule();
                _db.Insert(defaultSchedule);
            }

            _db.CreateTable <ExerciseBlock>();
            _db.CreateTable <MostRecentExercise>();

            if (!hasExerciseSchedule && !ExerciseBlocks.Any())
            {
                var defaultExercises = ExerciseBlock.CreateDefaultExercises();
                _db.InsertAll(defaultExercises);
            }

            _db.CreateTable <ExerciseHistory>();

            _db.CreateTable <MovementLocation>();

#if DEBUG
            var now = DateTime.Now.Date;
            if (!ExerciseHistories.Any(eh => eh.RecordedDate < now))
            {
                _db.InsertAll(new List <ExerciseHistory>
                {
                    new ExerciseHistory
                    {
                        QuantityNotified  = 10,
                        ExerciseName      = "test",
                        RecordedDate      = DateTime.Now.AddDays(-1),
                        QuantityCompleted = 10
                    },
                    new ExerciseHistory
                    {
                        QuantityNotified  = 10,
                        ExerciseName      = "test",
                        RecordedDate      = DateTime.Now.AddDays(-2),
                        QuantityCompleted = 10
                    },
                    new ExerciseHistory
                    {
                        QuantityNotified  = 10,
                        ExerciseName      = "test",
                        RecordedDate      = DateTime.Now.AddDays(-3),
                        QuantityCompleted = 10
                    },
                });
            }
#endif
        }
Ejemplo n.º 4
0
 public DateTime GetMinimumExerciseHistoryDate()
 {
     return(ExerciseHistories.Where(eh => eh.QuantityNotified > 0).OrderBy(eh => eh.RecordedDate).FirstOrDefault()?.RecordedDate ?? DateTime.Now.Date);
 }
Ejemplo n.º 5
0
 public List <ExerciseHistory> GetExerciseHistoryForDay(DateTime date)
 {
     return(ExerciseHistories.Where(eh => eh.RecordedDate == date && eh.QuantityNotified > 0).OrderBy(eh => eh.ExerciseName).ToList());
 }