/// <summary>
 /// Initializes a new instance of the <see cref="MonthSummaryViewModel"/> class.
 /// </summary>
 /// <param name="model">The first measurement for this month.</param>
 public MonthSummaryViewModel(Measurement measurement)
 {
     this.model = new MonthSummary();
     this.model.Month = new DateTime(measurement.DateTime.Year, measurement.DateTime.Month, 1);
     this.model.TotalMeasures = 1;
     this.model.TotalGlucose = measurement.GlucoseValue;
     this.model.TotalInsuline = measurement.InsulineUnits;
 }
        /// <summary>
        /// Calculates the summary for this month.
        /// </summary>
        /// <returns><see cref="MonthSummary"/> with this month's totals and averages.</returns>
        public MonthSummary CalculateSummary()
        {
            var summary = new MonthSummary()
            {
                Month = new DateTime(this.Year, this.Month, 1),
                TotalMeasures = this.Measurements.Count,
                TotalGlucose = this.Measurements.Sum(m => m.GlucoseValue),
                TotalInsuline = this.Measurements.Sum(m => m.InsulineUnits)
            };

            var dayMeasurements = from m in this.Measurements
                                  orderby m.DateTime descending
                                  group m by m.DateTime.Day into measurementsByDay
                                  select measurementsByDay;

            summary.MonthlyDayGlucoAverage = Convert.ToInt32(Math.Round(dayMeasurements.Average(d => d.Average(m => m.GlucoseValue))));
            summary.DailyAverageInsuline = Convert.ToInt32(Math.Round(dayMeasurements.Average(d => d.Sum(m => m.InsulineUnits))));

            return summary;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MonthSummaryViewModel"/> class.
 /// </summary>
 public MonthSummaryViewModel()
 {
     this.model = new MonthSummary();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MonthSummaryViewModel"/> class.
 /// </summary>
 /// <param name="model">The underlying model.</param>
 public MonthSummaryViewModel(MonthSummary model)
 {
     this.model = model;
 }
Exemple #5
0
        /// <summary>
        /// Updates the summary.
        /// </summary>
        /// <param name="monthSummary">The month summary.</param>
        /// <returns></returns>
        internal static async Task UpdateSummary(MonthSummary monthSummary)
        {
            var viewModel = new MonthSummaryViewModel(monthSummary);

            var oldSummary = SummaryData.FindItemByMonth(monthSummary.Month);
            if (oldSummary != null)
            {
                SummaryData.Remove(oldSummary);
            }

            SummaryData.Add(viewModel);
            SummaryData.OrderByMonthDesc();
            await StorageManager.WriteSummaryDataAsync(SummaryData.Select(d => d.Model));
        }