Пример #1
0
        private void UpdateData()
        {
            Profil    = DataStore.GetSettingsAsync().First();
            Objectifs = DataStore.GetObjectifAsync().First();
            Glucose_Data.Clear();
            Weight_Data.Clear();
            Last_Glycemia = null;
            Last_Hb1Ac    = null;
            Last_Pression = null;
            Last_Weight   = null;
            Average       = 0;
            Nbr_Hight     = 0;
            Nbr_Low       = 0;
            Nbr_Normal    = 0;
            Min           = 0;
            Max           = 0;
            foreach (var item in DataStore.GetGlucosAsync().Where(i => i.Date >= DateTime.Now.AddDays(-7)))
            {
                Glucose_Data.Add(GlycemiaConverter.Convert(item, Profil.GlycemiaUnit));
            }
            foreach (var item in DataStore.GetWeightAsync())
            {
                Weight_Data.Add(WeightConverter.Convert(item, Profil.WeightUnit));
            }
            pression_data = new ObservableCollection <Pression_Model>(DataStore.GetPressionAsync().Where(i => i.Date.Date == DateTime.Now.Date));
            Hb1Ac_Data    = new ObservableCollection <Hb1Ac_Model>(DataStore.GetHb1acAsync());

            if (Glucose_Data.Count > 0)
            {
                Last_Glycemia = Glucose_Data.OrderBy(i => i.Date).Last();
                Average       = (Profil.GlycemiaUnit == "mg / dL") ? Math.Round((Glucose_Data.Sum(i => i.Glycemia)) / Glucose_Data.Count, 0) : Math.Round((Glucose_Data.Sum(i => i.Glycemia)) / Glucose_Data.Count, 3);
                Min           = Glucose_Data.OrderBy(i => i.Glycemia).First().Glycemia;
                Max           = Glucose_Data.OrderBy(i => i.Glycemia).Last().Glycemia;
                if (Profil.GlycemiaUnit == "mg / dL")
                {
                    Nbr_Normal = Glucose_Data.Where(i => i.Glycemia >= Objectifs.Min_Glycemia & i.Glycemia <= Objectifs.Max_Glycemia).Count();
                    Nbr_Hight  = Glucose_Data.Where(i => i.Glycemia > Objectifs.Max_Glycemia).Count();
                    Nbr_Low    = Glucose_Data.Where(i => i.Glycemia < Objectifs.Min_Glycemia).Count();
                    if (Last_Glycemia.Glycemia < Objectifs.Min_Glycemia & Last_Glycemia.Glycemia != 0)
                    {
                        GlucoseColor = Color.FromHex("#f1c40f");
                    }
                    if (Last_Glycemia.Glycemia >= Objectifs.Min_Glycemia & Last_Glycemia.Glycemia <= Objectifs.Max_Glycemia)
                    {
                        GlucoseColor = Color.FromHex("#0AC774");
                    }
                    if (Last_Glycemia.Glycemia > Objectifs.Max_Glycemia)
                    {
                        GlucoseColor = Color.FromHex("#C72D14");
                    }
                }
                else
                {
                    Nbr_Normal = Glucose_Data.Where(i => i.Glycemia >= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit) & i.Glycemia <= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit)).Count();
                    Nbr_Hight  = Glucose_Data.Where(i => i.Glycemia > GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit)).Count();
                    Nbr_Low    = Glucose_Data.Where(i => i.Glycemia < GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit)).Count();
                    if (Last_Glycemia.Glycemia < GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit) & Average != 0)
                    {
                        GlucoseColor = Color.FromHex("#f1c40f");
                    }
                    if (Last_Glycemia.Glycemia >= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit) & Average <= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit))
                    {
                        GlucoseColor = Color.FromHex("#2ecc71");
                    }
                    if (Last_Glycemia.Glycemia > GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit))
                    {
                        GlucoseColor = Color.FromHex("#e74c3c");
                    }
                }
            }
            if (pression_data.Count > 0)
            {
                Last_Pression = Pression_Data.Where(i => i.Date.Date <= DateTime.Now.Date).OrderBy(i => i.Date).Last();
            }
            if (Hb1Ac_Data.Count > 0)
            {
                Last_Hb1Ac = Hb1Ac_Data.Where(i => i.Date.Date <= DateTime.Now.Date).OrderBy(i => i.Date).Last();
            }
            if (Weight_Data.Count > 0)
            {
                Last_Weight = Weight_Data.Where(i => i.Date.Date <= DateTime.Now.Date).OrderBy(i => i.Date).Last();
            }
            if (DataStore.GetStepsAsync().Count() > 0)
            {
                if (DataStore.GetStepsAsync().Where(i => i.Date.Date == DateTime.Now.Date).Count() > 0)
                {
                    Steps = DataStore.GetStepsAsync().Single(i => i.Date.Date == DateTime.Now.Date).Steps;
                }
            }
            NextMedication();
        }
 private void UpdateData()
 {
     if (!(Selected_MaxDate >= Selected_MinDate))
     {
         DependencyService.Get <IMessage>().ShortAlert("Date Non Valide");
         return;
     }
     Pression_Data.Clear();
     Min_sys        = null;
     Max_sys        = null;
     Average_sys    = 0;
     Nbr_Hight_sys  = 0;
     Nbr_Low_sys    = 0;
     Nbr_Normal_sys = 0;
     Min_dia        = null;
     Max_dia        = null;
     Average_dia    = 0;
     Nbr_Hight_dia  = 0;
     Nbr_Low_dia    = 0;
     Nbr_Normal_dia = 0;
     foreach (var item in DataStore.GetPressionAsync().Where(i => i.Date.Date >= Selected_MinDate & i.Date.Date <= Selected_MaxDate))
     {
         Pression_Data.Add(item);
     }
     if (Pression_Data.Count > 0)
     {
         Pression_Data  = new ObservableCollection <Pression_Model>(Pression_Data.OrderBy(i => i.Date));
         Min_sys        = Pression_Data.OrderBy(i => i.Systolique).First();
         Max_sys        = Pression_Data.OrderBy(i => i.Systolique).Last();
         Nbr_Normal_sys = Pression_Data.Where(i => i.Systolique >= 90 & i.Systolique <= 120).Count();
         Nbr_Hight_sys  = Pression_Data.Where(i => i.Systolique > 120).Count();
         Nbr_Low_sys    = Pression_Data.Where(i => i.Systolique < 90).Count();
         MaximumChart   = Convert.ToInt32(Max_sys.Systolique + 30);
         Average_sys    = Math.Round(Convert.ToDouble(Pression_Data.Sum(i => i.Systolique) / Pression_Data.Count), 1);
         Min_dia        = Pression_Data.OrderBy(i => i.Diastolique).First();
         Max_dia        = Pression_Data.OrderBy(i => i.Diastolique).Last();
         Nbr_Normal_dia = Pression_Data.Where(i => i.Diastolique >= 60 & i.Diastolique <= 80).Count();
         Nbr_Hight_dia  = Pression_Data.Where(i => i.Diastolique > 80).Count();
         Nbr_Low_dia    = Pression_Data.Where(i => i.Diastolique < 60).Count();
         Average_dia    = Math.Round(Convert.ToDouble(Pression_Data.Sum(i => i.Diastolique) / Pression_Data.Count), 1);
         if (string.IsNullOrWhiteSpace(Message))
         {
             Message = Resources["Last_F"] + " " + Resources["Blood_pressure"] + " : " + Pression_Data.Last().Systolique + " mm Hg / " + Pression_Data.Last().Diastolique + " mm Hg";
         }
     }
     if (Average_sys >= 90 & Average_sys <= 120)
     {
         Sys_Color = Color.FromHex("#0AC774");
     }
     if (Average_sys < 90)
     {
         Sys_Color = Color.FromHex("#f1c40f");
     }
     if (Average_sys > 120)
     {
         Sys_Color = Color.FromHex("#C72D14");
     }
     if (Average_dia >= 60 & Average_dia <= 80)
     {
         Dia_Color = Color.FromHex("#0AC774");
     }
     if (Average_dia < 60)
     {
         Dia_Color = Color.FromHex("#f1c40f");
     }
     if (Average_dia > 80)
     {
         Dia_Color = Color.FromHex("#C72D14");
     }
 }