Beispiel #1
0
        /// <summary>
        /// Create a new miles to HealthVault
        /// </summary>
        public static bool SaveMilesToHV(PersonInfo info, DateTime dateRecorded,
            double distance, ProfileModel profile)
        {
            ApproximateDateTime hvDate = new ApproximateDateTime(
                new ApproximateDate(dateRecorded.Year, dateRecorded.Month, dateRecorded.Day),
                new ApproximateTime(
                    dateRecorded.Hour, dateRecorded.Minute, dateRecorded.Second));

            Exercise newData = new Exercise((ApproximateDateTime)hvDate,
                new CodableValue("walk", new CodedValue("walk", "aerobic-activities")));

            DisplayValue hvDisplay = new DisplayValue(distance, "Miles");

            //convert miles into meters
            if (distance > 0)
            {
                newData.Distance = new Length(DataConversion.ConvertMilesToMeters(distance),
                    hvDisplay);
            }

            if (profile.UserCtx.user_stride > 0)
                newData.Details.Add(ExerciseDetail.Steps_count,
                    new ExerciseDetail(new CodedValue(ExerciseDetail.Steps_count, "exercise-detail-names"),
                        new StructuredMeasurement(
                            DataConversion.GetStepsFromDistanceAndStride(distance, profile.UserCtx.user_stride),
                            new CodableValue("Count", new CodedValue("Count", "exercise-units")))));

            if (profile.UserCtx.user_weight > 0)
                newData.Details.Add(ExerciseDetail.CaloriesBurned_calories,
                    new ExerciseDetail(new CodedValue(ExerciseDetail.CaloriesBurned_calories, "exercise-detail-names"),
                        new StructuredMeasurement(
                            DataConversion.GetEnergyFromDistanceAndWeightNotNullable(distance, profile.UserCtx.user_weight),
                            new CodableValue("Calories", new CodedValue("Calories", "exercise-units")))
                            ));

            info.SelectedRecord.NewItem(newData);
            return true; //Success
        }
Beispiel #2
0
        /// <summary>
        /// Create a new step to HealthVault
        /// </summary>
        public static bool SaveStepsToHV(PersonInfo info, DateTime dateRecorded,
            long steps, ProfileModel profile)
        {
            ApproximateDateTime hvDate = new ApproximateDateTime(
                new ApproximateDate(dateRecorded.Year, dateRecorded.Month, dateRecorded.Day),
                new ApproximateTime(
                    dateRecorded.Hour, dateRecorded.Minute, dateRecorded.Second));

            Exercise newData = new Exercise(hvDate,
                new CodableValue("walk", new CodedValue("walk", "aerobic-activities")));

            newData.Details.Add(ExerciseDetail.Steps_count,
                new ExerciseDetail(new CodedValue(ExerciseDetail.Steps_count, "exercise-detail-names"),
                    new StructuredMeasurement(
                        (double)steps,
                        new CodableValue("Count", new CodedValue("Count", "exercise-units")))));

            if (profile.UserCtx.user_stride > 0)
            {
                double? distance = DataConversion.GetDistanceFromSteps(profile.UserCtx.user_stride,
                    steps);
                if (distance.HasValue && distance.Value > 0)
                {
                    newData.Distance = new Length(DataConversion.ConvertMilesToMeters(distance.Value));
                }

                if (profile.UserCtx.user_weight > 0)
                {
                    newData.Details.Add(ExerciseDetail.CaloriesBurned_calories,
                        new ExerciseDetail(new CodedValue(ExerciseDetail.CaloriesBurned_calories, "exercise-detail-names"),
                            new StructuredMeasurement(
                                DataConversion.GetEnergyFromSteps(profile.UserCtx.user_stride,
                                profile.UserCtx.user_weight, (int)steps).Value,
                                new CodableValue("Calories", new CodedValue("Calories", "exercise-units")))
                        ));
                }
            }
            info.SelectedRecord.NewItem(newData);
            return true; //Success
        }
Beispiel #3
0
        public static walk_log PopulateWalkLogFromHV(walk_log entity,
            Exercise exercise, ProfileModel profile)
        {
            entity.log_user = profile.UserCtx.user_id;

            //TODO: obtain weight from HV when the steps were recorded
            entity.log_weight = profile.UserCtx.user_weight;

            entity.log_date = new DateTime(
                exercise.When.ApproximateDate.Year,
                exercise.When.ApproximateDate.Month.HasValue ?
                    exercise.When.ApproximateDate.Month.Value : 1,
                exercise.When.ApproximateDate.Day.HasValue ?
                    exercise.When.ApproximateDate.Day.Value : 1,
                exercise.When.ApproximateTime.Hour,
                exercise.When.ApproximateTime.Minute,
                exercise.When.ApproximateTime.Second.HasValue ?
                    exercise.When.ApproximateTime.Second.Value : 1);

            long steps = (long)exercise.Details[ExerciseDetail.Steps_count].Value.Value;
            entity.log_steps = steps;

            int aerobicSteps = 0;
            try
            {
                aerobicSteps = (int)exercise.Details[ExerciseDetail.AerobicSteps_count].Value.Value;
            }
            catch
            {
                // eat
            }
            entity.log_aerobicsteps = aerobicSteps;

            if (exercise.Distance != null)
            {
                entity.log_distance = DataConversion.ConvertMetersToMiles(
                    exercise.Distance.Meters);
            }
            else
            {
                // Get distance from steps
                entity.log_distance = DataConversion.GetDistanceFromSteps(
                    profile.UserCtx.user_stride,
                    steps);
            }

            double? calories = null;
            try
            {
                calories =
                    exercise.Details[ExerciseDetail.CaloriesBurned_calories].Value.Value;
            }
            catch
            {
                // eat calorie errors
            }
            if (calories.HasValue)
            {
                entity.log_calories = calories.Value;
            }
            else
            {
                // Get energy from steps
                entity.log_calories = DataConversion.GetEnergyFromSteps(
                    profile.UserCtx.user_stride,
                    profile.UserCtx.user_weight,
                    steps);
            }
            entity.hv_item_id = exercise.Key.Id;
            entity.updated_at = DateTime.Now;
            return entity;
        }