public ChartSummary GetMonthlyChart() { List <Workout_Active> tempresults = new List <Workout_Active>(); ChartSummary chart = new WorkOutDBLayer.WorkOutActiveDb.ChartSummary(); try { chart.ChartData = new List <int>(); int Calorie = 0; DateTime reference = DateTime.Now; Calendar calendar = CultureInfo.CurrentCulture.Calendar; IEnumerable <int> daysInMonth = Enumerable.Range(1, calendar.GetDaysInMonth(reference.Year, reference.Month)); List <Tuple <DateTime, DateTime> > weeks = daysInMonth.Select(day => new DateTime(reference.Year, reference.Month, day)) .GroupBy(d => calendar.GetWeekOfYear(d, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday)) .Select(g => new Tuple <DateTime, DateTime>(g.First(), g.Last())) .ToList(); weeks.ForEach(x => { Calorie = 0; foreach (Workout_Active item in db.WorkOutsActive.Where(a => a.End_Date >= x.Item1 && a.End_Date <= x.Item2).ToList()) { Calorie += db.WorkOutCollection.FirstOrDefault(a => a.WorkOutId == item.WorkOutId).CaloriesBurnPerMin; } chart.ChartData.Add(Calorie); }); } catch (Exception ex) { throw; } return(chart); }
public ChartSummary GetYearlyChart() { List <Workout_Active> tempresults = new List <Workout_Active>(); ChartSummary chart = new WorkOutDBLayer.WorkOutActiveDb.ChartSummary(); chart.ChartData = new List <int>(); chart.ChartLabel = new List <string>(); try { int Calorie = 0; for (int i = 1; i < 13; i++) { Calorie = 0; foreach (Workout_Active workoutactive in db.WorkOutsActive.Where(a => a.End_Date != null && a.End_Date.Value.Year == DateTime.Now.Year && a.End_Date.Value.Month == i).ToList()) { Calorie += db.WorkOutCollection.FirstOrDefault(a => a.WorkOutId == workoutactive.WorkOutId).CaloriesBurnPerMin; } chart.ChartLabel.Add(i.ToString()); chart.ChartData.Add(Calorie); } } catch (Exception ex) { throw; } return(chart); }
public ChartSummary GetWeeklyChart() { try { List <Workout_Active> tempresults = new List <Workout_Active>(); ChartSummary chart = new WorkOutDBLayer.WorkOutActiveDb.ChartSummary(); foreach (Workout_Active workoutactive in db.WorkOutsActive.Where(a => a.End_Date != null).ToList()) { if (GetWeekNumber(workoutactive.End_Date) == GetWeekNumber(DateTime.Now)) { tempresults.Add(workoutactive); } } chart.ChartData = new List <int>(); chart.ChartLabel = new List <string>() { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; chart.ChartData.Add(GetDayChart(tempresults, DayOfWeek.Monday)); chart.ChartData.Add(GetDayChart(tempresults, DayOfWeek.Tuesday)); chart.ChartData.Add(GetDayChart(tempresults, DayOfWeek.Wednesday)); chart.ChartData.Add(GetDayChart(tempresults, DayOfWeek.Thursday)); chart.ChartData.Add(GetDayChart(tempresults, DayOfWeek.Friday)); chart.ChartData.Add(GetDayChart(tempresults, DayOfWeek.Saturday)); chart.ChartData.Add(GetDayChart(tempresults, DayOfWeek.Sunday)); return(chart); } catch (Exception ex) { return(new ChartSummary()); } }