private void UpdateData() { if (!(Selected_MaxDate >= Selected_MinDate)) { DependencyService.Get <IMessage>().ShortAlert("Date Non Valide"); return; } Weight_Data.Clear(); Min = null; Max = null; IMC = 0; foreach (var item in DataStore.GetWeightAsync().Where(i => i.Date.Date >= Selected_MinDate & i.Date.Date <= Selected_MaxDate)) { Weight_Data.Add(WeightConverter.Convert(item, Settings.WeightUnit)); } if (Weight_Data.Count > 0) { Weight_Data = new ObservableCollection <Weight_Model>(Weight_Data.OrderBy(i => i.Date)); Min = Weight_Data.OrderBy(i => i.Weight).First(); Max = Weight_Data.OrderBy(i => i.Weight).Last(); MaximumChart = Convert.ToInt32(Max.Weight + 100); IMC = Math.Round(WeightConverter.DoubleWeightConvetBack(Weight_Data.OrderBy(i => i.Date).Last().Weight, Settings.WeightUnit) / Math.Pow(Profil.Height / 100, 2), 1); if (string.IsNullOrWhiteSpace(Message)) { Message = Resources["Last"] + " " + Resources["Weight_Label"] + " : " + Weight_Data.Last().Weight + " " + Settings.WeightUnit; } } if (IMC < 18.5) { GlucoseColor = Color.FromHex("#f1c40f"); } if (IMC >= 18.5 & IMC <= 25) { GlucoseColor = Color.FromHex("#2ecc71"); } if (IMC > 25) { GlucoseColor = Color.FromHex("#e74c3c"); } }
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(); }