public ViewModel() { ChartTitle = "Weight"; LineData3 = new ObservableCollection <Points>(); LineData5 = new ObservableCollection <Points>(); LineData10 = new ObservableCollection <Points>(); LineData25 = new ObservableCollection <Points>(); LineData50 = new ObservableCollection <Points>(); LineData75 = new ObservableCollection <Points>(); LineData90 = new ObservableCollection <Points>(); WHOData weightData = new WHOData(); Dictionary <WHOData.Percentile, List <double> > weightByGender; List <Double> weightList3; List <Double> weightList5; List <Double> weightList10; List <Double> weightList25; List <Double> weightList50; List <Double> weightList75; List <Double> weightList90; weightData.weightPercentile.TryGetValue(WHOData.Sex.Male, out weightByGender); weightByGender.TryGetValue(WHOData.Percentile.P3, out weightList3); weightByGender.TryGetValue(WHOData.Percentile.P5, out weightList5); weightByGender.TryGetValue(WHOData.Percentile.P10, out weightList10); weightByGender.TryGetValue(WHOData.Percentile.P25, out weightList25); weightByGender.TryGetValue(WHOData.Percentile.P50, out weightList50); weightByGender.TryGetValue(WHOData.Percentile.P75, out weightList75); weightByGender.TryGetValue(WHOData.Percentile.P90, out weightList90); for (int i = 0; i < weightData.ageList.Count(); i++) { LineData3.Add(new Points(weightData.ageList[i], weightList3[i])); LineData5.Add(new Points(weightData.ageList[i], weightList5[i])); LineData10.Add(new Points(weightData.ageList[i], weightList10[i])); LineData25.Add(new Points(weightData.ageList[i], weightList25[i])); LineData50.Add(new Points(weightData.ageList[i], weightList50[i])); LineData75.Add(new Points(weightData.ageList[i], weightList75[i])); LineData90.Add(new Points(weightData.ageList[i], weightList90[i])); } InputData = new ObservableCollection <Points>(); List <Double> weightList2; weightByGender.TryGetValue(WHOData.Percentile.P90, out weightList2); for (int i = 0; i < weightData.ageList.Count(); i++) { //InputData.Add(new Points(weightData.ageList[i], weightList2[i])); } //InputData.Add(new Points(1, 1)); }
async Task OnMeasurementClicked(MeasurementType measurementType) { CurrentMeasurementType = measurementType; String measurementTitle = MeasurementEnums.MeasurementTypeAsString(measurementType, CurrentContext.CurrentLanguage); viewModel.ChartTitle = measurementTitle; GrowthChart.Text = measurementTitle; try { viewModel.InputData.Clear(); } catch (Exception e) { // Changing children and reverting to this page causes a crash. viewModel = new ViewModel(); viewModel.ChartTitle = measurementTitle; } if (CurrentChild == null) { return; } GrowthChart.Text = measurementTitle; viewModel.InputData.Clear(); if (CurrentChild == null) { if (CurrentContext.CurrentLanguage == Language.ENGLISH) { await DisplayAlert("Error", "Please select a child", "OK"); return; } else { await DisplayAlert("Error", "Porfavor seleccione un niño", "OK"); return; } } List <Points> points = CurrentChild.GetSortedMeasurementListByType(measurementType); if (points == null) { CurrentChild.AddMeasurementForDateAndType(CurrentChild.Birthday, MeasurementType.HEIGHT, CurrentContext.CurrentUnits, 0.0); CurrentChild.AddMeasurementForDateAndType(CurrentChild.Birthday, MeasurementType.WEIGHT, CurrentContext.CurrentUnits, 0.0); CurrentChild.AddMeasurementForDateAndType(CurrentChild.Birthday, MeasurementType.HEAD_CIRCUMFERENCE, CurrentContext.CurrentUnits, 0.0); return; } foreach (Points pt in points) { viewModel.InputData.Add(pt); } viewModel.LineData3.Clear(); viewModel.LineData5.Clear(); viewModel.LineData10.Clear(); viewModel.LineData25.Clear(); viewModel.LineData50.Clear(); viewModel.LineData75.Clear(); viewModel.LineData90.Clear(); WHOData measurementData = new WHOData(); Dictionary <WHOData.Percentile, List <double> > measurementsByGender; List <Double> measurementList3; List <Double> measurementList5; List <Double> measurementList10; List <Double> measurementList25; List <Double> measurementList50; List <Double> measurementList75; List <Double> measurementList90; // Find list of measurements for measurement type and gender. TODO: Change this based on preferred units. switch (measurementType) { case MeasurementType.WEIGHT: measurementData.weightPercentile.TryGetValue(WHOData.AdaptChildGender(CurrentChild.ChildGender), out measurementsByGender); break; case MeasurementType.HEIGHT: measurementData.heightPercentile.TryGetValue(WHOData.AdaptChildGender(CurrentChild.ChildGender), out measurementsByGender); break; case MeasurementType.HEAD_CIRCUMFERENCE: measurementData.headPercentile.TryGetValue(WHOData.AdaptChildGender(CurrentChild.ChildGender), out measurementsByGender); break; default: measurementData.weightPercentile.TryGetValue(WHOData.AdaptChildGender(CurrentChild.ChildGender), out measurementsByGender); break; } measurementsByGender.TryGetValue(WHOData.Percentile.P3, out measurementList3); measurementsByGender.TryGetValue(WHOData.Percentile.P5, out measurementList5); measurementsByGender.TryGetValue(WHOData.Percentile.P10, out measurementList10); measurementsByGender.TryGetValue(WHOData.Percentile.P25, out measurementList25); measurementsByGender.TryGetValue(WHOData.Percentile.P50, out measurementList50); measurementsByGender.TryGetValue(WHOData.Percentile.P75, out measurementList75); measurementsByGender.TryGetValue(WHOData.Percentile.P90, out measurementList90); for (int i = 0; i < measurementData.ageList.Count(); i++) { viewModel.LineData3.Add(new Points(measurementData.ageList[i], measurementList3[i])); viewModel.LineData5.Add(new Points(measurementData.ageList[i], measurementList5[i])); viewModel.LineData10.Add(new Points(measurementData.ageList[i], measurementList10[i])); viewModel.LineData25.Add(new Points(measurementData.ageList[i], measurementList25[i])); viewModel.LineData50.Add(new Points(measurementData.ageList[i], measurementList50[i])); viewModel.LineData75.Add(new Points(measurementData.ageList[i], measurementList75[i])); viewModel.LineData90.Add(new Points(measurementData.ageList[i], measurementList90[i])); } }