From 6499e03c560de6b0f3552ea5b7d8cbf3f0a009ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Fri, 25 Oct 2019 15:05:57 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20l'impl=C3=A9mentation=20des=20stat?= =?UTF-8?q?s=20par=20dz,=20avion,=20pi=C3=A8ge=20et=20ann=C3=A8e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DropZoneService.cs | 3 +- .../Interface/IStatsService.cs | 18 ++++ Back/skydiveLogs-api.Business/StatsService.cs | 90 +++++++++++++++++++ .../Interface/IJumpRepository.cs | 1 + Back/skydiveLogs-api.Ioc/IocService.cs | 1 + Back/skydiveLogs-api.Model/Jump.cs | 4 +- Back/skydiveLogs-api.Model/Statistic.cs | 13 +++ .../Controllers/StatsController.cs | 39 ++++---- Back/skydiveLogs-api/DataContract/JumpResp.cs | 5 +- .../DataContract/StatisticResp.cs | 9 ++ Back/skydiveLogs-api/Mapper/ModelProfile.cs | 1 + 11 files changed, 159 insertions(+), 25 deletions(-) create mode 100644 Back/skydiveLogs-api.Business/Interface/IStatsService.cs create mode 100644 Back/skydiveLogs-api.Business/StatsService.cs create mode 100644 Back/skydiveLogs-api.Model/Statistic.cs create mode 100644 Back/skydiveLogs-api/DataContract/StatisticResp.cs diff --git a/Back/skydiveLogs-api.Business/DropZoneService.cs b/Back/skydiveLogs-api.Business/DropZoneService.cs index 79a5fdf..3a129c4 100644 --- a/Back/skydiveLogs-api.Business/DropZoneService.cs +++ b/Back/skydiveLogs-api.Business/DropZoneService.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; -using System.Text; + using skydiveLogs_api.Business.Interface; using skydiveLogs_api.Data.Interface; using skydiveLogs_api.Model; + namespace skydiveLogs_api.Business { public class DropZoneService : IDropZoneService diff --git a/Back/skydiveLogs-api.Business/Interface/IStatsService.cs b/Back/skydiveLogs-api.Business/Interface/IStatsService.cs new file mode 100644 index 0000000..bb1b99c --- /dev/null +++ b/Back/skydiveLogs-api.Business/Interface/IStatsService.cs @@ -0,0 +1,18 @@ +using skydiveLogs_api.Model; +using System.Collections.Generic; + +namespace skydiveLogs_api.Business.Interface +{ + public interface IStatsService + { + IEnumerable GetStatsByDz(); + + IEnumerable GetStatsByAircraft(); + + IEnumerable GetStatsByJumpType(); + + IEnumerable GetStatsByRig(); + + IEnumerable GetStatsByYear(); + } +} diff --git a/Back/skydiveLogs-api.Business/StatsService.cs b/Back/skydiveLogs-api.Business/StatsService.cs new file mode 100644 index 0000000..d16ac02 --- /dev/null +++ b/Back/skydiveLogs-api.Business/StatsService.cs @@ -0,0 +1,90 @@ +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.GetAllJumps(); + + return allJumps.GroupBy(j => j.AircraftId, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + public IEnumerable GetStatsByDz() + { + var allJumps = _jumpRepository.GetAllJumps(); + + return allJumps.GroupBy(j => j.DropZoneId, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + public IEnumerable GetStatsByJumpType() + { + var allJumps = _jumpRepository.GetAllJumps(); + + return allJumps.GroupBy(j => j.JumpTypeId, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + public IEnumerable GetStatsByRig() + { + var allJumps = _jumpRepository.GetAllJumps(); + + return allJumps.GroupBy(j => j.GearId, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + public IEnumerable GetStatsByYear() + { + var allJumps = _jumpRepository.GetAllJumps(); + + return allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + private readonly IJumpRepository _jumpRepository; + } +} diff --git a/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs b/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs index bb1bfbd..452b4da 100644 --- a/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs +++ b/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs @@ -8,6 +8,7 @@ namespace skydiveLogs_api.Data.Interface public interface IJumpRepository { IEnumerable GetAllJumps(); + Jump GetJumpById(int id); } } diff --git a/Back/skydiveLogs-api.Ioc/IocService.cs b/Back/skydiveLogs-api.Ioc/IocService.cs index 0af8e1b..d2a70a0 100644 --- a/Back/skydiveLogs-api.Ioc/IocService.cs +++ b/Back/skydiveLogs-api.Ioc/IocService.cs @@ -20,6 +20,7 @@ namespace skydiveLogs_api.Ioc _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); + _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); diff --git a/Back/skydiveLogs-api.Model/Jump.cs b/Back/skydiveLogs-api.Model/Jump.cs index 4ba199b..7873174 100644 --- a/Back/skydiveLogs-api.Model/Jump.cs +++ b/Back/skydiveLogs-api.Model/Jump.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace skydiveLogs_api.Model { @@ -23,5 +21,7 @@ namespace skydiveLogs_api.Model public bool WithCutaway { get; set; } public string Notes { get; set; } + + public DateTime JumpDate { get; set; } } } diff --git a/Back/skydiveLogs-api.Model/Statistic.cs b/Back/skydiveLogs-api.Model/Statistic.cs new file mode 100644 index 0000000..197b4aa --- /dev/null +++ b/Back/skydiveLogs-api.Model/Statistic.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace skydiveLogs_api.Model +{ + public class Statistic + { + public string Label { get; set; } + + public int Nb { get; set; } + } +} diff --git a/Back/skydiveLogs-api/Controllers/StatsController.cs b/Back/skydiveLogs-api/Controllers/StatsController.cs index 5e97d96..5e6cc3a 100644 --- a/Back/skydiveLogs-api/Controllers/StatsController.cs +++ b/Back/skydiveLogs-api/Controllers/StatsController.cs @@ -6,7 +6,6 @@ using AutoMapper; using skydiveLogs_api.Business.Interface; using skydiveLogs_api.DataContract; -using skydiveLogs_api.Model; namespace skydiveLogs_api.Controllers @@ -15,60 +14,62 @@ namespace skydiveLogs_api.Controllers [ApiController] public class StatsController : ControllerBase { - public StatsController(IDropZoneService dropZoneService, + public StatsController(IStatsService statsService, IMapper mapper) { - _dropZoneService = dropZoneService; + _statsService = statsService; _mapper = mapper; } [HttpGet("ByDz")] [EnableCors] - public IEnumerable ByDz() + public IEnumerable ByDz() { - var result = _dropZoneService.GetAllDzs(); + var result = _statsService.GetStatsByDz(); - return _mapper.Map>(result); + return _mapper.Map>(result); } [HttpGet("ByAircraft")] [EnableCors] - public IEnumerable ByAircraft() + public IEnumerable ByAircraft() { - var result = _dropZoneService.GetAllDzs(); + var result = _statsService.GetStatsByAircraft(); - return _mapper.Map>(result); + return _mapper.Map>(result); } [HttpGet("ByJumpType")] [EnableCors] - public IEnumerable ByJumpType() + public IEnumerable ByJumpType() { - var result = _dropZoneService.GetAllDzs(); + var result = _statsService.GetStatsByJumpType(); - return _mapper.Map>(result); + return _mapper.Map>(result); } [HttpGet("ByRig")] [EnableCors] - public IEnumerable ByRig() + public IEnumerable ByRig() { - var result = _dropZoneService.GetAllDzs(); + var result = _statsService.GetStatsByRig(); - return _mapper.Map>(result); + return _mapper.Map>(result); } [HttpGet("ByYear")] [EnableCors] - public IEnumerable ByYear() + public IEnumerable ByYear() { - var result = _dropZoneService.GetAllDzs(); + var result = _statsService.GetStatsByYear(); - return _mapper.Map>(result); + return _mapper.Map>(result); } + #region Private properties + private readonly IStatsService _statsService; - private readonly IDropZoneService _dropZoneService; private readonly IMapper _mapper; + #endregion } } diff --git a/Back/skydiveLogs-api/DataContract/JumpResp.cs b/Back/skydiveLogs-api/DataContract/JumpResp.cs index f812dfc..95dea6e 100644 --- a/Back/skydiveLogs-api/DataContract/JumpResp.cs +++ b/Back/skydiveLogs-api/DataContract/JumpResp.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace skydiveLogs_api.DataContract { @@ -24,5 +21,7 @@ namespace skydiveLogs_api.DataContract public bool WithCutaway { get; set; } public string Notes { get; set; } + + public DateTime JumpDate { get; set; } } } diff --git a/Back/skydiveLogs-api/DataContract/StatisticResp.cs b/Back/skydiveLogs-api/DataContract/StatisticResp.cs new file mode 100644 index 0000000..e8b84ca --- /dev/null +++ b/Back/skydiveLogs-api/DataContract/StatisticResp.cs @@ -0,0 +1,9 @@ +namespace skydiveLogs_api.DataContract +{ + public class StatisticResp + { + public string Label { get; set; } + + public int Nb { get; set; } + } +} diff --git a/Back/skydiveLogs-api/Mapper/ModelProfile.cs b/Back/skydiveLogs-api/Mapper/ModelProfile.cs index 2e4431a..30f1545 100644 --- a/Back/skydiveLogs-api/Mapper/ModelProfile.cs +++ b/Back/skydiveLogs-api/Mapper/ModelProfile.cs @@ -18,6 +18,7 @@ namespace skydiveLogs_api.Mapper CreateMap(); CreateMap(); CreateMap(); + CreateMap(); } } }