Exemple #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);
                    });
                }
            }
        }
        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);
                    });
                }
            }
        }
        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;
                    });
                }
            }
        }
Exemple #4
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"))
                {
                    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);
                    });
                }
            }
        }
Exemple #6
0
        private void DoItemAdd(DateTime when, Mood mood,
                               Stress stress, Wellbeing wellbeing)
        {
            EmotionalStateModel emotion = new EmotionalStateModel();

            emotion.When      = when;
            emotion.Mood      = mood;
            emotion.Stress    = stress;
            emotion.Wellbeing = wellbeing;
            this.EmotionList.Add(emotion);
        }
Exemple #7
0
        // Save the reading to HealthVault
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            EmotionalStateModel model = new EmotionalStateModel();

            model.Mood      = (Mood)c_MoodSlider.Value;
            model.Stress    = (Stress)c_StressSlider.Value;
            model.Wellbeing = (Wellbeing)c_WellbeingSlider.Value;
            model.When      = DateTime.Now;
            HealthVaultMethods.PutThings(model, PutThingsCompleted);
            SetProgressBarVisibility(true);
        }
Exemple #8
0
 void RenderPlantValue(EmotionalStateModel emotion)
 {
     Dispatcher.BeginInvoke(() =>
     {
         c_vmudi_plant_wellbeing.Source = new BitmapImage(new Uri(
                                                              string.Format("Images/plant/myplant_wellbeing_{0}.png", emotion.Wellbeing.ToString().ToLower()),
                                                              UriKind.Relative));
         c_vmudi_plant_mood.Source = new BitmapImage(new Uri(
                                                         string.Format("Images/plant/myplant_mood_{0}.png", emotion.Mood.ToString().ToLower()),
                                                         UriKind.Relative));
         c_vmudi_plant_stress.Source = new BitmapImage(new Uri(
                                                           string.Format("Images/plant/myplant_stress_{0}.png", emotion.Stress.ToString().ToLower()),
                                                           UriKind.Relative));
     });
 }
Exemple #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;
                    });
                }
            }
        }
        // Save the readings to HealthVault
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            EmotionalStateModel model = new EmotionalStateModel();

            model.Mood      = (Mood)(moodSliderSelector.DataSource.SelectedItem as ValueData).ID;
            model.Stress    = (Stress)(stressSliderSelector.DataSource.SelectedItem as ValueData).ID;
            model.Wellbeing = (Wellbeing)(wellbeingSliderSelector.DataSource.SelectedItem as ValueData).ID;
            model.Note      = Txt_Note.Text;
            model.When      = DateTime.Now;
            if (!App.IsTrial)
            {
                HealthVaultMethods.PutThings(model, PutThingsCompleted);
                SetProgressBarVisibility(true);
            }
            else
            {
                SetProgressBarVisibility(true);
                TrialModeStorageProvider.Instance.TrialMode.emotionalStates.Add(model);
                TrialModeStorageProvider.Instance.Save();
                SetProgressBarVisibility(false);
                SetUserToast("Mood successfully saved on the device!");
            }
        }
        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);
                    });
                }
            }
        }
        void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            
            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);
                    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++;
                }
            }

            // Final numbers
            int c = 50 * c50 + 30 * c30 + 20 * c20;
            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);

        }
 void RenderPlantValue(EmotionalStateModel emotion)
 {
     Dispatcher.BeginInvoke(() =>
         {
             c_vmudi_plant_wellbeing.Source = new BitmapImage(new Uri(
                    string.Format("Images/plant/myplant_wellbeing_{0}.png", emotion.Wellbeing.ToString().ToLower()),
                    UriKind.Relative));
             c_vmudi_plant_mood.Source = new BitmapImage(new Uri(
                    string.Format("Images/plant/myplant_mood_{0}.png", emotion.Mood.ToString().ToLower()),
                    UriKind.Relative));
             c_vmudi_plant_stress.Source = new BitmapImage(new Uri(
                    string.Format("Images/plant/myplant_stress_{0}.png", emotion.Stress.ToString().ToLower()),
                    UriKind.Relative));
         });
 }
 private void DoItemAdd(DateTime when, Mood mood, 
     Stress stress, Wellbeing wellbeing, String note)
 {
     EmotionalStateModel emotion = new EmotionalStateModel();
     emotion.When = when;
     emotion.Mood = mood;
     emotion.Stress = stress;
     emotion.Wellbeing = wellbeing;
     emotion.Note = note;
     this.EmotionList.Add(emotion);
 }
 // Save the reading to HealthVault
 private void Btn_SaveReadingToHealthVault_Click(object sender, RoutedEventArgs e)
 {
     EmotionalStateModel model = new EmotionalStateModel();
     model.Mood = (Mood)c_MoodSlider.Value;
     model.Stress = (Stress)c_StressSlider.Value;
     model.Wellbeing = (Wellbeing)c_WellbeingSlider.Value;
     model.When = DateTime.Now;
     model.Note = GetNote();
     HealthVaultMethods.PutThings(model, PutThingsCompleted);
     SetProgressBarVisibility(true);
 }
        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;
                    });
                }
            }
        }
Exemple #17
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);
        }
Exemple #18
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);
                });
            }
        }