示例#1
0
        /// <summary>
        /// Returns step count for given day
        /// </summary>
        /// <returns>Step count for given day</returns>
        public async Task <StepCountData> GetTotalStepCountAsync(DateTime day)
        {
            // Get history from 1 day
            var readings = await Pedometer.GetSystemHistoryAsync(day.Date, TimeSpan.FromDays(1));

            return(StepCountData.FromPedometerReadings(readings));
        }
示例#2
0
        /// <summary>
        /// Returns steps for given day at given resolution
        /// </summary>
        /// <param name="day">Day to fetch data for</param>
        /// <param name="resolution">Resolution in minutes. Minimum resolution is five minutes.</param>
        /// <returns>List of steps counts for the given day at given resolution.</returns>
        public async Task <List <KeyValuePair <TimeSpan, uint> > > GetStepsCountsForDay(DateTime day, uint resolution)
        {
            List <KeyValuePair <TimeSpan, uint> > steps = new List <KeyValuePair <TimeSpan, uint> >();
            uint numIntervals = (((24 * 60) / resolution) + 1);

            if (day.Date.Equals(DateTime.Today))
            {
                numIntervals = (uint)((DateTime.Now - DateTime.Today).TotalMinutes / resolution) + 1;
            }

            uint totalSteps = 0;

            for (uint i = 0; i < numIntervals; i++)
            {
                TimeSpan ts        = TimeSpan.FromMinutes(i * resolution);
                DateTime startTime = day.Date + ts;
                if (startTime < DateTime.Now)
                {
                    // Get history from startTime to the resolution duration
                    var readings = await Pedometer.GetSystemHistoryAsync(startTime, TimeSpan.FromMinutes(resolution));

                    // Compute the deltas
                    var stepsDelta = StepCountData.FromPedometerReadings(readings);

                    // Add to the total count
                    totalSteps += stepsDelta.TotalCount;
                    steps.Add(new KeyValuePair <TimeSpan, uint>(ts, totalSteps));
                }
                else
                {
                    break;
                }
            }
            return(steps);
        }
示例#3
0
        public async Task <List <ReadingByDate> > GetStepsForHour(int hour, int days)
        {
            List <ReadingByDate> stepsByDay = new List <ReadingByDate>();

            for (int i = 0; i < days; i++)
            {
                try
                {
                    var dateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).Subtract(TimeSpan.FromDays(i));
                    Debug.WriteLine("hour: " + i);
                    Debug.WriteLine("date: " + dateTime);

                    if (hour == 0)
                    {
                        hour = 1;
                    }
                    var stepsForDay = await _stepCounter.GetStepCountForRangeAsync(dateTime, TimeSpan.FromHours(hour));

                    var data = StepCountData.FromLumiaStepCount(stepsForDay);
                    stepsByDay.Add(new ReadingByDate
                    {
                        DateTime          = dateTime.AddHours(hour),
                        RunningStepsCount = data.RunningCount,
                        WalkingStepsCount = data.WalkingCount,
                        TotalStepsCount   = data.TotalCount
                    });
                }
                catch (Exception exception)
                {
                    Debug.WriteLine(exception.Message);
                }
            }
            return(stepsByDay);
        }
示例#4
0
文件: OEMTask.cs 项目: sorryb/UWP
        /// <summary>
        /// Gets number of steps for current day
        /// </summary>
        /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns>
        private async Task <bool> GetStepsAsync()
        {
            // First try the pedometer
            try
            {
                var readings = await Pedometer.GetSystemHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);

                _steps = StepCountData.FromPedometerReadings(readings);
                return(true);
            }
            catch (Exception)
            {
                // Continue to the fallback
            }

            // Fall back to using Lumia Sensor Core.
            IStepCounter stepCounter = null;

            try
            {
                //var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;

                if (DeviceTypeHelper.GetDeviceFormFactorType() == DeviceFormFactorType.Phone)
                {
                    stepCounter = await StepCounter.GetDefaultAsync();

                    StepCount count = await stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);

                    _steps = StepCountData.FromLumiaStepCount(count);
                }
                else
                {
                    var obj = await SenseRecording.LoadFromFileAsync("Simulations\\short recording.txt");

                    if (!await CallSensorCoreApiAsync(async() => {
                        stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12));
                        StepCount count = await stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);
                        _steps = StepCountData.FromLumiaStepCount(count);
                    }))
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                _lastError = SenseHelper.GetSenseError(e.HResult);
                return(false);
            }
            finally
            {
                if (stepCounter != null && typeof(StepCounter) == stepCounter.GetType())
                {
                    ((StepCounter)stepCounter).Dispose();
                }
            }
            return(true);
        }
示例#5
0
        /// <summary>
        /// Returns step count for given day
        /// </summary>
        /// <returns>Step count for given day</returns>
        public async Task <StepCountData> GetTotalStepCountAsync(DateTime day)
        {
            if (_stepCounter != null && _sensorActive)
            {
                StepCount steps = await _stepCounter.GetStepCountForRangeAsync(day.Date, TimeSpan.FromDays(1));

                return(StepCountData.FromLumiaStepCount(steps));
            }
            return(null);
        }
示例#6
0
        /// <summary>
        /// Gets number of steps for current day
        /// </summary>
        /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns>
        private async Task <bool> GetStepsAsync()
        {
            // First try the pedometer
            try
            {
                var readings = await Pedometer.GetSystemHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);

                _steps = StepCountData.FromPedometerReadings(readings);
                return(true);
            }
            catch (Exception)
            {
                // Continue to the fallback
            }

            // Fall back to using Lumia Sensor Core.
            StepCounter stepCounter = null;

            try
            {
                stepCounter = await StepCounter.GetDefaultAsync();

                StepCount count = await stepCounter.GetStepCountForRangeAsync(
                    DateTime.Now.Date,
                    DateTime.Now - DateTime.Now.Date);

                _steps = StepCountData.FromLumiaStepCount(count);
            }
            catch (Exception e)
            {
                _lastError = SenseHelper.GetSenseError(e.HResult);
                return(false);
            }
            finally
            {
                if (stepCounter != null)
                {
                    stepCounter.Dispose();
                }
            }
            return(true);
        }
示例#7
0
        public async Task <List <ReadingByDate> > GetStepsForHour(int hour, int days)
        {
            List <ReadingByDate> stepsByDay = new List <ReadingByDate>();

            for (int i = 0; i < days; i++)
            {
                var dateTime    = DateTime.Now.Subtract(TimeSpan.FromDays(i));
                var stepsForDay = await Pedometer.GetSystemHistoryAsync(dateTime, TimeSpan.FromHours(hour));

                var data = StepCountData.FromPedometerReadings(stepsForDay);
                stepsByDay.Add(new ReadingByDate
                {
                    DateTime          = dateTime.AddHours(hour),
                    RunningStepsCount = data.RunningCount,
                    WalkingStepsCount = data.WalkingCount,
                    TotalStepsCount   = data.TotalCount
                });
            }
            return(stepsByDay);
        }