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);
                    });
                }
            }
        }
Exemplo n.º 2
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);
                    });
                }
            }
        }
Exemplo n.º 3
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);
                    });
                }
            }
        }
Exemplo n.º 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);
                });
            }
        }
Exemplo 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;
                    });
                }
            }
        }
Exemplo n.º 6
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;
                    });
                }
            }
        }
        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);
                    });
                }
            }
        }
Exemplo n.º 8
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);
        }
        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 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;
                    });
                }
            }
        }
Exemplo n.º 11
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);
                });
            }
        }