Exemplo n.º 1
0
        private async void ReadingChanged(ActivitySensor sender, ActivitySensorReadingChangedEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                ActivitySensorReading reading = args.Reading;

                SendMessage(reading.Activity.ToString());
            });
        }
 /// <summary>
 /// This is the event handler for ReadingChanged events.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 async private void ReadingChanged(object sender, ActivitySensorReadingChangedEventArgs e)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         ActivitySensorReading reading        = e.Reading;
         ScenarioOutput_Activity.Text         = reading.Activity.ToString();
         ScenarioOutput_Confidence.Text       = reading.Confidence.ToString();
         ScenarioOutput_ReadingTimestamp.Text = reading.Timestamp.ToString("u");
     });
 }
Exemplo n.º 3
0
 /// <summary>
 /// Update the reading in the screen.
 /// </summary>
 /// <returns>Nothing/returns>
 /// <param name="sender">The sender of the event</param>
 /// <param name="e">Event arguments</param>
 async private void ActivitySensor_ReadingChanged(object sender, ActivitySensorReadingChangedEventArgs e)
 {
     if (ReadingChanged != null)
     {
         await Task.Run(() =>
         {
             ActivitySensorReading reading = e.Reading;
             // Call into the reading changed handler registered by the client
             ReadingChanged(this, reading.Activity);
         });
     }
 }
Exemplo n.º 4
0
        void DisplayReading(ActivitySensorReading reading)
        {
            var bitmapImage = new BitmapImage(
                new Uri($"ms-appx:///Assets/{reading.Activity}.png"));

            this.activityImage.Source = bitmapImage;

            this.txtActivity.Text = reading.Activity.ToString();

            var confidenceLabel =
                reading.Confidence == ActivitySensorReadingConfidence.High ? "certain" : "unsure";

            this.txtActivityDetails.Text =
                $"{confidenceLabel} of this at {reading.Timestamp:hh.mm}";
        }
Exemplo n.º 5
0
        /// <summary>
        /// Updates the summary in the screen.
        /// </summary>
        /// <returns>Asynchronous task/returns>
        /// <param name="DayOffset">Day offset</param>
        /// <returns>Asyncrhonous Task</returns>
        public async Task UpdateSummaryAsync(uint DayOffset)
        {
            // Read current activity
            ActivitySensorReading reading = await _sensor.GetCurrentReadingAsync();

            if (reading != null)
            {
                ActivityData <Windows.Devices.Sensors.ActivityType> .Instance().CurrentActivity = reading.Activity;
            }

            // Fetch activity history for the day
            DateTime startDate = DateTime.Today.Subtract(TimeSpan.FromDays(DayOffset));
            DateTime endDate   = startDate + TimeSpan.FromDays(1);

            var history = await ActivitySensor.GetSystemHistoryAsync(startDate, TimeSpan.FromDays(1));

            // Create a dictionary to store data
            Dictionary <Windows.Devices.Sensors.ActivityType, TimeSpan> activitySummary = new Dictionary <Windows.Devices.Sensors.ActivityType, TimeSpan>();

            // Initialize timespan for all entries
            var activityTypes = Enum.GetValues(typeof(Windows.Devices.Sensors.ActivityType));

            foreach (var type in activityTypes)
            {
                activitySummary[(Windows.Devices.Sensors.ActivityType)type] = TimeSpan.Zero;
            }

            if (history.Count == 0 || history[0].Timestamp > startDate)
            {
                ActivitySensorReading firstReading = await GetActivityAtAsync(startDate);

                if (firstReading != null)
                {
                    List <ActivitySensorReading> finalHistory = new List <ActivitySensorReading>(history);
                    finalHistory.Insert(0, firstReading);
                    history = finalHistory.AsReadOnly();
                }
            }

            // Update the timespan for all activities in the dictionary
            if (history.Count > 0)
            {
                Windows.Devices.Sensors.ActivityType currentActivity = history[0].Activity;
                DateTime currentDate = history[0].Timestamp.DateTime;
                foreach (var item in history)
                {
                    if (item.Timestamp >= startDate)
                    {
                        TimeSpan duration = TimeSpan.Zero;
                        if (currentDate < startDate)
                        {
                            // If first activity of the day started already yesterday, set start time to midnight.
                            currentDate = startDate;
                        }
                        if (item.Timestamp > endDate)
                        {
                            // If last activity extends over to next day, set end time to midnight.
                            duration = endDate - currentDate;
                            break;
                        }
                        else
                        {
                            duration = item.Timestamp - currentDate;
                        }
                        activitySummary[currentActivity] += duration;
                    }
                    currentActivity = item.Activity;
                    currentDate     = item.Timestamp.DateTime;
                }
            }

            // Prepare the summary to add it to data source
            List <ActivityDuration <Windows.Devices.Sensors.ActivityType> > historyList = new List <ActivityDuration <Windows.Devices.Sensors.ActivityType> >();

            foreach (var activityType in activityTypes)
            {
                // For each entry in the summary add the type and duration to data source
                historyList.Add(new ActivityDuration <Windows.Devices.Sensors.ActivityType>((Windows.Devices.Sensors.ActivityType)activityType, activitySummary[(Windows.Devices.Sensors.ActivityType)activityType]));
            }

            // Update the singleton instance of the data source
            ActivityData <Windows.Devices.Sensors.ActivityType> .Instance().History = historyList;

            ActivityData <Windows.Devices.Sensors.ActivityType> .Instance().Date = startDate;
        }