public async Task ExecuteLoadSeedDataCommand() { if (IsBusy) { return; } _dataClient = DependencyService.Get <IUserFoodDataService>(); _chartDataService = DependencyService.Get <IChartDataService>(); IsBusy = true; Foods = (await _dataClient.GetFoodsAsync()).ToObservableCollection(); CalorieItems = (await _chartDataService.GetWeeklyCaloriesDataPointsAsync(Foods)).ToObservableCollection(); var total = 0.0; int days = 0; foreach (var item in CalorieItems) { if (item.Value > 0) { total += item.Value; days++; } Debug.WriteLine("datecreated {0} Calories {1} Target {2}", item.Name, item.Value, item.Size); } AverageCalories = (total / days); IsBusy = false; IsInitialized = true; }
public async Task ExecuteLoadSeedDataCommand() { if (IsBusy) { return; } IsBusy = true; Foods = (await _DataClient.GetFoodsAsync()).ToObservableCollection(); WeeklyCaloriesChartDataPoints = (await _ChartDataService.GetWeeklyCaloriesDataPointsAsync(Foods)) .OrderBy(x => x.Name) .Select(x => new ChartDataPoint(x.Name, x.Value)) .ToObservableCollection(); AverageWeeklyCalories = string.Format("{0}", WeeklyCaloriesChartDataPoints.Average(x => x.YValue)); Debug.WriteLine("Weekly Average Calories: {0}", AverageWeeklyCalories); IsInitialized = true; IsBusy = false; }