コード例 #1
0
ファイル: ProfilePage.xaml.cs プロジェクト: Leo-Ngok/CVD_Calc
        private async void Button_Clicked(object sender, EventArgs e)
        {
            try
            {
                height = double.Parse(height_text.Text);
                weight = double.Parse(weight_text.Text);
                sybp   = double.Parse(sybp_text.Text);
                dibp   = double.Parse(dibp_text.Text);
                chol   = double.Parse(chol_text.Text);
                hdl    = double.Parse(hdl_text.Text);
                gen    = Extendparse(gend.SelectedItem.ToString());
                smo    = Extendparse(smok.SelectedItem.ToString());
                dia    = Extendparse(diab.SelectedItem.ToString());
                assertgt0(height);
                assertgt0(weight);
                assertgt0(sybp);
                assertgt0(dibp);
                assertgt0(chol);
                assertgt0(hdl);
            }
            catch (Exception)
            {
                await DisplayAlert("Error", "The value(s) you input is/are not valid", "Retry");

                return;
            }
            DB_pdata pdata = new DB_pdata()
            {
                dob  = DOB.Date,
                heig = height,
                hdll = hdl,
                Cho  = chol,
                Dbp  = dibp,
                diaB = dia,
                weig = weight,
                genD = gen,
                Sbp  = sybp,
                smoK = smo
            };

            using (SQLiteConnection conn = new SQLiteConnection(App.DB_persondata))
            {
                conn.CreateTable <DB_pdata>();
                conn.DeleteAll <DB_pdata>();
                int nbf = conn.Insert(pdata);
                if (nbf > 0)
                {
                    await DisplayAlert("Successful", "saved", "close"); await((MainPage)Application.Current.MainPage).NavigateFromMenu((int)MenuItemType.Home);
                }
                else
                {
                    await DisplayAlert("Failure", "record failed to be saved", "retry");
                }
            }
        }
コード例 #2
0
        private void Button_Clicked(object sender, EventArgs e)
        {
            int k = (int)lang;

            try
            {
                height = double.Parse(height_text.Text);
                weight = double.Parse(weight_text.Text);
                sybp   = double.Parse(sybp_text.Text);
                dibp   = double.Parse(dibp_text.Text);
                chol   = double.Parse(chol_text.Text);
                hdl    = double.Parse(hdl_text.Text);
                gen    = Extendparse(gend.SelectedItem.ToString());
                smo    = Extendparse(smok.SelectedItem.ToString());
                dia    = Extendparse(diab.SelectedItem.ToString());
                //med = Extendparse(tba.SelectedItem.ToString());
                assertgt0(height);
                assertgt0(weight);
                assertgt0(sybp);
                assertgt0(dibp);
                assertgt0(chol);
                assertgt0(hdl);
            }
            catch (Exception)
            {
                DisplayAlert(new string[] { "Error", "錯誤", "错误" }[k],
                             new string[] { "The value(s) you input is/are not valid", "輸入的數值無效", "输入的数值无效" }[k]
                             , new string[] { "Retry", "重試", "重试" }[k]);
                return;
            }
            DB_pdata pdata = new DB_pdata()
            {
                dob  = DOB.Date, heig = height,
                hdll = hdl, Cho = chol,
                Dbp  = dibp, diaB = dia,
                weig = weight, genD = gen,
                Sbp  = sybp, smoK = smo
            };

            using (SQLiteConnection conn = new SQLiteConnection(App.DBPATH))
            {
                conn.CreateTable <DB_pdata>();
                conn.DeleteAll <DB_pdata>();
                int nbf = conn.Insert(pdata);
                if (nbf > 0)
                {
                    DisplayAlert(new string[] { "Successful", "成功", "成功" }[k],
                                 new string[] { "saved", "已儲存", "已储存" }[k], new string[] { "close", "關閉", "关闭" }[k]);
                }
                else
                {
                    DisplayAlert("Failure", "record failed to be saved", "retry");
                }
            }
        }
コード例 #3
0
        private static double calcvd(DB_pdata c, double tem, weatherkey aq, bool ishol)
        {
            DateTime td  = DateTime.Today;
            double   age = (DateTime.Today.Year - c.dob.Year);

            if (td.Month < c.dob.Month || td.Day < c.dob.Day)
            {
                age--;
            }

            double height      = c.heig;
            double weight      = c.weig;
            bool   gender      = c.genD;
            double SP          = c.Sbp;
            double DP          = c.Dbp;
            double CL          = c.Cho;
            double BH          = c.hdll;
            bool   is_smoker   = c.smoK;
            bool   is_diabetic = c.diaB;

            double temp = tem;

            double frs = 0;

            double pm_2_5 = aq.PM2_5_level;
            double pm_10  = aq.PM_10_level;
            double so2    = aq.SO2_level;
            double no2    = aq.NO2_level;

            //age factor=====================================
            if (age >= 30 && age < 35)
            {
                frs--;
            }
            else if (age >= 40 && age < 45)
            {
                frs++;
            }
            else if (age >= 45 && age < 50)
            {
                frs += 2;
            }
            else if (age >= 50 && age < 55)
            {
                frs += 3;
            }
            else if (age >= 55 && age < 60)
            {
                frs += 4;
            }
            else if (age >= 60 && age < 65)
            {
                frs += 5;
            }
            else if (age >= 65 && age < 70)
            {
                frs += 6;
            }
            else if (age >= 70 && age < 75)
            {
                frs += 7;
            }
            //cholesterol level===============================
            if (CL < 160)
            {
                frs -= 3;
            }
            else if (CL >= 160 && CL < 200)
            {
                frs += 0;
            }
            else if (CL >= 200 && CL < 240)
            {
                frs++;
            }
            else if (CL >= 240 && CL < 280)
            {
                frs += 2;
            }
            else
            {
                frs += 3;
            }
            //blood HDL=======================================
            if (BH < 35)
            {
                frs += 2;
            }
            else if (BH >= 35 && BH < 45)
            {
                frs++;
            }
            else if (BH >= 45 && BH < 60)
            {
                frs += 0;
            }
            else
            {
                frs -= 2;
            }
            //blood pressure==================================
            if (SP >= 160 || DP >= 100)
            {
                frs += 3;
            }
            else if (SP >= 140 || DP >= 90)
            {
                frs += 2;
            }
            else if (SP >= 130 || DP >= 85)
            {
                frs++;
            }
            //else frs += 0;
            //is_diabetic=====================================
            if (is_diabetic)
            {
                frs += 2;
            }
            //is_smoker=======================================
            if (is_smoker)
            {
                frs += 2;
            }
            //convert to probability
            if (frs <= -3)
            {
                frs = 0.01;
            }
            else if (frs == -2)
            {
                frs = 0.02;
            }
            else if (frs == -1)
            {
                frs = 0.02;
            }
            else if (frs == 0)
            {
                frs = 0.03;
            }
            else if (frs == 1)
            {
                frs = 0.04;
            }
            else if (frs == 2)
            {
                frs = 0.04;
            }
            else if (frs == 3)
            {
                frs = 0.06;
            }
            else if (frs == 4)
            {
                frs = 0.07;
            }
            else if (frs == 5)
            {
                frs = 0.09;
            }
            else if (frs == 6)
            {
                frs = 0.11;
            }
            else if (frs == 7)
            {
                frs = 0.14;
            }
            else if (frs == 8)
            {
                frs = 0.18;
            }
            else if (frs == 9)
            {
                frs = 0.22;
            }
            else if (frs == 10)
            {
                frs = 0.27;
            }
            else if (frs == 11)
            {
                frs = 0.33;
            }
            else if (frs == 12)
            {
                frs = 0.4;
            }
            else if (frs == 13)
            {
                frs = 0.47;
            }
            else if (frs == 14)
            {
                frs = 0.56;
            }

            //temperature=====================================
            if (temp > 26)
            {
                frs *= Math.Pow(1.17, (temp - 26));
            }
            else if (temp < 26)
            {
                frs *= Math.Pow(1.12, (-temp + 26));
            }
            //air quality=====================================
            if (pm_2_5 > 96.2)
            {
                frs *= Math.Pow(1.27, (pm_2_5 - 96.2) / 10);
            }
            if (pm_10 > 115.6 && age >= 65)
            {
                frs *= Math.Pow(1.012, (pm_10 - 115.6) / 10);
            }
            if (so2 >= 53.21)
            {
                frs *= Math.Pow(1.01, (so2 - 53.21) / 10);
            }
            if (no2 >= 53.08)
            {
                frs *= Math.Pow(1.019, (no2 - 53.08) / 10);
            }

            //holiday factor
            if (ishol)
            {
                frs *= 2.375;
            }
            CrossLocalNotifications.Current.Show("CVD Calculated", "your cvd index is" + frs, 100000);
            return(frs);
        }