Esempio n. 1
0
 public static WalkLogModel Fetch(int id)
 {
     DataClassesDataContext db = new DataClassesDataContext();
     walk_log t;
     var query = (from g in db.walk_logs
                  where g.log_user == id
                  select g);
     if (query.ToList().Count == 0)
     {
         t = new walk_log();
         t.log_user = id;
         db.GetTable<walk_log>().InsertOnSubmit(t);
     }
     else
     {
         t = query.First();
     }
     WalkLogModel p = new WalkLogModel(t);
     return p;
 }
Esempio n. 2
0
 public static void Insert(walk_log t)
 {
     DataClassesDataContext db = new DataClassesDataContext();
     t.updated_at = DateTime.Now;
     db.GetTable<walk_log>().InsertOnSubmit(t);
     db.SubmitChanges();
 }
Esempio n. 3
0
 public static void Save(int userId, DateTime date,
     long steps, long aerobicSteps)
 {
     DataClassesDataContext db = new DataClassesDataContext();
     walk_log t = new walk_log();
     t.log_user = userId;
     t.log_date = date;
     t.log_steps = steps;
     t.log_aerobicsteps = aerobicSteps;
     db.GetTable<walk_log>().InsertOnSubmit(t);
     db.SubmitChanges();
 }
Esempio n. 4
0
        private static void ProcessStepsHealthItem(HealthRecordItem item, ProfileModel profile)
        {
            if (item.TypeId.Equals(AerobicSession.TypeId))
            {
                AerobicSession aerobic = (AerobicSession)item;

                // Only add items with Steps
                if (aerobic.Session.NumberOfSteps > 0)
                {

                    // Is Step in Cache ?
                    DataClassesDataContext db = new DataClassesDataContext();
                    var query = (from g in db.walk_logs
                                 where ((g.log_user == profile.UserCtx.user_id) &&
                                       (g.hv_item_id == item.Key.Id))
                                 select g).SingleOrDefault();
                    // Update or Insert?
                    if (query != null)
                    {
                        query =
                            PopulateWalkLogFromHV(
                                query, aerobic, profile);
                        db.SubmitChanges();
                    }
                    else
                    {
                        walk_log entity = new walk_log();
                        entity = PopulateWalkLogFromHV(
                            entity, aerobic, profile);
                        WalkLogModel.Insert(entity);
                    }
                }

            }
            else if (item.TypeId.Equals(Exercise.TypeId))
            {
                Exercise exercise = (Exercise)item;

                // Only add items with Steps
                double numberOfSteps = 0;
                try
                {
                    numberOfSteps =
                        exercise.Details[ExerciseDetail.Steps_count].Value.Value;
                }
                catch
                {
                    WlkMiTracer.Instance.Log("HVSync.cs:ProcessStepsHealthItem", WlkMiEvent.AppDomain, WlkMiCat.Warning,
                        string.Format("UserId {0} has no pedometer data in HV item", profile.UserCtx.user_id));
                    return;
                }

                if (numberOfSteps > 0)
                {

                    // Is Step in Cache ?
                    DataClassesDataContext db = new DataClassesDataContext();
                    var query = (from g in db.walk_logs
                                 where ((g.log_user == profile.UserCtx.user_id) &&
                                       (g.hv_item_id == item.Key.Id))
                                 select g).SingleOrDefault();
                    // Update or Insert?
                    if (query != null)
                    {
                        query =
                            PopulateWalkLogFromHV(
                                query, exercise, profile);
                        db.SubmitChanges();
                    }
                    else
                    {
                        walk_log entity = new walk_log();
                        entity = PopulateWalkLogFromHV(
                            entity, exercise, profile);
                        WalkLogModel.Insert(entity);
                    }
                }
            }
        }
Esempio n. 5
0
 private WalkLogModel(walk_log g)
 {
     this.data = g;
 }
Esempio n. 6
0
        public static walk_log PopulateWalkLogFromHV(walk_log entity,
            AerobicSession aerobics, 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 = aerobics.When.ToDateTime();
            entity.log_steps = aerobics.Session.NumberOfSteps;
            entity.log_aerobicsteps = aerobics.Session.NumberOfAerobicSteps;

            if (aerobics.Session.Distance != null)
            {
                entity.log_distance = aerobics.Session.Distance.Meters / 1609.344;
            }
            else
            {
                // Get distance from steps
                entity.log_distance = DataConversion.GetDistanceFromSteps(
                    profile.UserCtx.user_stride,
                    aerobics.Session.NumberOfSteps.Value);
            }

            if (aerobics.Session.Energy.HasValue)
            {
                entity.log_calories = aerobics.Session.Energy;
            }
            else
            {
                // Get energy from steps
                entity.log_calories = DataConversion.GetEnergyFromSteps(
                    profile.UserCtx.user_stride,
                    profile.UserCtx.user_weight,
                    aerobics.Session.NumberOfSteps.Value);
            }
            entity.hv_item_id = aerobics.Key.Id;
            entity.updated_at = DateTime.Now;
            return entity;
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
 partial void Deletewalk_log(walk_log instance);
Esempio n. 9
0
 partial void Updatewalk_log(walk_log instance);
Esempio n. 10
0
 partial void Insertwalk_log(walk_log instance);
Esempio n. 11
0
		private void detach_walk_logs(walk_log entity)
		{
			this.SendPropertyChanging();
			entity.user = null;
		}
Esempio n. 12
0
		private void attach_walk_logs(walk_log entity)
		{
			this.SendPropertyChanging();
			entity.user = this;
		}