Exemplo n.º 1
0
        public GraphsPage()
        {
            Title = "BP Readings";
            List <BPMRecords> Allrecord = new List <BPMRecords>();
            List <BPMRecords> record    = new List <BPMRecords>();

            //BPMRecords recode = new BPMRecords(3, 1, 2018, 138.02, 92.02, 105);
            //records(recode);

            #if __IOS__
            var resourcePrefix = "MoniHealth.iOS.Resources.";
            #endif

            #if __ANDROID__
            var resourcePrefix = "MoniHealth.Android.Resources.";
            #else
            var resourcePrefix = "MoniHealth.Pages.";
            #endif

            var editor = new Label {
                Text = "loading...", FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label))
            };

            #region How to load a text file embedded resource
            var    assembly = IntrospectionExtensions.GetTypeInfo(typeof(GraphsPage)).Assembly;
            Stream stream   = assembly.GetManifestResourceStream(resourcePrefix + "tempdata.txt");

            string text    = "";
            string alltext = "";
            int    count   = 0;
            using (var reader = new StreamReader(stream))
            {
                while ((text = reader.ReadLine()) != null)
                {
                    alltext = alltext + "\n" + text;
                    Allrecord.Add(new BPMRecords(text));
                    count = count + 1;
                }
                //text = reader.ReadLine();
            }
            #endregion
            editor.Text = alltext;

            //record.Add(new BPMRecords(text));
            //record.Add(new BPMRecords("1-Mar-18", 138.12, 85.12, 105));
            var Lastest = new Label {
                Text = " ", FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label))
            };
            var specificDates = new Label {
                Text = "", FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label))
            };


            Button Submit = new Button
            {
                Text              = "  Submit  ",
                Font              = Font.SystemFontOfSize(NamedSize.Small),
                BorderWidth       = 1,
                BorderColor       = Color.Silver,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start
            };

            Entry StartDate = new Entry
            {
                Keyboard          = Keyboard.Text,
                FontSize          = 10,
                Placeholder       = "Enter Start Date",
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.Start
            };
            Entry EndDate = new Entry
            {
                Keyboard          = Keyboard.Text,
                FontSize          = 10,
                Placeholder       = "Enter End Date",
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.Start
            };

            Button ViewGraph = new Button
            {
                Text              = "  ViewGraph  ",
                Font              = Font.SystemFontOfSize(NamedSize.Small),
                BorderWidth       = 1,
                BorderColor       = Color.Silver,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start
            };
            ViewGraph.Clicked += ViewGraphButton;



            Lastest.Text = Allrecord[count - 1].readingToString();

            Last = Allrecord[count - 1];

            record = Allrecord.Where(x => x.Month == 6 && x.Year == 2018).ToList();
            foreach (var reading in record)
            {
                specificDates.Text = specificDates.Text + reading.readingToString() + "\n";
            }


            /*Button createButton = new Button
             * {
             *
             *  Text = "Create Account",
             *  Font = Font.SystemFontOfSize(NamedSize.Small),
             *  BorderWidth = 1,
             *  HorizontalOptions = LayoutOptions.Center,
             *  VerticalOptions = LayoutOptions.CenterAndExpand
             * };
             * createButton.Clicked += OnButtonClicked;*/


            /*StackLayout stackLayout = new StackLayout { };
             *
             * stackLayout.Children.Add(editor);
             * Content = new ScrollView
             * {
             *  Content = stackLayout
             * };*/

            /*List<Entry> entries = new List<Entry>
             * {new Entry((float)record[count-2].Systolic)
             *  {
             *      Color = SKColor.Parse("#FF1493"),
             *      Label = record[count-2].Date,
             *      ValueLabel = record[count - 2].Systolic.ToString()
             *  },
             *
             * new Entry((float)record[count-1].Systolic)
             *  {
             *      Color = SKColor.Parse("#AA1493"),
             *      Label = record[count-1].Date,
             *      ValueLabel = record[count - 1].Systolic.ToString()
             *  }
             *
             *  };*/

            /*List<Entry> entries = new List<Entry> { };
             * double findmin = 300;
             * for (int i = 0; i <= 7; i++)
             * {
             *  entries.Add(new Entry((float)record[i].Systolic));
             *  entries[i].Label = record[i].Date;
             *  entries[i].ValueLabel = record[i].Systolic.ToString();
             *  entries[i].Color = SKColor.Parse("#FF1493");
             *
             *
             *  if (findmin >= record[i].Systolic)
             *  {
             *      findmin = record[i].Systolic;
             *  }
             * }
             *
             *
             *
             * ChartView chart1 = new ChartView
             * {
             *  Chart = new LineChart { Entries = entries, MinValue = (int)findmin,  },
             *  HeightRequest = 160,
             *  //Chart.DrawCaptionElements()
             *
             * };*/

            /*try
             * {
             *  Content = chart1;
             * }
             * catch (Exception e)
             * {
             *  if (e.InnerException != null)
             *  {
             *      string err = e.InnerException.Message;
             *  }
             * }*/


            StackLayout stackLayout = new StackLayout
            {
                Margin          = new Thickness(20),
                VerticalOptions = LayoutOptions.StartAndExpand,
                Children        =
                {
                    /*new Label { Text = (recode[0].ToStringArray()),
                     * FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
                     * FontAttributes = FontAttributes.Bold}*/
                    /*chart1,*/ Lastest, StartDate, EndDate, Submit, ViewGraph, specificDates, editor
                }
            };

            Content = new ScrollView
            {
                Content = stackLayout,
            };
        }
Exemplo n.º 2
0
        public GraphsPage()
        {
            Title = "BP Readings";

            //BPMRecords recode = new BPMRecords(3, 1, 2018, 138.02, 92.02, 105);
            //records(recode);

            #if __IOS__
            var resourcePrefix = "MoniHealth.iOS.Resources.";
            #endif

            #if __ANDROID__
            var resourcePrefix = "MoniHealth.Android.Resources.";
            #else
            var resourcePrefix = "MoniHealth.Pages.";
            #endif

            var editor = new Label {
                Text = "loading...", FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label))
            };

            #region How to load a text file embedded resource
            var    assembly = IntrospectionExtensions.GetTypeInfo(typeof(GraphsPage)).Assembly;
            Stream stream   = assembly.GetManifestResourceStream(resourcePrefix + "tempdata.txt");

            string text    = "";
            string alltext = "";
            using (var reader = new StreamReader(stream))
            {
                while ((text = reader.ReadLine()) != null)
                {
                    alltext = alltext + "\n" + text;
                    Allrecord.Add(new BPMRecords(text));
                    count = count + 1;
                }
                //text = reader.ReadLine();
            }
            #endregion
            editor.Text = alltext;

            //record.Add(new BPMRecords(text));
            //record.Add(new BPMRecords("1-Mar-18", 138.12, 85.12, 105));
            var Lastest = new Label {
                Text = " ", FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label))
            };

            #region Buttons and picker elements
            Button Submit = new Button
            {
                Text              = "  Submit  ",
                Font              = Font.SystemFontOfSize(NamedSize.Small),
                BorderWidth       = 1,
                BorderColor       = Color.Silver,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start
            };

            var Start = new Label {
                Text = "Start Date:", FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)), VerticalOptions = LayoutOptions.Center
            };
            DatePicker StartDate = new DatePicker
            {
                MinimumDate       = Allrecord[0].AllDate,
                MaximumDate       = Allrecord[count - 1].AllDate,
                FontSize          = 15,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.FillAndExpand,

                Date = Allrecord[0].AllDate,
            };
            start = StartDate.Date;
            StartDate.DateSelected += StartDateChanged;

            var End = new Label {
                Text = "End Date:  ", FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)), VerticalOptions = LayoutOptions.Center
            };
            DatePicker EndDate = new DatePicker
            {
                MinimumDate       = StartDate.Date,
                MaximumDate       = DateTime.Today,
                FontSize          = 15,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Date = Allrecord[count - 1].AllDate
            };
            end = EndDate.Date;
            EndDate.DateSelected += EndDateChanged;

            Button ViewGraph = new Button
            {
                Text              = "  ViewGraph  ",
                Font              = Font.SystemFontOfSize(NamedSize.Small),
                BorderWidth       = 1,
                BorderColor       = Color.Silver,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start
            };
            ViewGraph.Clicked += ViewGraphButton;

            Picker typeOfGraph = new Picker
            {
                Title             = "Type of Data in Graph",
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.Start
            };
            typeOfGraph.Items.Add("Systolic");
            typeOfGraph.Items.Add("Diastolic");
            typeOfGraph.Items.Add("HeartBeat");
            typeOfGraph.Items.Add("All");

            typeOfGraph.SelectedIndex         = 0;
            typeOfGraphs.Text                 = "Type of Graph: \n" /*+ typeOfGraph.Items[typeOfGraph.SelectedIndex]*/;
            typeOfGraph.SelectedIndexChanged += TypeOfGraphChanged;
            #endregion

            #region Adding data
            Input = new Button
            {
                Text              = "  Manual Input  ",
                Font              = Font.SystemFontOfSize(NamedSize.Small),
                BorderWidth       = 1,
                BorderColor       = Color.Silver,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start
            };
            Input.Clicked += InputButton;
            inputStack.Children.Add(Input);
            inputDateString = new Label {
                Text = "Input Date:", FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)), VerticalOptions = LayoutOptions.Center
            };
            inputDatePicker = new DatePicker
            {
                MinimumDate       = new DateTime(2018, 1, 1),
                MaximumDate       = DateTime.Today,
                FontSize          = 15,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.FillAndExpand,

                Date = DateTime.Today,
            };
            inputDate = DateTime.Today;
            inputDatePicker.DateSelected += InputDateChanged;
            inputTimeString = new Label {
                Text = "Input Time:", FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)), VerticalOptions = LayoutOptions.Center
            };
            inputTimePicker = new TimePicker
            {
                FontSize          = 15,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            //inputTimePicker.SetBinding(TimePicker.TimeProperty, "StartTime");
            inputTimePicker.PropertyChanged += InputTimeChanged;

            inputSystolic = new Entry
            {
                Keyboard        = Keyboard.Numeric,
                FontSize        = 13,
                Placeholder     = "Enter Systolic",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            inputDiastolic = new Entry
            {
                Keyboard        = Keyboard.Numeric,
                FontSize        = 13,
                Placeholder     = "Enter Diastolic",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            inputHeartBeat = new Entry
            {
                Keyboard        = Keyboard.Numeric,
                FontSize        = 13,
                Placeholder     = "Enter HeartBeat",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            SubmitInput = new Button
            {
                Text              = "  Submit Input  ",
                Font              = Font.SystemFontOfSize(NamedSize.Small),
                BorderWidth       = 1,
                BorderColor       = Color.Silver,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start
            };
            SubmitInput.Clicked += SubInputButton;
            CancelInput          = new Button
            {
                Text              = "  Cancel Input  ",
                Font              = Font.SystemFontOfSize(NamedSize.Small),
                BorderWidth       = 1,
                BorderColor       = Color.Silver,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start
            };
            CancelInput.Clicked += CancelInputButton;
            #endregion


            avgOfLastTen.Text = AverageLastTen();

            //Lastest.Text ="Latest Reading: "+ Allrecord[count - 1].readingToString();
            Lastest.Text = "Your most recent blood pressure measurement taken on 3-5-2019 was 124/85 mmHG, with a heartrate of 99";

            Last = Allrecord[count - 1];
            //start = StartDate.Date;
            //end = EndDate.Date;
            Submit.Clicked += SubmitButton;

            ;

            /*record = Allrecord.Where(x => x.AllDate >= StartDate.Date && x.AllDate <= EndDate.Date).ToList();
             * foreach (var reading in record)
             * {
             *  specificDates.Text = specificDates.Text + reading.readingToString() + "\n";
             * }*/

            #region Old greaphs method

            /*Button createButton = new Button
             * {
             *
             *  Text = "Create Account",
             *  Font = Font.SystemFontOfSize(NamedSize.Small),
             *  BorderWidth = 1,
             *  HorizontalOptions = LayoutOptions.Center,
             *  VerticalOptions = LayoutOptions.CenterAndExpand
             * };
             * createButton.Clicked += OnButtonClicked;*/


            /*StackLayout stackLayout = new StackLayout { };
             *
             * stackLayout.Children.Add(editor);
             * Content = new ScrollView
             * {
             *  Content = stackLayout
             * };*/

            /*List<Entry> entries = new List<Entry>
             * {new Entry((float)record[count-2].Systolic)
             *  {
             *      Color = SKColor.Parse("#FF1493"),
             *      Label = record[count-2].Date,
             *      ValueLabel = record[count - 2].Systolic.ToString()
             *  },
             *
             * new Entry((float)record[count-1].Systolic)
             *  {
             *      Color = SKColor.Parse("#AA1493"),
             *      Label = record[count-1].Date,
             *      ValueLabel = record[count - 1].Systolic.ToString()
             *  }
             *
             *  };*/

            /*List<Entry> entries = new List<Entry> { };
             * double findmin = 300;
             * for (int i = 0; i <= 7; i++)
             * {
             *  entries.Add(new Entry((float)record[i].Systolic));
             *  entries[i].Label = record[i].Date;
             *  entries[i].ValueLabel = record[i].Systolic.ToString();
             *  entries[i].Color = SKColor.Parse("#FF1493");
             *
             *
             *  if (findmin >= record[i].Systolic)
             *  {
             *      findmin = record[i].Systolic;
             *  }
             * }
             *
             *
             *
             * ChartView chart1 = new ChartView
             * {
             *  Chart = new LineChart { Entries = entries, MinValue = (int)findmin,  },
             *  HeightRequest = 160,
             *  //Chart.DrawCaptionElements()
             *
             * };*/

            /*try
             * {
             *  Content = chart1;
             * }
             * catch (Exception e)
             * {
             *  if (e.InnerException != null)
             *  {
             *      string err = e.InnerException.Message;
             *  }
             * }*/
            #endregion

            #region mini graph



            List <Microcharts.Entry> minientries = new List <Microcharts.Entry> {
            };
            double findmin    = 300;
            int    m          = 0;
            var    recordmini = Allrecord.Where(x => x.AllDate >= Allrecord[count - 10].AllDate && x.AllDate <= Allrecord[count - 1].AllDate).ToList();
            foreach (var reading in recordmini)
            {
                minientries.Add(new Microcharts.Entry((float)reading.Systolic));
                minientries[m].Label      = reading.AllDate.ToShortDateString();
                minientries[m].ValueLabel = reading.Systolic.ToString();
                minientries[m].Color      = SKColor.Parse("#FF1493");
                m++;

                if (findmin >= reading.Systolic)
                {
                    findmin = reading.Systolic;
                }
            }



            ChartView chart1 = new ChartView
            {
                Chart = new LineChart {
                    Entries = minientries, MinValue = (int)findmin,
                },
                HeightRequest = 160,
            };

            /*
             * try
             * {
             *  Content = chart1;
             * }
             * catch (Exception e)
             * {
             *  if (e.InnerException != null)
             *  {
             *      string err = e.InnerException.Message;
             *  }
             * }*/
            #endregion

            MainChart = chart1;


            StackLayout stackLayout = new StackLayout
            {
                Margin          = new Thickness(20),
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children        =
                {
                    /*new Label { Text = (recode[0].ToStringArray()),
                     *  FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
                     * FontAttributes = FontAttributes.Bold}*/
                    Lastest, new Label {
                        Text = ""
                    },       new Label {
                        Text = "Previous 10 recorded Systolic Blood Pressure Levels"
                    },       chart1, avgOfLastTen,
                    new StackLayout()
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Orientation       = StackOrientation.Horizontal, Children = { Start, StartDate   }
                    },
                    new StackLayout()
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Orientation       = StackOrientation.Horizontal, Children = { End,   EndDate     }
                    },
                    new StackLayout()
                    {
                        Orientation = StackOrientation.Horizontal,Children = { typeOfGraphs,                                      typeOfGraph }
                    },
                    new StackLayout()
                    {
                        Orientation = StackOrientation.Horizontal,Children = { Submit,                                            ViewGraph   }
                    },
                    avgOfSD, specificDates,
                    inputStack
                }
            };


            Content = new ScrollView
            {
                Content = stackLayout,
                Margin  = new Thickness(0, 0, 0, 10)
            };
        }