Exemplo n.º 1
0
        public static double[] CalculateAverageSeries(DateTime selectedDate, int rangeInDays, List <History> history, ReturnSeriesOf returnSeriesOf)
        {
            List <double[]> collectionOfDays = GetCollection(selectedDate, rangeInDays, history, returnSeriesOf);

            return(GetAverage(collectionOfDays));
        }
Exemplo n.º 2
0
        public static double[] CalculateSeries(DateTime date, List <History> history, ReturnSeriesOf returnSeriesOf)
        {
            double[] series      = new double[_minsInOneDay];
            DateTime timeCounter = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);

            History[] historyEntries = history.Where(x => x.IsSameDate(date)).OrderBy(x => x.DateTime).ToArray();
            if (historyEntries.Length == 0)
            {
                return(new double[_minsInOneDay]);
            }

            int    historyCount = 1; //skip the first element at 00:00 of 0
            double calsPerMin   = CalculateCaloriesPerMin(historyEntries, historyCount);

            double caloriesBurnt = 0;

            // itterate through the minutes of the day
            for (int i = 0; i < _minsInOneDay; i++)
            {
                if (historyCount < historyEntries.Length - 1)
                {
                    if (historyEntries[historyCount].IsSameTimeInMins(timeCounter))
                    {
                        historyCount++;
                        calsPerMin = CalculateCaloriesPerMin(historyEntries, historyCount);
                    }
                }
                switch (returnSeriesOf)
                {
                case ReturnSeriesOf.CaloriesBurnt:
                    caloriesBurnt += calsPerMin;
                    series[i]      = caloriesBurnt;
                    break;

                case ReturnSeriesOf.CaloriesPerMin:
                    series[i] = calsPerMin;
                    break;

                default:
                    break;
                }
                timeCounter = timeCounter.AddMinutes(1);

                if (timeCounter > DateTime.Now)
                {
                    break;
                }
            }
            return(series);
        }
Exemplo n.º 3
0
        public static List <double[]> GetCollection(DateTime selectedDate, int rangeInDays, List <History> history, ReturnSeriesOf returnDataSetType)
        {
            List <double[]> collectionOfDays = new List <double[]>();

            // Get previous days to calculate average
            // Only select those that are the same day of the week
            // Only look back as far as the rangeInDays
            // Not including the selected day
            for (int i = 1; i < rangeInDays; i++)
            {
                DateTime date = selectedDate.AddDays(-i);
                if (date.DayOfWeek == selectedDate.DayOfWeek)
                {
                    List <History> currentHistory = new List <History>();
                    currentHistory = history.Where(x => x.IsSameDate(date)).OrderBy(x => x.DateTime).ToList();
                    if (currentHistory.Count > 0)
                    {
                        collectionOfDays.Add(CalculateSeries(date, history, returnDataSetType));
                    }
                }
            }
            return(collectionOfDays);
        }