protected async Task RetrieveDataTrendsForCurrentBaby(Common.DataModel.MobileServicesDataSource currentDataSource, string babyId) { var latestDataTrendsRaw = await currentDataSource.GetDataTrends(babyId); var latestDataTrends = latestDataTrendsRaw.AsViewModel(CurrentBaby.DateOfBirth); DefaultViewModel.DataTrends = latestDataTrends; DefaultViewModel.CanShowActivityByHourGraph = latestDataTrends.FeedsOverLastDay != null && latestDataTrends.FeedsOverLastDay.Any() || latestDataTrends.SleepsOverLastDay != null && latestDataTrends.SleepsOverLastDay.Any() || latestDataTrends.ChangesOverLastDay != null && latestDataTrends.ChangesOverLastDay.Any(); DefaultViewModel.CanShowMoodByDayGraph = latestDataTrends.BabysMoodOverLastWeek != null && latestDataTrends.BabysMoodOverLastWeek.Any() || latestDataTrends.ParentsMoodOverLastWeek != null && latestDataTrends.ParentsMoodOverLastWeek.Any(); DefaultViewModel.CanShowMeasurementsByWeekGraph = (latestDataTrends.LengthSinceBirth != null && latestDataTrends.LengthSinceBirth.Any()) || (latestDataTrends.WeightSinceBirth != null && latestDataTrends.WeightSinceBirth.Any()); var startOfCurrentDay = DateTimeOffset.Now.Date; DefaultViewModel.TotalFeedsForDay = latestDataTrendsRaw.FeedsOverLastDay .Count(feed => feed.StartTime.ToLocalTime() >= startOfCurrentDay); DefaultViewModel.TotalSleepTimeForDay = latestDataTrendsRaw.SleepsOverLastDay .Where(sleep => sleep.StartTime.ToLocalTime() >= startOfCurrentDay) .Aggregate(TimeSpan.Zero, (a, b) => a.Add((b.EndTime ?? DateTime.UtcNow) - b.StartTime), a => a); DefaultViewModel.TotalChangesForDay = latestDataTrendsRaw.ChangesOverLastDay .Count(change => change.StartTime.ToLocalTime() >= startOfCurrentDay); }
protected async Task RetrieveAllBabies(SettingsViewModel currentSettings, Common.DataModel.MobileServicesDataSource currentDataSource) { var babies = await currentDataSource.GetBabies(currentSettings.FamilyId); foreach (var baby in babies) { // Current baby was already added when loaded if (baby.Id == CurrentBaby.Id) { continue; } DefaultViewModel.Babies.Add(baby.AsViewModel()); } }
protected async Task <string> RetrieveMostRecentlyAccessedBaby(SettingsViewModel currentSettings, Common.DataModel.MobileServicesDataSource currentDataSource) { var babyId = currentSettings.MostRecentlyAccessedBabyId; if (CurrentBaby == null) { var baby = await currentDataSource.GetBaby(babyId); CurrentBaby = baby.AsViewModel(); } CurrentBaby.ShowAgeInWeeks = SettingsViewModel.Current.ShowAgeInWeeks; DefaultViewModel.CurrentBaby = CurrentBaby; DefaultViewModel.PropertyChanged += DefaultViewModel_PropertyChanged; return(babyId); }
protected async Task RetrieveLatestMeasurementsForCurrentBaby(SettingsViewModel currentSettings, Common.DataModel.MobileServicesDataSource currentDataSource, string babyId) { var latestMeasurement = await currentDataSource.GetLatestMeasurement(babyId); DefaultViewModel.LatestMeasurement = latestMeasurement != null?latestMeasurement.AsViewModel(currentSettings.UseMetricUnits, CurrentBaby.AsModel()) : null; DefaultViewModel.ShowWeightMeasurement = latestMeasurement != null && latestMeasurement.Weight.HasValue; DefaultViewModel.ShowLengthMeasurement = latestMeasurement != null && latestMeasurement.Length.HasValue; }