Exemplo n.º 1
0
        public async Task <Statistics> GetStatistics(string user)
        {
            List <MonthData> months = await m_DataProvider.GetMany(x => x.Username == user);

            var domainMonths = months.Select(x => x.ToDomain());

            //need to prune days that are later than the currentdate
            var domainWeeks = months.SelectMany(x => x.Weeks);
            //to do this we need to extract a ew object for each day, and project the date
            //into the new object, because date is only recorded for each week
            //the Select with index parameter helps here
            var domainDays = domainWeeks.SelectMany(w => w.Days.Select(
                                                        (d, i) => new { Date = w.StartingDate.AddDays(i), GoodOrNot = d.GoodOrNot }))
                             .Where(x => x.Date < DateTime.Now)
                             .OrderBy(x => x.Date);;

            var good = domainDays.Aggregate(
                new { Longest = 0, Current = 0 },
                (x, y) => y.GoodOrNot > 0
                ? new { Longest = Math.Max(x.Longest, x.Current + 1), Current = x.Current + 1 }
                : new { Longest = x.Longest, Current = 0 });

            var bad = domainDays.Aggregate(
                new { Longest = 0, Current = 0 },
                (x, y) => y.GoodOrNot < 0
                ? new { Longest = Math.Max(x.Longest, x.Current + 1), Current = x.Current + 1 }
                : new { Longest = x.Longest, Current = 0 });
            //fetch the data and look for sequences
            Statistics statistics = new Statistics
            {
                CurrentRunOfBadDays  = bad.Current,
                CurrentRunOfGoodDays = good.Current,
                LongestRunOfBadDays  = bad.Longest,
                LongestRunOfGoodDays = good.Longest
            };

            return(statistics);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new Statistics object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static Statistics CreateStatistics(global::System.Int32 id)
 {
     Statistics statistics = new Statistics();
     statistics.Id = id;
     return statistics;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Statistics EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStatistics(Statistics statistics)
 {
     base.AddObject("Statistics", statistics);
 }