Beispiel #1
0
        public void ImportGpxFile_CorrectSessionDurationCalculated()
        {
            ExerciseSession sut = ExerciseSession.Create(_gpxTrack);

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Duration, Is.EqualTo(new TimeSpan(0, 0, 23)));
        }
 private void LoadContentsOfGpxFile(HttpPostedFileBase file, ImportViewModel importViewModel)
 {
     try
     {
         GpxTrack track = GpxEngine.GetGpxTrackFromFile(file);
         if (track != null)
         {
             ExerciseSession session = ExerciseSession.Create(track);
             _db.ExerciseSessions.AddOrUpdate(s => s.Name, session);
             _db.SaveChanges();
             importViewModel.FilesImported++;
         }
         else
         {
             importViewModel.FilesFailed.Add(new FailedFile
             {
                 Filename     = file.FileName,
                 ErrorMessage = "File could not be processed."
             });
         }
     }
     catch (Exception e)
     {
         _log.Error(string.Format("Failed to import file {0} with message: {1}", file.FileName, e.Message));
         importViewModel.FilesFailed.Add(new FailedFile
         {
             Filename     = file.FileName,
             ErrorMessage = e.Message
         });
     }
 }
        public IHttpActionResult PutExerciseSession(int id, ExerciseSession exerciseSession)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != exerciseSession.ExerciseSessionID)
            {
                return(BadRequest());
            }

            db.Entry(exerciseSession).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExerciseSessionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #4
0
        public void ImportGpxFile_CorrectSessionDistanceCalculated()
        {
            ExerciseSession sut = ExerciseSession.Create(_gpxTrack);

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Distance, Is.EqualTo(0.12));
        }
Beispiel #5
0
        private async Task <ExerciseSession> GetExerciseSessionComplete(IStatementResultCursor reader)
        {
            var exerciseSession = new ExerciseSession();

            while (await reader.FetchAsync())
            {
                var exerciseSessionId = Guid.Parse(reader.Current[0].ToString());
                if (exerciseSession.Id != exerciseSessionId)
                {
                    exerciseSession = new ExerciseSession()
                    {
                        Id           = exerciseSessionId,
                        Note         = reader.Current[1]?.ToString(),
                        ExerciseName = reader.Current[2].ToString(),
                        Records      = new List <ExerciseRecord>()
                    };
                }
                exerciseSession.Records.Add(new ExerciseRecord()
                {
                    Id             = Guid.Parse(reader.Current[3].ToString()),
                    EpochTimestamp = double.Parse(reader.Current[4].ToString()),
                    Set            = reader.Current[5].ToString(),
                    Reps           = (Int64)reader.Current[6],
                    Value          = double.Parse(reader.Current[7].ToString()),
                    Unit           = reader.Current[8]?.ToString(),
                    DropSet        = (bool)reader.Current[9],
                    Note           = reader.Current[10]?.ToString()
                });
            }
            return(exerciseSession);
        }
        public void ActivityProcessor_Can_Set_UnknownType_For_Null_Argument()
        {
            ExerciseSession exerciseSession = null;
            ActivityType    result          = ActivityProcessor.GetActivityType(exerciseSession);

            Assert.That(result, Is.EqualTo(ActivityType.Unknown));
        }
Beispiel #7
0
        public void CanSetMultipleTrackSegmentsToTrack()
        {
            var sut = new ExerciseSession();

            sut.TrackSegments = new[] { new TrackSegment(), new TrackSegment() };

            Assert.That(sut.TrackSegments.Count(), Is.EqualTo(2));
        }
Beispiel #8
0
        public ActionResult DeleteConfirmed(int id)
        {
            ExerciseSession exerciseSession = db.ExerciseSessions.Find(id);

            db.ExerciseSessions.Remove(exerciseSession);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void ActivityProcessor_Can_Set_UnknownType_For_RandonName()
        {
            var exerciseSession = new ExerciseSession {
                Name = "svuprustgisdh;a"
            };
            ActivityType result = ActivityProcessor.GetActivityType(exerciseSession);

            Assert.That(result, Is.EqualTo(ActivityType.Unknown));
        }
        public void ActivityProcessor_Can_Set_UnknownType_For_EmptyName()
        {
            var exerciseSession = new ExerciseSession {
                Name = string.Empty
            };
            ActivityType result = ActivityProcessor.GetActivityType(exerciseSession);

            Assert.That(result, Is.EqualTo(ActivityType.Unknown));
        }
Beispiel #11
0
        public void ImportGpxFile_MoreAccurateTrackElevationCalculated()
        {
            ExerciseSession sut = ExerciseSession.Create(_gpxTrack);

            //var sut = session.TrackSegments as List<TrackSegment>;

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Elevation, Is.EqualTo(17));
        }
Beispiel #12
0
        public void ImportGpxFile_CorrectTrackElevationCalculated()
        {
            ExerciseSession sut = ExerciseSession.Create(_gpxTrack);

            //var sut = session.TrackSegments as List<TrackSegment>;

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Elevation, Is.EqualTo(17).Within(0.1).Percent);
        }
        public void ActivityProcessor_Can_Set_CyclingActivityType()
        {
            var exerciseSession = new ExerciseSession {
                Name = "[Cycling 9/7/17 7:53 am]]"
            };
            ActivityType result = ActivityProcessor.GetActivityType(exerciseSession);

            Assert.That(result, Is.EqualTo(ActivityType.Cycling));
        }
        public void ActivityProcessor_Can_Set_RunningActivityType()
        {
            var exerciseSession = new ExerciseSession {
                Name = "[Running 20/7/17 12:25 pm]"
            };
            ActivityType result = ActivityProcessor.GetActivityType(exerciseSession);

            Assert.That(result, Is.EqualTo(ActivityType.Running));
        }
Beispiel #15
0
        public void ImportGpxFile_CorrectSegmentElevationCalculated()
        {
            ExerciseSession session = ExerciseSession.Create(_gpxTrack);
            var             sut     = session.TrackSegments as List <TrackSegment>;

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Count, Is.EqualTo(2));
            Assert.That(sut[0].Elevation, Is.EqualTo(7));
            Assert.That(sut[1].Elevation, Is.EqualTo(10).Within(0.1).Percent);
        }
Beispiel #16
0
        public void ImportGpxFile_CorrectSegmentDurationCalculated()
        {
            ExerciseSession session = ExerciseSession.Create(_gpxTrack);
            var             sut     = session.TrackSegments as List <TrackSegment>;

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Count, Is.EqualTo(2));
            Assert.That(sut[0].Duration, Is.EqualTo(new DateTime(2009, 8, 24, 9, 9, 29).Subtract(new DateTime(2009, 8, 24, 9, 9, 19))));
            Assert.That(sut[1].Duration, Is.EqualTo(new DateTime(2009, 8, 24, 9, 11, 43).Subtract(new DateTime(2009, 8, 24, 9, 11, 30))));
        }
Beispiel #17
0
        public void ImportGpxFile_CorrectSegmentDistanceCalculated()
        {
            ExerciseSession session = ExerciseSession.Create(_gpxTrack);
            var             sut     = session.TrackSegments as List <TrackSegment>;

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Count, Is.EqualTo(2));
            Assert.That(sut[0].Distance, Is.EqualTo(0.0499477).Within(0.1).Percent);
            Assert.That(sut[1].Distance, Is.EqualTo(0.0708563).Within(0.1).Percent);
        }
        public IHttpActionResult GetExerciseSession(int id)
        {
            ExerciseSession exerciseSession = db.ExerciseSessions.Find(id);

            if (exerciseSession == null)
            {
                return(NotFound());
            }

            return(Ok(exerciseSession));
        }
Beispiel #19
0
 public ActionResult Edit([Bind(Include = "ExerciseSessionID,StartTime,EndTime,ExerciseTypeID")] ExerciseSession exerciseSession)
 {
     if (ModelState.IsValid)
     {
         db.Entry(exerciseSession).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ExerciseTypeID = new SelectList(db.ExerciseTypes, "ExerciseTypeID", "Description", exerciseSession.ExerciseTypeID);
     return(View(exerciseSession));
 }
        public IHttpActionResult PostExerciseSession(ExerciseSession exerciseSession)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ExerciseSessions.Add(exerciseSession);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = exerciseSession.ExerciseSessionID }, exerciseSession));
        }
Beispiel #21
0
        public void OnceBeforeTests()
        {
            _runningSession = new ExerciseSession {
                ActivityType = ActivityType.Running
            };
            _runningSession.Duration = new TimeSpan(0, 0, 30, 0);
            _runningSession.Distance = 6;

            _cyclingSession = new ExerciseSession {
                ActivityType = ActivityType.Cycling
            };
            _cyclingSession.Duration = new TimeSpan(0, 0, 30, 0);
            _cyclingSession.Distance = 12;
        }
Beispiel #22
0
        // GET: ExerciseSessions/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ExerciseSession exerciseSession = db.ExerciseSessions.Find(id);

            if (exerciseSession == null)
            {
                return(HttpNotFound());
            }
            return(View(exerciseSession));
        }
        public IHttpActionResult DeleteExerciseSession(int id)
        {
            ExerciseSession exerciseSession = db.ExerciseSessions.Find(id);

            if (exerciseSession == null)
            {
                return(NotFound());
            }

            db.ExerciseSessions.Remove(exerciseSession);
            db.SaveChanges();

            return(Ok(exerciseSession));
        }
        internal static int GetCaloriesBurned(ExerciseSession exerciseSession)
        {
            // met is the measure of calorie burn rate for a given activity
            double   met      = 11; // default set as met for running at 6.7mph (9 min miles)
            double   weight   = 90;
            TimeSpan duration = exerciseSession.Duration ?? new TimeSpan();

            if (exerciseSession.ActivityType == ActivityType.Cycling)
            {
                met = 10; // this is the met for cycling at between 14 - 15.5 mph
            }

            return(Convert.ToInt32(Math.Round(CalculateCalories(met, duration.TotalMinutes, weight), MidpointRounding.AwayFromZero)));
        }
Beispiel #25
0
        // GET: ExerciseSessions/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ExerciseSession exerciseSession = db.ExerciseSessions.Find(id);

            if (exerciseSession == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ExerciseTypeID = new SelectList(db.ExerciseTypes, "ExerciseTypeID", "Description", exerciseSession.ExerciseTypeID);
            return(View(exerciseSession));
        }
Beispiel #26
0
        private async Task <ExerciseSession> GetExerciseSession(IStatementResultCursor reader)
        {
            ExerciseSession item = null;

            while (await reader.FetchAsync())
            {
                item = new ExerciseSession()
                {
                    Id           = Guid.Parse(reader.Current[0].ToString()),
                    Note         = reader.Current[1]?.ToString(),
                    ExerciseName = reader.Current[2].ToString()
                };
            }
            return(item);
        }
        public async Task <IActionResult> Update(
            Guid id, [FromBody] ExerciseSessionUpdateApi exerciseSessionUpdate)
        {
            if (await _exerciseSessionRepository.Get(id) == null)
            {
                return(NotFound());
            }

            var exerciseSession = new ExerciseSession
            {
                Id   = id,
                Note = exerciseSessionUpdate.Note
            };

            await _exerciseSessionRepository.Update(exerciseSession);

            return(NoContent());
        }
Beispiel #28
0
        public async Task <IList <ExerciseSession> > ByWorkoutSession(Guid workoutSessionId)
        {
            var list = new List <ExerciseSession>();

            using (var session = _graphRepository.Driver.Session())
            {
                var reader = await session.RunAsync(
                    @"MATCH (er:ExerciseRecord)-[r:FOR_EXERCISE_SESSION]->(es:ExerciseSession)-[:FOR_EXERCISE]->(e:Exercise), 
                    (es)-[:FOR_WORKOUT_SESSION]->(ws:WorkoutSession { id: $id })
                    RETURN es.id, es.note, e.name, er.id, er.epochTimestamp, er.set, er.reps, er.value, er.unit, er.dropSet, er.note
                    ORDER BY er.epochTimestamp",
                    new { id = workoutSessionId.ToString() });


                var exerciseSession = new ExerciseSession();
                while (await reader.FetchAsync())
                {
                    var exerciseSessionId = Guid.Parse(reader.Current[0].ToString());
                    if (exerciseSession.Id != exerciseSessionId)
                    {
                        exerciseSession = new ExerciseSession()
                        {
                            Id           = exerciseSessionId,
                            Note         = reader.Current[1]?.ToString(),
                            ExerciseName = reader.Current[2].ToString(),
                            Records      = new List <ExerciseRecord>()
                        };
                        list.Add(exerciseSession);
                    }
                    exerciseSession.Records.Add(new ExerciseRecord()
                    {
                        Id             = Guid.Parse(reader.Current[3].ToString()),
                        EpochTimestamp = double.Parse(reader.Current[4].ToString()),
                        Set            = reader.Current[5].ToString(),
                        Reps           = (Int64)reader.Current[6],
                        Value          = double.Parse(reader.Current[7].ToString()),
                        Unit           = reader.Current[8]?.ToString(),
                        DropSet        = (bool)reader.Current[9],
                        Note           = reader.Current[10]?.ToString()
                    });
                }
            }
            return(list);
        }
Beispiel #29
0
        public async Task <ExerciseSession> Update(ExerciseSession exerciseSession)
        {
            using (var session = _graphRepository.Driver.Session())
            {
                var reader = await session.RunAsync(
                    @"MATCH (es:ExerciseSession { id: $id })-[:FOR_EXERCISE]->(e:Exercise)
                        SET es.note = $note
                        RETURN es.id, es.note, e.name",
                    new
                {
                    id   = exerciseSession.Id.ToString(),
                    note = exerciseSession.Note
                }
                    );

                exerciseSession = await GetExerciseSession(reader);
            }
            return(exerciseSession);
        }
Beispiel #30
0
        public static ActivityType GetActivityType(ExerciseSession exerciseSession)
        {
            if (exerciseSession != null && !string.IsNullOrWhiteSpace(exerciseSession.Name))
            {
                // to do consider using reg from settings for matching, in order to extend to other gpx types
                // update: in fact the regex pattern should be part of the gpx setup, with a seperate gpx template
                // for each type of import. E.g. Strava, Garmin, Runkeeper, etc
                if (exerciseSession.Name.Contains("Running"))
                {
                    return(ActivityType.Running);
                }
                if (exerciseSession.Name.Contains("Cycling"))
                {
                    return(ActivityType.Cycling);
                }
            }

            return(ActivityType.Unknown);
        }