From eb42aebfd139df9026d6eaa2e87bdba501fc00cc Mon Sep 17 00:00:00 2001 From: sandre Date: Thu, 22 Jan 2026 16:30:47 +0100 Subject: [PATCH] Begin with add services and interfaces --- Back/skydiveLogs-api.Domain/UserStats.cs | 42 -- .../Interfaces/IStatsByDzService.cs | 14 + .../Interfaces/IStatsByGearService.cs | 14 + .../Interfaces/IStatsByJumpTypeService.cs | 14 + .../IStatsByYearByJumpTypeService.cs | 14 + .../Interfaces/IStatsByYearService.cs | 13 + .../IStatsForLastMonthByDzService.cs | 14 + .../IStatsForLastMonthByJumpTypeService.cs | 14 + .../IStatsForLastYearByDzService.cs | 14 + .../IStatsForLastYearByJumpTypeService.cs | 14 + .../Interfaces/IStatsService.cs | 21 - .../StatsByDzService.cs | 399 ++++++++++++++++++ .../StatsByGearService.cs | 396 +++++++++++++++++ .../StatsByJumpTypeService.cs | 396 +++++++++++++++++ .../StatsByYearByJumpTypeService.cs | 396 +++++++++++++++++ .../StatsByYearService.cs | 396 +++++++++++++++++ .../StatsForLastMonthByDzService.cs | 396 +++++++++++++++++ .../StatsForLastMonthByJumpTypeService.cs | 396 +++++++++++++++++ .../StatsForLastYearByDzService.cs | 396 +++++++++++++++++ .../StatsForLastYearByJumpTypeService.cs | 396 +++++++++++++++++ .../StatsService.cs | 344 +-------------- .../Repositories/IUserStatsRepository.cs | 13 - Back/skydiveLogs-api.Ioc/IocService.cs | 12 +- 23 files changed, 3717 insertions(+), 407 deletions(-) delete mode 100644 Back/skydiveLogs-api.Domain/UserStats.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByDzService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByGearService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByJumpTypeService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearByJumpTypeService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByDzService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByJumpTypeService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByDzService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByJumpTypeService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsByDzService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsByGearService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsByJumpTypeService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsByYearByJumpTypeService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsByYearService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByDzService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByJumpTypeService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByDzService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByJumpTypeService.cs delete mode 100644 Back/skydiveLogs-api.DomainService/Repositories/IUserStatsRepository.cs diff --git a/Back/skydiveLogs-api.Domain/UserStats.cs b/Back/skydiveLogs-api.Domain/UserStats.cs deleted file mode 100644 index 0303b74..0000000 --- a/Back/skydiveLogs-api.Domain/UserStats.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Collections.Generic; - -namespace skydiveLogs_api.Domain -{ - public class UserStats - { - #region Public Constructors - - public UserStats() - { - ByAircraft = new List(); - ByDz = new List(); - ByGear = new List(); - ByJumpType = new List(); - ByYear = new List(); - ForLastMonthByDz = new List(); - ForLastMonthByJumpType = new List(); - ForLastYearByDz = new List(); - ForLastYearByJumpType = new List(); - ByYearByJumpType = new List(); - } - - #endregion Public Constructors - - #region Public Properties - - public IEnumerable ByAircraft { get; set; } - public IEnumerable ByDz { get; set; } - public IEnumerable ByGear { get; set; } - public IEnumerable ByJumpType { get; set; } - public IEnumerable ByYear { get; set; } - public IEnumerable ForLastMonthByDz { get; set; } - 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; } - - #endregion Public Properties - } -} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByDzService.cs new file mode 100644 index 0000000..20e2b9a --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByDzService.cs @@ -0,0 +1,14 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByDzService + { + #region Public Methods + + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByGearService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByGearService.cs new file mode 100644 index 0000000..69077d5 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByGearService.cs @@ -0,0 +1,14 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByGearService + { + #region Public Methods + + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByJumpTypeService.cs new file mode 100644 index 0000000..ec89782 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByJumpTypeService.cs @@ -0,0 +1,14 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByJumpTypeService + { + #region Public Methods + + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearByJumpTypeService.cs new file mode 100644 index 0000000..d14db86 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearByJumpTypeService.cs @@ -0,0 +1,14 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByYearByJumpTypeService + { + #region Public Methods + + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearService.cs new file mode 100644 index 0000000..780ff1c --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearService.cs @@ -0,0 +1,13 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByYearService + { + #region Public Methods + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByDzService.cs new file mode 100644 index 0000000..57d0a33 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByDzService.cs @@ -0,0 +1,14 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsForLastMonthByDzService + { + #region Public Methods + + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByJumpTypeService.cs new file mode 100644 index 0000000..7dc7565 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByJumpTypeService.cs @@ -0,0 +1,14 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsForLastMonthByJumpTypeService + { + #region Public Methods + + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByDzService.cs new file mode 100644 index 0000000..ad0f651 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByDzService.cs @@ -0,0 +1,14 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsForLastYearByDzService + { + #region Public Methods + + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByJumpTypeService.cs new file mode 100644 index 0000000..7ee94da --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByJumpTypeService.cs @@ -0,0 +1,14 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsForLastYearByJumpTypeService + { + #region Public Methods + + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs index a04913b..f01349e 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs @@ -1,5 +1,4 @@ using skydiveLogs_api.Domain; -using System.Collections.Generic; namespace skydiveLogs_api.DomainBusiness.Interfaces { @@ -9,26 +8,6 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces SimpleSummary GetSimpleSummary(); - IEnumerable GetStatsByAircraft(); - - IEnumerable GetStatsByDz(); - - IEnumerable GetStatsByGear(); - - IEnumerable GetStatsByJumpType(); - - IEnumerable GetStatsByYear(); - - IEnumerable GetStatsForLastMonthByDz(); - - IEnumerable GetStatsForLastMonthByJumpType(); - - IEnumerable GetStatsForLastYearByDz(); - - IEnumerable GetStatsForLastYearByJumpType(); - - IEnumerable GetStatsByYearByJumpType(); - void Reset(); #endregion Public Methods diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByDzService.cs new file mode 100644 index 0000000..0664085 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByDzService.cs @@ -0,0 +1,399 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsByDzService : IStatsByDzService + { + #region Public Constructors + + public StatsByDzService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + // var allStats = GetAllStats(); + // if (!allStats.ByAircraft.Any()) + // { + // var allJumps = _jumpService.GetAllJumps(); + // var results = new List(); + + // if (allJumps.Any()) + // { + // results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + // j => j, + // (groupby, jumps) => new Statistic + // { + // Label = groupby.ToString(), + // Nb = jumps.Count() + // })]; + // } + + // allStats.ByAircraft = results; + // _userStatsRepository.Update(allStats); + // } + + // return allStats.ByAircraft; + return null; + } + + 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 IEnumerable GetStatsByAircraft() + { + var allStats = GetAllStats(); + if (!allStats.ByAircraft.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByAircraft = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByAircraft; + } + + public IEnumerable GetStatsByDz() + { + var allStats = GetAllStats(); + if (!allStats.ByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByDz; + } + + public IEnumerable GetStatsByGear() + { + var allStats = GetAllStats(); + if (!allStats.ByGear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByGear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByGear; + } + + public IEnumerable GetStatsByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByJumpType; + } + + public IEnumerable GetStatsByYear() + { + var allStats = GetAllStats(); + if (!allStats.ByYear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByYear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYear; + } + + public IEnumerable GetStatsForLastMonthByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByDz; + } + + public IEnumerable GetStatsForLastMonthByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByJumpType; + } + + public IEnumerable GetStatsForLastYearByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastYearByDz; + } + + public IEnumerable GetStatsForLastYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + 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() + })]; + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + + 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); + } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _userStatsRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByGearService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByGearService.cs new file mode 100644 index 0000000..177fbad --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByGearService.cs @@ -0,0 +1,396 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsByGearService : IStatsByGearService + { + #region Public Constructors + + public StatsByGearService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository, + IStatsByGearRepository statsByGearRepository, + IStatsByJumpTypeRepository statsByJumpTypeRepository, + IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository, + IStatsByYearRepository statsByYearRepository, + IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository, + IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository, + IStatsForLastYearByDzRepository statsForLastYearByDzRepository, + IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + _statsByGearRepository = statsByGearRepository; + _statsByJumpTypeRepository = statsByJumpTypeRepository; + _statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository; + _statsByYearRepository = statsByYearRepository; + _statsForLastMonthByDzRepository = statsForLastMonthByDzRepository; + _statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository; + _statsForLastYearByDzRepository = statsForLastYearByDzRepository; + _statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository; + } + + #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 IEnumerable GetStatsByAircraft() + { + var allStats = GetAllStats(); + if (!allStats.ByAircraft.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByAircraft = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByAircraft; + } + + public IEnumerable GetStatsByDz() + { + var allStats = GetAllStats(); + if (!allStats.ByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByDz; + } + + public IEnumerable GetStatsByGear() + { + var allStats = GetAllStats(); + if (!allStats.ByGear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByGear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByGear; + } + + public IEnumerable GetStatsByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByJumpType; + } + + public IEnumerable GetStatsByYear() + { + var allStats = GetAllStats(); + if (!allStats.ByYear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByYear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYear; + } + + public IEnumerable GetStatsForLastMonthByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByDz; + } + + public IEnumerable GetStatsForLastMonthByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByJumpType; + } + + public IEnumerable GetStatsForLastYearByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastYearByDz; + } + + public IEnumerable GetStatsForLastYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + 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() + })]; + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + + 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); + } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _userStatsRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + private readonly IStatsByGearRepository _statsByGearRepository; + private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository; + private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository; + private readonly IStatsByYearRepository _statsByYearRepository; + private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository; + private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository; + private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository; + private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByJumpTypeService.cs new file mode 100644 index 0000000..9a46f75 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByJumpTypeService.cs @@ -0,0 +1,396 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsByJumpTypeService : IStatsByJumpTypeService + { + #region Public Constructors + + public StatsByJumpTypeService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository, + IStatsByGearRepository statsByGearRepository, + IStatsByJumpTypeRepository statsByJumpTypeRepository, + IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository, + IStatsByYearRepository statsByYearRepository, + IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository, + IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository, + IStatsForLastYearByDzRepository statsForLastYearByDzRepository, + IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + _statsByGearRepository = statsByGearRepository; + _statsByJumpTypeRepository = statsByJumpTypeRepository; + _statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository; + _statsByYearRepository = statsByYearRepository; + _statsForLastMonthByDzRepository = statsForLastMonthByDzRepository; + _statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository; + _statsForLastYearByDzRepository = statsForLastYearByDzRepository; + _statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository; + } + + #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 IEnumerable GetStatsByAircraft() + { + var allStats = GetAllStats(); + if (!allStats.ByAircraft.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByAircraft = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByAircraft; + } + + public IEnumerable GetStatsByDz() + { + var allStats = GetAllStats(); + if (!allStats.ByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByDz; + } + + public IEnumerable GetStatsByGear() + { + var allStats = GetAllStats(); + if (!allStats.ByGear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByGear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByGear; + } + + public IEnumerable GetStatsByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByJumpType; + } + + public IEnumerable GetStatsByYear() + { + var allStats = GetAllStats(); + if (!allStats.ByYear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByYear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYear; + } + + public IEnumerable GetStatsForLastMonthByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByDz; + } + + public IEnumerable GetStatsForLastMonthByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByJumpType; + } + + public IEnumerable GetStatsForLastYearByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastYearByDz; + } + + public IEnumerable GetStatsForLastYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + 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() + })]; + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + + 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); + } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _userStatsRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + private readonly IStatsByGearRepository _statsByGearRepository; + private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository; + private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository; + private readonly IStatsByYearRepository _statsByYearRepository; + private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository; + private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository; + private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository; + private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByYearByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByYearByJumpTypeService.cs new file mode 100644 index 0000000..ac10b65 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByYearByJumpTypeService.cs @@ -0,0 +1,396 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsByYearByJumpTypeService : IStatsByYearByJumpTypeService + { + #region Public Constructors + + public StatsByYearByJumpTypeService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository, + IStatsByGearRepository statsByGearRepository, + IStatsByJumpTypeRepository statsByJumpTypeRepository, + IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository, + IStatsByYearRepository statsByYearRepository, + IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository, + IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository, + IStatsForLastYearByDzRepository statsForLastYearByDzRepository, + IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + _statsByGearRepository = statsByGearRepository; + _statsByJumpTypeRepository = statsByJumpTypeRepository; + _statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository; + _statsByYearRepository = statsByYearRepository; + _statsForLastMonthByDzRepository = statsForLastMonthByDzRepository; + _statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository; + _statsForLastYearByDzRepository = statsForLastYearByDzRepository; + _statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository; + } + + #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 IEnumerable GetStatsByAircraft() + { + var allStats = GetAllStats(); + if (!allStats.ByAircraft.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByAircraft = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByAircraft; + } + + public IEnumerable GetStatsByDz() + { + var allStats = GetAllStats(); + if (!allStats.ByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByDz; + } + + public IEnumerable GetStatsByGear() + { + var allStats = GetAllStats(); + if (!allStats.ByGear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByGear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByGear; + } + + public IEnumerable GetStatsByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByJumpType; + } + + public IEnumerable GetStatsByYear() + { + var allStats = GetAllStats(); + if (!allStats.ByYear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByYear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYear; + } + + public IEnumerable GetStatsForLastMonthByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByDz; + } + + public IEnumerable GetStatsForLastMonthByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByJumpType; + } + + public IEnumerable GetStatsForLastYearByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastYearByDz; + } + + public IEnumerable GetStatsForLastYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + 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() + })]; + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + + 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); + } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _userStatsRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + private readonly IStatsByGearRepository _statsByGearRepository; + private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository; + private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository; + private readonly IStatsByYearRepository _statsByYearRepository; + private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository; + private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository; + private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository; + private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByYearService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByYearService.cs new file mode 100644 index 0000000..c6891bd --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByYearService.cs @@ -0,0 +1,396 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsByYearService : IStatsByYearService + { + #region Public Constructors + + public StatsByYearService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository, + IStatsByGearRepository statsByGearRepository, + IStatsByJumpTypeRepository statsByJumpTypeRepository, + IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository, + IStatsByYearRepository statsByYearRepository, + IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository, + IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository, + IStatsForLastYearByDzRepository statsForLastYearByDzRepository, + IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + _statsByGearRepository = statsByGearRepository; + _statsByJumpTypeRepository = statsByJumpTypeRepository; + _statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository; + _statsByYearRepository = statsByYearRepository; + _statsForLastMonthByDzRepository = statsForLastMonthByDzRepository; + _statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository; + _statsForLastYearByDzRepository = statsForLastYearByDzRepository; + _statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository; + } + + #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 IEnumerable GetStatsByAircraft() + { + var allStats = GetAllStats(); + if (!allStats.ByAircraft.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByAircraft = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByAircraft; + } + + public IEnumerable GetStatsByDz() + { + var allStats = GetAllStats(); + if (!allStats.ByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByDz; + } + + public IEnumerable GetStatsByGear() + { + var allStats = GetAllStats(); + if (!allStats.ByGear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByGear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByGear; + } + + public IEnumerable GetStatsByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByJumpType; + } + + public IEnumerable GetStatsByYear() + { + var allStats = GetAllStats(); + if (!allStats.ByYear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByYear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYear; + } + + public IEnumerable GetStatsForLastMonthByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByDz; + } + + public IEnumerable GetStatsForLastMonthByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByJumpType; + } + + public IEnumerable GetStatsForLastYearByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastYearByDz; + } + + public IEnumerable GetStatsForLastYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + 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() + })]; + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + + 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); + } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _userStatsRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + private readonly IStatsByGearRepository _statsByGearRepository; + private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository; + private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository; + private readonly IStatsByYearRepository _statsByYearRepository; + private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository; + private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository; + private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository; + private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByDzService.cs new file mode 100644 index 0000000..ad16b2f --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByDzService.cs @@ -0,0 +1,396 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsForLastMonthByDzService : IStatsForLastMonthByDzService + { + #region Public Constructors + + public StatsForLastMonthByDzService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository, + IStatsByGearRepository statsByGearRepository, + IStatsByJumpTypeRepository statsByJumpTypeRepository, + IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository, + IStatsByYearRepository statsByYearRepository, + IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository, + IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository, + IStatsForLastYearByDzRepository statsForLastYearByDzRepository, + IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + _statsByGearRepository = statsByGearRepository; + _statsByJumpTypeRepository = statsByJumpTypeRepository; + _statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository; + _statsByYearRepository = statsByYearRepository; + _statsForLastMonthByDzRepository = statsForLastMonthByDzRepository; + _statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository; + _statsForLastYearByDzRepository = statsForLastYearByDzRepository; + _statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository; + } + + #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 IEnumerable GetStatsByAircraft() + { + var allStats = GetAllStats(); + if (!allStats.ByAircraft.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByAircraft = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByAircraft; + } + + public IEnumerable GetStatsByDz() + { + var allStats = GetAllStats(); + if (!allStats.ByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByDz; + } + + public IEnumerable GetStatsByGear() + { + var allStats = GetAllStats(); + if (!allStats.ByGear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByGear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByGear; + } + + public IEnumerable GetStatsByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByJumpType; + } + + public IEnumerable GetStatsByYear() + { + var allStats = GetAllStats(); + if (!allStats.ByYear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByYear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYear; + } + + public IEnumerable GetStatsForLastMonthByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByDz; + } + + public IEnumerable GetStatsForLastMonthByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByJumpType; + } + + public IEnumerable GetStatsForLastYearByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastYearByDz; + } + + public IEnumerable GetStatsForLastYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + 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() + })]; + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + + 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); + } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _userStatsRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + private readonly IStatsByGearRepository _statsByGearRepository; + private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository; + private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository; + private readonly IStatsByYearRepository _statsByYearRepository; + private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository; + private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository; + private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository; + private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByJumpTypeService.cs new file mode 100644 index 0000000..7fd779e --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByJumpTypeService.cs @@ -0,0 +1,396 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsForLastMonthByJumpTypeService : IStatsForLastMonthByJumpTypeService + { + #region Public Constructors + + public StatsForLastMonthByJumpTypeService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository, + IStatsByGearRepository statsByGearRepository, + IStatsByJumpTypeRepository statsByJumpTypeRepository, + IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository, + IStatsByYearRepository statsByYearRepository, + IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository, + IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository, + IStatsForLastYearByDzRepository statsForLastYearByDzRepository, + IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + _statsByGearRepository = statsByGearRepository; + _statsByJumpTypeRepository = statsByJumpTypeRepository; + _statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository; + _statsByYearRepository = statsByYearRepository; + _statsForLastMonthByDzRepository = statsForLastMonthByDzRepository; + _statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository; + _statsForLastYearByDzRepository = statsForLastYearByDzRepository; + _statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository; + } + + #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 IEnumerable GetStatsByAircraft() + { + var allStats = GetAllStats(); + if (!allStats.ByAircraft.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByAircraft = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByAircraft; + } + + public IEnumerable GetStatsByDz() + { + var allStats = GetAllStats(); + if (!allStats.ByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByDz; + } + + public IEnumerable GetStatsByGear() + { + var allStats = GetAllStats(); + if (!allStats.ByGear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByGear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByGear; + } + + public IEnumerable GetStatsByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByJumpType; + } + + public IEnumerable GetStatsByYear() + { + var allStats = GetAllStats(); + if (!allStats.ByYear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByYear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYear; + } + + public IEnumerable GetStatsForLastMonthByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByDz; + } + + public IEnumerable GetStatsForLastMonthByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByJumpType; + } + + public IEnumerable GetStatsForLastYearByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastYearByDz; + } + + public IEnumerable GetStatsForLastYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + 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() + })]; + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + + 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); + } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _userStatsRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + private readonly IStatsByGearRepository _statsByGearRepository; + private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository; + private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository; + private readonly IStatsByYearRepository _statsByYearRepository; + private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository; + private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository; + private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository; + private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByDzService.cs new file mode 100644 index 0000000..4ed6259 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByDzService.cs @@ -0,0 +1,396 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsForLastYearByDzService : IStatsForLastYearByDzService + { + #region Public Constructors + + public StatsForLastYearByDzService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository, + IStatsByGearRepository statsByGearRepository, + IStatsByJumpTypeRepository statsByJumpTypeRepository, + IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository, + IStatsByYearRepository statsByYearRepository, + IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository, + IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository, + IStatsForLastYearByDzRepository statsForLastYearByDzRepository, + IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + _statsByGearRepository = statsByGearRepository; + _statsByJumpTypeRepository = statsByJumpTypeRepository; + _statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository; + _statsByYearRepository = statsByYearRepository; + _statsForLastMonthByDzRepository = statsForLastMonthByDzRepository; + _statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository; + _statsForLastYearByDzRepository = statsForLastYearByDzRepository; + _statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository; + } + + #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 IEnumerable GetStatsByAircraft() + { + var allStats = GetAllStats(); + if (!allStats.ByAircraft.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByAircraft = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByAircraft; + } + + public IEnumerable GetStatsByDz() + { + var allStats = GetAllStats(); + if (!allStats.ByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByDz; + } + + public IEnumerable GetStatsByGear() + { + var allStats = GetAllStats(); + if (!allStats.ByGear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByGear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByGear; + } + + public IEnumerable GetStatsByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByJumpType; + } + + public IEnumerable GetStatsByYear() + { + var allStats = GetAllStats(); + if (!allStats.ByYear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByYear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYear; + } + + public IEnumerable GetStatsForLastMonthByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByDz; + } + + public IEnumerable GetStatsForLastMonthByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByJumpType; + } + + public IEnumerable GetStatsForLastYearByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastYearByDz; + } + + public IEnumerable GetStatsForLastYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + 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() + })]; + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + + 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); + } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _userStatsRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + private readonly IStatsByGearRepository _statsByGearRepository; + private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository; + private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository; + private readonly IStatsByYearRepository _statsByYearRepository; + private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository; + private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository; + private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository; + private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByJumpTypeService.cs new file mode 100644 index 0000000..30143d5 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByJumpTypeService.cs @@ -0,0 +1,396 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsForLastYearByJumpTypeService : IStatsForLastYearByJumpTypeService + { + #region Public Constructors + + public StatsForLastYearByJumpTypeService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository, + IStatsByGearRepository statsByGearRepository, + IStatsByJumpTypeRepository statsByJumpTypeRepository, + IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository, + IStatsByYearRepository statsByYearRepository, + IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository, + IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository, + IStatsForLastYearByDzRepository statsForLastYearByDzRepository, + IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + _statsByGearRepository = statsByGearRepository; + _statsByJumpTypeRepository = statsByJumpTypeRepository; + _statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository; + _statsByYearRepository = statsByYearRepository; + _statsForLastMonthByDzRepository = statsForLastMonthByDzRepository; + _statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository; + _statsForLastYearByDzRepository = statsForLastYearByDzRepository; + _statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository; + } + + #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 IEnumerable GetStatsByAircraft() + { + var allStats = GetAllStats(); + if (!allStats.ByAircraft.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByAircraft = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByAircraft; + } + + public IEnumerable GetStatsByDz() + { + var allStats = GetAllStats(); + if (!allStats.ByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByDz; + } + + public IEnumerable GetStatsByGear() + { + var allStats = GetAllStats(); + if (!allStats.ByGear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByGear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByGear; + } + + public IEnumerable GetStatsByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByJumpType; + } + + public IEnumerable GetStatsByYear() + { + var allStats = GetAllStats(); + if (!allStats.ByYear.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ByYear = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYear; + } + + public IEnumerable GetStatsForLastMonthByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByDz; + } + + public IEnumerable GetStatsForLastMonthByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastMonthByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastMonthByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastMonthByJumpType; + } + + public IEnumerable GetStatsForLastYearByDz() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByDz.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByDz = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ForLastYearByDz; + } + + public IEnumerable GetStatsForLastYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ForLastYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + })]; + } + + allStats.ForLastYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + 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() + })]; + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + + 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); + } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _userStatsRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + private readonly IStatsByGearRepository _statsByGearRepository; + private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository; + private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository; + private readonly IStatsByYearRepository _statsByYearRepository; + private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository; + private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository; + private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository; + private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs index 6f0982b..d32e7c9 100644 --- a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs @@ -1,7 +1,5 @@ using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; -using skydiveLogs_api.DomainService.Repositories; -using System.Collections.Generic; using System.Linq; namespace skydiveLogs_api.DomainBusiness @@ -10,13 +8,9 @@ namespace skydiveLogs_api.DomainBusiness { #region Public Constructors - public StatsService(IJumpService jumpService, - IUserStatsRepository userStatsRepository, - IIdentityService identityService) + public StatsService(IJumpService jumpService) { _jumpService = jumpService; - _identityService = identityService; - _userStatsRepository = userStatsRepository; } #endregion Public Constructors @@ -43,339 +37,29 @@ namespace skydiveLogs_api.DomainBusiness return results; } - public IEnumerable GetStatsByAircraft() - { - var allStats = GetAllStats(); - if (!allStats.ByAircraft.Any()) - { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => j.Aircraft.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByAircraft = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByAircraft; - } - - public IEnumerable GetStatsByDz() - { - var allStats = GetAllStats(); - if (!allStats.ByDz.Any()) - { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => j.DropZone.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByDz = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByDz; - } - - public IEnumerable GetStatsByGear() - { - var allStats = GetAllStats(); - if (!allStats.ByGear.Any()) - { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByGear = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByGear; - } - - public IEnumerable GetStatsByJumpType() - { - var allStats = GetAllStats(); - if (!allStats.ByJumpType.Any()) - { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => j.JumpType.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByJumpType = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByJumpType; - } - - public IEnumerable GetStatsByYear() - { - var allStats = GetAllStats(); - if (!allStats.ByYear.Any()) - { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => j.JumpDate.Year, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByYear = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByYear; - } - - public IEnumerable GetStatsForLastMonthByDz() - { - var allStats = GetAllStats(); - if (!allStats.ForLastMonthByDz.Any()) - { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); - var yearOfLastJump = lastJump.JumpDate.Year; - var monthOfLastJump = lastJump.JumpDate.Month; - - results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) - .GroupBy(j => j.DropZone.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ForLastMonthByDz = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ForLastMonthByDz; - } - - public IEnumerable GetStatsForLastMonthByJumpType() - { - var allStats = GetAllStats(); - if (!allStats.ForLastMonthByJumpType.Any()) - { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); - var yearOfLastJump = lastJump.JumpDate.Year; - var monthOfLastJump = lastJump.JumpDate.Month; - - results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) - .GroupBy(j => j.JumpType.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ForLastMonthByJumpType = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ForLastMonthByJumpType; - } - - public IEnumerable GetStatsForLastYearByDz() - { - var allStats = GetAllStats(); - if (!allStats.ForLastYearByDz.Any()) - { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); - var yearOfLastJump = lastJump.JumpDate.Year; - - results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) - .GroupBy(j => j.DropZone.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ForLastYearByDz = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ForLastYearByDz; - } - - public IEnumerable GetStatsForLastYearByJumpType() - { - var allStats = GetAllStats(); - if (!allStats.ForLastYearByJumpType.Any()) - { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); - var yearOfLastJump = lastJump.JumpDate.Year; - - results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) - .GroupBy(j => j.JumpType.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ForLastYearByJumpType = results; - _userStatsRepository.Update(allStats); - } - - 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(); - 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; + // 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); + // _userStatsRepository.Update(myStats); } #endregion Public Methods - #region Private Methods - - private UserStats GetAllStats() - { - var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); - if (allStats == null) - { - allStats = new UserStats - { - User = _identityService.ConnectedUser - }; - _userStatsRepository.Add(allStats); - } - - return allStats; - } - - #endregion Private Methods - #region Private Fields - private readonly IIdentityService _identityService; private readonly IJumpService _jumpService; - private readonly IUserStatsRepository _userStatsRepository; #endregion Private Fields } diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IUserStatsRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IUserStatsRepository.cs deleted file mode 100644 index ef462a7..0000000 --- a/Back/skydiveLogs-api.DomainService/Repositories/IUserStatsRepository.cs +++ /dev/null @@ -1,13 +0,0 @@ -using skydiveLogs_api.Domain; - -namespace skydiveLogs_api.DomainService.Repositories -{ - public interface IUserStatsRepository : IRepository - { - #region Public Methods - - UserStats GetAll(User user); - - #endregion Public Methods - } -} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Ioc/IocService.cs b/Back/skydiveLogs-api.Ioc/IocService.cs index 82c4435..e6d83a6 100644 --- a/Back/skydiveLogs-api.Ioc/IocService.cs +++ b/Back/skydiveLogs-api.Ioc/IocService.cs @@ -32,13 +32,23 @@ namespace skydiveLogs_api.Ioc _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); - _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddSingleton(); _services.AddScoped();