Beispiel #1
0
        public Objectifs_ViewModel(IDataStore dataStore, INavigation navigation)
        {
            DataStore         = dataStore;
            Navigation        = navigation;
            Profil            = DataStore.GetSettingsAsync().First();
            GlycemiaConverter = new GlycemiaConverter();
            WeightConverter   = new WeightConverter();

            Objectifs = DataStore.GetObjectifAsync().First();
            var new_max   = GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit);
            var new_min   = GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit);
            var new_weght = WeightConverter.DoubleWeightConvet(Objectifs.Weight_Objectif, Profil.WeightUnit);

            Max_Glycemia = new_max.ToString();
            Min_Glycemia = new_min.ToString();
            Objectifs.Weight_Objectif = new_weght;

            SaveCommand = new Command(async() =>
            {
                await ExecuteOnSaveObjectifs();
            });
        }
Beispiel #2
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()
        {
            IsBusy = true;
            Glucose_Data.Clear();
            Slices.Clear();
            Min        = null;
            Max        = null;
            Average    = 0;
            Nbr_Normal = 0;
            Nbr_Hight  = 0;
            Nbr_Low    = 0;
            if (type == "All")
            {
                foreach (var item in DataStore.GetGlucosAsync().Where(i => i.Date.Date >= Selected_MinDate & i.Date.Date <= Selected_MaxDate))
                {
                    Glucose_Data.Add(GlycemiaConverter.Convert(item, Profil.GlycemiaUnit));
                }
            }
            else
            {
                foreach (var item in DataStore.GetGlucosAsync().Where(i => i.Date.Date >= Selected_MinDate & i.Date.Date <= Selected_MaxDate).Where(i => i.Glucose_time == type))
                {
                    Glucose_Data.Add(GlycemiaConverter.Convert(item, Profil.GlycemiaUnit));
                }
            }

            if (Glucose_Data.Count > 0)
            {
                Glucose_Data = new ObservableCollection <Glucose_Model>(Glucose_Data.OrderBy(i => i.Date));
                Min          = Glucose_Data.OrderBy(i => i.Glycemia).First();
                Max          = Glucose_Data.OrderBy(i => i.Glycemia).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);
                Nbr_Normal   = (Profil.GlycemiaUnit == "mg / dL") ? Glucose_Data.Where(i => i.Glycemia >= Objectifs.Min_Glycemia & i.Glycemia <= Objectifs.Max_Glycemia).Count() : 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    = (Profil.GlycemiaUnit == "mg / dL") ? Glucose_Data.Where(i => i.Glycemia > Objectifs.Max_Glycemia).Count() : Glucose_Data.Where(i => i.Glycemia > GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit)).Count();
                Nbr_Low      = (Profil.GlycemiaUnit == "mg / dL") ? Glucose_Data.Where(i => i.Glycemia < Objectifs.Min_Glycemia).Count() : Glucose_Data.Where(i => i.Glycemia < GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit)).Count();
                MaximumChart = (Profil.GlycemiaUnit == "mg / dL") ? Convert.ToInt32(Max.Glycemia + 100) : Convert.ToInt32(Max.Glycemia + 10);
                if (Average < GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit))
                {
                    GlucoseColor = Color.FromHex("#f1c40f");
                }
                if (Average >= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit) & Average <= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit))
                {
                    GlucoseColor = Color.FromHex("#2ecc71");
                }
                if (Average > GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit))
                {
                    GlucoseColor = Color.FromHex("#e74c3c");
                }
                Min_Glycemia = GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit);
                Max_Glycemia = GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit);
                Max_Widh     = MaximumChart - Max_Glycemia;
                Good_Wigh    = Max_Glycemia - Min_Glycemia;
            }
            Slices.Add(new Slice_Model
            {
                type  = "Normal",
                value = Nbr_Normal
            });
            Slices.Add(new Slice_Model
            {
                type  = "Elevée",
                value = Nbr_Hight
            });
            Slices.Add(new Slice_Model
            {
                type  = "Basse",
                value = Nbr_Low
            });
            IsBusy = false;
        }
        public GlucoseStatistique_ViewModel(INavigation navigation, IDataStore dataStore)
        {
            Navigation = navigation;
            DataStore  = dataStore;
            Profil     = DataStore.GetSettingsAsync().First();
            Objectifs  = dataStore.GetObjectifAsync().First();

            Glucose_Data      = new ObservableCollection <Glucose_Model>();
            GlycemiaConverter = new GlycemiaConverter();
            Message           = Resources["Target"] + " : " + GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit).ToString() + " " + Profil.GlycemiaUnit + " " + Resources["And"] + " " + GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit).ToString() + " " + Profil.GlycemiaUnit;
            Slices            = new ObservableCollection <Slice_Model>();
            type                = "All";
            Selected_MaxDate    = DateTime.Now.Date;
            Selected_MinDate    = DateTime.Now.Date;
            Selected_Index      = 0;
            Selected_Date_Index = 0;
            SegmentItems        = new ObservableCollection <SfSegmentItem>
            {
                new SfSegmentItem()
                {
                    Text = Resources["All"]
                },
                new SfSegmentItem()
                {
                    Text = Resources["Empty"]
                },
                new SfSegmentItem()
                {
                    Text = Resources["Before_Meal"]
                },
                new SfSegmentItem()
                {
                    Text = Resources["After_Meals"]
                },
            };
            DateItems = new ObservableCollection <SfSegmentItem>
            {
                new SfSegmentItem()
                {
                    Text = Resources["Today"]
                },
                new SfSegmentItem()
                {
                    Text = "7 " + Resources["Days"]
                },
                new SfSegmentItem()
                {
                    Text = "14 " + Resources["Days"]
                },
                new SfSegmentItem()
                {
                    Text = "30 " + Resources["Days"]
                },
                new SfSegmentItem()
                {
                    Text = "90 " + Resources["Days"]
                }
            };
            FiltreCommand = new Command(() =>
            {
                UpdateData();
            });
            UpdateData();
            MessagingCenter.Subscribe <GlucoseStatistique_Page>(this, "Filter", (sender) =>
            {
                UpdateData();
            });
        }