Ejemplo n.º 1
0
        void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            ObservableCollection <EmotionalStateModel> emotionList
                = new ObservableCollection <EmotionalStateModel>();

            SetProgressBarVisibility(false);
            if (e.ErrorText == null)
            {
                XElement responseNode = XElement.Parse(e.ResponseXml);
                foreach (XElement thing in responseNode.Descendants("thing"))
                {
                    DateTime            when           = Convert.ToDateTime(thing.Element("eff-date").Value);
                    EmotionalStateModel emotionalState = new EmotionalStateModel();
                    emotionalState.When = when;
                    emotionalState.Parse(thing.Descendants("data-xml").Descendants("emotion").Single());

                    Dispatcher.BeginInvoke(() => {
                        DoItemAdd(
                            emotionalState.When,
                            emotionalState.Mood,
                            emotionalState.Stress,
                            emotionalState.Wellbeing);
                    });
                }
            }
        }
Ejemplo n.º 2
0
        void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            SetProgressBarVisibility(false);

            if (e.ErrorText == null)
            {
                XElement responseNode = XElement.Parse(e.ResponseXml);
                // using linq to get the latest reading of emotional state
                XElement latestEmotion = (from thingNode in responseNode.Descendants("thing")
                                          orderby Convert.ToDateTime(thingNode.Element("eff-date").Value) descending
                                          select thingNode).FirstOrDefault <XElement>();

                EmotionalStateModel emotionalState =
                    new EmotionalStateModel();
                emotionalState.Parse(latestEmotion.Descendants("data-xml").Descendants("emotion").Single());

                string lastTime = Convert.ToDateTime(latestEmotion.Element("eff-date").Value).ToString();

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    c_LastUpdated.Text     += lastTime;
                    c_MoodSlider.Value      = (double)emotionalState.Mood;
                    c_StressSlider.Value    = (double)emotionalState.Stress;
                    c_WellbeingSlider.Value = (double)emotionalState.Wellbeing;
                    this.DataContext        = this;
                    //c_Mood.Text += System.Enum.GetName(typeof(Mood), emotionalState.Mood);
                    //c_Stress.Text += System.Enum.GetName(typeof(Stress), emotionalState.Stress);
                    //c_Wellbeing.Text += System.Enum.GetName(typeof(Wellbeing), emotionalState.Wellbeing);
                });
            }
        }
        void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            ObservableCollection <EmotionalStateModel> emotionList
                = new ObservableCollection <EmotionalStateModel>();

            SetProgressBarVisibility(false);
            if (e.ErrorText == null)
            {
                XElement responseNode = XElement.Parse(e.ResponseXml);
                foreach (XElement thing in responseNode.Descendants("thing"))
                {
                    EmotionalStateModel emotionalState = new EmotionalStateModel();
                    emotionalState.Parse(thing);

                    Dispatcher.BeginInvoke(() => {
                        DoItemAdd(
                            emotionalState.When,
                            emotionalState.Mood,
                            emotionalState.Stress,
                            emotionalState.Wellbeing,
                            emotionalState.Note);
                    });
                }
            }
        }
Ejemplo n.º 4
0
        void DoShellAuthentication(object sender, HealthVaultResponseEventArgs e)
        {
            SetProgressBarVisibility(false);

            App.HealthVaultService.SaveSettings(SettingsFilename);

            string url;

            if (_addingRecord)
            {
                url = App.HealthVaultService.GetUserAuthorizationUrl();
            }
            else
            {
                url = App.HealthVaultService.GetApplicationCreationUrl();
            }

            App.HealthVaultShellUrl = url;

            // If we are  using hosted browser via the hosted browser page
            Uri pageUri = new Uri("/HostedBrowser.xaml", UriKind.RelativeOrAbsolute);

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                NavigationService.Navigate(pageUri);
            });
        }
Ejemplo n.º 5
0
        void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            SetProgressBarVisibility(false);

            if (e.ErrorText == null)
            {
                XElement responseNode = XElement.Parse(e.ResponseXml);
                // using linq to get the latest reading of emotional state
                XElement latestEmotion = (from thingNode in responseNode.Descendants("thing")
                                          orderby Convert.ToDateTime(thingNode.Element("eff-date").Value) descending
                                          select thingNode).FirstOrDefault <XElement>();

                if (latestEmotion != null)
                {
                    EmotionalStateModel emotionalState =
                        new EmotionalStateModel();
                    emotionalState.Parse(latestEmotion);

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        c_LastUpdated.Text = string.Format("Last Update - {0}", emotionalState.When.ToString("MMM dd, yyyy"));

                        //c_MoodSlider.Value = (double)emotionalState.Mood;
                        //c_StressSlider.Value = (double)emotionalState.Stress;
                        //c_WellbeingSlider.Value = (double)emotionalState.Wellbeing;
                        this.DataContext = this;
                    });
                }
            }
        }
Ejemplo n.º 6
0
        void AuthenticationCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            SetProgressBarVisibility(false);

            if (e != null && e.ErrorText != null)
            {
                SetErrorMesasge(e.ErrorText);
                return;
            }

            if (App.HealthVaultService.CurrentRecord == null)
            {
                App.HealthVaultService.CurrentRecord = App.HealthVaultService.Records[0];
            }

            App.HealthVaultService.SaveSettings(App.SettingsFilename);
            if (App.HealthVaultService.CurrentRecord != null)
            {
                SetRecordName(App.HealthVaultService.CurrentRecord.RecordName);
                // We are only interested in the last item
                HealthVaultMethods.GetThings(EmotionalStateModel.TypeId, 1, null, null, GetThingsCompleted);
                SetProgressBarVisibility(true);
            }

            // Check to see if we should upload all the reading from Trial
            if (TrialModeStorageProvider.Instance.TrialStage == TrialState.UpgradeData)
            {
                if (TrialModeStorageProvider.Instance.TrialMode.emotionalStates.Count > 0)
                {
                    Dispatcher.BeginInvoke(() =>
                    {
                        MessageBoxResult result = MessageBox.Show(string.Format("You have {0} emotional state item(s).",
                                                                                TrialModeStorageProvider.Instance.TrialMode.emotionalStates.Count),
                                                                  "Upload local items to HealthVault", MessageBoxButton.OKCancel);
                        if (result == MessageBoxResult.Cancel)
                        {
                            CancelUpgrade();
                        }
                        if (result == MessageBoxResult.OK)
                        {
                            if (TrialModeStorageProvider.Instance.TrialMode.emotionalStates.Count > 0)
                            {
                                HealthVaultMethods.PutThings(TrialModeStorageProvider.Instance.TrialMode.emotionalStates,
                                                             PutThingsDoUpgradeCompleted);
                                SetProgressBarVisibility(true);
                            }
                        }
                    });
                }
                else
                {
                    EnjoyHealthVault();
                }
            }
        }
Ejemplo n.º 7
0
 void PutThingsCompleted(object sender, HealthVaultResponseEventArgs e)
 {
     SetProgressBarVisibility(false);
     if (e.ErrorText != null)
     {
         SetErrorMesasge(e.ErrorText);
     }
     else
     {
         SetUserToast("Mood successfully saved!");
     }
 }
Ejemplo n.º 8
0
 void PutThingsDoUpgradeCompleted(object sender, HealthVaultResponseEventArgs e)
 {
     SetProgressBarVisibility(false);
     if (e.ErrorText != null)
     {
         SetErrorMesasge(e.ErrorText);
     }
     else
     {
         SetUserToast("Reading(s) successfully moved to HealthVault, enjoy!");
         TrialModeStorageProvider.Instance.DeleteStore();
     }
 }
Ejemplo n.º 9
0
        void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            SetProgressBarVisibility(false);

            if (e.ErrorText == null)
            {
                XElement responseNode = XElement.Parse(e.ResponseXml);
                // using LINQ to get the latest reading of emotional state
                XElement latestEmotion = (from thingNode in responseNode.Descendants("thing")
                                          orderby Convert.ToDateTime(thingNode.Element("eff-date").Value) descending
                                          select thingNode).FirstOrDefault <XElement>();

                if (latestEmotion != null)
                {
                    EmotionalStateModel emotionalState =
                        new EmotionalStateModel();
                    emotionalState.Parse(latestEmotion);

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        c_LastUpdated.Text +=
                            string.Format("{0} - \nMood:{1}, Stress:{2}, Wellbeing:{3}",
                                          emotionalState.When.ToString("MMM dd, yyyy"),
                                          System.Enum.GetName(typeof(Mood), emotionalState.Mood),
                                          System.Enum.GetName(typeof(Stress), emotionalState.Stress),
                                          System.Enum.GetName(typeof(Wellbeing), emotionalState.Wellbeing));
                        this.DataContext = this;
                    });
                }
                else
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        c_LastUpdated.Text = "No readings! Time to track mood.";
                        this.DataContext   = this;
                    });
                }
            }
        }
Ejemplo n.º 10
0
        void AuthenticationCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            SetProgressBarVisibility(false);

            if (e != null && e.ErrorText != null)
            {
                SetRecordName(e.ErrorText);
                return;
            }

            if (App.HealthVaultService.CurrentRecord == null)
            {
                App.HealthVaultService.CurrentRecord = App.HealthVaultService.Records[0];
            }

            App.HealthVaultService.SaveSettings(SettingsFilename);
            if (App.HealthVaultService.CurrentRecord != null)
            {
                SetRecordName(App.HealthVaultService.CurrentRecord.RecordName);
                // We are only interested in the last item
                HealthVaultMethods.GetThings(EmotionalStateModel.TypeId, 1, null, null, GetThingsCompleted);
                SetProgressBarVisibility(true);
            }
        }
Ejemplo n.º 11
0
        void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            SetProgressBarVisibility(false);

            if (e != null && e.ErrorText != null)
            {
                SetErrorMesasge(e.ErrorText);
                return;
            }

            XElement responseNode = XElement.Parse(e.ResponseXml);

            foreach (XElement thing in responseNode.Descendants("thing"))
            {
                EmotionalStateModel emotionalState = new EmotionalStateModel();
                emotionalState.Parse(thing);
                this.emotionList.Add(emotionalState);
            }

            /*
             * Algorithm
             * 1. Read last 1 month's readings
             * 2. Weight 50% to 4th week
             * 3. Weight 25% to 1-3 week
             * 4. Weight 25% to how many readings (Good is 4/wk)
             */
            DateTime time50p = baseTime.Subtract(new TimeSpan(7, 0, 0, 0));
            DateTime time30p = baseTime.Subtract(new TimeSpan(14, 0, 0, 0));

            int m = 0; int s = 0; int w = 0;
            int c50 = 0; int c30 = 0; int c20 = 0;

            foreach (EmotionalStateModel emotion in emotionList)
            {
                if (emotion.When >= time50p)
                {
                    m += (int)emotion.Mood * 50;
                    s += (int)emotion.Stress * 50;
                    w += (int)emotion.Wellbeing * 50;
                    c50++;
                }
                else if (emotion.When >= time30p)
                {
                    m += (int)emotion.Mood * 30;
                    s += (int)emotion.Stress * 30;
                    w += (int)emotion.Wellbeing * 30;
                    c30++;
                }
                else
                {
                    m += (int)emotion.Mood * 20;
                    s += (int)emotion.Stress * 20;
                    w += (int)emotion.Wellbeing * 20;
                    c20++;
                }
            }

            //TODO: Test all the features with a record having no readings
            //TODO: Test with a record having garbled xml
            //Final numbers
            int c = 50 * c50 + 30 * c30 + 20 * c20;

            if (c != 0) // Avoid divide by Zero error
            {
                m = m / c;
                s = s / c;
                w = w / c;
            }

            EmotionalStateModel resultEmotion = new EmotionalStateModel();

            resultEmotion.Mood      = (Mood)m;
            resultEmotion.Stress    = (Stress)s;
            resultEmotion.Wellbeing = (Wellbeing)w;
            RenderPlantValue(resultEmotion);
        }