Split tables for the stats (#6)

Reviewed-on: #6
Co-authored-by: sandre <perso@sebastienandre.com>
Co-committed-by: sandre <perso@sebastienandre.com>
This commit was merged in pull request #6.
This commit is contained in:
2026-01-26 13:38:07 +00:00
committed by sandre
parent 677e74df10
commit b25e947d62
59 changed files with 1956 additions and 373 deletions

View File

@@ -0,0 +1,16 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsByAircraftService
{
#region Public Methods
IEnumerable<StatsByAircraft> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,16 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsByDzService
{
#region Public Methods
IEnumerable<StatsByDz> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,16 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsByGearService
{
#region Public Methods
IEnumerable<StatsByGear> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,16 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsByJumpTypeService
{
#region Public Methods
IEnumerable<StatsByJumpType> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,16 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsByYearByJumpTypeService
{
#region Public Methods
IEnumerable<StatsByYearByJumpType> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,15 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsByYearService
{
#region Public Methods
IEnumerable<StatsByYear> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,16 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsForLastMonthByDzService
{
#region Public Methods
IEnumerable<StatsForLastMonthByDz> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,16 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsForLastMonthByJumpTypeService
{
#region Public Methods
IEnumerable<StatsForLastMonthByJumpType> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,16 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsForLastYearByDzService
{
#region Public Methods
IEnumerable<StatsForLastYearByDz> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,16 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsForLastYearByJumpTypeService
{
#region Public Methods
IEnumerable<StatsForLastYearByJumpType> GetStats();
void Reset();
#endregion Public Methods
}
}

View File

@@ -0,0 +1,68 @@
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 StatsByAircraftService : IStatsByAircraftService
{
#region Public Constructors
public StatsByAircraftService(IJumpService jumpService,
IIdentityService identityService,
IStatsByAircraftRepository statsByAircraftRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsByAircraftRepository = statsByAircraftRepository;
}
#endregion Public Constructors
#region Public Methods
public IEnumerable<StatsByAircraft> GetStats()
{
var allStats = _statsByAircraftRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsByAircraft>();
if (allJumps.Any())
{
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
j => j,
(groupby, jumps) => new StatsByAircraft
{
Aircraft = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsByAircraftRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsByAircraftRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsByAircraftRepository _statsByAircraftRepository;
#endregion Private Fields
}
}

View File

@@ -0,0 +1,68 @@
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<StatsByDz> GetStats()
{
var allStats = _statsByDzRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsByDz>();
if (allJumps.Any())
{
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
j => j,
(groupby, jumps) => new StatsByDz
{
DropZone = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsByDzRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsByDzRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsByDzRepository _statsByDzRepository;
#endregion Private Fields
}
}

View File

@@ -0,0 +1,68 @@
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,
IStatsByGearRepository statsByGearRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsByGearRepository = statsByGearRepository;
}
#endregion Public Constructors
#region Public Methods
public IEnumerable<StatsByGear> GetStats()
{
var allStats = _statsByGearRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsByGear>();
if (allJumps.Any())
{
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
j => j,
(groupby, jumps) => new StatsByGear
{
Gear = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsByGearRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsByGearRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsByGearRepository _statsByGearRepository;
#endregion Private Fields
}
}

View File

@@ -0,0 +1,68 @@
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,
IStatsByJumpTypeRepository statsByJumpTypeRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsByJumpTypeRepository = statsByJumpTypeRepository;
}
#endregion Public Constructors
#region Public Methods
public IEnumerable<StatsByJumpType> GetStats()
{
var allStats = _statsByJumpTypeRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsByJumpType>();
if (allJumps.Any())
{
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
j => j,
(groupby, jumps) => new StatsByJumpType
{
JumpType = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsByJumpTypeRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsByJumpTypeRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository;
#endregion Private Fields
}
}

View File

@@ -0,0 +1,69 @@
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,
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository;
}
#endregion Public Constructors
#region Public Methods
public IEnumerable<StatsByYearByJumpType> GetStats()
{
var allStats = _statsByYearByJumpTypeRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsByYearByJumpType>();
if (allJumps.Any())
{
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
j => j,
(groupby, jumps) => new StatsByYearByJumpType
{
Year = groupby.Year.ToString(),
JumpType = groupby.Name.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsByYearByJumpTypeRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsByYearByJumpTypeRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository;
#endregion Private Fields
}
}

View File

@@ -0,0 +1,68 @@
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,
IStatsByYearRepository statsByYearRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsByYearRepository = statsByYearRepository;
}
#endregion Public Constructors
#region Public Methods
public IEnumerable<StatsByYear> GetStats()
{
var allStats = _statsByYearRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsByYear>();
if (allJumps.Any())
{
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
j => j,
(groupby, jumps) => new StatsByYear
{
Year = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsByYearRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsByYearRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsByYearRepository _statsByYearRepository;
#endregion Private Fields
}
}

View File

@@ -0,0 +1,73 @@
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,
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
}
#endregion Public Constructors
#region Public Methods
public IEnumerable<StatsForLastMonthByDz> GetStats()
{
var allStats = _statsForLastMonthByDzRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsForLastMonthByDz>();
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 StatsForLastMonthByDz
{
DropZone = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsForLastMonthByDzRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsForLastMonthByDzRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
#endregion Private Fields
}
}

View File

@@ -0,0 +1,73 @@
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,
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository;
}
#endregion Public Constructors
#region Public Methods
public IEnumerable<StatsForLastMonthByJumpType> GetStats()
{
var allStats = _statsForLastMonthByJumpTypeRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsForLastMonthByJumpType>();
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 StatsForLastMonthByJumpType
{
JumpType = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsForLastMonthByJumpTypeRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsForLastMonthByJumpTypeRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository;
#endregion Private Fields
}
}

View File

@@ -0,0 +1,72 @@
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,
IStatsForLastYearByDzRepository statsForLastYearByDzRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
}
#endregion Public Constructors
#region Public Methods
public IEnumerable<StatsForLastYearByDz> GetStats()
{
var allStats = _statsForLastYearByDzRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsForLastYearByDz>();
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 StatsForLastYearByDz
{
DropZone = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsForLastYearByDzRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsForLastYearByDzRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
#endregion Private Fields
}
}

View File

@@ -0,0 +1,74 @@
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,
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository;
}
#endregion Public Constructors
#region Public Methods
public IEnumerable<StatsForLastYearByJumpType> GetStats()
{
var allStats = _statsForLastYearByJumpTypeRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsForLastYearByJumpType>();
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 StatsForLastYearByJumpType
{
JumpType = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsForLastYearByJumpTypeRepository.Add(results);
return results;
}
return allStats;
}
public void Reset()
{
_statsForLastYearByJumpTypeRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository;
#endregion Private Fields
}
}

View File

@@ -1,6 +1,5 @@
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
using skydiveLogs_api.DomainService.Repositories;
using System.Collections.Generic;
using System.Linq;
@@ -11,12 +10,28 @@ namespace skydiveLogs_api.DomainBusiness
#region Public Constructors
public StatsService(IJumpService jumpService,
IUserStatsRepository userStatsRepository,
IIdentityService identityService)
IStatsByAircraftService statsByAircraftService,
IStatsByDzService statsByDzService,
IStatsByGearService statsByGearService,
IStatsByJumpTypeService statsByJumpTypeService,
IStatsByYearByJumpTypeService statsByYearByJumpTypeService,
IStatsByYearService statsByYearService,
IStatsForLastMonthByDzService statsForLastMonthByDzService,
IStatsForLastMonthByJumpTypeService statsForLastMonthByJumpTypeService,
IStatsForLastYearByDzService statsForLastYearByDzService,
IStatsForLastYearByJumpTypeService statsForLastYearByJumpTypeService)
{
_jumpService = jumpService;
_identityService = identityService;
_userStatsRepository = userStatsRepository;
_statsByAircraftService = statsByAircraftService;
_statsByDzService = statsByDzService;
_statsByGearService = statsByGearService;
_statsByJumpTypeService = statsByJumpTypeService;
_statsByYearByJumpTypeService = statsByYearByJumpTypeService;
_statsByYearService = statsByYearService;
_statsForLastMonthByDzService = statsForLastMonthByDzService;
_statsForLastMonthByJumpTypeService = statsForLastMonthByJumpTypeService;
_statsForLastYearByDzService = statsForLastYearByDzService;
_statsForLastYearByJumpTypeService = statsForLastYearByJumpTypeService;
}
#endregion Public Constructors
@@ -43,339 +58,136 @@ namespace skydiveLogs_api.DomainBusiness
return results;
}
public void Reset()
{
_statsByAircraftService.Reset();
_statsByDzService.Reset();
_statsByGearService.Reset();
_statsByJumpTypeService.Reset();
_statsByYearByJumpTypeService.Reset();
_statsByYearService.Reset();
_statsForLastMonthByDzService.Reset();
_statsForLastMonthByJumpTypeService.Reset();
_statsForLastYearByDzService.Reset();
_statsForLastYearByJumpTypeService.Reset();
}
public IEnumerable<Statistic> GetStatsByAircraft()
{
var allStats = GetAllStats();
if (!allStats.ByAircraft.Any())
var tmp = _statsByAircraftService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
Label = a.Aircraft,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByDz()
{
var allStats = GetAllStats();
if (!allStats.ByDz.Any())
var tmp = _statsByDzService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
Label = a.DropZone,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByGear()
{
var allStats = GetAllStats();
if (!allStats.ByGear.Any())
var tmp = _statsByGearService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
Label = a.Gear,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByJumpType()
{
var allStats = GetAllStats();
if (!allStats.ByJumpType.Any())
var tmp = _statsByJumpTypeService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
Label = a.JumpType,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByYear()
{
var allStats = GetAllStats();
if (!allStats.ByYear.Any())
var tmp = _statsByYearService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
Label = a.Year,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
{
var allStats = GetAllStats();
if (!allStats.ForLastMonthByDz.Any())
var tmp = _statsForLastMonthByDzService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
Label = a.DropZone,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
{
var allStats = GetAllStats();
if (!allStats.ForLastMonthByJumpType.Any())
var tmp = _statsForLastMonthByJumpTypeService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
Label = a.JumpType,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsForLastYearByDz()
{
var allStats = GetAllStats();
if (!allStats.ForLastYearByDz.Any())
var tmp = _statsForLastYearByDzService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
Label = a.DropZone,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
{
var allStats = GetAllStats();
if (!allStats.ForLastYearByJumpType.Any())
var tmp = _statsForLastYearByJumpTypeService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
Label = a.JumpType,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByYearByJumpType()
{
var allStats = GetAllStats();
if (!allStats.ByYearByJumpType.Any())
var tmp = _statsByYearByJumpTypeService.GetStats();
return [.. tmp.Select(a => new Statistic
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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;
_userStatsRepository.Update(myStats);
Label = a.Year,
Label2 = a.JumpType,
Nb = a.Nb
})];
}
#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;
private readonly IStatsByAircraftService _statsByAircraftService;
private readonly IStatsByDzService _statsByDzService;
private readonly IStatsByGearService _statsByGearService;
private readonly IStatsByJumpTypeService _statsByJumpTypeService;
private readonly IStatsByYearByJumpTypeService _statsByYearByJumpTypeService;
private readonly IStatsByYearService _statsByYearService;
private readonly IStatsForLastMonthByDzService _statsForLastMonthByDzService;
private readonly IStatsForLastMonthByJumpTypeService _statsForLastMonthByJumpTypeService;
private readonly IStatsForLastYearByDzService _statsForLastYearByDzService;
private readonly IStatsForLastYearByJumpTypeService _statsForLastYearByJumpTypeService;
#endregion Private Fields
}