From 9ad39da4c7a43bd5fd755e58df7c178c5d2d2aeb Mon Sep 17 00:00:00 2001 From: sandre Date: Thu, 8 Jan 2026 11:49:45 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20stats=20pour=20avoir=20le=20nb=20d?= =?UTF-8?q?e=20sauts=20par=20type=20et=20par=20ann=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Back/skydiveLogs-api.Domain/UserStats.cs | 2 ++ .../Interfaces/IStatsService.cs | 3 ++ .../StatsService.cs | 28 +++++++++++++++++++ .../Controllers/StatsController.cs | 9 ++++++ 4 files changed, 42 insertions(+) diff --git a/Back/skydiveLogs-api.Domain/UserStats.cs b/Back/skydiveLogs-api.Domain/UserStats.cs index 19c158f..0303b74 100644 --- a/Back/skydiveLogs-api.Domain/UserStats.cs +++ b/Back/skydiveLogs-api.Domain/UserStats.cs @@ -17,6 +17,7 @@ namespace skydiveLogs_api.Domain ForLastMonthByJumpType = new List(); ForLastYearByDz = new List(); ForLastYearByJumpType = new List(); + ByYearByJumpType = new List(); } #endregion Public Constructors @@ -32,6 +33,7 @@ namespace skydiveLogs_api.Domain public IEnumerable ForLastMonthByJumpType { get; set; } public IEnumerable ForLastYearByDz { get; set; } public IEnumerable ForLastYearByJumpType { get; set; } + public IEnumerable ByYearByJumpType { get; set; } public int Id { get; set; } public User User { get; set; } diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs index 343a97e..a04913b 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs @@ -26,6 +26,9 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces IEnumerable GetStatsForLastYearByDz(); IEnumerable GetStatsForLastYearByJumpType(); + + IEnumerable GetStatsByYearByJumpType(); + void Reset(); #endregion Public Methods diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs index a2684ef..378f69a 100644 --- a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs @@ -304,6 +304,34 @@ namespace skydiveLogs_api.DomainBusiness return allStats.ForLastYearByJumpType; } + public IEnumerable GetStatsByYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year }, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.Year.ToString(), + Label2 = groupby.Name.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + public void Reset() { var resetStats = new UserStats(); diff --git a/Back/skydiveLogs-api/Controllers/StatsController.cs b/Back/skydiveLogs-api/Controllers/StatsController.cs index eb5235e..f934d16 100644 --- a/Back/skydiveLogs-api/Controllers/StatsController.cs +++ b/Back/skydiveLogs-api/Controllers/StatsController.cs @@ -95,6 +95,15 @@ namespace skydiveLogs_api.Controllers return result; } + [HttpGet("ByYearByJumpType")] + [EnableCors] + public IEnumerable ByYearByJumpType() + { + var result = _statsService.GetStatsByYearByJumpType(); + + return _mapper.Map>(result); + } + [HttpGet("Reset")] [EnableCors] public void Reset()