using System.Collections.Generic; using System.Linq; using skydiveLogs_api.Business.Interface; using skydiveLogs_api.Data.Interface; using skydiveLogs_api.Model; namespace skydiveLogs_api.Business { public class StatsService : IStatsService { public StatsService(IJumpRepository jumpRepository) { _jumpRepository = jumpRepository; } public IEnumerable GetStatsByAircraft() { var allJumps = _jumpRepository.GetAll(); return allJumps.GroupBy(j => j.Aircraft.Id, j => j, (groupby, jumps) => new Statistic { Label = groupby.ToString(), Nb = jumps.Count() }) .ToList(); } public IEnumerable GetStatsByDz() { var allJumps = _jumpRepository.GetAll(); return allJumps.GroupBy(j => j.DropZone.Id, j => j, (groupby, jumps) => new Statistic { Label = groupby.ToString(), Nb = jumps.Count() }) .ToList(); } public IEnumerable GetStatsByJumpType() { var allJumps = _jumpRepository.GetAll(); return allJumps.GroupBy(j => j.JumpType.Id, j => j, (groupby, jumps) => new Statistic { Label = groupby.ToString(), Nb = jumps.Count() }) .ToList(); } public IEnumerable GetStatsByGear() { var allJumps = _jumpRepository.GetAll(); return allJumps.GroupBy(j => j.Gear.Id, j => j, (groupby, jumps) => new Statistic { Label = groupby.ToString(), Nb = jumps.Count() }) .ToList(); } public IEnumerable GetStatsByYear() { var allJumps = _jumpRepository.GetAll(); return allJumps.GroupBy(j => j.JumpDate.Year, j => j, (groupby, jumps) => new Statistic { Label = groupby.ToString(), Nb = jumps.Count() }) .ToList(); } private readonly IJumpRepository _jumpRepository; } }