/// <summary> /// Fills HistoryRangeModelItem with the information from HistoryRangeModel /// </summary> /// <param name="binCount">binCount in HistoryRangeModel</param> /// <param name="model">HistoryRangeModel itself</param> /// <param name="row">HistoryRangeModelItem to add to UI</param> /// <param name="type">Type of teh hisotry session</param> /// <param name="icon">icon to show for this row</param> /// <param name="titleFormat">format for the title</param> /// <param name="amountFormat">amount format</param> /// <returns></returns> HistoryRangeModelItem FillRow(int binCount, HistoryRangeModel model, HistoryRangeModelItem row, SessionType type, string icon, string titleFormat, string amountFormat, string amountText = null) { if (!String.IsNullOrEmpty(icon)) { row.Icon = icon; } if (!String.IsNullOrEmpty(titleFormat)) { double totalValue = model.Total[(int)type]; if (SessionType.Nurse == type) { //totalValue *= 60; // To minutes totalValue /= (0 < binCount ? binCount : 7); // Per day in week row.Title = String.Format(titleFormat, new object[] { totalValue }); } else { totalValue /= (0 < binCount ? binCount : 7); row.Title = String.Format(titleFormat, new object[] { totalValue }); // Per day in week } } if (null != model) { double maxValue = model.MaxRangeValue[(int)type]; maxValue = Math.Max(1.0, maxValue); for (int i = 0; i < binCount; i++) { row.BinsInfo.Add(model.RangeNames[i]); double amount = model.RangeValues[(int)type, i]; row.BinsAmountValue.Add(String.Format(amountFormat, amount)); row.BinsAmountText.Add(String.IsNullOrEmpty(amountText) ? String.Empty : amountText); row.BarHeights.Add(Math.Max(0.0, (row.MaxBarHeight * amount) / maxValue)); } } else { // Fill with default empty values for (int i = 0; i < binCount; i++) { row.BinsInfo.Add(String.Empty); row.BinsAmountValue.Add(String.Empty); row.BinsAmountText.Add(String.Empty); row.BarHeights.Add(0.0); } } return(row); }
public List <HistoryRangeModel> GetWeek(DateTime start) { if (null == ProfileManager.Instance.CurrentProfile) { return(null); } if (DateTime.MinValue < start && start < DateTime.MaxValue) { // Always align with start of the week start = start.DayOfWeek != DayOfWeek.Sunday ? start.StartOfWeek(DayOfWeek.Sunday) : start; // Always check for existing bounds if (start < GetMinDate()) { start = GetMinDate(); } if (start > GetMaxDate()) { start = GetMaxDate(); } DateTime end = start + TimeSpan.FromDays(7); IEnumerable <HistoryModel> sessions = from s in _sessions where ((s.StartTime >= start) && (s.EndTime <= end)) orderby(s.StartTime) select s; List <HistoryRangeModel> ranges = new List <HistoryRangeModel>(); // Total summary: HistoryRangeModel range = new HistoryRangeModel(); range.Process(sessions, start, Timeframe.Week, null); ranges.Add(range); if (0 < ProfileManager.Instance.CurrentProfile?.Babies?.Count) { // Summary for each child: foreach (BabyModel baby in ProfileManager.Instance.CurrentProfile.Babies) { range = new HistoryRangeModel(); range.Process(sessions, start, Timeframe.Week, baby.Id); ranges.Add(range); } } return(ranges); } return(null); }
public HistoryRangeModel GetMonth(DateTime start) { HistoryRangeModel range = new HistoryRangeModel(); int daysInMonth = DateTime.DaysInMonth(start.Year, start.Month); DateTime end = start + TimeSpan.FromDays(daysInMonth); IEnumerable <HistoryModel> sessions = from s in _sessions where ((s.StartTime >= start) && (s.EndTime <= end)) select s; range.Process(sessions, start, Timeframe.Month, null); return(range); }