コード例 #1
0
ファイル: BandCloudClient.cs プロジェクト: talmuth/unBand
        public async Task <List <BandEventBase> > GetUserActivity(int?topCount = null, DateTime?startDate = null, DateTime?endDate = null)
        {
            var url      = GET_USER_ACTIVITY_URL + GenerateEventsQuery(topCount, startDate, endDate, "TimeOfDay");
            var response = await AuthenticatedRequest(url);

            var rv = new List <BandEventBase>();

            dynamic json = JObject.Parse(response);

            var curDay = DateTime.MinValue;
            UserDailyActivity curActivity = null;

            foreach (var rawUserActivity in json.value)
            {
                if (curDay.Date != rawUserActivity.TimeOfDay.Value.Date)
                {
                    if (curActivity != null)
                    {
                        rv.Add(curActivity);
                    }

                    curActivity = UserDailyActivity.Create(rawUserActivity);

                    curDay = rawUserActivity.TimeOfDay.Value;
                }
                else
                {
                    curActivity.AddSegment(rawUserActivity);
                }
            }

            return(rv);
        }
コード例 #2
0
        /// <summary>
        /// Returns a UserActivity object that tracks a User's activity across a given day
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static UserDailyActivity Create(JObject json)
        {
            var activity = new UserDailyActivity(json);

            activity.Segments = new List <BandEventBase>();

            // add this as the first segment of the day
            activity.AddSegment(json);

            return(activity);
        }
コード例 #3
0
ファイル: UserDailyActivity.cs プロジェクト: misspierc/unBand
        /// <summary>
        /// Returns a UserActivity object that tracks a User's activity across a given day
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static UserDailyActivity Create(JObject json)
        {
            var activity = new UserDailyActivity(json);

            activity.Segments = new List<BandEventBase>();

            // add this as the first segment of the day
            activity.AddSegment(json);

            return activity;
        }
コード例 #4
0
        public void AddSegment(JObject json)
        {
            // 1. Add the segment as a new UserActivity segment to this one
            // 2. Add the values to the running tally for the day

            var segment = new UserDailyActivity(json);

            Segments.Add(segment);

            // add in the values that need to be totalled over the lifetime of the day
            // Note: this means that asking for values such as UvExposure or HeartRate
            //       at the day level will return a value (the value for the first hour)
            //       but don't really make much sense
            StepsTaken     += segment.StepsTaken;
            TotalDistance  += segment.TotalDistance;
            CaloriesBurned += segment.CaloriesBurned;

            if (HeartRate.Lowest == 0 || HeartRate.Lowest > segment.HeartRate.Lowest)
            {
                HeartRate.Lowest = segment.HeartRate.Lowest;
            }

            if (HeartRate.Peak < segment.HeartRate.Peak)
            {
                HeartRate.Peak = segment.HeartRate.Peak;
            }

            // calculate average heart rate, ignoring segments that have no value
            if (segment.HeartRate.Average != 0)
            {
                _averageHeartRateSampleCount++;
                _aggregateAverageHeartRate += segment.HeartRate.Average;

                HeartRate.Average = _aggregateAverageHeartRate / _averageHeartRateSampleCount;
            }
        }
コード例 #5
0
ファイル: UserDailyActivity.cs プロジェクト: misspierc/unBand
        public void AddSegment(JObject json)
        {
            // 1. Add the segment as a new UserActivity segment to this one
            // 2. Add the values to the running tally for the day

            var segment = new UserDailyActivity(json);

            Segments.Add(segment);

            // add in the values that need to be totalled over the lifetime of the day
            // Note: this means that asking for values such as UvExposure or HeartRate
            //       at the day level will return a value (the value for the first hour)
            //       but don't really make much sense
            StepsTaken += segment.StepsTaken;
            TotalDistance += segment.TotalDistance;
            CaloriesBurned += segment.CaloriesBurned;

            if (HeartRate.Lowest == 0 || HeartRate.Lowest > segment.HeartRate.Lowest)
                HeartRate.Lowest = segment.HeartRate.Lowest;

            if (HeartRate.Peak < segment.HeartRate.Peak)
                HeartRate.Peak = segment.HeartRate.Peak;

            // calculate average heart rate, ignoring segments that have no value
            if (segment.HeartRate.Average != 0)
            {
                _averageHeartRateSampleCount++;
                _aggregateAverageHeartRate += segment.HeartRate.Average;

                HeartRate.Average = _aggregateAverageHeartRate / _averageHeartRateSampleCount;
            }
        }