using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; using System.Collections.Generic; using System.Linq; namespace skydiveLogs_api.DomainBusiness { public class StatsService : IStatsService { #region Public Constructors public StatsService(IJumpService jumpService, IStatsByAircraftService statsByAircraftService, IStatsByDzService statsByDzService, IStatsByGearService statsByGearService, IStatsByJumpTypeService statsByJumpTypeService, IStatsByYearByJumpTypeService statsByYearByJumpTypeService, IStatsByYearService statsByYearService, IStatsForLastMonthByDzService statsForLastMonthByDzService, IStatsForLastMonthByJumpTypeService statsForLastMonthByJumpTypeService, IStatsForLastYearByDzService statsForLastYearByDzService, IStatsForLastYearByJumpTypeService statsForLastYearByJumpTypeService) { _jumpService = jumpService; _statsByAircraftService = statsByAircraftService; _statsByDzService = statsByDzService; _statsByGearService = statsByGearService; _statsByJumpTypeService = statsByJumpTypeService; _statsByYearByJumpTypeService = statsByYearByJumpTypeService; _statsByYearService = statsByYearService; _statsForLastMonthByDzService = statsForLastMonthByDzService; _statsForLastMonthByJumpTypeService = statsForLastMonthByJumpTypeService; _statsForLastYearByDzService = statsForLastYearByDzService; _statsForLastYearByJumpTypeService = statsForLastYearByJumpTypeService; } #endregion Public Constructors #region Public Methods public SimpleSummary GetSimpleSummary() { var allJumps = _jumpService.GetAllJumps(); var results = new SimpleSummary(); if (allJumps.Any()) { var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); results = new SimpleSummary { LastJump = lastJump, TotalJumps = allJumps.Count(), TotalCutaways = allJumps.Where(j => j.WithCutaway).Count() }; } return results; } public void Reset() { // var resetStats = new UserStats(); // var myStats = GetAllStats(); // myStats.ByAircraft = resetStats.ByAircraft; // myStats.ByDz = resetStats.ByDz; // myStats.ByGear = resetStats.ByGear; // myStats.ByJumpType = resetStats.ByJumpType; // myStats.ByYear = resetStats.ByYear; // myStats.ForLastMonthByDz = resetStats.ForLastMonthByDz; // myStats.ForLastMonthByJumpType = resetStats.ForLastMonthByJumpType; // myStats.ForLastYearByDz = resetStats.ForLastYearByDz; // myStats.ForLastYearByJumpType = resetStats.ForLastYearByJumpType; // myStats.ByYearByJumpType = resetStats.ByYearByJumpType; // _userStatsRepository.Update(myStats); } public IEnumerable GetStatsByAircraft() { var tmp = _statsByAircraftService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.Aircraft, Nb = a.Nb })]; } public IEnumerable GetStatsByDz() { var tmp = _statsByDzService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.DropZone, Nb = a.Nb })]; } public IEnumerable GetStatsByGear() { var tmp = _statsByGearService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.Gear, Nb = a.Nb })]; } public IEnumerable GetStatsByJumpType() { var tmp = _statsByJumpTypeService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.JumpType, Nb = a.Nb })]; } public IEnumerable GetStatsByYear() { var tmp = _statsByYearService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.Year, Nb = a.Nb })]; } public IEnumerable GetStatsForLastMonthByDz() { var tmp = _statsForLastMonthByDzService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.DropZone, Nb = a.Nb })]; } public IEnumerable GetStatsForLastMonthByJumpType() { var tmp = _statsForLastMonthByJumpTypeService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.JumpType, Nb = a.Nb })]; } public IEnumerable GetStatsForLastYearByDz() { var tmp = _statsForLastYearByDzService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.DropZone, Nb = a.Nb })]; } public IEnumerable GetStatsForLastYearByJumpType() { var tmp = _statsForLastYearByJumpTypeService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.JumpType, Nb = a.Nb })]; } public IEnumerable GetStatsByYearByJumpType() { var tmp = _statsByYearByJumpTypeService.GetStats(); return [.. tmp.Select(a => new Statistic { Label = a.Year, Label2 = a.JumpType, Nb = a.Nb })]; } #endregion Public Methods #region Private Fields private readonly IJumpService _jumpService; private readonly IStatsByAircraftService _statsByAircraftService; private readonly IStatsByDzService _statsByDzService; private readonly IStatsByGearService _statsByGearService; private readonly IStatsByJumpTypeService _statsByJumpTypeService; private readonly IStatsByYearByJumpTypeService _statsByYearByJumpTypeService; private readonly IStatsByYearService _statsByYearService; private readonly IStatsForLastMonthByDzService _statsForLastMonthByDzService; private readonly IStatsForLastMonthByJumpTypeService _statsForLastMonthByJumpTypeService; private readonly IStatsForLastYearByDzService _statsForLastYearByDzService; private readonly IStatsForLastYearByJumpTypeService _statsForLastYearByJumpTypeService; #endregion Private Fields } }